Improved drag-to-scroll activation on pinout widget, allowing for activation even in the absence of widget focus
This commit is contained in:
@@ -50,4 +50,23 @@ namespace Widgets::PinoutWidgets
|
||||
|
||||
QGraphicsView::keyReleaseEvent(event);
|
||||
}
|
||||
|
||||
void PinoutContainer::mousePressEvent(QMouseEvent* event) {
|
||||
if (this->dragMode() == QGraphicsView::DragMode::ScrollHandDrag) {
|
||||
return QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
|
||||
const auto modifiers = event->modifiers();
|
||||
if ((modifiers & Qt::KeyboardModifier::ControlModifier) != 0) {
|
||||
const auto viewSize = this->size();
|
||||
const auto sceneRect = this->pinoutScene->sceneRect();
|
||||
this->setDragMode(
|
||||
sceneRect.width() > viewSize.width() || sceneRect.height() > viewSize.height()
|
||||
? QGraphicsView::DragMode::ScrollHandDrag
|
||||
: QGraphicsView::DragMode::NoDrag
|
||||
);
|
||||
}
|
||||
|
||||
return QGraphicsView::mousePressEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QGraphicsView>
|
||||
#include <QResizeEvent>
|
||||
#include <QKeyEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include "src/Targets/TargetDescriptor.hpp"
|
||||
|
||||
@@ -21,6 +22,7 @@ namespace Widgets::PinoutWidgets
|
||||
void resizeEvent(QResizeEvent* event) override;
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
void keyReleaseEvent(QKeyEvent* event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
protected:
|
||||
const Targets::TargetDescriptor& targetDescriptor;
|
||||
|
||||
Reference in New Issue
Block a user