Add focus indication to editor and viewer header

This commit is contained in:
Veronica Berglyd Olsen
2024-06-18 22:42:52 +02:00
parent 930c60ae4a
commit c6569b63e5
4 changed files with 53 additions and 15 deletions
+23
View File
@@ -326,6 +326,11 @@ class GuiMain(QMainWindow):
def postLaunchTasks(self, cmdOpen: str | None) -> None:
"""Process tasks after the main window has been created."""
QApplication.processEvents()
app = QApplication.instance()
if isinstance(app, QApplication):
app.focusChanged.connect(self._appFocusChanged)
# Check that config loaded fine
if CONFIG.hasError:
SHARED.error(CONFIG.errorText())
@@ -948,6 +953,24 @@ class GuiMain(QMainWindow):
# Private Slots
##
@pyqtSlot("QWidget*", "QWidget*")
def _appFocusChanged(self, old: QWidget, new: QWidget) -> None:
"""Alert main widgets that they have received or lost focus."""
if isinstance(new, QWidget):
docEditor = False
docViewer = False
if self.docEditor.isAncestorOf(new):
docEditor = True
elif self.docViewer.isAncestorOf(new):
docViewer = True
self.docEditor.changeFocusState(docEditor)
self.docViewer.changeFocusState(docViewer)
logger.debug("Main focus switched to: %s", type(new).__name__)
return
@pyqtSlot(bool)
def _focusModeChanged(self, focusMode: bool) -> None:
"""Handle change of focus mode. The Main GUI Focus Mode hides