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