From e41fdbd6e30486ae7311dd8ae591b5108761ee74 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 31 Dec 2019 19:17:40 +1100 Subject: [PATCH] implemented autoscrolling derivatives of TimelineViewBase around the playhead --- app/common/autoscroll.h | 13 +++++++++ app/config/config.cpp | 4 ++- .../tabs/preferencesgeneraltab.cpp | 15 ++++++++++ .../preferences/tabs/preferencesgeneraltab.h | 5 ++-- .../timelinewidget/view/timelineviewbase.cpp | 29 +++++++++++++++++++ .../timelinewidget/view/timelineviewbase.h | 8 +++++ app/window/mainwindow/mainmenu.cpp | 22 -------------- app/window/mainwindow/mainmenu.h | 3 -- 8 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 app/common/autoscroll.h diff --git a/app/common/autoscroll.h b/app/common/autoscroll.h new file mode 100644 index 000000000..5331267d2 --- /dev/null +++ b/app/common/autoscroll.h @@ -0,0 +1,13 @@ +#ifndef AUTOSCROLL_H +#define AUTOSCROLL_H + +class AutoScroll { +public: + enum Method { + kNone, + kPage, + kSmooth + }; +}; + +#endif // AUTOSCROLL_H diff --git a/app/config/config.cpp b/app/config/config.cpp index 6be80212c..e09e7ad99 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -26,8 +26,9 @@ #include #include -#include "core.h" +#include "common/autoscroll.h" #include "common/filefunctions.h" +#include "core.h" #include "window/mainwindow/mainwindow.h" Config Config::current_config_; @@ -70,6 +71,7 @@ void Config::SetDefaults() config_map_["DropFileOnMediaToReplace"] = false; config_map_["AddDefaultEffectsToClips"] = true; config_map_["AutoscaleByDefault"] = false; + config_map_["Autoscroll"] = AutoScroll::kPage; config_map_["DefaultSequenceWidth"] = 1920; config_map_["DefaultSequenceHeight"] = 1080; diff --git a/app/dialog/preferences/tabs/preferencesgeneraltab.cpp b/app/dialog/preferences/tabs/preferencesgeneraltab.cpp index d2d2354d4..bae7e65af 100644 --- a/app/dialog/preferences/tabs/preferencesgeneraltab.cpp +++ b/app/dialog/preferences/tabs/preferencesgeneraltab.cpp @@ -6,6 +6,7 @@ #include #include +#include "common/autoscroll.h" #include "dialog/sequence/sequence.h" #include "project/item/sequence/sequence.h" @@ -61,6 +62,18 @@ PreferencesGeneralTab::PreferencesGeneralTab() row++; + general_layout->addWidget(new QLabel(tr("Auto-Scroll Method:")), row, 0); + + // ComboBox indices match enum indicies + autoscroll_method_ = new QComboBox(); + autoscroll_method_->addItem(tr("None"), AutoScroll::kNone); + autoscroll_method_->addItem(tr("Page Scrolling"), AutoScroll::kPage); + autoscroll_method_->addItem(tr("Smooth Scrolling"), AutoScroll::kSmooth); + autoscroll_method_->setCurrentIndex(Config::Current()["Autoscroll"].toInt()); + general_layout->addWidget(autoscroll_method_, row, 1); + + row++; + general_layout->addWidget(new QLabel(tr("Default Sequence Settings:")), row, 0); // General -> Default Sequence Settings @@ -78,6 +91,8 @@ void PreferencesGeneralTab::Accept() 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(); + + Config::Current()["Autoscroll"] = autoscroll_method_->currentData(); } void PreferencesGeneralTab::edit_default_sequence_settings() diff --git a/app/dialog/preferences/tabs/preferencesgeneraltab.h b/app/dialog/preferences/tabs/preferencesgeneraltab.h index 87b753c82..0ae724414 100644 --- a/app/dialog/preferences/tabs/preferencesgeneraltab.h +++ b/app/dialog/preferences/tabs/preferencesgeneraltab.h @@ -22,11 +22,10 @@ private slots: void edit_default_sequence_settings(); private: - /** - * @brief UI widget for selecting the UI language - */ QComboBox* language_combobox_; + QComboBox* autoscroll_method_; + /** * @brief A sequence we can feed to a SequenceDialog to change the defaults */ diff --git a/app/widget/timelinewidget/view/timelineviewbase.cpp b/app/widget/timelinewidget/view/timelineviewbase.cpp index 03ef8e357..2c37d617a 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.cpp +++ b/app/widget/timelinewidget/view/timelineviewbase.cpp @@ -5,7 +5,9 @@ #include #include +#include "common/autoscroll.h" #include "common/timecodefunctions.h" +#include "config/config.h" TimelineViewBase::TimelineViewBase(QWidget *parent) : QGraphicsView(parent), @@ -56,6 +58,18 @@ void TimelineViewBase::SetTime(const int64_t time) { playhead_ = time; + switch (static_cast(Config::Current()["Autoscroll"].toInt())) { + case AutoScroll::kNone: + // Do nothing + break; + case AutoScroll::kPage: + PageScrollToPlayhead(); + break; + case AutoScroll::kSmooth: + CenterScrollOnPlayhead(); + break; + } + // Force redraw for playhead viewport()->update(); } @@ -172,6 +186,21 @@ void TimelineViewBase::CenterScrollOnPlayhead() horizontalScrollBar()->setValue(qRound(GetPlayheadX()) - viewport()->width()/2); } +void TimelineViewBase::PageScrollToPlayhead() +{ + int playhead_pos = qRound(GetPlayheadX()); + + int viewport_padding = viewport()->width() / 16; + + if (playhead_pos < horizontalScrollBar()->value()) { + // Anchor the playhead to the RIGHT of where we scroll to + horizontalScrollBar()->setValue(playhead_pos - viewport()->width() + viewport_padding); + } else if (playhead_pos > horizontalScrollBar()->value() + viewport()->width()) { + // Anchor the playhead to the LEFT of where we scroll to + horizontalScrollBar()->setValue(playhead_pos - viewport_padding); + } +} + void TimelineViewBase::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); diff --git a/app/widget/timelinewidget/view/timelineviewbase.h b/app/widget/timelinewidget/view/timelineviewbase.h index cd5e1e7c0..516656573 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.h +++ b/app/widget/timelinewidget/view/timelineviewbase.h @@ -71,6 +71,14 @@ private slots: */ void CenterScrollOnPlayhead(); + /** + * @brief Slot to handle page scrolling of the playhead + * + * If the playhead is outside the current scroll bounds, this function will scroll to where it is. Otherwise it will + * do nothing. + */ + void PageScrollToPlayhead(); + }; #endif // TIMELINEVIEWBASE_H diff --git a/app/window/mainwindow/mainmenu.cpp b/app/window/mainwindow/mainmenu.cpp index 65ef4ad77..2da6030a4 100644 --- a/app/window/mainwindow/mainmenu.cpp +++ b/app/window/mainwindow/mainmenu.cpp @@ -280,25 +280,6 @@ MainMenu::MainMenu(QMainWindow *parent) : tools_menu_->addSeparator(); - QActionGroup* autoscroll_group = new QActionGroup(this); - - tools_autoscroll_none_item_ = tools_menu_->AddItem("autoscrollno", nullptr, nullptr); - //tools_autoscroll_none_item_->setData(olive::AUTOSCROLL_NO_SCROLL); - tools_autoscroll_none_item_->setCheckable(true); - autoscroll_group->addAction(tools_autoscroll_none_item_); - - tools_autoscroll_page_item_ = tools_menu_->AddItem("autoscrollpage", nullptr, nullptr); - //tools_autoscroll_page_item_->setData(olive::AUTOSCROLL_PAGE_SCROLL); - tools_autoscroll_page_item_->setCheckable(true); - autoscroll_group->addAction(tools_autoscroll_page_item_); - - tools_autoscroll_smooth_item_ = tools_menu_->AddItem("autoscrollsmooth", nullptr, nullptr); - //tools_autoscroll_smooth_item_->setData(olive::AUTOSCROLL_SMOOTH_SCROLL); - tools_autoscroll_smooth_item_->setCheckable(true); - autoscroll_group->addAction(tools_autoscroll_smooth_item_); - - tools_menu_->addSeparator(); - tools_preferences_item_ = tools_menu_->AddItem("prefs", Core::instance(), SLOT(DialogPreferencesShow()), "Ctrl+,"); // @@ -608,9 +589,6 @@ void MainMenu::Retranslate() tools_transition_item_->setText(tr("Transition Tool")); tools_snapping_item_->setText(tr("Enable Snapping")); tools_autocut_silence_item_->setText(tr("Auto-Cut Silence")); - tools_autoscroll_none_item_->setText(tr("No Auto-Scroll")); - tools_autoscroll_page_item_->setText(tr("Page Auto-Scroll")); - tools_autoscroll_smooth_item_->setText(tr("Smooth Auto-Scroll")); tools_preferences_item_->setText(tr("Preferences")); // Help menu diff --git a/app/window/mainwindow/mainmenu.h b/app/window/mainwindow/mainmenu.h index 27ac06932..9444dfad5 100644 --- a/app/window/mainwindow/mainmenu.h +++ b/app/window/mainwindow/mainmenu.h @@ -226,9 +226,6 @@ private: QAction* tools_transition_item_; QAction* tools_snapping_item_; QAction* tools_autocut_silence_item_; - QAction* tools_autoscroll_none_item_; - QAction* tools_autoscroll_page_item_; - QAction* tools_autoscroll_smooth_item_; QAction* tools_preferences_item_; Menu* help_menu_;