Merge pull request #311 from vkbo/view_comments
Comment Rendering in Document Viewer
This commit is contained in:
+5
-5
@@ -141,6 +141,7 @@ class Config:
|
||||
## State
|
||||
self.showRefPanel = True
|
||||
self.viewComments = True
|
||||
self.viewSynopsis = True
|
||||
|
||||
# Check Qt5 Versions
|
||||
verQt = splitVersionNumber(QT_VERSION_STR)
|
||||
@@ -478,6 +479,9 @@ class Config:
|
||||
self.viewComments = self._parseLine(
|
||||
cnfParse, cnfSec, "viewcomments", self.CNF_BOOL, self.viewComments
|
||||
)
|
||||
self.viewSynopsis = self._parseLine(
|
||||
cnfParse, cnfSec, "viewsynopsis", self.CNF_BOOL, self.viewSynopsis
|
||||
)
|
||||
|
||||
## Path
|
||||
cnfSec = "Path"
|
||||
@@ -569,6 +573,7 @@ class Config:
|
||||
cnfParse.add_section(cnfSec)
|
||||
cnfParse.set(cnfSec,"showrefpanel",str(self.showRefPanel))
|
||||
cnfParse.set(cnfSec,"viewcomments",str(self.viewComments))
|
||||
cnfParse.set(cnfSec,"viewsynopsis",str(self.viewSynopsis))
|
||||
|
||||
## Path
|
||||
cnfSec = "Path"
|
||||
@@ -753,11 +758,6 @@ class Config:
|
||||
self.confChanged = True
|
||||
return self.showRefPanel
|
||||
|
||||
def setViewComments(self, checkState):
|
||||
self.viewComments = checkState
|
||||
self.confChanged = True
|
||||
return self.viewComments
|
||||
|
||||
def getErrData(self):
|
||||
errMessage = "<br>".join(self.errData)
|
||||
self.hasError = False
|
||||
|
||||
+8
-7
@@ -66,7 +66,7 @@ class ToHtml(Tokenizer):
|
||||
# Setters
|
||||
##
|
||||
|
||||
def setPreview(self, forPreview, doComments):
|
||||
def setPreview(self, forPreview, doComments, doSynopsis):
|
||||
"""If we're using this class to generate markdown preview, we
|
||||
need to make a few changes to formatting, which is managed by
|
||||
these flags.
|
||||
@@ -75,6 +75,7 @@ class ToHtml(Tokenizer):
|
||||
self.genMode = self.M_PREVIEW
|
||||
self.doKeywords = True
|
||||
self.doComments = doComments
|
||||
self.doSynopsis = doSynopsis
|
||||
self.repDict["\t"] = " "*8
|
||||
self._buildRegEx()
|
||||
return
|
||||
@@ -287,18 +288,18 @@ class ToHtml(Tokenizer):
|
||||
def _formatSynopsis(self, tText):
|
||||
"""Apply HTML formatting to synopsis.
|
||||
"""
|
||||
if self.genMode == self.M_EXPORT:
|
||||
return "<p class='synopsis'><strong>Synopsis: </strong>%s</p>\n" % tText
|
||||
if self.genMode == self.M_PREVIEW:
|
||||
return "<p class='comment'><span class='synopsis'>Synopsis: </span>%s</p>\n" % tText
|
||||
else:
|
||||
return "<p class='comment'>%s</p>\n" % tText
|
||||
return "<p class='synopsis'><strong>Synopsis: </strong>%s</p>\n" % tText
|
||||
|
||||
def _formatComments(self, tText):
|
||||
"""Apply HTML formatting to comments.
|
||||
"""
|
||||
if self.genMode == self.M_EXPORT:
|
||||
return "<p class='comment'><strong>Comment: </strong>%s</p>\n" % tText
|
||||
else:
|
||||
if self.genMode == self.M_PREVIEW:
|
||||
return "<p class='comment'>%s</p>\n" % tText
|
||||
else:
|
||||
return "<p class='comment'><strong>Comment: </strong>%s</p>\n" % tText
|
||||
|
||||
def _formatKeywords(self, tText):
|
||||
"""Apply HTML formatting to keywords.
|
||||
|
||||
+8
-1
@@ -136,7 +136,7 @@ class GuiDocViewer(QTextBrowser):
|
||||
logger.debug("Generating preview for item %s" % tHandle)
|
||||
sPos = self.verticalScrollBar().value()
|
||||
aDoc = ToHtml(self.theProject, self.theParent)
|
||||
aDoc.setPreview(True, self.mainConf.viewComments)
|
||||
aDoc.setPreview(True, self.mainConf.viewComments, self.mainConf.viewSynopsis)
|
||||
aDoc.setLinkHeaders(True)
|
||||
|
||||
# Be extra careful here to prevent crashes when first opening a
|
||||
@@ -366,6 +366,10 @@ class GuiDocViewer(QTextBrowser):
|
||||
" margin-left: 1em;"
|
||||
" margin-right: 1em;"
|
||||
"}}\n"
|
||||
".synopsis {{"
|
||||
" color: rgb({mColR},{mColG},{mColB});"
|
||||
" font-wright: bold;"
|
||||
"}}\n"
|
||||
).format(
|
||||
textSize = self.mainConf.textSize,
|
||||
preSize = self.mainConf.textSize*0.9,
|
||||
@@ -387,6 +391,9 @@ class GuiDocViewer(QTextBrowser):
|
||||
kColR = self.theTheme.colKey[0],
|
||||
kColG = self.theTheme.colKey[1],
|
||||
kColB = self.theTheme.colKey[2],
|
||||
mColR = self.theTheme.colMod[0],
|
||||
mColG = self.theTheme.colMod[1],
|
||||
mColB = self.theTheme.colMod[2],
|
||||
)
|
||||
self.qDocument.setDefaultStyleSheet(styleSheet)
|
||||
|
||||
|
||||
@@ -114,11 +114,6 @@ class GuiMainMenu(QMenuBar):
|
||||
self.theProject.setAutoOutline(theMode)
|
||||
return True
|
||||
|
||||
def _toggleViewComments(self):
|
||||
self.mainConf.setViewComments(self.aViewDocComments.isChecked())
|
||||
self.theParent.docViewer.reloadText()
|
||||
return True
|
||||
|
||||
def _showAbout(self):
|
||||
"""Show the about dialog.
|
||||
"""
|
||||
@@ -314,14 +309,6 @@ class GuiMainMenu(QMenuBar):
|
||||
self.aCloseView.triggered.connect(self.theParent.closeDocViewer)
|
||||
self.docuMenu.addAction(self.aCloseView)
|
||||
|
||||
# Document > Toggle View Comments
|
||||
self.aViewDocComments = QAction("Show Comments", self)
|
||||
self.aViewDocComments.setStatusTip("Show comments in view panel")
|
||||
self.aViewDocComments.setCheckable(True)
|
||||
self.aViewDocComments.setChecked(self.mainConf.viewComments)
|
||||
self.aViewDocComments.toggled.connect(self._toggleViewComments)
|
||||
self.docuMenu.addAction(self.aViewDocComments)
|
||||
|
||||
# Document > Separator
|
||||
self.docuMenu.addSeparator()
|
||||
|
||||
|
||||
+25
-1
@@ -62,7 +62,7 @@ class GuiPreferences(PagedDialog):
|
||||
self.tabAutoRep = GuiConfigEditAutoReplaceTab(self.theParent)
|
||||
|
||||
self.addTab(self.tabGeneral, "General")
|
||||
self.addTab(self.tabLayout, "Layout")
|
||||
self.addTab(self.tabLayout, "Text Layout")
|
||||
self.addTab(self.tabEditing, "Editor")
|
||||
self.addTab(self.tabAutoRep, "Auto-Replace")
|
||||
|
||||
@@ -506,6 +506,26 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
self.showLineEndings
|
||||
)
|
||||
|
||||
# Render Options
|
||||
# ==============
|
||||
self.mainForm.addGroupLabel("Render Text")
|
||||
|
||||
## Render Comments
|
||||
self.viewComments = QSwitch()
|
||||
self.viewComments.setChecked(self.mainConf.viewComments)
|
||||
self.mainForm.addRow(
|
||||
"Render comments in document view panel",
|
||||
self.viewComments
|
||||
)
|
||||
|
||||
## Render Synopsis
|
||||
self.viewSynopsis = QSwitch()
|
||||
self.viewSynopsis.setChecked(self.mainConf.viewSynopsis)
|
||||
self.mainForm.addRow(
|
||||
"Render synopsis in document view panel",
|
||||
self.viewSynopsis
|
||||
)
|
||||
|
||||
return
|
||||
|
||||
def saveValues(self):
|
||||
@@ -523,6 +543,8 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
tabWidth = self.tabWidth.value()
|
||||
showTabsNSpaces = self.showTabsNSpaces.isChecked()
|
||||
showLineEndings = self.showLineEndings.isChecked()
|
||||
viewComments = self.viewComments.isChecked()
|
||||
viewSynopsis = self.viewSynopsis.isChecked()
|
||||
|
||||
self.mainConf.textFont = textFont
|
||||
self.mainConf.textSize = textSize
|
||||
@@ -534,6 +556,8 @@ class GuiConfigEditLayoutTab(QWidget):
|
||||
self.mainConf.tabWidth = tabWidth
|
||||
self.mainConf.showTabsNSpaces = showTabsNSpaces
|
||||
self.mainConf.showLineEndings = showLineEndings
|
||||
self.mainConf.viewComments = viewComments
|
||||
self.mainConf.viewSynopsis = viewSynopsis
|
||||
|
||||
self.mainConf.confChanged = True
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[Main]
|
||||
timestamp = 2020-06-09 23:05:17
|
||||
timestamp = 2020-06-13 22:59:36
|
||||
theme = default
|
||||
syntax = default_light
|
||||
icons = typicons_colour_light
|
||||
@@ -54,6 +54,7 @@ askbeforebackup = True
|
||||
[State]
|
||||
showrefpanel = True
|
||||
viewcomments = True
|
||||
viewsynopsis = True
|
||||
|
||||
[Path]
|
||||
lastpath =
|
||||
|
||||
@@ -70,6 +70,7 @@ def testConfigSetTreeColWidths(nwTemp,nwRef):
|
||||
assert theConf.setTreeColWidths([0, 0, 0])
|
||||
assert theConf.confChanged
|
||||
assert theConf.setTreeColWidths([120, 30, 50])
|
||||
assert theConf.setProjColWidths([140, 55, 140])
|
||||
assert theConf.saveConfig()
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
@@ -82,6 +83,8 @@ def testConfigSetPanePos(nwTemp,nwRef):
|
||||
assert theConf.confChanged
|
||||
assert theConf.setMainPanePos([300, 800])
|
||||
assert theConf.setDocPanePos([400, 400])
|
||||
assert theConf.setViewPanePos([500, 150])
|
||||
assert theConf.setOutlinePanePos([500, 150])
|
||||
assert theConf.saveConfig()
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
assert not theConf.confChanged
|
||||
@@ -92,8 +95,6 @@ def testConfigFlags(nwTemp,nwRef):
|
||||
refConf = path.join(nwRef, "novelwriter.conf")
|
||||
assert not theConf.setShowRefPanel(False)
|
||||
assert theConf.setShowRefPanel(True)
|
||||
assert not theConf.setViewComments(False)
|
||||
assert theConf.setViewComments(True)
|
||||
assert theConf.confChanged
|
||||
assert theConf.saveConfig()
|
||||
assert cmpFiles(tmpConf, refConf, [2])
|
||||
|
||||
Reference in New Issue
Block a user