Keep keyboard focus if scene item other than proxy widget is clicked

This commit is contained in:
G.K.MacGregor
2022-05-15 13:08:58 +01:00
parent ec4bdd6f7f
commit bcc0d0d8e7
2 changed files with 25 additions and 1 deletions

View File

@@ -703,6 +703,7 @@ void LevelOneScene::hideGUIElements(bool hidden)
} }
} }
// Implements Ctrl+mousewheel zoom
bool LevelOneScene::eventFilter(QObject *object, QEvent *event) bool LevelOneScene::eventFilter(QObject *object, QEvent *event)
{ {
Q_UNUSED(object); Q_UNUSED(object);
@@ -719,6 +720,26 @@ bool LevelOneScene::eventFilter(QObject *object, QEvent *event)
return false; 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) void LevelOneScene::setFullScreenColour(const QColor &newColor)
{ {
if (!static_cast<TeletextWidget *>(m_levelOneProxyWidget->widget())->pageRender()->mix()) { if (!static_cast<TeletextWidget *>(m_levelOneProxyWidget->widget())->pageRender()->mix()) {

View File

@@ -134,9 +134,12 @@ signals:
void mouseZoomIn(); void mouseZoomIn();
void mouseZoomOut(); void mouseZoomOut();
private: protected:
bool eventFilter(QObject *, QEvent *); bool eventFilter(QObject *, QEvent *);
void keyPressEvent(QKeyEvent *);
void keyReleaseEvent(QKeyEvent *);
private:
QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem; QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem;
QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25]; QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25];
QGraphicsProxyWidget *m_levelOneProxyWidget; QGraphicsProxyWidget *m_levelOneProxyWidget;