Clean up flags in all GUI classes

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 21:09:49 +02:00
parent 20c5993e2d
commit 8fff376076
32 changed files with 236 additions and 229 deletions
+27 -38
View File
@@ -65,7 +65,8 @@ from novelwriter.text.counting import standardCounter
from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
QtAlignRight, QtModCtrl, QtMouseLeft, QtModeNone, QtModShift
QtAlignRight, QtKeepAnchor, QtModCtrl, QtMouseLeft, QtModeNone, QtModShift,
QtMoveAnchor, QtMoveLeft, QtMoveRight
)
if TYPE_CHECKING: # pragma: no cover
@@ -656,8 +657,8 @@ class GuiDocEditor(QPlainTextEdit):
"""Make a text selection."""
if start >= 0 and length > 0:
cursor = self.textCursor()
cursor.setPosition(start, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(start + length, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(start, QtMoveAnchor)
cursor.setPosition(start + length, QtKeepAnchor)
self.setTextCursor(cursor)
return
@@ -1092,8 +1093,8 @@ class GuiDocEditor(QPlainTextEdit):
block = cursor.block()
if block.isValid():
pos += block.position()
cursor.setPosition(pos, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(pos + length, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(pos, QtMoveAnchor)
cursor.setPosition(pos + length, QtKeepAnchor)
cursor.insertText(text)
self._completer.hide()
return
@@ -1153,9 +1154,7 @@ class GuiDocEditor(QPlainTextEdit):
block = pCursor.block()
sCursor = self.textCursor()
sCursor.setPosition(block.position() + cPos)
sCursor.movePosition(
QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, cLen
)
sCursor.movePosition(QtMoveRight, QtKeepAnchor, cLen)
if suggest:
ctxMenu.addSeparator()
ctxMenu.addAction(self.tr("Spelling Suggestion(s)"))
@@ -1351,8 +1350,8 @@ class GuiDocEditor(QPlainTextEdit):
else:
resIdx = 0 if doLoop else maxIdx
cursor.setPosition(resS[resIdx], QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(resE[resIdx], QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(resS[resIdx], QtMoveAnchor)
cursor.setPosition(resE[resIdx], QtKeepAnchor)
self.setTextCursor(cursor)
self.docSearch.setResultCount(resIdx + 1, len(resS))
@@ -1398,8 +1397,8 @@ class GuiDocEditor(QPlainTextEdit):
break
if hasSelection:
cursor.setPosition(origA, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(origB, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(origA, QtMoveAnchor)
cursor.setPosition(origB, QtKeepAnchor)
else:
cursor.setPosition(origA)
@@ -1502,8 +1501,8 @@ class GuiDocEditor(QPlainTextEdit):
if blockS != blockE:
posE = blockS.position() + blockS.length() - 1
cursor.clearSelection()
cursor.setPosition(posS, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(posE, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(posS, QtMoveAnchor)
cursor.setPosition(posE, QtKeepAnchor)
self.setTextCursor(cursor)
numB = 0
@@ -1580,8 +1579,8 @@ class GuiDocEditor(QPlainTextEdit):
if select == _SelectAction.MOVE_AFTER:
cursor.setPosition(posE + len(before + after))
elif select == _SelectAction.KEEP_SELECTION:
cursor.setPosition(posE + len(before), QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(posS + len(before), QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(posE + len(before), QtMoveAnchor)
cursor.setPosition(posS + len(before), QtKeepAnchor)
elif select == _SelectAction.KEEP_POSITION:
cursor.setPosition(posO + len(before))
@@ -1603,9 +1602,7 @@ class GuiDocEditor(QPlainTextEdit):
self._allowAutoReplace(False)
for posC in range(posS, posE+1):
cursor.setPosition(posC)
cursor.movePosition(
QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.KeepAnchor, 2
)
cursor.movePosition(QtMoveLeft, QtKeepAnchor, 2)
selText = cursor.selectedText()
nS = len(selText)
@@ -1625,16 +1622,12 @@ class GuiDocEditor(QPlainTextEdit):
cursor.setPosition(posC)
if pC in closeCheck:
cursor.beginEditBlock()
cursor.movePosition(
QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.KeepAnchor, 1
)
cursor.movePosition(QtMoveLeft, QtKeepAnchor, 1)
cursor.insertText(oQuote)
cursor.endEditBlock()
else:
cursor.beginEditBlock()
cursor.movePosition(
QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.KeepAnchor, 1
)
cursor.movePosition(QtMoveLeft, QtKeepAnchor, 1)
cursor.insertText(cQuote)
cursor.endEditBlock()
@@ -1850,9 +1843,7 @@ class GuiDocEditor(QPlainTextEdit):
cursor.beginEditBlock()
cursor.clearSelection()
cursor.setPosition(rS)
cursor.movePosition(
QTextCursor.MoveOperation.Right, QTextCursor.MoveMode.KeepAnchor, rE-rS
)
cursor.movePosition(QtMoveRight, QtKeepAnchor, rE-rS)
cursor.insertText(cleanText.rstrip() + "\n")
cursor.endEditBlock()
@@ -2018,9 +2009,7 @@ class GuiDocEditor(QPlainTextEdit):
tInsert = tInsert + self._typPadChar
if nDelete > 0:
cursor.movePosition(
QTextCursor.MoveOperation.Left, QTextCursor.MoveMode.KeepAnchor, nDelete
)
cursor.movePosition(QtMoveLeft, QtKeepAnchor, nDelete)
cursor.insertText(tInsert)
return
@@ -2076,8 +2065,8 @@ class GuiDocEditor(QPlainTextEdit):
return cursor
cursor.clearSelection()
cursor.setPosition(sPos, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(ePos, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(sPos, QtMoveAnchor)
cursor.setPosition(ePos, QtKeepAnchor)
self.setTextCursor(cursor)
@@ -2101,8 +2090,8 @@ class GuiDocEditor(QPlainTextEdit):
posE = cursor.selectionEnd()
selTxt = cursor.selectedText()
if selTxt.startswith(nwUnicode.U_PSEP):
cursor.setPosition(posS+1, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(posE, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(posS+1, QtMoveAnchor)
cursor.setPosition(posE, QtKeepAnchor)
self.setTextCursor(cursor)
@@ -2441,11 +2430,11 @@ class GuiDocEditSearch(QFrame):
self.searchOpt.setIconSize(iSz)
self.searchOpt.setContentsMargins(0, 0, 0, 0)
self.searchLabel = QLabel(self.tr("Search"))
self.searchLabel = QLabel(self.tr("Search"), self)
self.searchLabel.setFont(self.boxFont)
self.searchLabel.setIndent(CONFIG.pxInt(6))
self.resultLabel = QLabel("?/?")
self.resultLabel = QLabel("?/?", self)
self.resultLabel.setFont(self.boxFont)
self.resultLabel.setMinimumWidth(SHARED.theme.getTextWidth("?/?", self.boxFont))
@@ -3047,7 +3036,7 @@ class GuiDocEditFooter(QWidget):
self.statusIcon.setFixedHeight(iPx)
self.statusIcon.setAlignment(QtAlignLeftTop)
self.statusText = QLabel(self.tr("Status"))
self.statusText = QLabel(self.tr("Status"), self)
self.statusText.setIndent(0)
self.statusText.setMargin(0)
self.statusText.setContentsMargins(0, 0, 0, 0)
+1 -1
View File
@@ -116,7 +116,7 @@ class GuiDocHighlighter(QSyntaxHighlighter):
# Cache Spell Error Format
self._spellErr = QTextCharFormat()
self._spellErr.setUnderlineColor(SHARED.theme.colSpell)
self._spellErr.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
self._spellErr.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
# Multiple or Trailing Spaces
if CONFIG.showMultiSpaces:
+6 -4
View File
@@ -49,7 +49,9 @@ from novelwriter.error import logException
from novelwriter.extensions.eventfilters import WheelEventFilter
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignCenterTop, QtAlignJustify, QtMouseLeft
from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtKeepAnchor, QtMouseLeft, QtMoveAnchor
)
logger = logging.getLogger(__name__)
@@ -452,8 +454,8 @@ class GuiDocViewer(QTextBrowser):
posE = cursor.selectionEnd()
selTxt = cursor.selectedText()
if selTxt.startswith(nwUnicode.U_PSEP):
cursor.setPosition(posS+1, QTextCursor.MoveMode.MoveAnchor)
cursor.setPosition(posE, QTextCursor.MoveMode.KeepAnchor)
cursor.setPosition(posS+1, QtMoveAnchor)
cursor.setPosition(posE, QtKeepAnchor)
self.setTextCursor(cursor)
@@ -635,7 +637,7 @@ class GuiDocViewHeader(QWidget):
self.setAutoFillBackground(True)
# Title Label
self.itemTitle = QLabel()
self.itemTitle = QLabel(self)
self.itemTitle.setText("")
self.itemTitle.setIndent(0)
self.itemTitle.setMargin(0)
+5 -5
View File
@@ -115,25 +115,25 @@ class GuiItemDetails(QWidget):
self.cCountName.setFont(fntLabel)
self.cCountName.setAlignment(QtAlignRight)
self.cCountData = QLabel("")
self.cCountData = QLabel("", self)
self.cCountData.setFont(fntValue)
self.cCountData.setAlignment(QtAlignRight)
# Word Count
self.wCountName = QLabel(" "+self.tr("Words"))
self.wCountName = QLabel(" "+self.tr("Words"), self)
self.wCountName.setFont(fntLabel)
self.wCountName.setAlignment(QtAlignRight)
self.wCountData = QLabel("")
self.wCountData = QLabel("", self)
self.wCountData.setFont(fntValue)
self.wCountData.setAlignment(QtAlignRight)
# Paragraph Count
self.pCountName = QLabel(" "+self.tr("Paragraphs"))
self.pCountName = QLabel(" "+self.tr("Paragraphs"), self)
self.pCountName.setFont(fntLabel)
self.pCountName.setAlignment(QtAlignRight)
self.pCountData = QLabel("")
self.pCountData = QLabel("", self)
self.pCountData.setFont(fntValue)
self.pCountData.setAlignment(QtAlignRight)
+35 -35
View File
@@ -70,7 +70,7 @@ class GuiOutlineView(QWidget):
self.outlineBar = GuiOutlineToolBar(self)
self.outlineBar.setEnabled(False)
self.splitOutline = QSplitter(Qt.Orientation.Vertical)
self.splitOutline = QSplitter(Qt.Orientation.Vertical, self)
self.splitOutline.addWidget(self.outlineTree)
self.splitOutline.addWidget(self.outlineData)
self.splitOutline.setOpaqueResize(False)
@@ -220,7 +220,7 @@ class GuiOutlineToolBar(QToolBar):
stretch.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
# Novel Selector
self.novelLabel = QLabel(self.tr("Outline of"))
self.novelLabel = QLabel(self.tr("Outline of"), self)
self.novelLabel.setContentsMargins(0, 0, mPx, 0)
self.novelValue = NovelSelector(self)
@@ -803,12 +803,12 @@ class GuiOutlineDetails(QScrollArea):
bFont = SHARED.theme.guiFontB
# Details Area
self.titleLabel = QLabel(self.tr("Title"))
self.fileLabel = QLabel(self.tr("Document"))
self.itemLabel = QLabel(self.tr("Status"))
self.titleValue = QLabel("")
self.fileValue = QLabel("")
self.itemValue = QLabel("")
self.titleLabel = QLabel(self.tr("Title"), self)
self.fileLabel = QLabel(self.tr("Document"), self)
self.itemLabel = QLabel(self.tr("Status"), self)
self.titleValue = QLabel("", self)
self.fileValue = QLabel("", self)
self.itemValue = QLabel("", self)
self.titleLabel.setFont(bFont)
self.fileLabel.setFont(bFont)
@@ -822,12 +822,12 @@ class GuiOutlineDetails(QScrollArea):
self.itemValue.setMaximumWidth(maxTitle)
# Stats Area
self.cCLabel = QLabel(self.tr("Characters"))
self.wCLabel = QLabel(self.tr("Words"))
self.pCLabel = QLabel(self.tr("Paragraphs"))
self.cCValue = QLabel("")
self.wCValue = QLabel("")
self.pCValue = QLabel("")
self.cCLabel = QLabel(self.tr("Characters"), self)
self.wCLabel = QLabel(self.tr("Words"), self)
self.pCLabel = QLabel(self.tr("Paragraphs"), self)
self.cCValue = QLabel("", self)
self.wCValue = QLabel("", self)
self.pCValue = QLabel("", self)
self.cCLabel.setFont(bFont)
self.wCLabel.setFont(bFont)
@@ -841,10 +841,10 @@ class GuiOutlineDetails(QScrollArea):
self.pCValue.setAlignment(QtAlignRight)
# Synopsis
self.synopLabel = QLabel(self.tr("Synopsis"))
self.synopLabel = QLabel(self.tr("Synopsis"), self)
self.synopLabel.setFont(bFont)
self.synopValue = QLabel("")
self.synopValue = QLabel("", self)
self.synopValue.setWordWrap(True)
self.synopValue.setAlignment(QtAlignLeftTop)
@@ -852,15 +852,15 @@ class GuiOutlineDetails(QScrollArea):
self.synopLWrap.addWidget(self.synopValue, 1)
# Tags
self.povKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.POV_KEY]))
self.focKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.FOCUS_KEY]))
self.chrKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.CHAR_KEY]))
self.pltKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY]))
self.timKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.TIME_KEY]))
self.wldKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.WORLD_KEY]))
self.objKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.OBJECT_KEY]))
self.entKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.ENTITY_KEY]))
self.cstKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.CUSTOM_KEY]))
self.povKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.POV_KEY]), self)
self.focKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.FOCUS_KEY]), self)
self.chrKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.CHAR_KEY]), self)
self.pltKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.PLOT_KEY]), self)
self.timKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.TIME_KEY]), self)
self.wldKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.WORLD_KEY]), self)
self.objKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.OBJECT_KEY]), self)
self.entKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.ENTITY_KEY]), self)
self.cstKeyLabel = QLabel(trConst(nwLabels.KEY_NAME[nwKeyWords.CUSTOM_KEY]), self)
self.povKeyLabel.setFont(bFont)
self.focKeyLabel.setFont(bFont)
@@ -882,15 +882,15 @@ class GuiOutlineDetails(QScrollArea):
self.entKeyLWrap = QHBoxLayout()
self.cstKeyLWrap = QHBoxLayout()
self.povKeyValue = QLabel("")
self.focKeyValue = QLabel("")
self.chrKeyValue = QLabel("")
self.pltKeyValue = QLabel("")
self.timKeyValue = QLabel("")
self.wldKeyValue = QLabel("")
self.objKeyValue = QLabel("")
self.entKeyValue = QLabel("")
self.cstKeyValue = QLabel("")
self.povKeyValue = QLabel("", self)
self.focKeyValue = QLabel("", self)
self.chrKeyValue = QLabel("", self)
self.pltKeyValue = QLabel("", self)
self.timKeyValue = QLabel("", self)
self.wldKeyValue = QLabel("", self)
self.objKeyValue = QLabel("", self)
self.entKeyValue = QLabel("", self)
self.cstKeyValue = QLabel("", self)
self.povKeyValue.setWordWrap(True)
self.focKeyValue.setWordWrap(True)
@@ -977,7 +977,7 @@ class GuiOutlineDetails(QScrollArea):
self.tagsForm.setVerticalSpacing(vSpace)
# Assemble
self.outerWidget = QWidget()
self.outerWidget = QWidget(self)
self.outerBox = QHBoxLayout()
self.outerBox.addWidget(self.mainGroup, 0)
self.outerBox.addWidget(self.tagsGroup, 1)
+1 -1
View File
@@ -271,7 +271,7 @@ class GuiProjectToolBar(QWidget):
self.setAutoFillBackground(True)
# Widget Label
self.viewLabel = QLabel(self.tr("Project Content"))
self.viewLabel = QLabel(self.tr("Project Content"), self)
self.viewLabel.setFont(SHARED.theme.guiFontB)
self.viewLabel.setContentsMargins(0, 0, 0, 0)
self.viewLabel.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
+1 -1
View File
@@ -71,7 +71,7 @@ class GuiProjectSearch(QWidget):
self._map: dict[str, tuple[int, float]] = {}
# Header
self.viewLabel = QLabel(self.tr("Project Search"))
self.viewLabel = QLabel(self.tr("Project Search"), self)
self.viewLabel.setFont(SHARED.theme.guiFontB)
self.viewLabel.setContentsMargins(mPx, tPx, 0, mPx)
+8 -8
View File
@@ -66,8 +66,8 @@ class GuiMainStatus(QStatusBar):
xM = CONFIG.pxInt(8)
# The Spell Checker Language
self.langIcon = QLabel("")
self.langText = QLabel(self.tr("None"))
self.langIcon = QLabel("", self)
self.langText = QLabel(self.tr("None"), self)
self.langIcon.setContentsMargins(0, 0, 0, 0)
self.langText.setContentsMargins(0, 0, xM, 0)
self.addPermanentWidget(self.langIcon)
@@ -75,7 +75,7 @@ class GuiMainStatus(QStatusBar):
# The Editor Status
self.docIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
self.docText = QLabel(self.tr("Editor"))
self.docText = QLabel(self.tr("Editor"), self)
self.docIcon.setContentsMargins(0, 0, 0, 0)
self.docText.setContentsMargins(0, 0, xM, 0)
self.addPermanentWidget(self.docIcon)
@@ -83,15 +83,15 @@ class GuiMainStatus(QStatusBar):
# The Project Status
self.projIcon = StatusLED(colNone, colSaved, colUnsaved, iPx, iPx, self)
self.projText = QLabel(self.tr("Project"))
self.projText = QLabel(self.tr("Project"), self)
self.projIcon.setContentsMargins(0, 0, 0, 0)
self.projText.setContentsMargins(0, 0, xM, 0)
self.addPermanentWidget(self.projIcon)
self.addPermanentWidget(self.projText)
# The Project and Session Stats
self.statsIcon = QLabel()
self.statsText = QLabel("")
self.statsIcon = QLabel(self)
self.statsText = QLabel("", self)
self.statsIcon.setContentsMargins(0, 0, 0, 0)
self.statsText.setContentsMargins(0, 0, xM, 0)
self.addPermanentWidget(self.statsIcon)
@@ -99,8 +99,8 @@ class GuiMainStatus(QStatusBar):
# The Session Clock
# Set the minimum width so the label doesn't rescale every second
self.timeIcon = QLabel()
self.timeText = QLabel("")
self.timeIcon = QLabel(self)
self.timeText = QLabel("", self)
self.timeText.setToolTip(self.tr("Session Time"))
self.timeText.setMinimumWidth(SHARED.theme.getTextWidth("00:00:00:"))
self.timeIcon.setContentsMargins(0, 0, 0, 0)
+4 -2
View File
@@ -171,7 +171,9 @@ class GuiTheme:
# Monospace Font
self.guiFontFixed = QFont()
self.guiFontFixed.setPointSizeF(0.95*self.fontPointSize)
self.guiFontFixed.setFamily(QFontDatabase.systemFont(QFontDatabase.FixedFont).family())
self.guiFontFixed.setFamily(
QFontDatabase.systemFont(QFontDatabase.SystemFont.FixedFont).family()
)
logger.debug("GUI Font Family: %s", self.guiFont.family())
logger.debug("GUI Font Point Size: %.2f", self.fontPointSize)
@@ -401,7 +403,7 @@ class GuiTheme:
font.setFamily("Arial")
font.setPointSize(10)
else:
font = fontDB.systemFont(QFontDatabase.GeneralFont)
font = fontDB.systemFont(QFontDatabase.SystemFont.GeneralFont)
CONFIG.guiFont = font.family()
CONFIG.guiFontSize = font.pointSize()
else: