+1
-1
@@ -326,7 +326,7 @@ class QSwitch(QAbstractButton):
|
|||||||
"""
|
"""
|
||||||
super().mouseReleaseEvent(event)
|
super().mouseReleaseEvent(event)
|
||||||
if event.button() == Qt.LeftButton:
|
if event.button() == Qt.LeftButton:
|
||||||
doAnim = QPropertyAnimation(self, b'offset', self)
|
doAnim = QPropertyAnimation(self, b"offset", self)
|
||||||
doAnim.setDuration(120)
|
doAnim.setDuration(120)
|
||||||
doAnim.setStartValue(self.offset)
|
doAnim.setStartValue(self.offset)
|
||||||
if self.isChecked():
|
if self.isChecked():
|
||||||
|
|||||||
+42
-14
@@ -38,7 +38,7 @@ from time import time
|
|||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QSize, QTimer, pyqtSlot, pyqtSignal, QRegExp, QRegularExpression,
|
Qt, QSize, QTimer, pyqtSlot, pyqtSignal, QRegExp, QRegularExpression,
|
||||||
QPointF, QObject, QRunnable
|
QPointF, QObject, QRunnable, QPropertyAnimation
|
||||||
)
|
)
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette,
|
QTextCursor, QTextOption, QKeySequence, QFont, QColor, QPalette,
|
||||||
@@ -774,11 +774,22 @@ class GuiDocEditor(QTextEdit):
|
|||||||
if self.mainConf.scollWithCursor:
|
if self.mainConf.scollWithCursor:
|
||||||
kMod = keyEvent.modifiers()
|
kMod = keyEvent.modifiers()
|
||||||
if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
|
if kMod == Qt.NoModifier or kMod == Qt.ShiftModifier:
|
||||||
|
hWid = self.viewport().height()
|
||||||
cPos = self.cursorRect().center().y()
|
cPos = self.cursorRect().center().y()
|
||||||
mPos = self.mainConf.scollToPoint * self.viewport().height()
|
mPos = self.mainConf.scollToPoint * hWid
|
||||||
vBar = self.verticalScrollBar()
|
vBar = self.verticalScrollBar()
|
||||||
vBar.setValue(vBar.value() + cPos - round(mPos * 0.01))
|
|
||||||
self.ensureCursorVisible()
|
# 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:
|
||||||
|
doAnim = QPropertyAnimation(vBar, b"value", self)
|
||||||
|
doAnim.setDuration(aDur)
|
||||||
|
doAnim.setStartValue(pOld)
|
||||||
|
doAnim.setEndValue(pNew)
|
||||||
|
doAnim.start()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -849,11 +860,18 @@ class GuiDocEditor(QTextEdit):
|
|||||||
"""
|
"""
|
||||||
userCursor = self.textCursor()
|
userCursor = self.textCursor()
|
||||||
userSelection = userCursor.hasSelection()
|
userSelection = userCursor.hasSelection()
|
||||||
|
posCursor = self.cursorForPosition(thePos)
|
||||||
|
|
||||||
mnuContext = QMenu()
|
mnuContext = QMenu()
|
||||||
|
|
||||||
# Cut, Copy and Paste
|
# Follow, Cut, Copy and Paste
|
||||||
# ===================
|
# ===========================
|
||||||
|
|
||||||
|
if self._followTag(theCursor=posCursor, loadTag=False):
|
||||||
|
mnuTag = QAction("Follow Tag", mnuContext)
|
||||||
|
mnuTag.triggered.connect(lambda: self._followTag(theCursor=posCursor))
|
||||||
|
mnuContext.addAction(mnuTag)
|
||||||
|
mnuContext.addSeparator()
|
||||||
|
|
||||||
if userSelection:
|
if userSelection:
|
||||||
mnuCut = QAction("Cut", mnuContext)
|
mnuCut = QAction("Cut", mnuContext)
|
||||||
@@ -892,10 +910,13 @@ class GuiDocEditor(QTextEdit):
|
|||||||
# Spell Checking
|
# Spell Checking
|
||||||
# ==============
|
# ==============
|
||||||
|
|
||||||
|
posCursor = self.cursorForPosition(thePos)
|
||||||
spellCheck = self.spellCheck
|
spellCheck = self.spellCheck
|
||||||
|
|
||||||
|
if posCursor.block().text().startswith("@"):
|
||||||
|
spellCheck = False
|
||||||
|
|
||||||
if spellCheck:
|
if spellCheck:
|
||||||
posCursor = self.cursorForPosition(thePos)
|
|
||||||
posCursor.select(QTextCursor.WordUnderCursor)
|
posCursor.select(QTextCursor.WordUnderCursor)
|
||||||
theWord = posCursor.selectedText().strip().strip(self.nonWord)
|
theWord = posCursor.selectedText().strip().strip(self.nonWord)
|
||||||
spellCheck &= theWord != ""
|
spellCheck &= theWord != ""
|
||||||
@@ -959,8 +980,8 @@ class GuiDocEditor(QTextEdit):
|
|||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _runCounter(self):
|
def _runCounter(self):
|
||||||
"""Decide whether to run the word counter, or stop the timer due
|
"""Decide whether to run the word counter, or not due to
|
||||||
to inactivity.
|
inactivity.
|
||||||
"""
|
"""
|
||||||
if self.wCounter.isRunning():
|
if self.wCounter.isRunning():
|
||||||
logger.verbose("Word counter is busy")
|
logger.verbose("Word counter is busy")
|
||||||
@@ -1024,7 +1045,7 @@ class GuiDocEditor(QTextEdit):
|
|||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _followTag(self, theCursor=None):
|
def _followTag(self, theCursor=None, loadTag=True):
|
||||||
"""Activated by Ctrl+Enter. Checks that we're in a block
|
"""Activated by Ctrl+Enter. Checks that we're in a block
|
||||||
starting with '@'. We then find the word under the cursor and
|
starting with '@'. We then find the word under the cursor and
|
||||||
check that it is after the ':'. If all this is fine, we have a
|
check that it is after the ':'. If all this is fine, we have a
|
||||||
@@ -1049,10 +1070,15 @@ class GuiDocEditor(QTextEdit):
|
|||||||
if wPos <= cPos:
|
if wPos <= cPos:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
logger.verbose("Attempting to follow tag '%s'" % theWord)
|
if loadTag:
|
||||||
self.theParent.docViewer.loadFromTag(theWord)
|
logger.verbose("Attempting to follow tag '%s'" % theWord)
|
||||||
|
self.theParent.docViewer.loadFromTag(theWord)
|
||||||
|
else:
|
||||||
|
logger.verbose("Potential tag '%s'" % theWord)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
def _openSpellContext(self):
|
def _openSpellContext(self):
|
||||||
"""Opens the spell check context menu at the current point of
|
"""Opens the spell check context menu at the current point of
|
||||||
@@ -2335,11 +2361,13 @@ class GuiDocEditFooter(QWidget):
|
|||||||
"""
|
"""
|
||||||
if self.theItem is None:
|
if self.theItem is None:
|
||||||
iLine = 0
|
iLine = 0
|
||||||
|
iDist = 0
|
||||||
else:
|
else:
|
||||||
theCursor = self.docEditor.textCursor()
|
theCursor = self.docEditor.textCursor()
|
||||||
iLine = theCursor.blockNumber() + 1
|
iLine = theCursor.blockNumber() + 1
|
||||||
|
iDist = 100*iLine/self.docEditor.qDocument.blockCount()
|
||||||
|
|
||||||
self.linesText.setText(f"Line: {iLine:n}")
|
self.linesText.setText(f"Line: {iLine:n} ({iDist:.0f}\u202f%)")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,13 @@ def testDocEditor(qtbot, yesToAll, nwFuncTemp, nwTempGUI, nwRef, nwTemp):
|
|||||||
nwGUI.mainMenu.aSpellCheck.setChecked(True)
|
nwGUI.mainMenu.aSpellCheck.setChecked(True)
|
||||||
assert nwGUI.mainMenu._toggleSpellCheck()
|
assert nwGUI.mainMenu._toggleSpellCheck()
|
||||||
|
|
||||||
|
# Change some settings
|
||||||
|
nwGUI.mainConf.hideHScroll = True
|
||||||
|
nwGUI.mainConf.hideVScroll = True
|
||||||
|
nwGUI.mainConf.scrollPastEnd = True
|
||||||
|
nwGUI.mainConf.scollToPoint = 80
|
||||||
|
nwGUI.mainConf.scollWithCursor = True
|
||||||
|
|
||||||
# Add a Character File
|
# Add a Character File
|
||||||
nwGUI.setFocus(1)
|
nwGUI.setFocus(1)
|
||||||
nwGUI.treeView.clearSelection()
|
nwGUI.treeView.clearSelection()
|
||||||
|
|||||||
Reference in New Issue
Block a user