From 1f4e15314c73516a03a7767dfc9a51f244446ac0 Mon Sep 17 00:00:00 2001 From: danteruiz Date: Fri, 30 Aug 2019 08:48:25 -0700 Subject: [PATCH] enable dragging the window --- launchers/qt/src/LauncherWindow.cpp | 19 +++++++++++++------ launchers/qt/src/LauncherWindow.h | 6 +++++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/launchers/qt/src/LauncherWindow.cpp b/launchers/qt/src/LauncherWindow.cpp index c647ac6e4e..b86c2ca84c 100644 --- a/launchers/qt/src/LauncherWindow.cpp +++ b/launchers/qt/src/LauncherWindow.cpp @@ -2,30 +2,37 @@ #include +#include + void LauncherWindow::keyPressEvent(QKeyEvent* event) { QQuickView::keyPressEvent(event); if (!event->isAccepted()) { - // std::cout << "Key press event\n"; } } void LauncherWindow::mousePressEvent(QMouseEvent* event) { QQuickView::mousePressEvent(event); if (!event->isAccepted()) { - //std::cout << "mouse press event\n"; + if (event->button() == Qt::LeftButton) { + _drag = true; + _previousMousePos = QCursor::pos(); + } } } void LauncherWindow::mouseReleaseEvent(QMouseEvent* event) { QQuickView::mouseReleaseEvent(event); - if (!event->isAccepted()) { - //std::cout << "mouse release event\n"; - } + _drag = false; } void LauncherWindow::mouseMoveEvent(QMouseEvent* event) { QQuickView::mouseMoveEvent(event); if (!event->isAccepted()) { - // std::cout << "mouse move event\n"; + if (_drag) { + QPoint cursorPos = QCursor::pos(); + QPoint offset = _previousMousePos - cursorPos; + _previousMousePos = cursorPos; + setPosition(position() - offset); + } } } diff --git a/launchers/qt/src/LauncherWindow.h b/launchers/qt/src/LauncherWindow.h index 903b0397dc..394d9aed41 100644 --- a/launchers/qt/src/LauncherWindow.h +++ b/launchers/qt/src/LauncherWindow.h @@ -1,5 +1,5 @@ #include - +#include class LauncherWindow : public QQuickView { public: @@ -7,4 +7,8 @@ public: void mousePressEvent(QMouseEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; + +private: + bool _drag { false }; + QPoint _previousMousePos; };