Change typewriter mode to scroll at any point

This commit is contained in:
Veronica K. B. Olsen
2020-10-18 19:25:12 +02:00
parent 7473c4272a
commit 8e222c1e67
2 changed files with 30 additions and 19 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# novelWriter ChangeLog
## Version 1.0 Release Beta 5 [2020-10-18]
## Version 1.0 Beta 5 [2020-10-18]
**Important Notes**
+29 -18
View File
@@ -61,6 +61,11 @@ logger = logging.getLogger(__name__)
class GuiDocEditor(QTextEdit):
MOVE_KEYS = (
Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down,
Qt.Key_PageUp, Qt.Key_PageDown
)
def __init__(self, theParent):
QTextEdit.__init__(self, theParent)
@@ -765,34 +770,40 @@ class GuiDocEditor(QTextEdit):
return
elif keyEvent == QKeySequence.Redo:
self.docAction(nwDocAction.REDO)
return
elif keyEvent == QKeySequence.Undo:
self.docAction(nwDocAction.UNDO)
return
elif keyEvent == QKeySequence.SelectAll:
self.docAction(nwDocAction.SEL_ALL)
else:
QTextEdit.keyPressEvent(self, keyEvent)
self.docFooter.updateLineCount()
return
if self.mainConf.scollWithCursor:
cOld = self.cursorRect().center().y()
QTextEdit.keyPressEvent(self, keyEvent)
kMod = keyEvent.modifiers()
if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
hWid = self.viewport().height()
cPos = self.cursorRect().center().y()
mPos = self.mainConf.scollToPoint * hWid
vBar = self.verticalScrollBar()
# Compute the needed scroll and duration
pOld = vBar.value()
pNew = pOld + cPos - round(mPos*0.01)
aDur = 150 + round(min(abs(pNew - pOld)/hWid, 1.0)*500)
if pNew >= 0:
okMod = kMod == Qt.NoModifier or kMod == Qt.ShiftModifier
okKey = keyEvent.key() not in self.MOVE_KEYS
if okMod and okKey:
cNew = self.cursorRect().center().y()
cMov = cNew - cOld
mPos = self.mainConf.scollToPoint * self.viewport().height() * 0.01
if abs(cMov) > 0 and cOld > mPos:
# Move the scroll bar
vBar = self.verticalScrollBar()
doAnim = QPropertyAnimation(vBar, b"value", self)
doAnim.setDuration(aDur)
doAnim.setStartValue(pOld)
doAnim.setEndValue(pNew)
doAnim.setDuration(150)
doAnim.setStartValue(vBar.value())
doAnim.setEndValue(vBar.value() + cMov)
doAnim.start()
else:
QTextEdit.keyPressEvent(self, keyEvent)
self.docFooter.updateLineCount()
return
def focusNextPrevChild(self, toNext):