Add hand tool dragging

If Hand Tool is selected we can now drag with a left click AS WELL AS
middle click. This keeps the view behaviour in line with other widgets
in Olive.

For simplicity it does not use handmovableview.
This commit is contained in:
Thomas Wilshaw
2020-06-16 14:41:35 +01:00
parent 7617ddabe3
commit 100da912ad
2 changed files with 22 additions and 2 deletions
+17 -2
View File
@@ -35,6 +35,7 @@
#include "render/backend/opengl/openglrenderfunctions.h"
#include "render/backend/opengl/openglshader.h"
#include "render/pixelformat.h"
#include "core.h"
OLIVE_NAMESPACE_ENTER
@@ -51,6 +52,9 @@ ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
zoomed_(false),
zoom_multiplier_(1.0)
{
connect(Core::instance(), &Core::ToolChanged, this, &ViewerDisplayWidget::ToolChanged);
ToolChanged(Core::instance()->tool());
}
ViewerDisplayWidget::~ViewerDisplayWidget()
@@ -84,6 +88,17 @@ void ViewerDisplayWidget::SetZoomData(bool flag, int percent)
}
}
void ViewerDisplayWidget::ToolChanged(Tool::Item tool)
{
if (tool == Tool::kHand) {
hand_tool_ = true;
setCursor(Qt::OpenHandCursor);
} else {
hand_tool_ = false;
unsetCursor();
}
}
QMatrix4x4 ViewerDisplayWidget::GetCompleteMatrix()
{
QMatrix4x4 mat;
@@ -180,7 +195,7 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
}
// If translation is enabled get current position in preperation for move event
if (event->button() == Qt::MiddleButton && zoomed_) {
if ((event->button() == Qt::MiddleButton || hand_tool_) && zoomed_) {
position_ = event->pos();
return;
}
@@ -195,7 +210,7 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
{
// Only allow translation if the image is larger than the container widget
if (event->buttons() & Qt::MiddleButton && zoomed_) {
if ((event->buttons() & Qt::MiddleButton || hand_tool_) && zoomed_) {
QPointF delta = event->pos() - position_;
// scale delta to widget size and zoom level
delta.setX(zoom_multiplier_ * delta.x() / width());