aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrien Tétar2015-07-23 15:55:25 +0200
committerAdrien Tétar2015-07-23 15:55:25 +0200
commitd925d69e39c888dd3be46cc19b212c8a1d22659e (patch)
treecb9d7895c16627e3566fcb29ceb482c66e4a0c91
parentef7b2a2cb8ac4ec52deb92037a20da33b63f7886 (diff)
downloadtrufont-d925d69e39c888dd3be46cc19b212c8a1d22659e.tar.bz2
spaceCenter: scroll to canvas region, featureTextEditor: always calc. viewport geometry on init.
-rw-r--r--Lib/defconQt/featureTextEditor.py14
-rw-r--r--Lib/defconQt/spaceCenter.py14
2 files changed, 21 insertions, 7 deletions
diff --git a/Lib/defconQt/featureTextEditor.py b/Lib/defconQt/featureTextEditor.py
index 4458ba1..ef16199 100644
--- a/Lib/defconQt/featureTextEditor.py
+++ b/Lib/defconQt/featureTextEditor.py
@@ -73,11 +73,13 @@ class TextEditor(QPlainTextEdit):
self._indent = " "
self.highlighter = Highlighter(self.document())
self.lineNumbers = LineNumberArea(self)
+ self.setPlainText(text)
+ # kick-in geometry update before arming signals bc blockCountChanged
+ # won't initially trigger if text is None or one-liner.
+ self.updateLineNumberAreaWidth()
self.blockCountChanged.connect(self.updateLineNumberAreaWidth)
self.updateRequest.connect(self.updateLineNumberArea)
-
- self.setPlainText(text)
-
+
def setFontParams(self, family='Roboto Mono', ptSize=10, isMono=True):
font = QFont(family, ptSize)
font.setFixedPitch(isMono)
@@ -115,7 +117,7 @@ class TextEditor(QPlainTextEdit):
def lineNumberAreaWidth(self):
digits = 1
top = max(1, self.blockCount())
- while (top >= 10):
+ while top >= 10:
top /= 10
digits += 1
# Avoid too frequent geometry changes
@@ -132,7 +134,7 @@ class TextEditor(QPlainTextEdit):
if rect.contains(self.viewport().rect()):
self.updateLineNumberAreaWidth(0)
- def updateLineNumberAreaWidth(self, newBlockCount):
+ def updateLineNumberAreaWidth(self, newBlockCount=None):
self.setViewportMargins(self.lineNumberAreaWidth(), 0, 0, 0)
def resizeEvent(self, event):
@@ -145,7 +147,7 @@ class TextEditor(QPlainTextEdit):
cursor.select(QTextCursor.LineUnderCursor)
lineLength = len(cursor.selectedText()) // len(self._indent)
cursor.movePosition(QTextCursor.StartOfLine)
- while (lineLength > 0):
+ while lineLength > 0:
cursor.movePosition(QTextCursor.NextCharacter, QTextCursor.KeepAnchor, len(self._indent))
if cursor.selectedText() == self._indent:
indent += 1
diff --git a/Lib/defconQt/spaceCenter.py b/Lib/defconQt/spaceCenter.py
index b2d4079..d2ff22d 100644
--- a/Lib/defconQt/spaceCenter.py
+++ b/Lib/defconQt/spaceCenter.py
@@ -308,8 +308,20 @@ class GlyphsCanvas(QWidget):
self._pointSizeChangedCallback = pointSizeChangedCallback
def setSelected(self, selected):
- # TODO: this should scroll to selection as well
self._selected = selected
+ if self._positions is not None:
+ cur_len = 0
+ line = -1
+ for index, li in enumerate(self._positions):
+ if cur_len + len(li) > self._selected:
+ pos, width = li[self._selected - cur_len]
+ line = index
+ break
+ cur_len += len(li)
+ if line > -1:
+ x = self.padding + pos + width/2
+ y = self.padding + (line+.5)*self.ptSize
+ self.scrollArea.ensureVisible(x, y, width/2+20, .5*self.ptSize+20)
self.update()
def setSelectionCallback(self, selectionChangedCallback):