Added starte view history class and connected mouse, menu and keyboard

This commit is contained in:
Veronica K. B. Olsen
2020-09-08 18:44:08 +02:00
parent 6ebc4ca268
commit 2a3df92b20
2 changed files with 84 additions and 6 deletions
+67 -6
View File
@@ -63,20 +63,22 @@ class GuiDocViewer(QTextBrowser):
self.setMinimumWidth(self.mainConf.pxInt(300)) self.setMinimumWidth(self.mainConf.pxInt(300))
self.setAutoFillBackground(True) self.setAutoFillBackground(True)
self.setOpenExternalLinks(False) self.setOpenExternalLinks(False)
self.setFocusPolicy(Qt.StrongFocus)
self.initViewer() self.initViewer()
# Document Header and Footer # Document Header and Footer
self.docHeader = GuiDocViewHeader(self) self.docHeader = GuiDocViewHeader(self)
self.docFooter = GuiDocViewFooter(self) self.docFooter = GuiDocViewFooter(self)
self.stickyRef = False self.docHistory = GuiDocViewHistory(self)
self.stickyRef = False
theOpt = QTextOption() theOpt = QTextOption()
if self.mainConf.doJustify: if self.mainConf.doJustify:
theOpt.setAlignment(Qt.AlignJustify) theOpt.setAlignment(Qt.AlignJustify)
self.qDocument.setDefaultTextOption(theOpt) self.qDocument.setDefaultTextOption(theOpt)
# Signals
self.anchorClicked.connect(self._linkClicked) self.anchorClicked.connect(self._linkClicked)
self.setFocusPolicy(Qt.StrongFocus)
# Context Menu # Context Menu
self.setContextMenuPolicy(Qt.CustomContextMenu) self.setContextMenuPolicy(Qt.CustomContextMenu)
@@ -169,6 +171,7 @@ class GuiDocViewer(QTextBrowser):
self.setHtml(aDoc.theResult.replace("\t", "!!tab!!")) self.setHtml(aDoc.theResult.replace("\t", "!!tab!!"))
self.setDocumentTitle(tHandle) self.setDocumentTitle(tHandle)
self.docHistory.append(tHandle)
# Loop through the text and put back in the tabs. Tabs are removed by # Loop through the text and put back in the tabs. Tabs are removed by
# the setHtml function, so the ToHtml class puts in a placeholder. # the setHtml function, so the ToHtml class puts in a placeholder.
@@ -217,8 +220,7 @@ class GuiDocViewer(QTextBrowser):
# the doc view panel is visible in case this request comes # the doc view panel is visible in case this request comes
# from outside this class. # from outside this class.
logger.verbose("Tag points to %s#%s" % (tHandle, sTitle)) logger.verbose("Tag points to %s#%s" % (tHandle, sTitle))
self.theParent.viewDocument(tHandle) self.theParent.viewDocument(tHandle, "#%s" % sTitle)
self.navigateTo("#%s" % sTitle)
return True return True
def docAction(self, theAction): def docAction(self, theAction):
@@ -252,6 +254,18 @@ class GuiDocViewer(QTextBrowser):
self.setSource(QUrl(tAnchor)) self.setSource(QUrl(tAnchor))
return True return True
def navBackward(self):
"""Navigate backwards in the document view history.
"""
self.docHistory.backward()
return
def navForward(self):
"""Navigate forwards in the document view history.
"""
self.docHistory.forward()
return
def updateDocMargins(self): def updateDocMargins(self):
"""Automatically adjust the margins so the text is centred if """Automatically adjust the margins so the text is centred if
Config.textFixedW is enabled or we're in Focus Mode. Otherwise, Config.textFixedW is enabled or we're in Focus Mode. Otherwise,
@@ -382,6 +396,15 @@ class GuiDocViewer(QTextBrowser):
self.updateDocMargins() self.updateDocMargins()
return return
def mouseReleaseEvent(self, theEvent):
"""Capture mouse click events on the document.
"""
if theEvent.button() == Qt.BackButton:
self.navBackward()
elif theEvent.button() == Qt.ForwardButton:
self.navForward()
return
## ##
# Internal Functions # Internal Functions
## ##
@@ -481,6 +504,44 @@ class GuiDocViewer(QTextBrowser):
# END Class GuiDocViewer # END Class GuiDocViewer
class GuiDocViewHistory():
def __init__(self, docViewer):
self.docViewer = docViewer
self._navHistory = []
self._navPosition = -1
return
def clear(self):
logger.verbose("Clear view history")
self._navHistory = []
self._navPosition = -1
return
def append(self, tHandle):
logger.verbose("Added %s to view history" % tHandle)
return
def forward(self):
logger.verbose("Move forwards in view history")
return True
def backward(self):
logger.verbose("Move backwards in view history")
return True
##
# Internal Functions
##
def _truncateHistory(self, atPos):
return
# END Class GuiDocViewHistory
# =============================================================================================== # # =============================================================================================== #
# The Embedded Document Header # The Embedded Document Header
# Only used by DocViewer, and is at a fixed position in the QTextBrowser's viewport # Only used by DocViewer, and is at a fixed position in the QTextBrowser's viewport
+17
View File
@@ -475,6 +475,23 @@ class GuiMainMenu(QMenuBar):
# View > Separator # View > Separator
self.viewMenu.addSeparator() self.viewMenu.addSeparator()
# View > Navigate Viewer Backward
self.aViewPrev = QAction("Navigate Viewer Backward", self)
self.aViewPrev.setStatusTip("Show the previous document in the right pane")
self.aViewPrev.setShortcut("Alt+Left")
self.aViewPrev.triggered.connect(self.theParent.docViewer.navBackward)
self.viewMenu.addAction(self.aViewPrev)
# View > Navigate Viewer Forward
self.aViewNext = QAction("Navigate Viewer Forward", self)
self.aViewNext.setStatusTip("Show the next document in the right pane")
self.aViewNext.setShortcut("Alt+Right")
self.aViewNext.triggered.connect(self.theParent.docViewer.navForward)
self.viewMenu.addAction(self.aViewNext)
# View > Separator
self.viewMenu.addSeparator()
# View > Toggle Distraction Free Mode # View > Toggle Distraction Free Mode
self.aFocusMode = QAction("Distraction Free Mode", self) self.aFocusMode = QAction("Distraction Free Mode", self)
self.aFocusMode.setStatusTip("Toggles distraction free mode, only showing text editor") self.aFocusMode.setStatusTip("Toggles distraction free mode, only showing text editor")