Merge pull request #1239 from simonsonc/viewer-wheel-event
viewer: add mouse wheel zooming
This commit is contained in:
commit
edd5148aa4
2 changed files with 27 additions and 0 deletions
|
@ -289,6 +289,32 @@ void MapWidget::mouseReleaseEvent(QMouseEvent* e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapWidget::wheelEvent(QWheelEvent* e)
|
||||||
|
{
|
||||||
|
if (!map_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPoint corner(map_->width(), map_->height());
|
||||||
|
QPoint zoomCoords;
|
||||||
|
double zoom;
|
||||||
|
if (e->delta() > 0)
|
||||||
|
{
|
||||||
|
zoom = 0.5;
|
||||||
|
QPoint center = corner / 2;
|
||||||
|
QPoint delta = e->pos() - center;
|
||||||
|
zoomCoords = zoom * delta + center;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zoom = 2.0;
|
||||||
|
zoomCoords = corner - e->pos();
|
||||||
|
}
|
||||||
|
|
||||||
|
map_->pan_and_zoom(zoomCoords.x(), zoomCoords.y(), zoom);
|
||||||
|
updateMap();
|
||||||
|
}
|
||||||
|
|
||||||
void MapWidget::keyPressEvent(QKeyEvent *e)
|
void MapWidget::keyPressEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,6 +99,7 @@ protected:
|
||||||
void mousePressEvent(QMouseEvent* e);
|
void mousePressEvent(QMouseEvent* e);
|
||||||
void mouseMoveEvent(QMouseEvent* e);
|
void mouseMoveEvent(QMouseEvent* e);
|
||||||
void mouseReleaseEvent(QMouseEvent* e);
|
void mouseReleaseEvent(QMouseEvent* e);
|
||||||
|
void wheelEvent(QWheelEvent* e);
|
||||||
void keyPressEvent(QKeyEvent *e);
|
void keyPressEvent(QKeyEvent *e);
|
||||||
void export_to_file(unsigned width,
|
void export_to_file(unsigned width,
|
||||||
unsigned height,
|
unsigned height,
|
||||||
|
|
Loading…
Reference in a new issue