summaryrefslogtreecommitdiffstats
path: root/src/Authoring/Studio/Palettes
diff options
context:
space:
mode:
authorKaj Grönholm <kaj.gronholm@qt.io>2018-08-21 16:33:49 +0300
committerKaj Grönholm <kaj.gronholm@qt.io>2018-08-30 09:20:40 +0000
commit56e2804ef706806b210471d84bfaff6c1cc1b8c0 (patch)
tree2206c30527a6e420d18911540a0cce004719dbdc /src/Authoring/Studio/Palettes
parentbb7dad5c3bfce60fd7b1c4d05fef841c869a4abd (diff)
Support timeline zooming & panning with mouse
Timeline can be zoomed and panned using ALT + mouse as specified by design. Task-number: QT3DS-1585 Change-Id: I97c49e3e3f61564a840521d51bb8cf95f4fbccd3 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Palettes')
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp51
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h3
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp1
-rw-r--r--src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h4
4 files changed, 51 insertions, 8 deletions
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
index 16b7a20e..37d3700f 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.cpp
@@ -84,6 +84,7 @@ TimelineGraphicsScene::TimelineGraphicsScene(TimelineWidget *timelineWidget)
, m_rowManager(new RowManager(this, m_layoutTree, m_layoutTimeline))
, m_keyframeManager(new KeyframeManager(this))
, m_pressPos(invalidPoint)
+ , m_pressScreenPos(invalidPoint)
, m_timelineControl(new TimelineControl(this))
, m_currentCursor(-1)
{
@@ -451,6 +452,22 @@ void TimelineGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
g_StudioApp.setLastActiveView(m_widgetTimeline);
+ if ((event->modifiers() & Qt::AltModifier) && !m_dragging) {
+ if (event->button() == Qt::RightButton && !m_timelinePanning) {
+ // Start zooming
+ m_timelineZooming = true;
+ m_pressScreenPos = event->screenPos();
+ event->accept();
+ return;
+ } else if (event->button() == Qt::MiddleButton && !m_timelineZooming) {
+ // Start panning
+ m_timelinePanning = true;
+ m_pressPos = event->scenePos();
+ event->accept();
+ return;
+ }
+ }
+
// Ignore non-left presses if dragging
if (event->button() != Qt::LeftButton && (m_dragging || m_startRowMoverOnNextDrag)) {
event->accept();
@@ -561,10 +578,30 @@ void TimelineGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
void TimelineGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
+ if (m_timelineZooming) {
+ int deltaY = event->screenPos().y() - m_pressScreenPos.y();
+ int deltaX = event->screenPos().x() - m_pressScreenPos.x();
+ // Zooming in when moving down/right.
+ int delta = -deltaX - deltaY;
+ const int threshold = 20;
+ if (delta < -threshold) {
+ m_widgetTimeline->toolbar()->onZoomInButtonClicked();
+ m_pressScreenPos = event->screenPos();
+ } else if (delta > threshold) {
+ m_widgetTimeline->toolbar()->onZoomOutButtonClicked();
+ m_pressScreenPos = event->screenPos();
+ }
+ } else if (m_timelinePanning) {
+ int deltaX = event->scenePos().x() - m_pressPos.x();
+ QScrollBar *scrollbar = m_widgetTimeline->viewTimelineContent()->horizontalScrollBar();
+ scrollbar->setValue(scrollbar->value() - deltaX);
+ }
+
if (m_editedTimelineRow.isNull())
updateHoverStatus(event->scenePos());
- if (!m_dragging && m_pressPos != invalidPoint
+ if (!m_dragging && !m_timelineZooming && !m_timelinePanning
+ && m_pressPos != invalidPoint
&& (event->scenePos() - m_pressPos).manhattanLength() > 10) {
m_dragging = true;
}
@@ -670,6 +707,8 @@ void TimelineGraphicsScene::resetMousePressParams()
m_selectionRect->end();
m_rowMover->end();
m_dragging = false;
+ m_timelineZooming = false;
+ m_timelinePanning = false;
m_startRowMoverOnNextDrag = false;
m_rulerPressed = false;
m_keyframePressed = false;
@@ -680,6 +719,7 @@ void TimelineGraphicsScene::resetMousePressParams()
m_autoScrollTriggerTimer.stop();
m_timebarToolTip->hide();
m_pressPos = invalidPoint;
+ m_pressScreenPos = invalidPoint;
m_lastAutoScrollX = -1.0;
m_lastAutoScrollY = -1.0;
}
@@ -768,10 +808,10 @@ void TimelineGraphicsScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (!m_releaseSelectRow.isNull())
m_rowManager->selectRow(m_releaseSelectRow);
}
-
- resetMousePressParams();
}
+ resetMousePressParams();
+
QGraphicsScene::mouseReleaseEvent(event);
}
@@ -861,10 +901,11 @@ void TimelineGraphicsScene::keyReleaseEvent(QKeyEvent *keyEvent)
void TimelineGraphicsScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
+ // No context menu if user is pressing ALT (so panning/zooming timeline)
+ bool alt = event->modifiers() & Qt::AltModifier;
RowTree *row = m_rowManager->getRowAtPos(QPointF(0, event->scenePos().y()));
-
if (!row || m_widgetTimeline->isFullReconstructPending() || m_dragging
- || m_startRowMoverOnNextDrag || row->locked()) {
+ || m_startRowMoverOnNextDrag || row->locked() || alt) {
return;
}
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h
index 4166ca18..e452c12b 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/TimelineGraphicsScene.h
@@ -135,6 +135,7 @@ private:
RowManager *m_rowManager = nullptr;
KeyframeManager *m_keyframeManager = nullptr;
QPointF m_pressPos;
+ QPointF m_pressScreenPos;
QList<double> m_snapSteps;
CMouseCursor::Qt3DSMouseCursor m_currentCursor;
TimelineControl *m_timelineControl = nullptr;
@@ -143,6 +144,8 @@ private:
bool m_keyframePressed = false;
bool m_dragging = false;
bool m_startRowMoverOnNextDrag = false;
+ bool m_timelineZooming = false;
+ bool m_timelinePanning = false;
TimelineControlType m_clickedTimelineControlType = TimelineControlType::None;
TreeControlType m_clickedTreeControlType = TreeControlType::None;
double m_pressPosInKeyframe;
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp
index 385dda52..2bdeb2c5 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.cpp
@@ -86,7 +86,6 @@ TimelineToolbar::TimelineToolbar() : QToolBar()
m_scaleSlider->setFixedWidth(100);
m_scaleSlider->setMinimum(1);
m_scaleSlider->setMaximum(22);
- m_scaleSlider->setPageStep(.1);
m_scaleSlider->setValue(2);
m_timeLabel->setText(tr("0:00.000"));
diff --git a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h
index 0bd37377..3e65e45d 100644
--- a/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h
+++ b/src/Authoring/Studio/Palettes/TimelineGraphicsView/ui/TimelineToolbar.h
@@ -74,12 +74,12 @@ public:
public Q_SLOTS:
void updatePlayButtonState(bool started);
+ void onZoomInButtonClicked();
+ void onZoomOutButtonClicked();
private Q_SLOTS:
void onPlayButtonClicked();
void onZoomLevelChanged(int scale);
- void onZoomInButtonClicked();
- void onZoomOutButtonClicked();
void onDiButtonClicked();
private: