From 90613b857b7a81c8c5603c760a7635b912ea952e Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 13:52:08 +0100 Subject: [PATCH] Finished the zen mode functionality, and added full screen F11 shortcut --- nw/config.py | 13 +++++--- nw/gui/elements/doceditor.py | 54 ++++++++++++++++---------------- nw/gui/mainmenu.py | 9 +++++- nw/guimain.py | 30 ++++++++++++++++-- tests/reference/novelwriter.conf | 3 +- 5 files changed, 73 insertions(+), 36 deletions(-) diff --git a/nw/config.py b/nw/config.py index 340cab38..934d74d2 100644 --- a/nw/config.py +++ b/nw/config.py @@ -69,6 +69,7 @@ class Config: self.treeColWidth = [120, 30, 50] self.mainPanePos = [300, 800] self.docPanePos = [400, 400] + self.isFullScreen = False ## Project self.autoSaveProj = 60 @@ -245,6 +246,9 @@ class Config: self.docPanePos = self._parseLine( cnfParse, cnfSec, "docpane", self.CNF_LIST, self.docPanePos ) + self.isFullScreen = self._parseLine( + cnfParse, cnfSec, "fullscreen", self.CNF_BOOL, self.isFullScreen + ) ## Project cnfSec = "Project" @@ -369,10 +373,11 @@ class Config: ## Sizes cnfSec = "Sizes" cnfParse.add_section(cnfSec) - cnfParse.set(cnfSec,"geometry", self._packList(self.winGeometry)) - cnfParse.set(cnfSec,"treecols", self._packList(self.treeColWidth)) - cnfParse.set(cnfSec,"mainpane", self._packList(self.mainPanePos)) - cnfParse.set(cnfSec,"docpane", self._packList(self.docPanePos)) + cnfParse.set(cnfSec,"geometry", self._packList(self.winGeometry)) + cnfParse.set(cnfSec,"treecols", self._packList(self.treeColWidth)) + cnfParse.set(cnfSec,"mainpane", self._packList(self.mainPanePos)) + cnfParse.set(cnfSec,"docpane", self._packList(self.docPanePos)) + cnfParse.set(cnfSec,"fullscreen", str(self.isFullScreen)) ## Project cnfSec = "Project" diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index 404f8d75..f91ba3a8 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -297,33 +297,6 @@ class GuiDocEditor(QTextEdit): # General Class Methods ## - def resizeEvent(self, theEvent): - """Automatically adjust the margins so the text is centred, but - only if Config.textFixedW is set to True. - """ - QTextEdit.resizeEvent(self, theEvent) - - if self.mainConf.textFixedW or self.theParent.isZenMode: - vBar = self.verticalScrollBar() - if vBar.isVisible(): - sW = vBar.width() - else: - sW = 0 - tW = self.mainConf.textWidth - wW = self.width() - tM = int((wW - sW - tW)/2) - if tM < self.mainConf.textMargin: - tM = self.mainConf.textMargin - else: - tM = self.mainConf.textMargin - - docFormat = self.qDocument.rootFrame().frameFormat() - docFormat.setLeftMargin(tM) - docFormat.setRightMargin(tM) - self.qDocument.rootFrame().setFrameFormat(docFormat) - - return - def docAction(self, theAction): logger.verbose("Requesting action: %s" % theAction.name) if not self.theParent.hasProject: @@ -429,6 +402,33 @@ class GuiDocEditor(QTextEdit): QTextEdit.mouseReleaseEvent(self, mEvent) return + def resizeEvent(self, theEvent): + """Automatically adjust the margins so the text is centred, but + only if Config.textFixedW is set to True. + """ + QTextEdit.resizeEvent(self, theEvent) + + if self.mainConf.textFixedW or self.theParent.isZenMode: + vBar = self.verticalScrollBar() + if vBar.isVisible(): + sW = vBar.width() + else: + sW = 0 + tW = self.mainConf.textWidth + wW = self.width() + tM = int((wW - sW - tW)/2) + if tM < self.mainConf.textMargin: + tM = self.mainConf.textMargin + else: + tM = self.mainConf.textMargin + + docFormat = self.qDocument.rootFrame().frameFormat() + docFormat.setLeftMargin(tM) + docFormat.setRightMargin(tM) + self.qDocument.rootFrame().setFrameFormat(docFormat) + + return + ## # Internal Functions ## diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index b8c97e76..0212a136 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -411,7 +411,7 @@ class GuiMainMenu(QMenuBar): self.viewMenu.addSeparator() # View > Toggle Distraction Free Mode - menuItem = QAction("Distraction Free Mode", self) + menuItem = QAction("Zen Mode", self) menuItem.setStatusTip("Toggles distraction free mode, only showing text editor") menuItem.setShortcut("F8") menuItem.setCheckable(True) @@ -419,6 +419,13 @@ class GuiMainMenu(QMenuBar): menuItem.toggled.connect(self.theParent.toggleZenMode) self.viewMenu.addAction(menuItem) + # View > Toggle Full Screen + menuItem = QAction("Full Screen Mode", self) + menuItem.setStatusTip("Maximises the main window") + menuItem.setShortcut("F11") + menuItem.triggered.connect(self.theParent.toggleFullScreenMode) + self.viewMenu.addAction(menuItem) + # View > Separator self.viewMenu.addSeparator() diff --git a/nw/guimain.py b/nw/guimain.py index 26818817..efefc4c9 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -173,6 +173,9 @@ class GuiMain(QMainWindow): self.asDocTimer.start() self.statusBar.clearStatus() + if self.mainConf.isFullScreen: + self.toggleFullScreenMode() + logger.debug("GUI initialisation complete") return @@ -664,8 +667,9 @@ class GuiMain(QMainWindow): logger.info("Exiting %s" % nw.__package__) self.closeProject(True) - self.mainConf.setWinSize(self.width(), self.height()) self.mainConf.setTreeColWidths(self.treeView.getColumnSizes()) + if not self.mainConf.isFullScreen: + self.mainConf.setWinSize(self.width(), self.height()) if not self.isZenMode: self.mainConf.setMainPanePos(self.splitMain.sizes()) self.mainConf.setDocPanePos(self.splitView.sizes()) @@ -705,13 +709,33 @@ class GuiMain(QMainWindow): self.isZenMode = not self.isZenMode if self.isZenMode: - logger.debug("Activating Zen Mode") + logger.debug("Activating Zen mode") else: - logger.debug("Deactivating Zen Mode") + logger.debug("Deactivating Zen mode") isVisible = not self.isZenMode self.viewPane.setVisible(isVisible) self.treePane.setVisible(isVisible) + self.statusBar.setVisible(isVisible) + # self.mainMenu.setVisible(isVisible) + + return + + def toggleFullScreenMode(self): + """Main GUI full screen mode. The mode is tracked by the flag + in config. This only tracks whether the window has been + maximised using the internal commands, and may not be correct + if the user uses the system window manager. Currently, Qt + doesn't have access to the exact state of the window. + """ + + self.mainConf.isFullScreen = not self.mainConf.isFullScreen + if self.mainConf.isFullScreen: + logger.debug("Activating full screen mode") + else: + logger.debug("Deactivating full screen mode") + + self.setWindowState(self.windowState() ^ Qt.WindowFullScreen) return diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf index 239301e1..7f8a42c1 100644 --- a/tests/reference/novelwriter.conf +++ b/tests/reference/novelwriter.conf @@ -1,5 +1,5 @@ [Main] -timestamp = 2019-11-08 18:43:21 +timestamp = 2019-11-09 13:48:06 theme = default syntax = default_light guidark = False @@ -9,6 +9,7 @@ geometry = 1100, 650 treecols = 120, 30, 50 mainpane = 300, 800 docpane = 400, 400 +fullscreen = False [Project] autosaveproject = 60