Finished the zen mode functionality, and added full screen F11 shortcut

This commit is contained in:
Veronica K. B. Olsen
2019-11-09 13:52:08 +01:00
parent fedcf247e0
commit 90613b857b
5 changed files with 73 additions and 36 deletions
+9 -4
View File
@@ -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"
+27 -27
View File
@@ -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
##
+8 -1
View File
@@ -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()
+27 -3
View File
@@ -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
+2 -1
View File
@@ -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