From 98c50a41d3b8754f49802eb151b52133080586a9 Mon Sep 17 00:00:00 2001 From: Jesse Litton Date: Sat, 12 Aug 2017 10:54:49 -0500 Subject: [PATCH] Fix Ctrl/Alt key handling. --- docs/RELEASES | 3 +++ src/mainwindow.cpp | 1 - src/svgmapview.cpp | 27 +++++---------------------- src/svgmapview.h | 4 ---- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/docs/RELEASES b/docs/RELEASES index 6242c3f..232c4b3 100644 --- a/docs/RELEASES +++ b/docs/RELEASES @@ -6,6 +6,9 @@ didn't show itself when using Qt with Unity, but it does with KDE (and presumably Windows). + Change handling of ctrl/alt keys so that their up/down states + can no longer get out of sync when swapping between windows. + 0.9.4.1 - Fixed bug where #defines were not working with newest qt/gcc. (thanks Hibasnev!) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index e85c7e1..a56c6b2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1537,7 +1537,6 @@ void MainWindow::findLocation(const QString& location) QString fullName = regionMap->getSystemByAbbreviation(location.toUpper()); ui->mapView->findLocation(fullName); positionTo(regionMap->getSystemByAbbreviation(location)); - ui->mapView->resetCtrl(); } void MainWindow::logDirChanged(const QString& dir) diff --git a/src/svgmapview.cpp b/src/svgmapview.cpp index b8441b0..8f73083 100755 --- a/src/svgmapview.cpp +++ b/src/svgmapview.cpp @@ -19,6 +19,7 @@ */ #include "svgmapview.h" +#include // for queryKeyboardModifiers #include #include #include @@ -147,29 +148,11 @@ void SvgMapView::setLoadText(const QString text) void SvgMapView::keyPressEvent(QKeyEvent *event) { - if(event->key() == Qt::Key::Key_Control) - { - controlKeyDown = true; - } - else if(event->key() == Qt::Key::Key_Alt) - { - altKeyDown = true; - } - QGraphicsView::keyPressEvent(event); } void SvgMapView::keyReleaseEvent(QKeyEvent *event) { - if(event->key() == Qt::Key::Key_Control) - { - controlKeyDown = false; - } - else if(event->key() == Qt::Key::Key_Alt) - { - altKeyDown = false; - } - QGraphicsView::keyReleaseEvent(event); } @@ -180,8 +163,6 @@ void SvgMapView::mouseMoveEvent(QMouseEvent *event) void SvgMapView::mousePressEvent(QMouseEvent *event) { - - return QGraphicsView::mousePressEvent(event); } @@ -193,11 +174,13 @@ void SvgMapView::mouseReleaseEvent(QMouseEvent *event) void SvgMapView::wheelEvent(QWheelEvent *event) { - if(altKeyDown == true && controlKeyDown == true) + Qt::KeyboardModifiers mods = QApplication::queryKeyboardModifiers(); + + if(mods.testFlag(Qt::AltModifier) && mods.testFlag(Qt::ControlModifier)) { emit sendOpacity(event->delta()); } - else if(controlKeyDown) + else if(mods.testFlag(Qt::ControlModifier)) { setTransformationAnchor(AnchorViewCenter); qreal angle = event->delta() * .025f; diff --git a/src/svgmapview.h b/src/svgmapview.h index 9eec7e7..b81d20c 100755 --- a/src/svgmapview.h +++ b/src/svgmapview.h @@ -86,8 +86,6 @@ class SvgMapView : public QGraphicsView void addLine(QGraphicsLineItem *line); void updateLinesColor(QColor color); - void resetCtrl(){controlKeyDown = false;} - void openWormhole(const QString &systemName); void closeWormhole(const QString &systemName); @@ -144,8 +142,6 @@ public slots: QString m_pilotGraphic; QColor m_linesColor; - bool altKeyDown = false; - bool controlKeyDown = false; bool drawBridges = false; float zoom = 1;