Added menu entry and function for Zen mode, and cleaned up editor resizing

This commit is contained in:
Veronica K. B. Olsen
2019-11-09 01:19:17 +01:00
parent ee34e0e395
commit 472205f1a6
4 changed files with 43 additions and 36 deletions
+12 -8
View File
@@ -21,7 +21,7 @@ from PyQt5.QtWidgets import (
) )
from PyQt5.QtGui import ( from PyQt5.QtGui import (
QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor, QTextCursor, QTextOption, QIcon, QKeySequence, QFont, QColor,
QPalette, QTextDocument, QPalette, QTextDocument
) )
from nw.project import NWDoc from nw.project import NWDoc
@@ -185,7 +185,6 @@ class GuiDocEditor(QTextEdit):
tHandle = self.theHandle tHandle = self.theHandle
self.clearEditor() self.clearEditor()
self.loadText(tHandle) self.loadText(tHandle)
self.changeWidth()
else: else:
self.clearEditor() self.clearEditor()
@@ -298,11 +297,13 @@ class GuiDocEditor(QTextEdit):
# General Class Methods # General Class Methods
## ##
def changeWidth(self): def resizeEvent(self, theEvent):
"""Automatically adjust the margins so the text is centred, but """Automatically adjust the margins so the text is centred, but
only if Config.textFixedW is set to True. 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() vBar = self.verticalScrollBar()
if vBar.isVisible(): if vBar.isVisible():
sW = vBar.width() sW = vBar.width()
@@ -313,10 +314,13 @@ class GuiDocEditor(QTextEdit):
tM = int((wW - sW - tW)/2) tM = int((wW - sW - tW)/2)
if tM < self.mainConf.textMargin: if tM < self.mainConf.textMargin:
tM = self.mainConf.textMargin tM = self.mainConf.textMargin
docFormat = self.qDocument.rootFrame().frameFormat() else:
docFormat.setLeftMargin(tM) tM = self.mainConf.textMargin
docFormat.setRightMargin(tM)
self.qDocument.rootFrame().setFrameFormat(docFormat) docFormat = self.qDocument.rootFrame().frameFormat()
docFormat.setLeftMargin(tM)
docFormat.setRightMargin(tM)
self.qDocument.rootFrame().setFrameFormat(docFormat)
return return
+1 -1
View File
@@ -46,7 +46,7 @@ class GuiIcons:
DECO_MAP = { DECO_MAP = {
"export" : "export.svg", "export" : "export.svg",
"settings" : "settings.svg", "settings" : "gear.svg",
} }
def __init__(self, theParent): def __init__(self, theParent):
+12
View File
@@ -410,6 +410,18 @@ class GuiMainMenu(QMenuBar):
# View > Separator # View > Separator
self.viewMenu.addSeparator() 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 # View > Project Timeline
menuItem = QAction("Show Project Timeline", self) menuItem = QAction("Show Project Timeline", self)
menuItem.setStatusTip("Open the project timeline window") menuItem.setStatusTip("Open the project timeline window")
+18 -27
View File
@@ -47,6 +47,7 @@ class GuiMain(QMainWindow):
self.theProject = NWProject(self) self.theProject = NWProject(self)
self.theIndex = NWIndex(self.theProject, self) self.theIndex = NWIndex(self.theProject, self)
self.hasProject = False self.hasProject = False
self.isZenMode = False
logger.info("OS: %s" % ( logger.info("OS: %s" % (
self.mainConf.osType) self.mainConf.osType)
@@ -107,14 +108,12 @@ class GuiMain(QMainWindow):
self.splitView = QSplitter(Qt.Horizontal) self.splitView = QSplitter(Qt.Horizontal)
self.splitView.addWidget(self.editPane) self.splitView.addWidget(self.editPane)
self.splitView.addWidget(self.viewPane) self.splitView.addWidget(self.viewPane)
self.splitView.splitterMoved.connect(self._splitViewMove)
self.splitMain = QSplitter(Qt.Horizontal) self.splitMain = QSplitter(Qt.Horizontal)
self.splitMain.setContentsMargins(4,4,4,4) self.splitMain.setContentsMargins(4,4,4,4)
self.splitMain.addWidget(self.treePane) self.splitMain.addWidget(self.treePane)
self.splitMain.addWidget(self.splitView) self.splitMain.addWidget(self.splitView)
self.splitMain.setSizes(self.mainConf.mainPanePos) self.splitMain.setSizes(self.mainConf.mainPanePos)
self.splitMain.splitterMoved.connect(self._splitMainMove)
self.setCentralWidget(self.splitMain) self.setCentralWidget(self.splitMain)
@@ -359,7 +358,6 @@ class GuiMain(QMainWindow):
self.closeDocument() self.closeDocument()
if self.docEditor.loadText(tHandle): if self.docEditor.loadText(tHandle):
self.docEditor.setFocus() self.docEditor.setFocus()
self.docEditor.changeWidth()
self.theProject.setLastEdited(tHandle) self.theProject.setLastEdited(tHandle)
else: else:
return False return False
@@ -391,7 +389,6 @@ class GuiMain(QMainWindow):
vPos[0] = int(bPos[1]/2) vPos[0] = int(bPos[1]/2)
vPos[1] = bPos[1]-vPos[0] vPos[1] = bPos[1]-vPos[0]
self.splitView.setSizes(vPos) self.splitView.setSizes(vPos)
self.docEditor.changeWidth()
return True return True
@@ -698,9 +695,25 @@ class GuiMain(QMainWindow):
self.viewPane.setVisible(False) self.viewPane.setVisible(False)
vPos = [bPos[1],0] vPos = [bPos[1],0]
self.splitView.setSizes(vPos) self.splitView.setSizes(vPos)
self.docEditor.changeWidth()
return not self.viewPane.isVisible() 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 # Internal Functions
## ##
@@ -745,14 +758,6 @@ class GuiMain(QMainWindow):
# Events # 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): def closeEvent(self, theEvent):
if self.closeMain(): if self.closeMain():
theEvent.accept() theEvent.accept()
@@ -801,18 +806,4 @@ class GuiMain(QMainWindow):
return return
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 # END Class GuiMain