Let the shared class handle focus mode change to disconnect editor header from main GUI
This commit is contained in:
@@ -548,8 +548,8 @@ class GuiDocEditor(QPlainTextEdit):
|
|||||||
sH = hBar.height() if hBar.isVisible() else 0
|
sH = hBar.height() if hBar.isVisible() else 0
|
||||||
|
|
||||||
tM = self._vpMargin
|
tM = self._vpMargin
|
||||||
if CONFIG.textWidth > 0 or self.mainGui.isFocusMode:
|
if CONFIG.textWidth > 0 or SHARED.focusMode:
|
||||||
tW = CONFIG.getTextWidth(self.mainGui.isFocusMode)
|
tW = CONFIG.getTextWidth(SHARED.focusMode)
|
||||||
tM = max((wW - sW - tW)//2, self._vpMargin)
|
tM = max((wW - sW - tW)//2, self._vpMargin)
|
||||||
|
|
||||||
tB = self.frameWidth()
|
tB = self.frameWidth()
|
||||||
@@ -2894,6 +2894,9 @@ class GuiDocEditHeader(QWidget):
|
|||||||
|
|
||||||
self.setLayout(self.outerBox)
|
self.setLayout(self.outerBox)
|
||||||
|
|
||||||
|
# Other Signals
|
||||||
|
SHARED.focusModeChanged.connect(self._focusModeChanged)
|
||||||
|
|
||||||
# Fix Margins and Size
|
# Fix Margins and Size
|
||||||
# This is needed for high DPI systems. See issue #499.
|
# This is needed for high DPI systems. See issue #499.
|
||||||
self.setContentsMargins(0, 0, 0, 0)
|
self.setContentsMargins(0, 0, 0, 0)
|
||||||
@@ -2997,17 +3000,6 @@ class GuiDocEditHeader(QWidget):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def updateFocusMode(self) -> None:
|
|
||||||
"""Update the minimise/maximise icon of the Focus Mode button.
|
|
||||||
This function is called by the GuiMain class via the
|
|
||||||
toggleFocusMode function and should not be activated directly.
|
|
||||||
"""
|
|
||||||
if self.mainGui.isFocusMode:
|
|
||||||
self.minmaxButton.setIcon(SHARED.theme.getIcon("minimise"))
|
|
||||||
else:
|
|
||||||
self.minmaxButton.setIcon(SHARED.theme.getIcon("maximise"))
|
|
||||||
return
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Private Slots
|
# Private Slots
|
||||||
##
|
##
|
||||||
@@ -3025,6 +3017,12 @@ class GuiDocEditHeader(QWidget):
|
|||||||
self.docEditor.setCursorLine(blockNumber + 1)
|
self.docEditor.setCursorLine(blockNumber + 1)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(bool)
|
||||||
|
def _focusModeChanged(self, focusMode: bool) -> None:
|
||||||
|
"""Update minimise/maximise icon of the Focus Mode button."""
|
||||||
|
self.minmaxButton.setIcon(SHARED.theme.getIcon("minimise" if focusMode else "maximise"))
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Events
|
# Events
|
||||||
##
|
##
|
||||||
|
|||||||
+18
-20
@@ -104,9 +104,6 @@ class GuiMain(QMainWindow):
|
|||||||
# Initialise UserData Instance
|
# Initialise UserData Instance
|
||||||
SHARED.initSharedData(self, GuiTheme())
|
SHARED.initSharedData(self, GuiTheme())
|
||||||
|
|
||||||
# Core Settings
|
|
||||||
self.isFocusMode = False
|
|
||||||
|
|
||||||
# Prepare Main Window
|
# Prepare Main Window
|
||||||
self.resize(*CONFIG.mainWinSize)
|
self.resize(*CONFIG.mainWinSize)
|
||||||
self._updateWindowTitle()
|
self._updateWindowTitle()
|
||||||
@@ -233,6 +230,7 @@ class GuiMain(QMainWindow):
|
|||||||
SHARED.projectStatusChanged.connect(self.mainStatus.updateProjectStatus)
|
SHARED.projectStatusChanged.connect(self.mainStatus.updateProjectStatus)
|
||||||
SHARED.projectStatusMessage.connect(self.mainStatus.setStatusMessage)
|
SHARED.projectStatusMessage.connect(self.mainStatus.setStatusMessage)
|
||||||
SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage)
|
SHARED.spellLanguageChanged.connect(self.mainStatus.setLanguage)
|
||||||
|
SHARED.focusModeChanged.connect(self._focusModeChanged)
|
||||||
SHARED.indexChangedTags.connect(self.docViewerPanel.updateChangedTags)
|
SHARED.indexChangedTags.connect(self.docViewerPanel.updateChangedTags)
|
||||||
SHARED.indexScannedText.connect(self.docViewerPanel.projectItemChanged)
|
SHARED.indexScannedText.connect(self.docViewerPanel.projectItemChanged)
|
||||||
SHARED.indexScannedText.connect(self.projView.updateItemValues)
|
SHARED.indexScannedText.connect(self.projView.updateItemValues)
|
||||||
@@ -532,8 +530,8 @@ class GuiMain(QMainWindow):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Disable focus mode if it is active
|
# Disable focus mode if it is active
|
||||||
if self.isFocusMode:
|
if SHARED.focusMode:
|
||||||
self.toggleFocusMode()
|
SHARED.setFocusMode(False)
|
||||||
|
|
||||||
self.docEditor.saveCursorPosition()
|
self.docEditor.saveCursorPosition()
|
||||||
if self.docEditor.docChanged:
|
if self.docEditor.docChanged:
|
||||||
@@ -747,7 +745,7 @@ class GuiMain(QMainWindow):
|
|||||||
if not SHARED.hasProject:
|
if not SHARED.hasProject:
|
||||||
logger.error("No project open")
|
logger.error("No project open")
|
||||||
return False
|
return False
|
||||||
if tHandle is None and (self.docEditor.anyFocus() or self.isFocusMode):
|
if tHandle is None and (self.docEditor.anyFocus() or SHARED.focusMode):
|
||||||
tHandle = self.docEditor.docHandle
|
tHandle = self.docEditor.docHandle
|
||||||
self.projView.renameTreeItem(tHandle)
|
self.projView.renameTreeItem(tHandle)
|
||||||
return True
|
return True
|
||||||
@@ -919,7 +917,7 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
logger.info("Exiting novelWriter")
|
logger.info("Exiting novelWriter")
|
||||||
|
|
||||||
if not self.isFocusMode:
|
if not SHARED.focusMode:
|
||||||
CONFIG.setMainPanePos(self.splitMain.sizes())
|
CONFIG.setMainPanePos(self.splitMain.sizes())
|
||||||
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
CONFIG.setOutlinePanePos(self.outlineView.splitSizes())
|
||||||
if self.docViewerPanel.isVisible():
|
if self.docViewerPanel.isVisible():
|
||||||
@@ -997,30 +995,31 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def toggleFocusMode(self) -> None:
|
def toggleFocusMode(self) -> None:
|
||||||
"""Handle toggle focus mode. The Main GUI Focus Mode hides tree,
|
"""Toggle focus mode."""
|
||||||
|
if self.docEditor.docHandle:
|
||||||
|
SHARED.setFocusMode(not SHARED.focusMode)
|
||||||
|
return
|
||||||
|
|
||||||
|
@pyqtSlot(bool)
|
||||||
|
def _focusModeChanged(self, focusMode: bool) -> None:
|
||||||
|
"""Handle change of focus mode. The Main GUI Focus Mode hides tree,
|
||||||
view, statusbar and menu.
|
view, statusbar and menu.
|
||||||
"""
|
"""
|
||||||
if self.docEditor.docHandle is None:
|
if focusMode:
|
||||||
logger.error("No document open, so not activating Focus Mode")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.isFocusMode = not self.isFocusMode
|
|
||||||
if self.isFocusMode:
|
|
||||||
logger.debug("Activating Focus Mode")
|
logger.debug("Activating Focus Mode")
|
||||||
self.switchFocus(nwWidget.EDITOR)
|
self.switchFocus(nwWidget.EDITOR)
|
||||||
else:
|
else:
|
||||||
logger.debug("Deactivating Focus Mode")
|
logger.debug("Deactivating Focus Mode")
|
||||||
|
|
||||||
cursorVisible = self.docEditor.cursorIsVisible()
|
cursorVisible = self.docEditor.cursorIsVisible()
|
||||||
isVisible = not self.isFocusMode
|
isVisible = not focusMode
|
||||||
self.treePane.setVisible(isVisible)
|
self.treePane.setVisible(isVisible)
|
||||||
self.mainStatus.setVisible(isVisible)
|
self.mainStatus.setVisible(isVisible)
|
||||||
self.mainMenu.setVisible(isVisible)
|
self.mainMenu.setVisible(isVisible)
|
||||||
self.sideBar.setVisible(isVisible)
|
self.sideBar.setVisible(isVisible)
|
||||||
|
|
||||||
hideDocFooter = self.isFocusMode and CONFIG.hideFocusFooter
|
hideDocFooter = focusMode and CONFIG.hideFocusFooter
|
||||||
self.docEditor.docFooter.setVisible(not hideDocFooter)
|
self.docEditor.docFooter.setVisible(not hideDocFooter)
|
||||||
self.docEditor.docHeader.updateFocusMode()
|
|
||||||
|
|
||||||
if self.splitView.isVisible():
|
if self.splitView.isVisible():
|
||||||
self.splitView.setVisible(False)
|
self.splitView.setVisible(False)
|
||||||
@@ -1029,7 +1028,6 @@ class GuiMain(QMainWindow):
|
|||||||
|
|
||||||
if cursorVisible:
|
if cursorVisible:
|
||||||
self.docEditor.ensureCursorVisibleNoCentre()
|
self.docEditor.ensureCursorVisibleNoCentre()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(nwWidget)
|
@pyqtSlot(nwWidget)
|
||||||
@@ -1279,8 +1277,8 @@ class GuiMain(QMainWindow):
|
|||||||
"""Process escape keypress in the main window."""
|
"""Process escape keypress in the main window."""
|
||||||
if self.docEditor.docSearch.isVisible():
|
if self.docEditor.docSearch.isVisible():
|
||||||
self.docEditor.closeSearch()
|
self.docEditor.closeSearch()
|
||||||
elif self.isFocusMode:
|
elif SHARED.focusMode:
|
||||||
self.toggleFocusMode()
|
SHARED.setFocusMode(False)
|
||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot(int)
|
@pyqtSlot(int)
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class SharedData(QObject):
|
|||||||
projectStatusChanged = pyqtSignal(bool)
|
projectStatusChanged = pyqtSignal(bool)
|
||||||
projectStatusMessage = pyqtSignal(str)
|
projectStatusMessage = pyqtSignal(str)
|
||||||
spellLanguageChanged = pyqtSignal(str, str)
|
spellLanguageChanged = pyqtSignal(str, str)
|
||||||
|
focusModeChanged = pyqtSignal(bool)
|
||||||
indexScannedText = pyqtSignal(str)
|
indexScannedText = pyqtSignal(str)
|
||||||
indexChangedTags = pyqtSignal(list, list)
|
indexChangedTags = pyqtSignal(list, list)
|
||||||
indexCleared = pyqtSignal()
|
indexCleared = pyqtSignal()
|
||||||
@@ -76,6 +77,7 @@ class SharedData(QObject):
|
|||||||
self._lastAlert = ""
|
self._lastAlert = ""
|
||||||
self._idleTime = 0.0
|
self._idleTime = 0.0
|
||||||
self._idleRefTime = time()
|
self._idleRefTime = time()
|
||||||
|
self._focusMode = False
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -111,6 +113,11 @@ class SharedData(QObject):
|
|||||||
raise Exception("SharedData class not fully initialised")
|
raise Exception("SharedData class not fully initialised")
|
||||||
return self._spelling
|
return self._spelling
|
||||||
|
|
||||||
|
@property
|
||||||
|
def focusMode(self) -> bool:
|
||||||
|
"""Return the Focus Mode state."""
|
||||||
|
return self._focusMode
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hasProject(self) -> bool:
|
def hasProject(self) -> bool:
|
||||||
"""Return True if the project instance is populated."""
|
"""Return True if the project instance is populated."""
|
||||||
@@ -131,6 +138,17 @@ class SharedData(QObject):
|
|||||||
"""Return the last alert message."""
|
"""Return the last alert message."""
|
||||||
return self._lastAlert
|
return self._lastAlert
|
||||||
|
|
||||||
|
##
|
||||||
|
# Setters
|
||||||
|
##
|
||||||
|
|
||||||
|
def setFocusMode(self, state: bool) -> None:
|
||||||
|
"""Set focus mode on or off."""
|
||||||
|
if state is not self._focusMode:
|
||||||
|
self._focusMode = state
|
||||||
|
self.focusModeChanged.emit(state)
|
||||||
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Methods
|
# Methods
|
||||||
##
|
##
|
||||||
@@ -323,6 +341,7 @@ class SharedData(QObject):
|
|||||||
self._project = NWProject()
|
self._project = NWProject()
|
||||||
self._spelling = NWSpellEnchant(self._project)
|
self._spelling = NWSpellEnchant(self._project)
|
||||||
self.updateSpellCheckLanguage()
|
self.updateSpellCheckLanguage()
|
||||||
|
self._focusMode = False
|
||||||
return
|
return
|
||||||
|
|
||||||
def _resetIdleTimer(self) -> None:
|
def _resetIdleTimer(self) -> None:
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ def testGuiMain_Editing(qtbot, monkeypatch, nwGUI, projPath, tstPaths, mockRnd):
|
|||||||
def testGuiMain_Features(qtbot, nwGUI, projPath, mockRnd):
|
def testGuiMain_Features(qtbot, nwGUI, projPath, mockRnd):
|
||||||
"""Test various features of the main window."""
|
"""Test various features of the main window."""
|
||||||
buildTestProject(nwGUI, projPath)
|
buildTestProject(nwGUI, projPath)
|
||||||
assert nwGUI.isFocusMode is False
|
assert SHARED.focusMode is False
|
||||||
|
|
||||||
# Focus Mode
|
# Focus Mode
|
||||||
# ==========
|
# ==========
|
||||||
|
|||||||
Reference in New Issue
Block a user