Change typewriter mode to scroll at any point
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
# novelWriter ChangeLog
|
# novelWriter ChangeLog
|
||||||
|
|
||||||
## Version 1.0 Release Beta 5 [2020-10-18]
|
## Version 1.0 Beta 5 [2020-10-18]
|
||||||
|
|
||||||
**Important Notes**
|
**Important Notes**
|
||||||
|
|
||||||
|
|||||||
+29
-18
@@ -61,6 +61,11 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class GuiDocEditor(QTextEdit):
|
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):
|
def __init__(self, theParent):
|
||||||
QTextEdit.__init__(self, theParent)
|
QTextEdit.__init__(self, theParent)
|
||||||
|
|
||||||
@@ -765,34 +770,40 @@ class GuiDocEditor(QTextEdit):
|
|||||||
return
|
return
|
||||||
elif keyEvent == QKeySequence.Redo:
|
elif keyEvent == QKeySequence.Redo:
|
||||||
self.docAction(nwDocAction.REDO)
|
self.docAction(nwDocAction.REDO)
|
||||||
|
return
|
||||||
elif keyEvent == QKeySequence.Undo:
|
elif keyEvent == QKeySequence.Undo:
|
||||||
self.docAction(nwDocAction.UNDO)
|
self.docAction(nwDocAction.UNDO)
|
||||||
|
return
|
||||||
elif keyEvent == QKeySequence.SelectAll:
|
elif keyEvent == QKeySequence.SelectAll:
|
||||||
self.docAction(nwDocAction.SEL_ALL)
|
self.docAction(nwDocAction.SEL_ALL)
|
||||||
else:
|
return
|
||||||
QTextEdit.keyPressEvent(self, keyEvent)
|
|
||||||
self.docFooter.updateLineCount()
|
|
||||||
|
|
||||||
if self.mainConf.scollWithCursor:
|
if self.mainConf.scollWithCursor:
|
||||||
|
|
||||||
|
cOld = self.cursorRect().center().y()
|
||||||
|
QTextEdit.keyPressEvent(self, keyEvent)
|
||||||
|
|
||||||
kMod = keyEvent.modifiers()
|
kMod = keyEvent.modifiers()
|
||||||
if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
|
okMod = kMod == Qt.NoModifier or kMod == Qt.ShiftModifier
|
||||||
hWid = self.viewport().height()
|
okKey = keyEvent.key() not in self.MOVE_KEYS
|
||||||
cPos = self.cursorRect().center().y()
|
if okMod and okKey:
|
||||||
mPos = self.mainConf.scollToPoint * hWid
|
cNew = self.cursorRect().center().y()
|
||||||
vBar = self.verticalScrollBar()
|
cMov = cNew - cOld
|
||||||
|
mPos = self.mainConf.scollToPoint * self.viewport().height() * 0.01
|
||||||
# Compute the needed scroll and duration
|
if abs(cMov) > 0 and cOld > mPos:
|
||||||
pOld = vBar.value()
|
# Move the scroll bar
|
||||||
pNew = pOld + cPos - round(mPos*0.01)
|
vBar = self.verticalScrollBar()
|
||||||
aDur = 150 + round(min(abs(pNew - pOld)/hWid, 1.0)*500)
|
|
||||||
|
|
||||||
if pNew >= 0:
|
|
||||||
doAnim = QPropertyAnimation(vBar, b"value", self)
|
doAnim = QPropertyAnimation(vBar, b"value", self)
|
||||||
doAnim.setDuration(aDur)
|
doAnim.setDuration(150)
|
||||||
doAnim.setStartValue(pOld)
|
doAnim.setStartValue(vBar.value())
|
||||||
doAnim.setEndValue(pNew)
|
doAnim.setEndValue(vBar.value() + cMov)
|
||||||
doAnim.start()
|
doAnim.start()
|
||||||
|
|
||||||
|
else:
|
||||||
|
QTextEdit.keyPressEvent(self, keyEvent)
|
||||||
|
|
||||||
|
self.docFooter.updateLineCount()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def focusNextPrevChild(self, toNext):
|
def focusNextPrevChild(self, toNext):
|
||||||
|
|||||||
Reference in New Issue
Block a user