diff --git a/mainwidget.cpp b/mainwidget.cpp index 79f98fd..c4ac08c 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -703,6 +703,7 @@ void LevelOneScene::hideGUIElements(bool hidden) } } +// Implements Ctrl+mousewheel zoom bool LevelOneScene::eventFilter(QObject *object, QEvent *event) { Q_UNUSED(object); @@ -719,6 +720,26 @@ bool LevelOneScene::eventFilter(QObject *object, QEvent *event) return false; } +// Clicking outside the main text widget but still within the scene would +// cause keyboard focus loss. +// So on every keypress within the scene, wrench the focus back to the widget +// if necessary. +void LevelOneScene::keyPressEvent(QKeyEvent *keyEvent) +{ + if (focusItem() != m_levelOneProxyWidget) + setFocusItem(m_levelOneProxyWidget); + + QGraphicsScene::keyPressEvent(keyEvent); +} + +void LevelOneScene::keyReleaseEvent(QKeyEvent *keyEvent) +{ + if (focusItem() != m_levelOneProxyWidget) + setFocusItem(m_levelOneProxyWidget); + + QGraphicsScene::keyReleaseEvent(keyEvent); +} + void LevelOneScene::setFullScreenColour(const QColor &newColor) { if (!static_cast(m_levelOneProxyWidget->widget())->pageRender()->mix()) { diff --git a/mainwidget.h b/mainwidget.h index 27be91f..7549a1f 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -134,9 +134,12 @@ signals: void mouseZoomIn(); void mouseZoomOut(); -private: +protected: bool eventFilter(QObject *, QEvent *); + void keyPressEvent(QKeyEvent *); + void keyReleaseEvent(QKeyEvent *); +private: QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem; QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25]; QGraphicsProxyWidget *m_levelOneProxyWidget;