fixed #107 and added persistent configuration

This commit is contained in:
itsmattkc
2018-07-23 13:18:09 +01:00
parent b267ac6d6d
commit 9cdb309528
13 changed files with 192 additions and 79 deletions
+8
View File
@@ -1,6 +1,8 @@
#include "preferencesdialog.h"
#include "ui_preferencesdialog.h"
#include "io/config.h"
#include <QMenuBar>
#include <QAction>
#include <QDebug>
@@ -20,6 +22,8 @@ PreferencesDialog::PreferencesDialog(QWidget *parent) :
ui(new Ui::PreferencesDialog)
{
ui->setupUi(this);
ui->imgSeqFormatEdit->setText(config.img_seq_formats);
}
PreferencesDialog::~PreferencesDialog() {
@@ -69,3 +73,7 @@ void PreferencesDialog::setup_kbd_shortcuts(QMenuBar* menubar) {
}
}
}
void PreferencesDialog::on_buttonBox_accepted() {
config.img_seq_formats = ui->imgSeqFormatEdit->text();
}
+3
View File
@@ -19,6 +19,9 @@ public:
void setup_kbd_shortcuts(QMenuBar* menu);
private slots:
void on_buttonBox_accepted();
private:
Ui::PreferencesDialog *ui;
};
+13 -1
View File
@@ -17,12 +17,24 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>2</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Image sequence formats:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="imgSeqFormatEdit"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
+85 -15
View File
@@ -1,21 +1,66 @@
#include "config.h"
#ifdef _WIN32
#include <direct.h>
#include <windows.h>
#endif
#include <QFile>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QDebug>
float scale = 1.0f;
bool vsync = true;
bool hwaccel = false;
int padding = 8;
bool custom_scale = false;
bool saved_layout = false;
bool left_mouse_dominant = true;
bool show_track_lines = false;
bool scroll_zooms = false;
Config config;
void load_config() {
Config::Config()
: saved_layout(false),
show_track_lines(false),
scroll_zooms(false),
img_seq_formats("jpg|jpeg|bmp|tiff|tif|psd|png|tga|jp2|gif"),
edit_tool_selects_links(false),
edit_tool_also_seeks(false),
select_also_seeks(false),
paste_seeks(true)
{
}
void Config::load(QString path) {
QFile f(path);
if (f.exists() && f.open(QIODevice::ReadOnly)) {
QXmlStreamReader stream(&f);
while (!stream.atEnd()) {
stream.readNext();
if (stream.isStartElement()) {
if (stream.name() == "SavedLayout") {
stream.readNext();
saved_layout = (stream.text() == "1");
} else if (stream.name() == "ShowTrackLines") {
stream.readNext();
show_track_lines = (stream.text() == "1");
} else if (stream.name() == "ScrollZooms") {
stream.readNext();
scroll_zooms = (stream.text() == "1");
} else if (stream.name() == "EditToolSelectsLinks") {
stream.readNext();
edit_tool_selects_links = (stream.text() == "1");
} else if (stream.name() == "EditToolAlsoSeeks") {
stream.readNext();
edit_tool_also_seeks = (stream.text() == "1");
} else if (stream.name() == "SelectAlsoSeeks") {
stream.readNext();
select_also_seeks = (stream.text() == "1");
} else if (stream.name() == "PasteSeeks") {
stream.readNext();
paste_seeks = (stream.text() == "1");
} else if (stream.name() == "ImageSequenceFormats") {
stream.readNext();
img_seq_formats = stream.text().toString();
}
}
}
if (stream.hasError()) {
qDebug() << "[ERROR] Error parsing config XML." << stream.errorString();
}
f.close();
}
/*if (!custom_scale) {
#ifdef _WIN32
// Get Windows UI scale - TODO may not be compatible with XP
@@ -40,10 +85,35 @@ void load_config() {
}*/
}
void save_config() {
void Config::save(QString path) {
QFile f(path);
if (!f.open(QIODevice::WriteOnly)) {
qDebug() << "[ERROR] Could not save configuration";
return;
}
QXmlStreamWriter stream(&f);
stream.setAutoFormatting(true);
stream.writeStartDocument(); // doc
stream.writeStartElement("Configuration"); // configuration
stream.writeTextElement("Version", SAVE_VERSION);
stream.writeTextElement("SavedLayout", QString::number(saved_layout));
stream.writeTextElement("ShowTrackLines", QString::number(show_track_lines));
stream.writeTextElement("ScrollZooms", QString::number(scroll_zooms));
stream.writeTextElement("EditToolSelectsLinks", QString::number(edit_tool_selects_links));
stream.writeTextElement("EditToolAlsoSeeks", QString::number(edit_tool_also_seeks));
stream.writeTextElement("SelectAlsoSeeks", QString::number(select_also_seeks));
stream.writeTextElement("PasteSeeks", QString::number(paste_seeks));
stream.writeTextElement("ImageSequenceFormats", img_seq_formats);
stream.writeEndElement();
stream.writeEndDocument(); // doc
f.close();
/*#ifdef _WIN32
_mkdir("conf");
#else
mkdir("conf", 0777);
#endif*/
}
+18 -11
View File
@@ -1,18 +1,25 @@
#ifndef CONFIG_H
#define CONFIG_H
extern const char* version;
extern float scale;
extern bool vsync;
extern bool hwaccel;
//extern int padding;
extern bool custom_scale;
extern bool saved_layout;
extern bool show_track_lines;
#include <QString>
extern bool scroll_zooms;
#define SAVE_VERSION "180722"
void load_config();
void save_config();
struct Config {
Config();
bool saved_layout;
bool show_track_lines;
bool scroll_zooms;
bool edit_tool_selects_links;
bool edit_tool_also_seeks;
bool select_also_seeks;
bool paste_seeks;
QString img_seq_formats;
void load(QString path);
void save(QString path);
};
extern Config config;
#endif // CONFIG_H
+24 -16
View File
@@ -32,6 +32,7 @@
#define OLIVE_FILE_FILTER "Olive Project (*.ove)"
QTimer autorecovery_timer;
QString config_dir;
void MainWindow::setup_layout() {
panel_project->show();
@@ -128,6 +129,9 @@ MainWindow::MainWindow(QWidget *parent) :
}
f.close();
}
config_dir = data_dir + "/config.xml";
config.load(config_dir);
}
}
}
@@ -139,6 +143,9 @@ MainWindow::~MainWindow() {
QFile::remove(autorecovery_filename);
}
}
if (!config_dir.isEmpty()) {
config.save(config_dir);
}
delete ui;
@@ -203,12 +210,6 @@ void MainWindow::on_actionZoom_out_triggered()
}
}
void MainWindow::on_actionTimeline_Track_Lines_toggled(bool e)
{
show_track_lines = e;
panel_timeline->redraw_all_clips(false);
}
void MainWindow::on_actionExport_triggered()
{
if (sequence == NULL) {
@@ -498,6 +499,7 @@ void MainWindow::windowMenu_About_To_Be_Shown() {
}
void MainWindow::viewMenu_About_To_Be_Shown() {
ui->actionTimeline_Track_Lines->setChecked(config.show_track_lines);
ui->actionFrames->setChecked(panel_viewer->timecode_view == TIMECODE_FRAMES);
ui->actionDrop_Frame->setChecked(panel_viewer->timecode_view == TIMECODE_DROP);
if (sequence != NULL) ui->actionDrop_Frame->setEnabled(frame_rate_is_droppable(sequence->frame_rate));
@@ -532,20 +534,20 @@ void MainWindow::on_actionNon_Drop_Frame_triggered()
}
void MainWindow::toolMenu_About_To_Be_Shown() {
ui->actionEdit_Tool_Also_Seeks->setChecked(panel_timeline->edit_tool_also_seeks);
ui->actionEdit_Tool_Selects_Links->setChecked(panel_timeline->edit_tool_selects_links);
ui->actionSelecting_Also_Seeks->setChecked(panel_timeline->select_also_seeks);
ui->actionSeek_to_the_End_of_Pastes->setChecked(panel_timeline->paste_seeks);
ui->actionEdit_Tool_Also_Seeks->setChecked(config.edit_tool_also_seeks);
ui->actionEdit_Tool_Selects_Links->setChecked(config.edit_tool_selects_links);
ui->actionSelecting_Also_Seeks->setChecked(config.select_also_seeks);
ui->actionSeek_to_the_End_of_Pastes->setChecked(config.paste_seeks);
ui->actionToggle_Snapping->setChecked(panel_timeline->snapping);
ui->actionScroll_Wheel_Zooms->setChecked(scroll_zooms);
ui->actionScroll_Wheel_Zooms->setChecked(config.scroll_zooms);
}
void MainWindow::on_actionEdit_Tool_Selects_Links_triggered() {
panel_timeline->edit_tool_selects_links = !panel_timeline->edit_tool_selects_links;
config.edit_tool_selects_links = !config.edit_tool_selects_links;
}
void MainWindow::on_actionEdit_Tool_Also_Seeks_triggered() {
panel_timeline->edit_tool_also_seeks = !panel_timeline->edit_tool_also_seeks;
config.edit_tool_also_seeks = !config.edit_tool_also_seeks;
}
void MainWindow::on_actionDuplicate_triggered() {
@@ -555,12 +557,12 @@ void MainWindow::on_actionDuplicate_triggered() {
}
void MainWindow::on_actionSelecting_Also_Seeks_triggered() {
panel_timeline->select_also_seeks = !panel_timeline->select_also_seeks;
config.select_also_seeks = !config.select_also_seeks;
}
void MainWindow::on_actionSeek_to_the_End_of_Pastes_triggered()
{
panel_timeline->paste_seeks = !panel_timeline->paste_seeks;
config.paste_seeks = !config.paste_seeks;
}
void MainWindow::on_actionAdd_Default_Transition_triggered() {
@@ -610,7 +612,7 @@ void MainWindow::load_recent_project() {
void MainWindow::on_actionScroll_Wheel_Zooms_triggered()
{
scroll_zooms = !scroll_zooms;
config.scroll_zooms = !config.scroll_zooms;
}
void MainWindow::on_actionLink_Unlink_triggered()
@@ -661,3 +663,9 @@ void MainWindow::on_actionRipple_Delete_In_Out_triggered()
panel_timeline->delete_in_out(true);
}
}
void MainWindow::on_actionTimeline_Track_Lines_triggered()
{
config.show_track_lines = !config.show_track_lines;
panel_timeline->redraw_all_clips(false);
}
+3 -3
View File
@@ -38,9 +38,7 @@ private slots:
void on_actionZoom_In_triggered();
void on_actionZoom_out_triggered();
void on_actionTimeline_Track_Lines_toggled(bool arg1);
void on_actionZoom_out_triggered();
void on_actionExport_triggered();
@@ -168,6 +166,8 @@ private slots:
void on_actionRipple_Delete_In_Out_triggered();
void on_actionTimeline_Track_Lines_triggered();
private:
Ui::MainWindow *ui;
void setup_layout();
+25 -11
View File
@@ -14,6 +14,7 @@
#include "io/previewgenerator.h"
#include "project/undo.h"
#include "mainwindow.h"
#include "io/config.h"
#include <QFileDialog>
#include <QString>
@@ -303,24 +304,38 @@ void Project::process_file_list(QStringList& files) {
QVector<QString> image_sequence_urls;
QVector<bool> image_sequence_importassequence;
QStringList image_sequence_formats = config.img_seq_formats.split("|");
TimelineAction* ta = new TimelineAction();
for (int i=0;i<files.count();i++) {
QString file(files.at(i));
bool skip = false;
// heuristic to determine whether file is part of an image sequence
int lastcharindex = file.lastIndexOf(".")-1;
if (lastcharindex == -2 || lastcharindex <= file.lastIndexOf('/')) {
lastcharindex = file.length() - 1;
/* Heuristic to determine whether file is part of an image sequence */
// check file extension (assume it's not a
int lastcharindex = file.lastIndexOf(".");
bool found = true;
if (lastcharindex != -1 && lastcharindex > file.lastIndexOf('/')) {
// image_sequence_formats
found = false;
QString ext = file.mid(lastcharindex+1);
for (int j=0;j<image_sequence_formats.size();j++) {
if (ext == image_sequence_formats.at(j)) {
found = true;
break;
}
}
} else {
lastcharindex = file.length();
}
if (file[lastcharindex].isDigit()) {
if (found && file[lastcharindex-1].isDigit()) {
bool is_img_sequence = false;
// how many digits are in the filename?
int digit_count = 0;
QString ext = file.mid(lastcharindex+1);
int digit_test = lastcharindex;
int digit_test = lastcharindex-1;
while (file[digit_test].isDigit()) {
digit_count++;
digit_test--;
@@ -328,7 +343,6 @@ void Project::process_file_list(QStringList& files) {
// retrieve number from filename
digit_test++;
lastcharindex++;
int file_number = file.mid(digit_test, digit_count).toInt();
// Check if there are files with the same filename but just different numbers
@@ -343,7 +357,7 @@ void Project::process_file_list(QStringList& files) {
// add image sequence url to a vector in case the user imported several files that
// we're interpreting as a possible sequence
bool found = false;
found = false;
for (int i=0;i<image_sequence_urls.size();i++) {
if (image_sequence_urls.at(i) == new_filename) {
// either SKIP if we're importing as a sequence, or leave it if we aren't
@@ -364,7 +378,7 @@ void Project::process_file_list(QStringList& files) {
}
}
}
}
}
if (!skip) {
ta->add_media(import_file(file, files.at(i)));
@@ -380,7 +394,7 @@ void Project::process_file_list(QStringList& files) {
}
void Project::import_dialog() {
QStringList files = QFileDialog::getOpenFileNames(this, "Import media...", "", "All Files (*.*)");
QStringList files = QFileDialog::getOpenFileNames(this, "Import media...", "", "All Files (*)");
process_file_list(files);
}
-2
View File
@@ -15,8 +15,6 @@ class QXmlStreamWriter;
class QXmlStreamReader;
class QFile;
#define SAVE_VERSION "180722"
#define MEDIA_TYPE_FOOTAGE 0
#define MEDIA_TYPE_SEQUENCE 1
#define MEDIA_TYPE_FOLDER 2
+2 -5
View File
@@ -15,6 +15,7 @@
#include "effects/transition.h"
#include "ui_viewer.h"
#include "project/undo.h"
#include "io/config.h"
#include <QTime>
#include <QScrollBar>
@@ -32,10 +33,6 @@ Timeline::Timeline(QWidget *parent) :
snapped(false),
rect_select_init(false),
rect_select_proc(false),
edit_tool_selects_links(false),
edit_tool_also_seeks(false),
select_also_seeks(false),
paste_seeks(true),
snapping(true),
last_frame(0),
playhead(0),
@@ -716,7 +713,7 @@ void Timeline::paste() {
redraw_all_clips(true);
if (paste_seeks) {
if (config.paste_seeks) {
seek(paste_end);
}
}
+1 -5
View File
@@ -114,11 +114,7 @@ public:
qint64 start_msecs;
QTimer playback_updater;
// shared information
bool select_also_seeks;
bool edit_tool_selects_links;
bool edit_tool_also_seeks;
bool paste_seeks;
// shared information
int tool;
long cursor_frame;
int cursor_track;
+1 -1
View File
@@ -10,7 +10,7 @@
ScrollArea::ScrollArea(QWidget* parent) : QScrollArea(parent) {}
void ScrollArea::wheelEvent(QWheelEvent *e) {
if (scroll_zooms) {
if (config.scroll_zooms) {
e->ignore();
if (e->angleDelta().y() != 0) panel_timeline->set_zoom(e->angleDelta().y() > 0);
} else {
+9 -9
View File
@@ -336,7 +336,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) {
s.track = clip->track;
panel_timeline->selections.append(s);
if (panel_timeline->select_also_seeks) {
if (config.select_also_seeks) {
panel_timeline->seek(clip->timeline_in);
}
@@ -370,7 +370,7 @@ void TimelineWidget::mousePressEvent(QMouseEvent *event) {
}
break;
case TIMELINE_TOOL_EDIT:
if (panel_timeline->edit_tool_also_seeks) panel_timeline->seek(panel_timeline->drag_frame_start);
if (config.edit_tool_also_seeks) panel_timeline->seek(panel_timeline->drag_frame_start);
panel_timeline->selecting = true;
break;
case TIMELINE_TOOL_RAZOR:
@@ -828,7 +828,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
panel_timeline->cursor_track = getTrackFromScreenPoint(event->pos().y());
if (panel_timeline->tool == TIMELINE_TOOL_EDIT || panel_timeline->tool == TIMELINE_TOOL_RAZOR) {
panel_timeline->snap_to_clip(&panel_timeline->cursor_frame, !panel_timeline->edit_tool_also_seeks || !panel_timeline->selecting);
panel_timeline->snap_to_clip(&panel_timeline->cursor_frame, !config.edit_tool_also_seeks || !panel_timeline->selecting);
}
if (panel_timeline->selecting) {
int selection_count = 1 + qMax(panel_timeline->cursor_track, panel_timeline->drag_track_start) - qMin(panel_timeline->cursor_track, panel_timeline->drag_track_start) + panel_timeline->selection_offset;
@@ -846,7 +846,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
}
// select linked clips too
if (panel_timeline->edit_tool_selects_links) {
if (config.edit_tool_selects_links) {
for (int j=0;j<sequence->clip_count();j++) {
Clip* c = sequence->get_clip(j);
for (int k=0;k<panel_timeline->selections.size();k++) {
@@ -879,7 +879,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
}
}
if (panel_timeline->edit_tool_also_seeks) {
if (config.edit_tool_also_seeks) {
panel_timeline->seek(qMin(panel_timeline->drag_frame_start, panel_timeline->cursor_frame));
} else {
panel_timeline->repaint_timeline();
@@ -1199,7 +1199,7 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) {
int test_range = 5;
if (pos.y() > y_test_value-test_range && pos.y() < y_test_value+test_range) {
// if track lines are hidden, only resize track if a clip is already there
if (show_track_lines || cursor_contains_clip) {
if (config.show_track_lines || cursor_contains_clip) {
found = true;
track_resizing = true;
track_target = track;
@@ -1392,7 +1392,7 @@ void TimelineWidget::redraw_clips() {
}
// Draw track lines
if (show_track_lines) {
if (config.show_track_lines) {
clip_painter.setPen(QColor(0, 0, 0, 96));
audio_track_limit++;
if (video_track_limit == 0) video_track_limit--;
@@ -1521,7 +1521,7 @@ int TimelineWidget::getTrackFromScreenPoint(int y) {
int counter = ((!bottom_align && y > 0) || (bottom_align && y < 0)) ? 0 : -1;
int track_height = panel_timeline->calculate_track_height(counter, -1);
while (qAbs(y) > height_measure+track_height) {
if (show_track_lines && counter != -1) y--;
if (config.show_track_lines && counter != -1) y--;
height_measure += track_height;
if ((!bottom_align && y > 0) || (bottom_align && y < 0)) {
counter++;
@@ -1540,7 +1540,7 @@ int TimelineWidget::getScreenPointFromTrack(int track) {
if (bottom_align) counter--;
y += panel_timeline->calculate_track_height(counter, -1);
if (!bottom_align) counter++;
if (show_track_lines && counter != -1) y++;
if (config.show_track_lines && counter != -1) y++;
}
y++;
return (bottom_align) ? rect().height() - y : y;