implemented scroll wheel zooming in all TimelineViewBase derivatives

This commit is contained in:
itsmattkc
2019-12-31 19:49:09 +11:00
parent e41fdbd6e3
commit f65e1e52b5
11 changed files with 68 additions and 3 deletions
+17
View File
@@ -201,6 +201,23 @@ void CurveView::VerticalScaleChangedEvent(double scale)
}
}
void CurveView::wheelEvent(QWheelEvent *event)
{
if (WheelEventIsAZoomEvent(event)) {
if (event->delta() != 0) {
if (event->delta() > 0) {
emit ScaleChanged(scale_ * 1.1);
SetYScale(y_scale_ * 1.1);
} else {
emit ScaleChanged(scale_ * 0.9);
SetYScale(y_scale_ * 0.9);
}
}
} else {
KeyframeViewBase::wheelEvent(event);
}
}
QList<NodeKeyframe *> CurveView::GetKeyframesSortedByTime()
{
QList<NodeKeyframe *> sorted;
+2
View File
@@ -27,6 +27,8 @@ protected:
virtual void VerticalScaleChangedEvent(double scale) override;
virtual void wheelEvent(QWheelEvent* event) override;
private:
QList<NodeKeyframe*> GetKeyframesSortedByTime();
+1
View File
@@ -66,6 +66,7 @@ CurveWidget::CurveWidget(QWidget *parent) :
connect(ruler_, &TimeRuler::TimeChanged, this, &CurveWidget::UpdateBridgeTime);
connect(view_, &CurveView::TimeChanged, this, &CurveWidget::UpdateBridgeTime);
connect(view_->scene(), &QGraphicsScene::selectionChanged, this, &CurveWidget::SelectionChanged);
connect(view_, &CurveView::ScaleChanged, this, &CurveWidget::SetScale);
widget_bridge_layout_ = new QHBoxLayout();
widget_bridge_layout_->addStretch();
+3 -1
View File
@@ -26,11 +26,13 @@ public:
void SetTime(const int64_t& timestamp);
const double& GetScale();
void SetScale(const double& scale);
const double& GetVerticalScale();
void SetVerticalScale(const double& vscale);
public slots:
void SetScale(const double& scale);
signals:
void TimeChanged(const int64_t& timestamp);
+7
View File
@@ -6,6 +6,13 @@ KeyframeView::KeyframeView(QWidget *parent) :
setAlignment(Qt::AlignLeft | Qt::AlignTop);
}
void KeyframeView::wheelEvent(QWheelEvent *event)
{
if (!HandleZoomFromScroll(event)) {
KeyframeViewBase::wheelEvent(event);
}
}
void KeyframeView::AddKeyframe(NodeKeyframePtr key, int y)
{
QPoint global_pt(0, y);
+3
View File
@@ -9,6 +9,9 @@ class KeyframeView : public KeyframeViewBase
public:
KeyframeView(QWidget* parent = nullptr);
protected:
virtual void wheelEvent(QWheelEvent* event) override;
public slots:
void AddKeyframe(NodeKeyframePtr key, int y);
@@ -79,6 +79,9 @@ NodeParamView::NodeParamView(QWidget *parent) :
connect(ruler_, &TimeRuler::TimeChanged, this, &NodeParamView::RulerTimeChanged);
connect(keyframe_view_, &KeyframeView::TimeChanged, this, &NodeParamView::RulerTimeChanged);
// Connect keyframe view scaling to this
connect(keyframe_view_, &KeyframeView::ScaleChanged, this, &NodeParamView::SetScale);
splitter->addWidget(keyframe_area);
// Set both widgets to 50/50
+2 -1
View File
@@ -39,9 +39,10 @@ public:
const QList<Node*>& nodes();
const double& GetScale() const;
void SetScale(const double &scale);
public slots:
void SetScale(const double &scale);
void SetTime(const int64_t& timestamp);
signals:
@@ -116,7 +116,9 @@ void TimelineView::mouseDoubleClickEvent(QMouseEvent *event)
void TimelineView::wheelEvent(QWheelEvent *event)
{
if (Config::Current()["InvertTimelineScrollAxes"].toBool()) {
if (HandleZoomFromScroll(event)) {
return;
} else if (Config::Current()["InvertTimelineScrollAxes"].toBool()) {
QWheelEvent e(event->pos(),
event->delta(),
event->buttons(),
@@ -213,6 +213,29 @@ void TimelineViewBase::ScaleChangedEvent(double scale)
Q_UNUSED(scale)
}
bool TimelineViewBase::HandleZoomFromScroll(QWheelEvent *event)
{
if (WheelEventIsAZoomEvent(event)) {
// If CTRL is held (or a preference is set to swap CTRL behavior), we zoom instead of scrolling
if (event->delta() != 0) {
if (event->delta() > 0) {
emit ScaleChanged(scale_ * 2.0);
} else {
emit ScaleChanged(scale_ * 0.5);
}
}
return true;
}
return false;
}
bool TimelineViewBase::WheelEventIsAZoomEvent(QWheelEvent *event)
{
return (static_cast<bool>(event->modifiers() & Qt::ControlModifier) == !Config::Current()["ScrollZooms"].toBool());
}
void TimelineViewBase::SetLimitYAxis(bool e)
{
limit_y_axis_ = true;
@@ -34,6 +34,10 @@ protected:
virtual void ScaleChangedEvent(double scale);
bool HandleZoomFromScroll(QWheelEvent* event);
bool WheelEventIsAZoomEvent(QWheelEvent* event);
void SetLimitYAxis(bool e);
rational GetPlayheadTime();