From 9cdb309528016948193d3da0ee020e2821b659ea Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 23 Jul 2018 13:18:09 +0100 Subject: [PATCH] fixed #107 and added persistent configuration --- dialogs/preferencesdialog.cpp | 8 +++ dialogs/preferencesdialog.h | 3 + dialogs/preferencesdialog.ui | 14 ++++- io/config.cpp | 100 +++++++++++++++++++++++++++++----- io/config.h | 29 ++++++---- mainwindow.cpp | 40 ++++++++------ mainwindow.h | 6 +- panels/project.cpp | 36 ++++++++---- panels/project.h | 2 - panels/timeline.cpp | 7 +-- panels/timeline.h | 6 +- ui/scrollarea.cpp | 2 +- ui/timelinewidget.cpp | 18 +++--- 13 files changed, 192 insertions(+), 79 deletions(-) diff --git a/dialogs/preferencesdialog.cpp b/dialogs/preferencesdialog.cpp index a9090cdd6..2b5ed4bc1 100644 --- a/dialogs/preferencesdialog.cpp +++ b/dialogs/preferencesdialog.cpp @@ -1,6 +1,8 @@ #include "preferencesdialog.h" #include "ui_preferencesdialog.h" +#include "io/config.h" + #include #include #include @@ -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(); +} diff --git a/dialogs/preferencesdialog.h b/dialogs/preferencesdialog.h index 2d9471a8b..012f9b17a 100644 --- a/dialogs/preferencesdialog.h +++ b/dialogs/preferencesdialog.h @@ -19,6 +19,9 @@ public: void setup_kbd_shortcuts(QMenuBar* menu); +private slots: + void on_buttonBox_accepted(); + private: Ui::PreferencesDialog *ui; }; diff --git a/dialogs/preferencesdialog.ui b/dialogs/preferencesdialog.ui index cfc822350..aea695163 100644 --- a/dialogs/preferencesdialog.ui +++ b/dialogs/preferencesdialog.ui @@ -17,12 +17,24 @@ - 2 + 0 General + + + + + Image sequence formats: + + + + + + + diff --git a/io/config.cpp b/io/config.cpp index 30ae35d9e..8dcac0e3c 100644 --- a/io/config.cpp +++ b/io/config.cpp @@ -1,21 +1,66 @@ #include "config.h" -#ifdef _WIN32 -#include -#include -#endif +#include +#include +#include +#include -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*/ + } diff --git a/io/config.h b/io/config.h index b46bfdad7..703abbaf8 100644 --- a/io/config.h +++ b/io/config.h @@ -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 -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 diff --git a/mainwindow.cpp b/mainwindow.cpp index 556edaf7c..284d4461f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); +} diff --git a/mainwindow.h b/mainwindow.h index 7b97d60a3..2df090ffa 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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(); diff --git a/panels/project.cpp b/panels/project.cpp index 6ac1c9198..32a8d8ea6 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -14,6 +14,7 @@ #include "io/previewgenerator.h" #include "project/undo.h" #include "mainwindow.h" +#include "io/config.h" #include #include @@ -303,24 +304,38 @@ void Project::process_file_list(QStringList& files) { QVector image_sequence_urls; QVector image_sequence_importassequence; + QStringList image_sequence_formats = config.img_seq_formats.split("|"); TimelineAction* ta = new TimelineAction(); for (int i=0;i file.lastIndexOf('/')) { + // image_sequence_formats + found = false; + QString ext = file.mid(lastcharindex+1); + for (int j=0;jadd_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); } diff --git a/panels/project.h b/panels/project.h index 46ba522eb..ecb578bcf 100644 --- a/panels/project.h +++ b/panels/project.h @@ -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 diff --git a/panels/timeline.cpp b/panels/timeline.cpp index bfb763a72..9e8c4b648 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -15,6 +15,7 @@ #include "effects/transition.h" #include "ui_viewer.h" #include "project/undo.h" +#include "io/config.h" #include #include @@ -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); } } diff --git a/panels/timeline.h b/panels/timeline.h index abf143fb1..eadce092e 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -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; diff --git a/ui/scrollarea.cpp b/ui/scrollarea.cpp index 16a737549..6c07728ff 100644 --- a/ui/scrollarea.cpp +++ b/ui/scrollarea.cpp @@ -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 { diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 9f7d01443..0b695554c 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -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;jclip_count();j++) { Clip* c = sequence->get_clip(j); for (int k=0;kselections.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;