From acfbe421e23ab6c6c911afd6a30de5af8beaf935 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 31 Dec 2019 14:40:52 +1100 Subject: [PATCH] implemented much of the general tab and behavior tab in the PreferencesDialog --- app/config/config.cpp | 20 +++ app/dialog/preferences/preferences.cpp | 6 + .../tabs/preferencesbehaviortab.cpp | 123 +++++++++++++++--- .../preferences/tabs/preferencesbehaviortab.h | 9 +- .../tabs/preferencesgeneraltab.cpp | 61 ++++----- .../preferences/tabs/preferencesgeneraltab.h | 11 +- .../preferences/tabs/preferencestab.cpp | 5 + app/dialog/preferences/tabs/preferencestab.h | 2 + app/dialog/sequence/sequence.cpp | 7 +- app/dialog/sequence/sequence.h | 9 +- app/project/item/sequence/sequence.cpp | 9 +- 11 files changed, 189 insertions(+), 73 deletions(-) diff --git a/app/config/config.cpp b/app/config/config.cpp index 385aa4bbe..f3da4d484 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -56,6 +56,26 @@ void Config::SetDefaults() config_map_["AudioScrubbing"] = true; config_map_["AutorecoveryInterval"] = 1; config_map_["Language"] = "en_US"; + config_map_["ScrollZooms"] = false; + config_map_["EnableSeekToImport"] = false; + config_map_["EditToolAlsoSeeks"] = false; + config_map_["EditToolSelectsLinks"] = false; + config_map_["EnableDragFilesToTimeline"] = true; + config_map_["InvertTimelineScrollAxes"] = true; + config_map_["SelectAlsoSeeks"] = false; + config_map_["PasteSeeks"] = true; + config_map_["SelectAlsoSeeks"] = false; + config_map_["SetNameWithMarker"] = false; + config_map_["AutoSeekToBeginning"] = true; + config_map_["DropFileOnMediaToReplace"] = false; + config_map_["AddDefaultEffectsToClips"] = true; + config_map_["AutoscaleByDefault"] = false; + + config_map_["DefaultSequenceWidth"] = 1920; + config_map_["DefaultSequenceHeight"] = 1080; + config_map_["DefaultSequenceFrameRate"] = QVariant::fromValue(rational(1001, 30000)); + config_map_["DefaultSequenceAudioFrequency"] = 48000; + config_map_["DefaultSequenceAudioLayout"] = AV_CH_LAYOUT_STEREO; } void Config::Load() diff --git a/app/dialog/preferences/preferences.cpp b/app/dialog/preferences/preferences.cpp index f87e35024..6bb076abf 100644 --- a/app/dialog/preferences/preferences.cpp +++ b/app/dialog/preferences/preferences.cpp @@ -89,6 +89,12 @@ void PreferencesDialog::AddBoolPair(QCheckBox *ui, bool *value, bool restart_req void PreferencesDialog::accept() { + foreach (PreferencesTab* tab, tabs_) { + if (!tab->Validate()) { + return; + } + } + foreach (PreferencesTab* tab, tabs_) { tab->Accept(); } diff --git a/app/dialog/preferences/tabs/preferencesbehaviortab.cpp b/app/dialog/preferences/tabs/preferencesbehaviortab.cpp index 32aa493ab..be10d024b 100644 --- a/app/dialog/preferences/tabs/preferencesbehaviortab.cpp +++ b/app/dialog/preferences/tabs/preferencesbehaviortab.cpp @@ -3,6 +3,8 @@ #include #include +#include "config/config.h" + PreferencesBehaviorTab::PreferencesBehaviorTab() { QVBoxLayout* layout = new QVBoxLayout(this); @@ -12,37 +14,116 @@ PreferencesBehaviorTab::PreferencesBehaviorTab() layout->addWidget(behavior_tree_); behavior_tree_->setHeaderLabel(tr("Behavior")); - behavior_tree_->setRootIsDecorated(false); - AddItem(tr("Add Default Effects to New Clips")); - AddItem(tr("Automatically Seek to the Beginning When Playing at the End of a Sequence")); - AddItem(tr("Selecting Also Seeks")); - AddItem(tr("Edit Tool Also Seeks")); - AddItem(tr("Edit Tool Selects Links")); - AddItem(tr("Seek Also Selects")); - AddItem(tr("Seek to the End of Pastes")); - AddItem(tr("Scroll Wheel Zooms")); - AddItem(tr("Invert Timeline Scroll Axes")); - AddItem(tr("Enable Drag Files to Timeline")); - AddItem(tr("Auto-Scale By Default")); - AddItem(tr("Auto-Seek to Imported Clips")); - AddItem(tr("Audio Scrubbing")); - AddItem(tr("Drop Files on Media to Replace")); - AddItem(tr("Enable Hover Focus")); - AddItem(tr("Ask For Name When Setting Marker")); + QTreeWidgetItem* general_group = AddParent(tr("General")); + AddItem(tr("Enable hover focus"), + QStringLiteral("HoverFocus"), + tr("Panels will be considered focused when the mouse cursor is over them without having to click them."), + general_group); + AddItem(tr("Scroll wheel zooms by default instead of scrolling"), + QStringLiteral("ScrollZooms"), + tr("Holding CTRL while using Olive toggles this setting"), + general_group); - //scroll_wheel_zooms->setToolTip(tr("Hold CTRL to toggle this setting")); + QTreeWidgetItem* audio_group = AddParent(tr("Audio")); + AddItem(tr("Enable audio scrubbing"), + QStringLiteral("AudioScrubbing"), + audio_group); + + QTreeWidgetItem* timeline_group = AddParent(tr("Timeline")); + AddItem(tr("Auto-Seek to Imported Clips"), + QStringLiteral("EnableSeekToImport"), + timeline_group); + AddItem(tr("Edit Tool Also Seeks"), + QStringLiteral("EditToolAlsoSeeks"), + timeline_group); + AddItem(tr("Edit Tool Selects Links"), + QStringLiteral("EditToolSelectsLinks"), + timeline_group); + AddItem(tr("Enable Drag Files to Timeline"), + QStringLiteral("EnableDragFilesToTimeline"), + timeline_group); + AddItem(tr("Invert Timeline Scroll Axes"), + QStringLiteral("InvertTimelineScrollAxes"), + timeline_group); + AddItem(tr("Seek Also Selects"), + QStringLiteral("SelectAlsoSeeks"), + timeline_group); + AddItem(tr("Seek to the End of Pastes"), + QStringLiteral("PasteSeeks"), + timeline_group); + AddItem(tr("Selecting Also Seeks"), + QStringLiteral("SelectAlsoSeeks"), + timeline_group); + + QTreeWidgetItem* playback_group = AddParent(tr("Playback")); + AddItem(tr("Ask For Name When Setting Marker"), + QStringLiteral("SetNameWithMarker"), + playback_group); + AddItem(tr("Automatically rewind at the end of a sequence"), + QStringLiteral("AutoSeekToBeginning"), + playback_group); + + QTreeWidgetItem* project_group = AddParent(tr("Project")); + AddItem(tr("Drop Files on Media to Replace"), + QStringLiteral("DropFileOnMediaToReplace"), + project_group); + + QTreeWidgetItem* node_group = AddParent(tr("Nodes")); + AddItem(tr("Add Default Effects to New Clips"), + QStringLiteral("AddDefaultEffectsToClips"), + node_group); + AddItem(tr("Auto-Scale By Default"), + QStringLiteral("AutoscaleByDefault"), + node_group); } void PreferencesBehaviorTab::Accept() { + QMap::const_iterator iterator; + for (iterator=config_map_.begin();iterator!=config_map_.end();iterator++) { + Config::Current()[iterator.value()] = (iterator.key()->checkState(0) == Qt::Checked); + } } -void PreferencesBehaviorTab::AddItem(const QString &text, const QString& tooltip) +QTreeWidgetItem* PreferencesBehaviorTab::AddItem(const QString &text, const QString &config_key, const QString& tooltip, QTreeWidgetItem* parent) { QTreeWidgetItem* item = new QTreeWidgetItem({text}); item->setToolTip(0, tooltip); - item->setCheckState(0, Qt::Unchecked); - behavior_tree_->addTopLevelItem(item); + item->setCheckState(0, Config::Current()[config_key].toBool() ? Qt::Checked : Qt::Unchecked); + + config_map_.insert(item, config_key); + + if (parent) { + parent->addChild(item); + } else { + behavior_tree_->addTopLevelItem(item); + } + + return item; +} + +QTreeWidgetItem *PreferencesBehaviorTab::AddItem(const QString &text, const QString &config_key, QTreeWidgetItem *parent) +{ + return AddItem(text, config_key, QString(), parent); +} + +QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text, const QString &tooltip, QTreeWidgetItem *parent) +{ + QTreeWidgetItem* item = new QTreeWidgetItem({text}); + item->setToolTip(0, tooltip); + + if (parent) { + parent->addChild(item); + } else { + behavior_tree_->addTopLevelItem(item); + } + + return item; +} + +QTreeWidgetItem *PreferencesBehaviorTab::AddParent(const QString &text, QTreeWidgetItem *parent) +{ + return AddParent(text, QString(), parent); } diff --git a/app/dialog/preferences/tabs/preferencesbehaviortab.h b/app/dialog/preferences/tabs/preferencesbehaviortab.h index f0590e4a5..b15c5ab48 100644 --- a/app/dialog/preferences/tabs/preferencesbehaviortab.h +++ b/app/dialog/preferences/tabs/preferencesbehaviortab.h @@ -14,9 +14,16 @@ public: virtual void Accept() override; private: - void AddItem(const QString& text, const QString &tooltip = QString()); + QTreeWidgetItem *AddParent(const QString& text, const QString &tooltip, QTreeWidgetItem *parent = nullptr); + QTreeWidgetItem *AddParent(const QString& text, QTreeWidgetItem *parent = nullptr); + + QTreeWidgetItem *AddItem(const QString& text, const QString& config_key, const QString &tooltip, QTreeWidgetItem *parent ); + QTreeWidgetItem *AddItem(const QString& text, const QString& config_key, QTreeWidgetItem *parent); + + QMap config_map_; QTreeWidget* behavior_tree_; + }; #endif // PREFERENCESBEHAVIORTAB_H diff --git a/app/dialog/preferences/tabs/preferencesgeneraltab.cpp b/app/dialog/preferences/tabs/preferencesgeneraltab.cpp index 0039efa09..249b441eb 100644 --- a/app/dialog/preferences/tabs/preferencesgeneraltab.cpp +++ b/app/dialog/preferences/tabs/preferencesgeneraltab.cpp @@ -6,6 +6,9 @@ #include #include +#include "dialog/sequence/sequence.h" +#include "project/item/sequence/sequence.h" + PreferencesGeneralTab::PreferencesGeneralTab() { QVBoxLayout* layout = new QVBoxLayout(this); @@ -19,10 +22,13 @@ PreferencesGeneralTab::PreferencesGeneralTab() // General -> Language general_layout->addWidget(new QLabel(tr("Language:")), row, 0); - language_combobox = new QComboBox(); + language_combobox_ = new QComboBox(); - // add default language (en-US) - language_combobox->addItem(QLocale::languageToString(QLocale("en-US").language())); + // Add default language (en-US) + language_combobox_->addItem(QLocale::languageToString(QLocale("en_US").language())); + + // Set sequence to pick up default parameters from the config + default_sequence_.set_default_parameters(); /* // add languages from file @@ -51,56 +57,33 @@ PreferencesGeneralTab::PreferencesGeneralTab() } */ - general_layout->addWidget(language_combobox, row, 1); + general_layout->addWidget(language_combobox_, row, 1); row++; - // General -> Thumbnail and Waveform Resolution - general_layout->addWidget(new QLabel(tr("Thumbnail Resolution:"), this), row, 0); - - thumbnail_res_spinbox = new QSpinBox(this); - thumbnail_res_spinbox->setMinimum(0); - thumbnail_res_spinbox->setMaximum(INT_MAX); - general_layout->addWidget(thumbnail_res_spinbox, row, 1); - - row++; - - general_layout->addWidget(new QLabel(tr("Waveform Resolution:"), this), row, 0); - - waveform_res_spinbox = new QSpinBox(this); - waveform_res_spinbox->setMinimum(0); - waveform_res_spinbox->setMaximum(INT_MAX); - general_layout->addWidget(waveform_res_spinbox, row, 1); - - row++; - - QPushButton* delete_preview_btn = new QPushButton(tr("Delete Previews")); - general_layout->addWidget(delete_preview_btn, row, 1); - //connect(delete_preview_btn, SIGNAL(clicked(bool)), this, SLOT(delete_all_previews())); - - row++; - - QHBoxLayout* misc_general = new QHBoxLayout(); + general_layout->addWidget(new QLabel(tr("Default Sequence Settings:")), row, 0); // General -> Default Sequence Settings - QPushButton* default_sequence_settings = new QPushButton(tr("Default Sequence Settings")); - default_sequence_settings->setEnabled(false); + QPushButton* default_sequence_settings = new QPushButton(tr("Edit")); connect(default_sequence_settings, SIGNAL(clicked(bool)), this, SLOT(edit_default_sequence_settings())); - misc_general->addWidget(default_sequence_settings); - - general_layout->addLayout(misc_general, row, 0); + general_layout->addWidget(default_sequence_settings, row, 1); layout->addStretch(); } void PreferencesGeneralTab::Accept() { - + Config::Current()["DefaultSequenceWidth"] = default_sequence_.video_params().width(); + Config::Current()["DefaultSequenceHeight"] = default_sequence_.video_params().height();; + Config::Current()["DefaultSequenceFrameRate"] = QVariant::fromValue(default_sequence_.video_params().time_base()); + Config::Current()["DefaultSequenceAudioFrequency"] = default_sequence_.audio_params().sample_rate(); + Config::Current()["DefaultSequenceAudioLayout"] = default_sequence_.audio_params().channel_layout(); } void PreferencesGeneralTab::edit_default_sequence_settings() { - /*NewSequenceDialog nsd(this, nullptr, &default_sequence); - nsd.SetNameEditable(false); - nsd.exec();*/ + SequenceDialog sd(&default_sequence_, SequenceDialog::kExisting, this); + sd.SetUndoable(false); + sd.SetNameIsEditable(false); + sd.exec(); } diff --git a/app/dialog/preferences/tabs/preferencesgeneraltab.h b/app/dialog/preferences/tabs/preferencesgeneraltab.h index c8364f863..87b753c82 100644 --- a/app/dialog/preferences/tabs/preferencesgeneraltab.h +++ b/app/dialog/preferences/tabs/preferencesgeneraltab.h @@ -5,6 +5,7 @@ #include #include "preferencestab.h" +#include "project/item/sequence/sequence.h" class PreferencesGeneralTab : public PreferencesTab { @@ -24,17 +25,13 @@ private: /** * @brief UI widget for selecting the UI language */ - QComboBox* language_combobox; + QComboBox* language_combobox_; /** - * @brief UI widget for selecting the resolution of the thumbnails to generate + * @brief A sequence we can feed to a SequenceDialog to change the defaults */ - QSpinBox* thumbnail_res_spinbox; + Sequence default_sequence_; - /** - * @brief UI widget for selecting the resolution of the waveforms to generate - */ - QSpinBox* waveform_res_spinbox; }; diff --git a/app/dialog/preferences/tabs/preferencestab.cpp b/app/dialog/preferences/tabs/preferencestab.cpp index 1fad11b7e..e9e813288 100644 --- a/app/dialog/preferences/tabs/preferencestab.cpp +++ b/app/dialog/preferences/tabs/preferencestab.cpp @@ -4,3 +4,8 @@ PreferencesTab::PreferencesTab() { } + +bool PreferencesTab::Validate() +{ + return true; +} diff --git a/app/dialog/preferences/tabs/preferencestab.h b/app/dialog/preferences/tabs/preferencestab.h index 9dcfc6f2a..c58a69f43 100644 --- a/app/dialog/preferences/tabs/preferencestab.h +++ b/app/dialog/preferences/tabs/preferencestab.h @@ -10,6 +10,8 @@ class PreferencesTab : public QWidget public: PreferencesTab(); + virtual bool Validate(); + virtual void Accept() = 0; }; diff --git a/app/dialog/sequence/sequence.cpp b/app/dialog/sequence/sequence.cpp index 86042a5bd..5548e1321 100644 --- a/app/dialog/sequence/sequence.cpp +++ b/app/dialog/sequence/sequence.cpp @@ -144,9 +144,14 @@ void SequenceDialog::SetUndoable(bool u) make_undoable_ = u; } +void SequenceDialog::SetNameIsEditable(bool e) +{ + name_field_->setEnabled(e); +} + void SequenceDialog::accept() { - if (name_field_->text().isEmpty()) { + if (name_field_->isEnabled() && name_field_->text().isEmpty()) { QMessageBox::critical(this, tr("Error editing Sequence"), tr("Please enter a name for this Sequence.")); return; } diff --git a/app/dialog/sequence/sequence.h b/app/dialog/sequence/sequence.h index 44c49ad0a..a9844b21b 100644 --- a/app/dialog/sequence/sequence.h +++ b/app/dialog/sequence/sequence.h @@ -71,10 +71,17 @@ public: /** * @brief Set whether the parameter changes should be made into an undo command or not * - * @param u + * Defaults to true. */ void SetUndoable(bool u); + /** + * @brief Set whether the name of this Sequence can be edited with this dialog + * + * Defaults to true. + */ + void SetNameIsEditable(bool e); + public slots: /** * @brief Function called when the user presses OK diff --git a/app/project/item/sequence/sequence.cpp b/app/project/item/sequence/sequence.cpp index 473550636..c379f4e0f 100644 --- a/app/project/item/sequence/sequence.cpp +++ b/app/project/item/sequence/sequence.cpp @@ -22,6 +22,7 @@ #include +#include "config/config.h" #include "common/channellayout.h" #include "common/timecodefunctions.h" #include "panel/panelmanager.h" @@ -150,7 +151,9 @@ void Sequence::set_audio_params(const AudioParams ¶ms) void Sequence::set_default_parameters() { - // FIXME: Make these configurable (hardcoded) - set_video_params(VideoParams(1920, 1080, rational(1001, 30000))); - set_audio_params(AudioParams(48000, AV_CH_LAYOUT_STEREO)); + set_video_params(VideoParams(Config::Current()["DefaultSequenceWidth"].toInt(), + Config::Current()["DefaultSequenceHeight"].toInt(), + Config::Current()["DefaultSequenceFrameRate"].value())); + set_audio_params(AudioParams(Config::Current()["DefaultSequenceAudioFrequency"].toInt(), + Config::Current()["DefaultSequenceAudioLayout"].toULongLong())); }