diff options
author | Tomi Korpipaa <tomi.korpipaa@qt.io> | 2018-03-13 09:37:23 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@qt.io> | 2018-03-13 10:12:00 +0000 |
commit | be95fd911daa1145ba464b7520ea938f0cd523fe (patch) | |
tree | a6fe44944de705f7b41253c08dff82e0edbaefed | |
parent | 0e624d198b7bf24c34991341ce0e5d5323c9119b (diff) |
Allow scrolling the scene view with mouse wheel or trackpad
Task-number: QT3DS-515
Change-Id: I00b2b089e8b916bdd5f213fa876d86827373d53c
Reviewed-by: Janne Kangas <janne.kangas@qt.io>
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r-- | src/Authoring/Studio/_Win/UI/PlayerContainerWnd.cpp | 83 | ||||
-rw-r--r-- | src/Authoring/Studio/_Win/UI/PlayerContainerWnd.h | 4 |
2 files changed, 46 insertions, 41 deletions
diff --git a/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.cpp b/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.cpp index 6a233e13..9572fca3 100644 --- a/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.cpp +++ b/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.cpp @@ -67,7 +67,7 @@ */ //============================================================================== CPlayerContainerWnd::CPlayerContainerWnd(CSceneView *inSceneView) - : QAbstractScrollArea(inSceneView) + : QScrollArea(inSceneView) , m_SceneView(inSceneView) , m_PlayerWnd(NULL) , m_IsMouseDown(false) @@ -116,7 +116,7 @@ void CPlayerContainerWnd::SetPlayerWndPosition(long &outLeftPresentationEdge, // Horizontal scrollbar does not exist if (m_ClientRect.width() < theClientRect.width()) { theHScrollPosition = - theClientRect.left() + (theClientRect.width() / 2) - (m_ClientRect.width() / 2); + theClientRect.left() + (theClientRect.width() / 2) - (m_ClientRect.width() / 2); outLeftPresentationEdge = theHScrollPosition; } else // This stays a negated value outLeftPresentationEdge = theHScrollPosition; @@ -124,13 +124,14 @@ void CPlayerContainerWnd::SetPlayerWndPosition(long &outLeftPresentationEdge, // Vertical scrollbar does not exist if (m_ClientRect.height() < theClientRect.height()) { theVScrollPosition = - theClientRect.top() + (theClientRect.height() / 2) - (m_ClientRect.height() / 2); + theClientRect.top() + (theClientRect.height() / 2) - (m_ClientRect.height() / 2); outTopPresentionEdge = theVScrollPosition; } else // This stays a negated value outTopPresentionEdge = theVScrollPosition; // Move the child player window - m_PlayerWnd->setGeometry(QRect(QPoint(theHScrollPosition, theVScrollPosition), m_ClientRect.size())); + m_PlayerWnd->setGeometry(QRect(QPoint(theHScrollPosition, theVScrollPosition), + m_ClientRect.size())); } //============================================================================== @@ -218,13 +219,15 @@ void CPlayerContainerWnd::RecenterClient() if (theClientSize.width() > theViewClientRect.width()) { // compute the size of the client rectangle to display m_ClientRect.setLeft( - (theViewClientRect.width() / 2) - (theClientSize.width() / 2) - (theClientSize.width() % 2)); + (theViewClientRect.width() / 2) - (theClientSize.width() / 2) + - (theClientSize.width() % 2)); m_ClientRect.setRight((theViewClientRect.width() / 2) + (theClientSize.width() / 2)); } if (theClientSize.height() > theViewClientRect.height()) { m_ClientRect.setTop( - (theViewClientRect.height() / 2) - (theClientSize.height() / 2) - (theClientSize.height() % 2)); + (theViewClientRect.height() / 2) - (theClientSize.height() / 2) + - (theClientSize.height() % 2)); m_ClientRect.setBottom((theViewClientRect.height() / 2) + (theClientSize.height() / 2)); } } @@ -301,34 +304,34 @@ void CPlayerContainerWnd::mousePressEvent(QMouseEvent *event) //============================================================================== void CPlayerContainerWnd::mouseReleaseEvent(QMouseEvent *event) { - if ((event->button() == Qt::LeftButton) || (event->button() == Qt::RightButton)) { - // Need to commit the current command when we have a mouse up. :) - g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseUp(SceneDragSenderType::Matte); - g_StudioApp.GetCore()->CommitCurrentCommand(); - m_IsMouseDown = false; - } else if (event->button() == Qt::MiddleButton) { - g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseUp(SceneDragSenderType::Matte); - g_StudioApp.GetCore()->CommitCurrentCommand(); - if (m_IsMiddleMouseDown) { - m_IsMouseDown = false; - m_IsMiddleMouseDown = false; - - const bool theCtrlKeyIsDown = event->modifiers() & Qt::ControlModifier; - const bool theAltKeyIsDown = event->modifiers() & Qt::AltModifier; - - if (!IsDeploymentView()) { - if (!theCtrlKeyIsDown && !theAltKeyIsDown) { - // none of the modifier key is pressed... reset to previous tool - m_SceneView->RestorePreviousTool(); - } else if (theCtrlKeyIsDown && theAltKeyIsDown) { - // since both modifier is down... let the ctrl has priority - m_SceneView->SetToolOnCtrl(); - } - m_SceneView->SetViewCursor(); - Q_EMIT toolChanged(); - } - } - } + if ((event->button() == Qt::LeftButton) || (event->button() == Qt::RightButton)) { + // Need to commit the current command when we have a mouse up. :) + g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseUp(SceneDragSenderType::Matte); + g_StudioApp.GetCore()->CommitCurrentCommand(); + m_IsMouseDown = false; + } else if (event->button() == Qt::MiddleButton) { + g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseUp(SceneDragSenderType::Matte); + g_StudioApp.GetCore()->CommitCurrentCommand(); + if (m_IsMiddleMouseDown) { + m_IsMouseDown = false; + m_IsMiddleMouseDown = false; + + const bool theCtrlKeyIsDown = event->modifiers() & Qt::ControlModifier; + const bool theAltKeyIsDown = event->modifiers() & Qt::AltModifier; + + if (!IsDeploymentView()) { + if (!theCtrlKeyIsDown && !theAltKeyIsDown) { + // none of the modifier key is pressed... reset to previous tool + m_SceneView->RestorePreviousTool(); + } else if (theCtrlKeyIsDown && theAltKeyIsDown) { + // since both modifier is down... let the ctrl has priority + m_SceneView->SetToolOnCtrl(); + } + m_SceneView->SetViewCursor(); + Q_EMIT toolChanged(); + } + } + } } //============================================================================== @@ -356,7 +359,7 @@ void CPlayerContainerWnd::mouseMoveEvent(QMouseEvent* event) long theToolMode = g_StudioApp.GetToolMode(); g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseDrag( - SceneDragSenderType::Matte, event->pos(), theToolMode, theModifierKeys); + SceneDragSenderType::Matte, event->pos(), theToolMode, theModifierKeys); } } @@ -380,9 +383,12 @@ void CPlayerContainerWnd::wheelEvent(QWheelEvent* event) const bool theAltKeyIsDown = event->modifiers() & Qt::AltModifier; // Mouse Wheel zooms the camera - if (!theCtrlKeyIsDown && !theAltKeyIsDown && !IsDeploymentView()) + if (!theCtrlKeyIsDown && !theAltKeyIsDown && !IsDeploymentView()) { g_StudioApp.GetCore()->GetDispatch()->FireSceneMouseWheel( - SceneDragSenderType::Matte, event->delta(), STUDIO_TOOLMODE_CAMERA_ZOOM); + SceneDragSenderType::Matte, event->delta(), STUDIO_TOOLMODE_CAMERA_ZOOM); + } else { + QScrollArea::wheelEvent(event); + } } void CPlayerContainerWnd::scrollContentsBy(int, int) @@ -445,9 +451,8 @@ QSize CPlayerContainerWnd::GetEffectivePresentationSize() const // presentation // This is a very dirty hack because we are of course hardcoding the size of the guides. // If the size of the guides never changes, the bet paid off. - if (g_StudioApp.GetRenderer().AreGuidesEnabled()) { + if (g_StudioApp.GetRenderer().AreGuidesEnabled()) theSize += QSize(32, 32); - } return theSize / fixedDevicePixelRatio(); } diff --git a/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.h b/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.h index 055be9af..08a33d1c 100644 --- a/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.h +++ b/src/Authoring/Studio/_Win/UI/PlayerContainerWnd.h @@ -35,7 +35,7 @@ #pragma once -#include <QScrollArea> +#include <QtWidgets/qscrollarea.h> class CSceneView; class CStudioApp; @@ -46,7 +46,7 @@ class CWGLRenderContext; // Class CPlayerContainerWnd //============================================================================== -class CPlayerContainerWnd : public QAbstractScrollArea +class CPlayerContainerWnd : public QScrollArea { Q_OBJECT //============================================================================== |