Added starte view history class and connected mouse, menu and keyboard
This commit is contained in:
+67
-6
@@ -63,20 +63,22 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.setMinimumWidth(self.mainConf.pxInt(300))
|
||||
self.setAutoFillBackground(True)
|
||||
self.setOpenExternalLinks(False)
|
||||
self.setFocusPolicy(Qt.StrongFocus)
|
||||
self.initViewer()
|
||||
|
||||
# Document Header and Footer
|
||||
self.docHeader = GuiDocViewHeader(self)
|
||||
self.docFooter = GuiDocViewFooter(self)
|
||||
self.stickyRef = False
|
||||
self.docHeader = GuiDocViewHeader(self)
|
||||
self.docFooter = GuiDocViewFooter(self)
|
||||
self.docHistory = GuiDocViewHistory(self)
|
||||
self.stickyRef = False
|
||||
|
||||
theOpt = QTextOption()
|
||||
if self.mainConf.doJustify:
|
||||
theOpt.setAlignment(Qt.AlignJustify)
|
||||
self.qDocument.setDefaultTextOption(theOpt)
|
||||
|
||||
# Signals
|
||||
self.anchorClicked.connect(self._linkClicked)
|
||||
self.setFocusPolicy(Qt.StrongFocus)
|
||||
|
||||
# Context Menu
|
||||
self.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
@@ -169,6 +171,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
|
||||
self.setHtml(aDoc.theResult.replace("\t", "!!tab!!"))
|
||||
self.setDocumentTitle(tHandle)
|
||||
self.docHistory.append(tHandle)
|
||||
|
||||
# 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.
|
||||
@@ -217,8 +220,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
# the doc view panel is visible in case this request comes
|
||||
# from outside this class.
|
||||
logger.verbose("Tag points to %s#%s" % (tHandle, sTitle))
|
||||
self.theParent.viewDocument(tHandle)
|
||||
self.navigateTo("#%s" % sTitle)
|
||||
self.theParent.viewDocument(tHandle, "#%s" % sTitle)
|
||||
return True
|
||||
|
||||
def docAction(self, theAction):
|
||||
@@ -252,6 +254,18 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.setSource(QUrl(tAnchor))
|
||||
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):
|
||||
"""Automatically adjust the margins so the text is centred if
|
||||
Config.textFixedW is enabled or we're in Focus Mode. Otherwise,
|
||||
@@ -382,6 +396,15 @@ class GuiDocViewer(QTextBrowser):
|
||||
self.updateDocMargins()
|
||||
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
|
||||
##
|
||||
@@ -481,6 +504,44 @@ class GuiDocViewer(QTextBrowser):
|
||||
|
||||
# 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
|
||||
# Only used by DocViewer, and is at a fixed position in the QTextBrowser's viewport
|
||||
|
||||
@@ -475,6 +475,23 @@ class GuiMainMenu(QMenuBar):
|
||||
# View > Separator
|
||||
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
|
||||
self.aFocusMode = QAction("Distraction Free Mode", self)
|
||||
self.aFocusMode.setStatusTip("Toggles distraction free mode, only showing text editor")
|
||||
|
||||
Reference in New Issue
Block a user