mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 11:45:53 +01:00
Add middle mouse button drag in the GraphView
Handle middle mouse button in `mouseMoveEvent()` (new) and `mousePressEvent()` methods.
This commit is contained in:
parent
74cf139b01
commit
e09f4d47cd
@ -342,10 +342,35 @@ void GraphView::resizeEvent(QResizeEvent *e)
|
|||||||
QGraphicsView::resizeEvent(e);
|
QGraphicsView::resizeEvent(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsView::mouseMoveEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
void GraphView::mousePressEvent(QMouseEvent *e)
|
void GraphView::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
|
||||||
if (e->button() == Qt::LeftButton)
|
if (e->button() == Qt::LeftButton)
|
||||||
newSliderPosition(mapToScene(e->pos()));
|
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);
|
QGraphicsView::mousePressEvent(e);
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ protected:
|
|||||||
void setUnits(Units units);
|
void setUnits(Units units);
|
||||||
|
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *e);
|
||||||
|
void mouseMoveEvent(QMouseEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
void wheelEvent(QWheelEvent *e);
|
void wheelEvent(QWheelEvent *e);
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e);
|
||||||
@ -122,6 +123,7 @@ private:
|
|||||||
qreal _minYRange;
|
qreal _minYRange;
|
||||||
|
|
||||||
qreal _zoom;
|
qreal _zoom;
|
||||||
|
int _xStartDrag;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHVIEW_H
|
#endif // GRAPHVIEW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user