1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

Add middle mouse button drag in the GraphView

Handle middle mouse button in `mouseMoveEvent()` (new) and `mousePressEvent()` methods.

(Removed preprocessor conditions; deprecated QMouseEvent::pos() / QMouseEvent::x() were chosen.)
This commit is contained in:
imonlyfourteen 2024-06-04 11:34:44 +00:00 committed by GitHub
parent e09f4d47cd
commit 9bb04d7154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -346,11 +346,7 @@ void GraphView::mouseMoveEvent(QMouseEvent *e)
{
if (e->buttons() & Qt::MiddleButton) {
QScrollBar *sb = horizontalScrollBar();
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
int x = e->x();
#else // QT 5.15
int x = e->position().toPoint().x();
#endif // QT 5.15
sb->setSliderPosition(sb->sliderPosition() - (x - _xStartDrag));
_xStartDrag = x;
}
@ -360,17 +356,10 @@ void GraphView::mouseMoveEvent(QMouseEvent *e)
void GraphView::mousePressEvent(QMouseEvent *e)
{
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
if (e->button() == Qt::LeftButton)
newSliderPosition(mapToScene(e->pos()));
else if (e->button() == Qt::MiddleButton)
_xStartDrag = e->x();
#else // QT 5.15
if (e->button() == Qt::LeftButton)
newSliderPosition(mapToScene(e->position().toPoint()));
else if (e->button() == Qt::MiddleButton)
_xStartDrag = e->position().toPoint().x();
#endif // QT 5.15
QGraphicsView::mousePressEvent(e);
}