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:
@@ -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());
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "render/backend/opengl/opengltexture.h"
|
||||
#include "render/color.h"
|
||||
#include "render/colormanager.h"
|
||||
#include "tool/tool.h"
|
||||
#include "viewersafemargininfo.h"
|
||||
#include "widget/manageddisplay/manageddisplay.h"
|
||||
#include "widget/timetarget/timetarget.h"
|
||||
@@ -118,6 +119,8 @@ public slots:
|
||||
|
||||
void SetZoomData(bool flag, int percent);
|
||||
|
||||
void ToolChanged(Tool::Item tool);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the user starts dragging from the viewer
|
||||
@@ -214,6 +217,8 @@ private:
|
||||
*/
|
||||
QPoint position_;
|
||||
|
||||
bool hand_tool_;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief Slot to connect just before the OpenGL context is destroyed to clean up resources
|
||||
|
||||
Reference in New Issue
Block a user