From 788bec45676327f41a2a93e0ce1ca5f83c1c020f Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Sat, 10 Oct 2020 17:52:18 +0200
Subject: [PATCH 1/3] Added line status icons
---
.../icons/fallback/status_lines-dark.svg | 78 +++++++++++++++++++
nw/assets/icons/fallback/status_lines.svg | 78 +++++++++++++++++++
nw/gui/theme.py | 1 +
3 files changed, 157 insertions(+)
create mode 100644 nw/assets/icons/fallback/status_lines-dark.svg
create mode 100644 nw/assets/icons/fallback/status_lines.svg
diff --git a/nw/assets/icons/fallback/status_lines-dark.svg b/nw/assets/icons/fallback/status_lines-dark.svg
new file mode 100644
index 00000000..a977f507
--- /dev/null
+++ b/nw/assets/icons/fallback/status_lines-dark.svg
@@ -0,0 +1,78 @@
+
+
diff --git a/nw/assets/icons/fallback/status_lines.svg b/nw/assets/icons/fallback/status_lines.svg
new file mode 100644
index 00000000..d249f307
--- /dev/null
+++ b/nw/assets/icons/fallback/status_lines.svg
@@ -0,0 +1,78 @@
+
+
diff --git a/nw/gui/theme.py b/nw/gui/theme.py
index 0af7df5e..88cdd72f 100644
--- a/nw/gui/theme.py
+++ b/nw/gui/theme.py
@@ -529,6 +529,7 @@ class GuiIcons:
"status_lang" : (None, None),
"status_time" : (None, None),
"status_stats" : (None, None),
+ "status_lines" : (None, None),
"doc_h1" : (QStyle.SP_FileIcon, "x-office-document"),
"doc_h2" : (QStyle.SP_FileIcon, "x-office-document"),
"doc_h3" : (QStyle.SP_FileIcon, "x-office-document"),
From 7105cd637feee81be4343c2730b1391252133a28 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Sat, 10 Oct 2020 17:52:37 +0200
Subject: [PATCH 2/3] Added line counter to document footer
---
nw/gui/doceditor.py | 44 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 43 insertions(+), 1 deletion(-)
diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py
index ba0b1945..d4498b5e 100644
--- a/nw/gui/doceditor.py
+++ b/nw/gui/doceditor.py
@@ -312,6 +312,8 @@ class GuiDocEditor(QTextEdit):
else:
self.setCursorLine(tLine)
+ self.docFooter.updateLineCount()
+
qApp.restoreOverrideCursor()
return True
@@ -462,6 +464,7 @@ class GuiDocEditor(QTextEdit):
theCursor = self.textCursor()
theCursor.setPosition(thePosition)
self.setTextCursor(theCursor)
+ self.docFooter.updateLineCount()
return True
def getCursorPosition(self):
@@ -488,6 +491,7 @@ class GuiDocEditor(QTextEdit):
theBlock = self.qDocument.findBlockByLineNumber(theLine)
if theBlock:
self.setCursorPosition(theBlock.position())
+ self.docFooter.updateLineCount()
logger.verbose("Cursor moved to line %d" % theLine)
return True
@@ -736,6 +740,7 @@ class GuiDocEditor(QTextEdit):
elif keyEvent == QKeySequence.Undo:
self.docAction(nwDocAction.UNDO)
else:
+ self.docFooter.updateLineCount()
QTextEdit.keyPressEvent(self, keyEvent)
return
@@ -759,6 +764,7 @@ class GuiDocEditor(QTextEdit):
if qApp.keyboardModifiers() == Qt.ControlModifier:
theCursor = self.cursorForPosition(mEvent.pos())
self._followTag(theCursor)
+ self.docFooter.updateLineCount()
QTextEdit.mouseReleaseEvent(self, mEvent)
return
@@ -2166,6 +2172,7 @@ class GuiDocEditFooter(QWidget):
self.sPx = int(round(0.9*self.theTheme.baseIconSize))
fPx = int(0.9*self.theTheme.fontPixelSize)
bSp = self.mainConf.pxInt(4)
+ hSp = self.mainConf.pxInt(6)
lblFont = self.font()
lblFont.setPointSizeF(0.9*self.theTheme.fontPointSize)
@@ -2191,6 +2198,23 @@ class GuiDocEditFooter(QWidget):
self.statusText.setPalette(self.thePalette)
self.statusText.setFont(lblFont)
+ # Lines
+ self.linesIcon = QLabel("")
+ self.linesIcon.setPixmap(self.theTheme.getPixmap("status_lines", (self.sPx, self.sPx)))
+ self.linesIcon.setContentsMargins(0, 0, 0, 0)
+ self.linesIcon.setFixedHeight(self.sPx)
+ self.linesIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop)
+
+ self.linesText = QLabel("Line: 0 of 0")
+ self.linesText.setIndent(0)
+ self.linesText.setMargin(0)
+ self.linesText.setContentsMargins(0, 0, 0, 0)
+ self.linesText.setAutoFillBackground(True)
+ self.linesText.setFixedHeight(fPx)
+ self.linesText.setAlignment(Qt.AlignLeft | Qt.AlignTop)
+ self.linesText.setPalette(self.thePalette)
+ self.linesText.setFont(lblFont)
+
# Words
self.wordsIcon = QLabel("")
self.wordsIcon.setPixmap(self.theTheme.getPixmap("status_stats", (self.sPx, self.sPx)))
@@ -2214,6 +2238,9 @@ class GuiDocEditFooter(QWidget):
self.outerBox.addWidget(self.statusIcon)
self.outerBox.addWidget(self.statusText)
self.outerBox.addStretch(1)
+ self.outerBox.addWidget(self.linesIcon)
+ self.outerBox.addWidget(self.linesText)
+ self.outerBox.addSpacing(hSp)
self.outerBox.addWidget(self.wordsIcon)
self.outerBox.addWidget(self.wordsText)
self.setLayout(self.outerBox)
@@ -2263,8 +2290,23 @@ class GuiDocEditFooter(QWidget):
return
+ def updateLineCount(self):
+ """Update the word count.
+ """
+ if self.theItem is None:
+ iLine = 0
+ nLine = 0
+ else:
+ theCursor = self.docEditor.textCursor()
+ iLine = theCursor.blockNumber() + 1
+ nLine = self.docEditor.qDocument.blockCount()
+
+ self.linesText.setText("Line: %d of %d" % (iLine, nLine))
+
+ return
+
def updateCounts(self):
- """Update the word counts.
+ """Update the word count.
"""
if self.theItem is None:
wCount = 0
From e9868744f4d7343b799301e0bfe328af6bac32b7 Mon Sep 17 00:00:00 2001
From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com>
Date: Sat, 10 Oct 2020 17:58:22 +0200
Subject: [PATCH 3/3] Remove the total line count, and trigger the update
*after* the key/mouse events
---
nw/gui/doceditor.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/nw/gui/doceditor.py b/nw/gui/doceditor.py
index d4498b5e..1d1d2a4e 100644
--- a/nw/gui/doceditor.py
+++ b/nw/gui/doceditor.py
@@ -740,8 +740,9 @@ class GuiDocEditor(QTextEdit):
elif keyEvent == QKeySequence.Undo:
self.docAction(nwDocAction.UNDO)
else:
- self.docFooter.updateLineCount()
QTextEdit.keyPressEvent(self, keyEvent)
+ self.docFooter.updateLineCount()
+
return
def focusNextPrevChild(self, toNext):
@@ -764,8 +765,10 @@ class GuiDocEditor(QTextEdit):
if qApp.keyboardModifiers() == Qt.ControlModifier:
theCursor = self.cursorForPosition(mEvent.pos())
self._followTag(theCursor)
- self.docFooter.updateLineCount()
+
QTextEdit.mouseReleaseEvent(self, mEvent)
+ self.docFooter.updateLineCount()
+
return
def resizeEvent(self, theEvent):
@@ -2205,7 +2208,7 @@ class GuiDocEditFooter(QWidget):
self.linesIcon.setFixedHeight(self.sPx)
self.linesIcon.setAlignment(Qt.AlignLeft | Qt.AlignTop)
- self.linesText = QLabel("Line: 0 of 0")
+ self.linesText = QLabel("Line: 0")
self.linesText.setIndent(0)
self.linesText.setMargin(0)
self.linesText.setContentsMargins(0, 0, 0, 0)
@@ -2295,13 +2298,11 @@ class GuiDocEditFooter(QWidget):
"""
if self.theItem is None:
iLine = 0
- nLine = 0
else:
theCursor = self.docEditor.textCursor()
iLine = theCursor.blockNumber() + 1
- nLine = self.docEditor.qDocument.blockCount()
- self.linesText.setText("Line: %d of %d" % (iLine, nLine))
+ self.linesText.setText(f"Line: {iLine:n}")
return