diff options
author | David Schulz <david.schulz@qt.io> | 2020-08-13 14:53:42 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2020-08-20 06:20:40 +0000 |
commit | 158fd92558dd1af8745612d2b6e30a3c40e7f8d2 (patch) | |
tree | df61c7b8377731fa579e02b1030894e5bba30289 | |
parent | 790757a8e8092e490bb6455a7ce290b35138fe50 (diff) |
SCXML: fix magnifier not hiding
Fixes: QTCREATORBUG-24463
Change-Id: I835550e32467992ea7ad2555c546d810e6e0bbad
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r-- | src/plugins/scxmleditor/common/magnifier.cpp | 18 | ||||
-rw-r--r-- | src/plugins/scxmleditor/common/magnifier.h | 3 | ||||
-rw-r--r-- | src/plugins/scxmleditor/common/mainwidget.cpp | 1 |
3 files changed, 22 insertions, 0 deletions
diff --git a/src/plugins/scxmleditor/common/magnifier.cpp b/src/plugins/scxmleditor/common/magnifier.cpp index 7b92176ada..c975c7a724 100644 --- a/src/plugins/scxmleditor/common/magnifier.cpp +++ b/src/plugins/scxmleditor/common/magnifier.cpp @@ -63,12 +63,16 @@ void Magnifier::showEvent(QShowEvent *e) { QWidget::showEvent(e); grabMouse(); + qApp->installEventFilter(this); + emit visibilityChanged(true); } void Magnifier::hideEvent(QHideEvent *e) { QWidget::hideEvent(e); releaseMouse(); + qApp->removeEventFilter(this); + emit visibilityChanged(false); } void Magnifier::mousePressEvent(QMouseEvent *e) @@ -98,6 +102,20 @@ void Magnifier::wheelEvent(QWheelEvent *e) m_ui.m_graphicsView->centerOn(m_mainView->mapToScene(pos() - m_topLeft + rect().center())); } +bool Magnifier::eventFilter(QObject * /*obj*/, QEvent *event) +{ + if (event->type() == QEvent::KeyRelease + && static_cast<QKeyEvent *>(event)->key() == Qt::Key_Alt) { + setVisible(false); + } + if (event->type() == QEvent::ApplicationStateChange + && QGuiApplication::applicationState() != Qt::ApplicationActive) { + setVisible(false); + } + + return false; +} + void Magnifier::moveEvent(QMoveEvent *e) { QWidget::moveEvent(e); diff --git a/src/plugins/scxmleditor/common/magnifier.h b/src/plugins/scxmleditor/common/magnifier.h index 2fa9fd23a3..cfbc4ff9ef 100644 --- a/src/plugins/scxmleditor/common/magnifier.h +++ b/src/plugins/scxmleditor/common/magnifier.h @@ -51,8 +51,11 @@ public: void setCurrentScene(PluginInterface::GraphicsScene *scene); void setTopLeft(const QPoint &topLeft); + bool eventFilter(QObject *obj, QEvent *event) override; + signals: void clicked(double zoomLevel); + void visibilityChanged(bool hidden); protected: void resizeEvent(QResizeEvent *e) override; diff --git a/src/plugins/scxmleditor/common/mainwidget.cpp b/src/plugins/scxmleditor/common/mainwidget.cpp index 766161cfdf..54131bd684 100644 --- a/src/plugins/scxmleditor/common/mainwidget.cpp +++ b/src/plugins/scxmleditor/common/mainwidget.cpp @@ -513,6 +513,7 @@ void MainWidget::addStateView(BaseItem *item) }); connect(view->view(), &GraphicsView::panningChanged, m_actionHandler->action(ActionPan), &QAction::setChecked); connect(view->view(), &GraphicsView::magnifierChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked); + connect(m_magnifier, &Magnifier::visibilityChanged, m_actionHandler->action(ActionMagnifier), &QAction::setChecked); connect(view->scene(), &GraphicsScene::openStateView, this, &MainWidget::addStateView, Qt::QueuedConnection); connect(view->scene(), &GraphicsScene::selectedStateCountChanged, this, [this](int count) { bool currentView = sender() == m_views.last()->scene(); |