From 472205f1a6157f0af368036fbef0b376931308c3 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 01:19:17 +0100 Subject: [PATCH 1/9] Added menu entry and function for Zen mode, and cleaned up editor resizing --- nw/gui/elements/doceditor.py | 20 +++++++++------- nw/gui/icons.py | 2 +- nw/gui/mainmenu.py | 12 ++++++++++ nw/guimain.py | 45 +++++++++++++++--------------------- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index db15998c..404f8d75 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -21,7 +21,7 @@ from PyQt5.QtWidgets import ( ) from PyQt5.QtGui import ( QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, - QPalette, QTextDocument, + QPalette, QTextDocument ) from nw.project import NWDoc @@ -185,7 +185,6 @@ class GuiDocEditor(QTextEdit): tHandle = self.theHandle self.clearEditor() self.loadText(tHandle) - self.changeWidth() else: self.clearEditor() @@ -298,11 +297,13 @@ class GuiDocEditor(QTextEdit): # General Class Methods ## - def changeWidth(self): + def resizeEvent(self, theEvent): """Automatically adjust the margins so the text is centred, but only if Config.textFixedW is set to True. """ - if self.mainConf.textFixedW: + QTextEdit.resizeEvent(self, theEvent) + + if self.mainConf.textFixedW or self.theParent.isZenMode: vBar = self.verticalScrollBar() if vBar.isVisible(): sW = vBar.width() @@ -313,10 +314,13 @@ class GuiDocEditor(QTextEdit): tM = int((wW - sW - tW)/2) if tM < self.mainConf.textMargin: tM = self.mainConf.textMargin - docFormat = self.qDocument.rootFrame().frameFormat() - docFormat.setLeftMargin(tM) - docFormat.setRightMargin(tM) - self.qDocument.rootFrame().setFrameFormat(docFormat) + else: + tM = self.mainConf.textMargin + + docFormat = self.qDocument.rootFrame().frameFormat() + docFormat.setLeftMargin(tM) + docFormat.setRightMargin(tM) + self.qDocument.rootFrame().setFrameFormat(docFormat) return diff --git a/nw/gui/icons.py b/nw/gui/icons.py index 34b9f529..88149b6e 100644 --- a/nw/gui/icons.py +++ b/nw/gui/icons.py @@ -46,7 +46,7 @@ class GuiIcons: DECO_MAP = { "export" : "export.svg", - "settings" : "settings.svg", + "settings" : "gear.svg", } def __init__(self, theParent): diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 1e935d68..65a0a8d3 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -410,6 +410,18 @@ class GuiMainMenu(QMenuBar): # View > Separator self.viewMenu.addSeparator() + # View > Toggle Zen Mode + menuItem = QAction("Zen Mode", self) + menuItem.setStatusTip("Toggles zen mode, only showing text editor") + menuItem.setShortcut("F8") + menuItem.setCheckable(True) + menuItem.setChecked(self.theParent.isZenMode) + menuItem.toggled.connect(self.theParent.toggleZenMode) + self.viewMenu.addAction(menuItem) + + # View > Separator + self.viewMenu.addSeparator() + # View > Project Timeline menuItem = QAction("Show Project Timeline", self) menuItem.setStatusTip("Open the project timeline window") diff --git a/nw/guimain.py b/nw/guimain.py index 169fa42f..551b9c8e 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -47,6 +47,7 @@ class GuiMain(QMainWindow): self.theProject = NWProject(self) self.theIndex = NWIndex(self.theProject, self) self.hasProject = False + self.isZenMode = False logger.info("OS: %s" % ( self.mainConf.osType) @@ -107,14 +108,12 @@ class GuiMain(QMainWindow): self.splitView = QSplitter(Qt.Horizontal) self.splitView.addWidget(self.editPane) self.splitView.addWidget(self.viewPane) - self.splitView.splitterMoved.connect(self._splitViewMove) self.splitMain = QSplitter(Qt.Horizontal) self.splitMain.setContentsMargins(4,4,4,4) self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.splitView) self.splitMain.setSizes(self.mainConf.mainPanePos) - self.splitMain.splitterMoved.connect(self._splitMainMove) self.setCentralWidget(self.splitMain) @@ -359,7 +358,6 @@ class GuiMain(QMainWindow): self.closeDocument() if self.docEditor.loadText(tHandle): self.docEditor.setFocus() - self.docEditor.changeWidth() self.theProject.setLastEdited(tHandle) else: return False @@ -391,7 +389,6 @@ class GuiMain(QMainWindow): vPos[0] = int(bPos[1]/2) vPos[1] = bPos[1]-vPos[0] self.splitView.setSizes(vPos) - self.docEditor.changeWidth() return True @@ -698,9 +695,25 @@ class GuiMain(QMainWindow): self.viewPane.setVisible(False) vPos = [bPos[1],0] self.splitView.setSizes(vPos) - self.docEditor.changeWidth() return not self.viewPane.isVisible() + def toggleZenMode(self): + """Main GUI Zen Mode hides tree, view pane and optionally also + statusbar and menu. + """ + + self.isZenMode = not self.isZenMode + if self.isZenMode: + logger.debug("Activating Zen Mode") + else: + logger.debug("Deactivating Zen Mode") + + isVisible = not self.isZenMode + self.viewPane.setVisible(isVisible) + self.treePane.setVisible(isVisible) + + return + ## # Internal Functions ## @@ -745,14 +758,6 @@ class GuiMain(QMainWindow): # Events ## - def resizeEvent(self, theEvent): - """Extend QMainWindow.resizeEvent to signal dependent GUI - elements that its pane may have changed size. - """ - QMainWindow.resizeEvent(self,theEvent) - self.docEditor.changeWidth() - return - def closeEvent(self, theEvent): if self.closeMain(): theEvent.accept() @@ -801,18 +806,4 @@ class GuiMain(QMainWindow): return return - def _splitMainMove(self, pWidth, pHeight): - """Alert dependent GUI elements that the main pane splitter has - been moved. - """ - self.docEditor.changeWidth() - return - - def _splitViewMove(self, pWidth, pHeight): - """Alert dependent GUI elements that the edit/view pane splitter - has been moved. - """ - self.docEditor.changeWidth() - return - # END Class GuiMain From 9c239f77dcdf922ddb886d27c1fedc3bb4324b1f Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 12:17:42 +0100 Subject: [PATCH 2/9] Don't save splitter positions if exiting when in zen mode --- nw/guimain.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nw/guimain.py b/nw/guimain.py index 551b9c8e..26818817 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -666,8 +666,9 @@ class GuiMain(QMainWindow): self.mainConf.setWinSize(self.width(), self.height()) self.mainConf.setTreeColWidths(self.treeView.getColumnSizes()) - self.mainConf.setMainPanePos(self.splitMain.sizes()) - self.mainConf.setDocPanePos(self.splitView.sizes()) + if not self.isZenMode: + self.mainConf.setMainPanePos(self.splitMain.sizes()) + self.mainConf.setDocPanePos(self.splitView.sizes()) self.mainConf.saveConfig() qApp.quit() From fedcf247e03c3dcfd6b290b167792adaabfc5a26 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 12:22:36 +0100 Subject: [PATCH 3/9] Let's label it 'distraction free mode' instead --- nw/gui/mainmenu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index 65a0a8d3..b8c97e76 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -410,9 +410,9 @@ class GuiMainMenu(QMenuBar): # View > Separator self.viewMenu.addSeparator() - # View > Toggle Zen Mode - menuItem = QAction("Zen Mode", self) - menuItem.setStatusTip("Toggles zen mode, only showing text editor") + # View > Toggle Distraction Free Mode + menuItem = QAction("Distraction Free Mode", self) + menuItem.setStatusTip("Toggles distraction free mode, only showing text editor") menuItem.setShortcut("F8") menuItem.setCheckable(True) menuItem.setChecked(self.theParent.isZenMode) 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 4/9] 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 From 8a30f8a98ef25d71a215ac7090013bdc15b616ac Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:11:03 +0100 Subject: [PATCH 5/9] That didn't work, trying a better approach to save full screen state --- nw/guimain.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nw/guimain.py b/nw/guimain.py index efefc4c9..2f8d943a 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -729,14 +729,16 @@ class GuiMain(QMainWindow): 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) + winState = self.windowState() & Qt.WindowFullScreen == Qt.WindowFullScreen + if winState: + logger.debug("Activated full screen mode") + else: + logger.debug("Deactivated full screen mode") + + self.mainConf.isFullScreen = winState + return ## From fab20c6c264a0625080cb39dcc021b68f756419b Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:24:59 +0100 Subject: [PATCH 6/9] Added a separate text width parameter for zen mode --- nw/config.py | 5 +++ nw/gui/dialogs/configeditor.py | 78 +++++++++++++++------------------- nw/gui/elements/doceditor.py | 5 ++- 3 files changed, 44 insertions(+), 44 deletions(-) diff --git a/nw/config.py b/nw/config.py index 934d74d2..145724e4 100644 --- a/nw/config.py +++ b/nw/config.py @@ -82,6 +82,7 @@ class Config: self.textWidth = 600 self.textMargin = 40 self.tabWidth = 40 + self.zenWidth = 800 self.doJustify = False self.autoSelect = True self.doReplace = True @@ -279,6 +280,9 @@ class Config: self.tabWidth = self._parseLine( cnfParse, cnfSec, "tabwidth", self.CNF_INT, self.tabWidth ) + self.zenWidth = self._parseLine( + cnfParse, cnfSec, "zenwidth", self.CNF_INT, self.zenWidth + ) self.doJustify = self._parseLine( cnfParse, cnfSec, "justify", self.CNF_BOOL, self.doJustify ) @@ -394,6 +398,7 @@ class Config: cnfParse.set(cnfSec,"width", str(self.textWidth)) cnfParse.set(cnfSec,"margin", str(self.textMargin)) cnfParse.set(cnfSec,"tabwidth", str(self.tabWidth)) + cnfParse.set(cnfSec,"zenwidth", str(self.zenWidth)) cnfParse.set(cnfSec,"justify", str(self.doJustify)) cnfParse.set(cnfSec,"autoselect", str(self.autoSelect)) cnfParse.set(cnfSec,"autoreplace", str(self.doReplace)) diff --git a/nw/gui/dialogs/configeditor.py b/nw/gui/dialogs/configeditor.py index 24c509bf..18532761 100644 --- a/nw/gui/dialogs/configeditor.py +++ b/nw/gui/dialogs/configeditor.py @@ -373,10 +373,8 @@ class GuiConfigEditEditor(QWidget): self.textFlowFixed = QCheckBox("Max text width",self) self.textFlowFixed.setToolTip("Maximum width of the text.") - if self.mainConf.textFixedW: - self.textFlowFixed.setCheckState(Qt.Checked) - else: - self.textFlowFixed.setCheckState(Qt.Unchecked) + self.textFlowFixed.setChecked(self.mainConf.textFixedW) + self.textFlowMax = QSpinBox(self) self.textFlowMax.setMinimum(300) self.textFlowMax.setMaximum(10000) @@ -385,10 +383,7 @@ class GuiConfigEditEditor(QWidget): self.textFlowJustify = QCheckBox("Justify text",self) self.textFlowJustify.setToolTip("Justify text in main document editor.") - if self.mainConf.doJustify: - self.textFlowJustify.setCheckState(Qt.Checked) - else: - self.textFlowJustify.setCheckState(Qt.Unchecked) + self.textFlowJustify.setChecked(self.mainConf.doJustify) self.textFlowForm.addWidget(self.textFlowFixed, 0, 0) self.textFlowForm.addWidget(self.textFlowMax, 0, 1) @@ -422,6 +417,22 @@ class GuiConfigEditEditor(QWidget): self.textMarginForm.addWidget(QLabel("px"), 2, 2) self.textMarginForm.setColumnStretch(4, 1) + # Zen Mode + self.zenMode = QGroupBox("Zen Mode", self) + self.zenModeForm = QGridLayout(self) + self.zenMode.setLayout(self.zenModeForm) + + self.zenDocWidth = QSpinBox(self) + self.zenDocWidth.setMinimum(300) + self.zenDocWidth.setMaximum(10000) + self.zenDocWidth.setSingleStep(10) + self.zenDocWidth.setValue(self.mainConf.zenWidth) + + self.zenModeForm.addWidget(QLabel("Document width"), 0, 0) + self.zenModeForm.addWidget(self.zenDocWidth, 0, 1) + self.zenModeForm.addWidget(QLabel("px"), 0, 2) + self.zenModeForm.setColumnStretch(3, 1) + # Automatic Features self.autoReplace = QGroupBox("Automatic Features", self) self.autoReplaceForm = QGridLayout(self) @@ -429,47 +440,29 @@ class GuiConfigEditEditor(QWidget): self.autoSelect = QCheckBox(self) self.autoSelect.setToolTip("Auto-select word under cursor when applying formatting.") - if self.mainConf.autoSelect: - self.autoSelect.setCheckState(Qt.Checked) - else: - self.autoSelect.setCheckState(Qt.Unchecked) + self.autoSelect.setChecked(self.mainConf.autoSelect) self.autoReplaceMain = QCheckBox(self) self.autoReplaceMain.setToolTip("Auto-replace text as you type.") - if self.mainConf.doReplace: - self.autoReplaceMain.setCheckState(Qt.Checked) - else: - self.autoReplaceMain.setCheckState(Qt.Unchecked) + self.autoReplaceMain.setChecked(self.mainConf.doReplace) self.autoReplaceSQ = QCheckBox(self) self.autoReplaceSQ.setToolTip("Auto-replace single quotes.") - if self.mainConf.doReplaceSQuote: - self.autoReplaceSQ.setCheckState(Qt.Checked) - else: - self.autoReplaceSQ.setCheckState(Qt.Unchecked) + self.autoReplaceSQ.setChecked(self.mainConf.doReplaceSQuote) self.autoReplaceDQ = QCheckBox(self) self.autoReplaceDQ.setToolTip("Auto-replace double quotes.") - if self.mainConf.doReplaceDQuote: - self.autoReplaceDQ.setCheckState(Qt.Checked) - else: - self.autoReplaceDQ.setCheckState(Qt.Unchecked) + self.autoReplaceDQ.setChecked(self.mainConf.doReplaceDQuote) self.autoReplaceDash = QCheckBox(self) self.autoReplaceDash.setToolTip( "Auto-replace double and triple hyphens with short and long dash." ) - if self.mainConf.doReplaceDash: - self.autoReplaceDash.setCheckState(Qt.Checked) - else: - self.autoReplaceDash.setCheckState(Qt.Unchecked) + self.autoReplaceDash.setChecked(self.mainConf.doReplaceDash) self.autoReplaceDots = QCheckBox(self) self.autoReplaceDots.setToolTip("Auto-replace three dots with ellipsis.") - if self.mainConf.doReplaceDots: - self.autoReplaceDots.setCheckState(Qt.Checked) - else: - self.autoReplaceDots.setCheckState(Qt.Unchecked) + self.autoReplaceDots.setChecked(self.mainConf.doReplaceDots) self.autoReplaceForm.addWidget(QLabel("Auto-select text"), 0, 0) self.autoReplaceForm.addWidget(self.autoSelect, 0, 1) @@ -534,16 +527,10 @@ class GuiConfigEditEditor(QWidget): self.showGuides.setLayout(self.showGuidesForm) self.showTabsNSpaces = QCheckBox("Show tabs and spaces",self) - if self.mainConf.showTabsNSpaces: - self.showTabsNSpaces.setCheckState(Qt.Checked) - else: - self.showTabsNSpaces.setCheckState(Qt.Unchecked) + self.showTabsNSpaces.setChecked(self.mainConf.showTabsNSpaces) self.showLineEndings = QCheckBox("Show line endings",self) - if self.mainConf.showTabsNSpaces: - self.showLineEndings.setCheckState(Qt.Checked) - else: - self.showLineEndings.setCheckState(Qt.Unchecked) + self.showLineEndings.setChecked(self.mainConf.showLineEndings) self.showGuidesForm.addWidget(self.showTabsNSpaces, 0, 0) self.showGuidesForm.addWidget(self.showLineEndings, 1, 0) @@ -552,9 +539,10 @@ class GuiConfigEditEditor(QWidget): self.outerBox.addWidget(self.textStyle, 0, 0, 1, 2) self.outerBox.addWidget(self.textFlow, 1, 0) self.outerBox.addWidget(self.textMargin, 1, 1) - self.outerBox.addWidget(self.quoteStyle, 2, 0) - self.outerBox.addWidget(self.autoReplace, 2, 1, 2, 1) - self.outerBox.addWidget(self.showGuides, 3, 0) + self.outerBox.addWidget(self.zenMode, 2, 0) + self.outerBox.addWidget(self.autoReplace, 3, 0, 2, 1) + self.outerBox.addWidget(self.quoteStyle, 2, 1, 2, 1) + self.outerBox.addWidget(self.showGuides, 4, 1) self.outerBox.setColumnStretch(2, 1) self.setLayout(self.outerBox) @@ -578,6 +566,10 @@ class GuiConfigEditEditor(QWidget): self.mainConf.textFixedW = textFixedW self.mainConf.doJustify = doJustify + zenWidth = self.zenDocWidth.value() + + self.mainConf.zenWidth = zenWidth + textMargin = self.textMarginDoc.value() tabWidth = self.textMarginTab.value() diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index f91ba3a8..dfbecf63 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -414,7 +414,10 @@ class GuiDocEditor(QTextEdit): sW = vBar.width() else: sW = 0 - tW = self.mainConf.textWidth + if self.theParent.isZenMode: + tW = self.mainConf.zenWidth + else: + tW = self.mainConf.textWidth wW = self.width() tM = int((wW - sW - tW)/2) if tM < self.mainConf.textMargin: From be2f812945e7df773efee87264f55bbf012b0539 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:34:02 +0100 Subject: [PATCH 7/9] Fix a few minor issues related to opening and resizing of window panes --- nw/gui/elements/doceditor.py | 58 ++++++++++++++++++++---------------- nw/guimain.py | 13 ++++++-- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/nw/gui/elements/doceditor.py b/nw/gui/elements/doceditor.py index dfbecf63..f5f22e2a 100644 --- a/nw/gui/elements/doceditor.py +++ b/nw/gui/elements/doceditor.py @@ -185,6 +185,7 @@ class GuiDocEditor(QTextEdit): tHandle = self.theHandle self.clearEditor() self.loadText(tHandle) + self.updateDocMargins() else: self.clearEditor() @@ -241,6 +242,35 @@ class GuiDocEditor(QTextEdit): return True + def updateDocMargins(self): + """Automatically adjust the margins so the text is centred, but + only if Config.textFixedW is set to True. + """ + + if self.mainConf.textFixedW or self.theParent.isZenMode: + vBar = self.verticalScrollBar() + if vBar.isVisible(): + sW = vBar.width() + else: + sW = 0 + if self.theParent.isZenMode: + tW = self.mainConf.zenWidth + else: + 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 + ## # Setters and Getters ## @@ -403,33 +433,11 @@ class GuiDocEditor(QTextEdit): return def resizeEvent(self, theEvent): - """Automatically adjust the margins so the text is centred, but - only if Config.textFixedW is set to True. + """If the text editor is resize, we must make sure the document + has its margins adjusted according to user preferences. """ QTextEdit.resizeEvent(self, theEvent) - - if self.mainConf.textFixedW or self.theParent.isZenMode: - vBar = self.verticalScrollBar() - if vBar.isVisible(): - sW = vBar.width() - else: - sW = 0 - if self.theParent.isZenMode: - tW = self.mainConf.zenWidth - else: - 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) - + self.updateDocMargins() return ## diff --git a/nw/guimain.py b/nw/guimain.py index 2f8d943a..ba275963 100644 --- a/nw/guimain.py +++ b/nw/guimain.py @@ -707,6 +707,10 @@ class GuiMain(QMainWindow): statusbar and menu. """ + if self.docEditor.theHandle is None: + logger.error("No document open, so not activating Zen Mode") + return False + self.isZenMode = not self.isZenMode if self.isZenMode: logger.debug("Activating Zen mode") @@ -714,12 +718,15 @@ class GuiMain(QMainWindow): 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 + if self.viewPane.isVisible(): + self.viewPane.setVisible(False) + elif self.docViewer.theHandle is not None: + self.viewPane.setVisible(True) + + return True def toggleFullScreenMode(self): """Main GUI full screen mode. The mode is tracked by the flag From 0db96bc1b278e87cbd7e955b938375e165b9086a Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:39:52 +0100 Subject: [PATCH 8/9] Fixed test --- tests/reference/novelwriter.conf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/reference/novelwriter.conf b/tests/reference/novelwriter.conf index 7f8a42c1..a4943b1a 100644 --- a/tests/reference/novelwriter.conf +++ b/tests/reference/novelwriter.conf @@ -1,5 +1,5 @@ [Main] -timestamp = 2019-11-09 13:48:06 +timestamp = 2019-11-09 14:38:32 theme = default syntax = default_light guidark = False @@ -22,6 +22,7 @@ fixedwidth = True width = 600 margin = 40 tabwidth = 40 +zenwidth = 800 justify = False autoselect = True autoreplace = True From 6eff01504a09749b7984932a59f0376423e02c97 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Sat, 9 Nov 2019 14:42:09 +0100 Subject: [PATCH 9/9] Added keyboard shortcuts to documentation --- docs/source/interface.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/interface.txt b/docs/source/interface.txt index 5818b65b..7a0ccca0 100644 --- a/docs/source/interface.txt +++ b/docs/source/interface.txt @@ -106,7 +106,9 @@ These are as following: ":kbd:`F3`", "Find next occurrence of word in current document. (Same as :kbd:`Ctrl-G`)" ":kbd:`F5`", "Export project dialog." ":kbd:`F7`", "Re-run spell checker." + ":kbd:`F8`", "Activate Zen Mode, hiding project tree and view panel." ":kbd:`F9`", "Re-build project indices." + ":kbd:`F11`", "Activate full screen mode." ":kbd:`Shift-Enter`", "Insert a hard line break at the cursor position." ":kbd:`Shift-F3`", "Find previous occurrence of word in current document. (Same as :kbd:`Ctrl-Shift-G`" ":kbd:`Shift-Space`", "Insert a non-breaking space at the cursor position."