Skip to content

Commit

Permalink
Merge pull request #842 from TomHarte/QtMouseEscape
Browse files Browse the repository at this point in the history
Adds F8+F12 as an alternative mouse-release combo for Qt.
  • Loading branch information
TomHarte authored Oct 3, 2020
2 parents f4a23af + 3891285 commit dcf8cb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion OSBindings/Qt/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ void MainWindow::setWindowTitle() {
break;
}

if(mouseIsCaptured) title += " (press control+escape to release mouse)";
if(mouseIsCaptured) title += " (press control+escape or F8+F12 to release mouse)";

QMainWindow::setWindowTitle(title);
}
Expand Down
23 changes: 18 additions & 5 deletions OSBindings/Qt/scantargetwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,25 @@ void ScanTargetWidget::setMouseDelegate(MouseDelegate *delegate) {
setMouseTracking(delegate);
}

void ScanTargetWidget::keyReleaseEvent(QKeyEvent *event) {
// Releasing F8 or F12 needs to be tracked but doesn't actively do anything,
// so I'm counting that as a Qt ignore.
if(event->key() == Qt::Key_F8) f8State = false;
if(event->key() == Qt::Key_F12) f12State = false;
event->ignore();
}

void ScanTargetWidget::keyPressEvent(QKeyEvent *event) {
// Use CTRL+Escape to end mouse captured mode, if currently captured; otherwise ignore the event.
// Empirical note: control actually appears to mean command on the Mac. I have no idea what the
// Mac's command key would actually be as a modifier. Fingers crossed control means control
// elsewhere (?).
if(mouseIsCaptured && event->key() == Qt::Key_Escape && event->modifiers()&Qt::ControlModifier) {
// Use either CTRL+Escape or F8+F12 to end mouse captured mode, if currently captured;
// otherwise ignore the event.

if(event->key() == Qt::Key_F8) f8State = true;
if(event->key() == Qt::Key_F12) f12State = true;

if(mouseIsCaptured && (
(event->key() == Qt::Key_Escape && event->modifiers()&Qt::ControlModifier) ||
(f8State && f12State)
)) {
releaseMouse();

QCursor cursor;
Expand Down
2 changes: 2 additions & 0 deletions OSBindings/Qt/scantargetwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ScanTargetWidget : public QOpenGLWidget {
void mouseReleaseEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void keyPressEvent(QKeyEvent *) override;
void keyReleaseEvent(QKeyEvent *) override;

void releaseMouse();
void setMouseButtonPressed(Qt::MouseButton, bool);
Expand All @@ -66,6 +67,7 @@ class ScanTargetWidget : public QOpenGLWidget {

MouseDelegate *mouseDelegate = nullptr;
bool mouseIsCaptured = false;
bool f8State = false, f12State = false; // To support F8+F12 as a mouse release combination.

private slots:
void vsync();
Expand Down

0 comments on commit dcf8cb1

Please sign in to comment.