implemented autoscrolling derivatives of TimelineViewBase around the playhead
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#ifndef AUTOSCROLL_H
|
||||
#define AUTOSCROLL_H
|
||||
|
||||
class AutoScroll {
|
||||
public:
|
||||
enum Method {
|
||||
kNone,
|
||||
kPage,
|
||||
kSmooth
|
||||
};
|
||||
};
|
||||
|
||||
#endif // AUTOSCROLL_H
|
||||
@@ -26,8 +26,9 @@
|
||||
#include <QMessageBox>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#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;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QPushButton>
|
||||
|
||||
#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()
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
|
||||
#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<AutoScroll::Method>(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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user