Change typewriter mode to scroll at any point
This commit is contained in:
+1
-1
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user