CTRL + scroll to zoom maps

This commit is contained in:
garak 2018-09-20 16:35:33 -04:00
parent b8836aa381
commit 730718e432
2 changed files with 36 additions and 1 deletions

View file

@ -680,6 +680,36 @@ void MainWindow::on_actionMap_Shift_triggered()
on_toolButton_Shift_clicked(); on_toolButton_Shift_clicked();
} }
void MainWindow::wheelEvent(QWheelEvent *event) {
const int THRESHOLD = 16;
QPoint moved = event->pixelDelta();
if (event->modifiers() & Qt::ControlModifier) {
ui->scrollArea->verticalScrollBar()->setEnabled(false);
ui->scrollArea->horizontalScrollBar()->setEnabled(false);
if (moved.y() >= THRESHOLD) {
scaleMapView(1);
event->accept();
}
else if (moved.y() <= -THRESHOLD) {
scaleMapView(-1);
event->accept();
}
}
}
void MainWindow::keyReleaseEvent(QKeyEvent *event) {
// when CTRL key is released after wheelEvent zooming, re-enable scrollbars
if(event->key() == Qt::Key_Control) {
ui->scrollArea->verticalScrollBar()->setEnabled(true);
ui->scrollArea->horizontalScrollBar()->setEnabled(true);
}
}
void MainWindow::scaleMapView(int s) { void MainWindow::scaleMapView(int s) {
if (s == 0) { // reset to default scale then scale again if (s == 0) { // reset to default scale then scale again
int scaleTo = editor->project->scale_exp; int scaleTo = editor->project->scale_exp;
@ -709,7 +739,7 @@ void MainWindow::scaleMapView(int s) {
void MainWindow::resetMapScale(int mag) void MainWindow::resetMapScale(int mag)
{ {
// safest way to un-scale map // easiest way to un-scale map
if (mag > 0) { if (mag > 0) {
for (int i = 0; i < mag; i++) { for (int i = 0; i < mag; i++) {
scaleMapView(-1); scaleMapView(-1);

View file

@ -9,6 +9,8 @@
#include <QGraphicsItemGroup> #include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent> #include <QGraphicsSceneMouseEvent>
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <QWheelEvent>
#include <QKeyEvent>
#include "project.h" #include "project.h"
#include "map.h" #include "map.h"
#include "editor.h" #include "editor.h"
@ -25,6 +27,9 @@ public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
virtual void wheelEvent(QWheelEvent *event);
virtual void keyReleaseEvent(QKeyEvent *event);
public slots: public slots:
void setStatusBarMessage(QString message, int timeout = 0); void setStatusBarMessage(QString message, int timeout = 0);