Collect all alignment flags into a new types module

This commit is contained in:
Veronica Berglyd Olsen
2024-04-01 18:27:18 +02:00
parent 468a0e7416
commit c3467d89c2
24 changed files with 195 additions and 171 deletions
+13 -12
View File
@@ -64,6 +64,9 @@ from novelwriter.gui.editordocument import GuiTextDocument
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.text.counting import standardCounter
from novelwriter.tools.lipsum import GuiLipsum
from novelwriter.types import (
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop, QtAlignRight
)
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -339,7 +342,7 @@ class GuiDocEditor(QPlainTextEdit):
options = QTextOption()
if CONFIG.doJustify:
options.setAlignment(Qt.AlignmentFlag.AlignJustify)
options.setAlignment(QtAlignJustify)
if CONFIG.showTabsNSpaces:
options.setFlags(options.flags() | QTextOption.Flag.ShowTabsAndSpaces)
if CONFIG.showLineEndings:
@@ -2514,8 +2517,8 @@ class GuiDocEditSearch(QFrame):
self.replaceButton.setToolTip(self.tr("Find and replace in current document"))
self.replaceButton.clicked.connect(self._doReplace)
self.mainBox.addWidget(self.searchLabel, 0, 0, 1, 2, Qt.AlignmentFlag.AlignLeft)
self.mainBox.addWidget(self.searchOpt, 0, 2, 1, 3, Qt.AlignmentFlag.AlignRight)
self.mainBox.addWidget(self.searchLabel, 0, 0, 1, 2, QtAlignLeft)
self.mainBox.addWidget(self.searchOpt, 0, 2, 1, 3, QtAlignRight)
self.mainBox.addWidget(self.showReplace, 1, 0, 1, 1)
self.mainBox.addWidget(self.searchBox, 1, 1, 1, 2)
self.mainBox.addWidget(self.searchButton, 1, 3, 1, 1)
@@ -2830,7 +2833,7 @@ class GuiDocEditHeader(QWidget):
self.itemTitle.setMargin(0)
self.itemTitle.setContentsMargins(0, 0, 0, 0)
self.itemTitle.setAutoFillBackground(True)
self.itemTitle.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop)
self.itemTitle.setAlignment(QtAlignCenterTop)
self.itemTitle.setFixedHeight(iPx)
lblFont = self.itemTitle.font()
@@ -3053,13 +3056,11 @@ class GuiDocEditFooter(QWidget):
self.setContentsMargins(0, 0, 0, 0)
self.setAutoFillBackground(True)
alLeftTop = Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop
# Status
self.statusIcon = QLabel("", self)
self.statusIcon.setContentsMargins(0, 0, 0, 0)
self.statusIcon.setFixedHeight(iPx)
self.statusIcon.setAlignment(alLeftTop)
self.statusIcon.setAlignment(QtAlignLeftTop)
self.statusText = QLabel(self.tr("Status"))
self.statusText.setIndent(0)
@@ -3067,14 +3068,14 @@ class GuiDocEditFooter(QWidget):
self.statusText.setContentsMargins(0, 0, 0, 0)
self.statusText.setAutoFillBackground(True)
self.statusText.setFixedHeight(fPx)
self.statusText.setAlignment(alLeftTop)
self.statusText.setAlignment(QtAlignLeftTop)
self.statusText.setFont(lblFont)
# Lines
self.linesIcon = QLabel("", self)
self.linesIcon.setContentsMargins(0, 0, 0, 0)
self.linesIcon.setFixedHeight(iPx)
self.linesIcon.setAlignment(alLeftTop)
self.linesIcon.setAlignment(QtAlignLeftTop)
self.linesText = QLabel("", self)
self.linesText.setIndent(0)
@@ -3082,14 +3083,14 @@ class GuiDocEditFooter(QWidget):
self.linesText.setContentsMargins(0, 0, 0, 0)
self.linesText.setAutoFillBackground(True)
self.linesText.setFixedHeight(fPx)
self.linesText.setAlignment(alLeftTop)
self.linesText.setAlignment(QtAlignLeftTop)
self.linesText.setFont(lblFont)
# Words
self.wordsIcon = QLabel("", self)
self.wordsIcon.setContentsMargins(0, 0, 0, 0)
self.wordsIcon.setFixedHeight(iPx)
self.wordsIcon.setAlignment(alLeftTop)
self.wordsIcon.setAlignment(QtAlignLeftTop)
self.wordsText = QLabel("", self)
self.wordsText.setIndent(0)
@@ -3097,7 +3098,7 @@ class GuiDocEditFooter(QWidget):
self.wordsText.setContentsMargins(0, 0, 0, 0)
self.wordsText.setAutoFillBackground(True)
self.wordsText.setFixedHeight(fPx)
self.wordsText.setAlignment(alLeftTop)
self.wordsText.setAlignment(QtAlignLeftTop)
self.wordsText.setFont(lblFont)
# Assemble Layout
+3 -2
View File
@@ -49,6 +49,7 @@ 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
logger = logging.getLogger(__name__)
@@ -164,7 +165,7 @@ class GuiDocViewer(QTextBrowser):
self.document().setDocumentMargin(0)
options = QTextOption()
if CONFIG.doJustify:
options.setAlignment(Qt.AlignmentFlag.AlignJustify)
options.setAlignment(QtAlignJustify)
self.document().setDefaultTextOption(options)
# Scroll bars
@@ -639,7 +640,7 @@ class GuiDocViewHeader(QWidget):
self.itemTitle.setMargin(0)
self.itemTitle.setContentsMargins(0, 0, 0, 0)
self.itemTitle.setAutoFillBackground(True)
self.itemTitle.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignTop)
self.itemTitle.setAlignment(QtAlignCenterTop)
self.itemTitle.setFixedHeight(iPx)
lblFont = self.itemTitle.font()
+2 -1
View File
@@ -47,6 +47,7 @@ from novelwriter.enum import nwDocMode, nwItemClass, nwOutline
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignRight
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -676,7 +677,7 @@ class GuiNovelTree(QTreeWidget):
newItem.setData(self.C_DATA, self.D_HANDLE, tHandle)
newItem.setData(self.C_DATA, self.D_TITLE, sTitle)
newItem.setData(self.C_DATA, self.D_KEY, tKey)
newItem.setTextAlignment(self.C_WORDS, Qt.AlignmentFlag.AlignRight)
newItem.setTextAlignment(self.C_WORDS, QtAlignRight)
self._updateTreeItemValues(newItem, novIdx, tHandle, sTitle)
self._treeMap[tKey] = newItem
+43 -45
View File
@@ -48,6 +48,7 @@ from novelwriter.error import logException
from novelwriter.common import checkInt, formatFileFilter, makeFileNameSafe
from novelwriter.constants import nwHeaders, trConst, nwKeyWords, nwLabels
from novelwriter.extensions.novelselector import NovelSelector
from novelwriter.types import QtAlignLeftTop, QtAlignRight, QtAlignRightTop
logger = logging.getLogger(__name__)
@@ -675,11 +676,11 @@ class GuiOutlineTree(QTreeWidget):
headItem = self.headerItem()
if isinstance(headItem, QTreeWidgetItem):
headItem.setTextAlignment(
self._colIdx[nwOutline.CCOUNT], Qt.AlignmentFlag.AlignRight)
self._colIdx[nwOutline.CCOUNT], QtAlignRight)
headItem.setTextAlignment(
self._colIdx[nwOutline.WCOUNT], Qt.AlignmentFlag.AlignRight)
self._colIdx[nwOutline.WCOUNT], QtAlignRight)
headItem.setTextAlignment(
self._colIdx[nwOutline.PCOUNT], Qt.AlignmentFlag.AlignRight)
self._colIdx[nwOutline.PCOUNT], QtAlignRight)
novStruct = SHARED.project.index.novelStructure(rootHandle=rootHandle, activeOnly=True)
for _, tHandle, sTitle, novIdx in novStruct:
@@ -705,9 +706,9 @@ class GuiOutlineTree(QTreeWidget):
trItem.setText(self._colIdx[nwOutline.CCOUNT], f"{novIdx.charCount:n}")
trItem.setText(self._colIdx[nwOutline.WCOUNT], f"{novIdx.wordCount:n}")
trItem.setText(self._colIdx[nwOutline.PCOUNT], f"{novIdx.paraCount:n}")
trItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], Qt.AlignmentFlag.AlignRight)
trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], Qt.AlignmentFlag.AlignRight)
trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], Qt.AlignmentFlag.AlignRight)
trItem.setTextAlignment(self._colIdx[nwOutline.CCOUNT], QtAlignRight)
trItem.setTextAlignment(self._colIdx[nwOutline.WCOUNT], QtAlignRight)
trItem.setTextAlignment(self._colIdx[nwOutline.PCOUNT], QtAlignRight)
refs = SHARED.project.index.getReferences(tHandle, sTitle)
trItem.setText(self._colIdx[nwOutline.POV], ", ".join(refs[nwKeyWords.POV_KEY]))
@@ -834,9 +835,9 @@ class GuiOutlineDetails(QScrollArea):
self.cCValue.setMinimumWidth(wCount)
self.wCValue.setMinimumWidth(wCount)
self.pCValue.setMinimumWidth(wCount)
self.cCValue.setAlignment(Qt.AlignRight)
self.wCValue.setAlignment(Qt.AlignRight)
self.pCValue.setAlignment(Qt.AlignRight)
self.cCValue.setAlignment(QtAlignRight)
self.wCValue.setAlignment(QtAlignRight)
self.pCValue.setAlignment(QtAlignRight)
# Synopsis
self.synopLabel = QLabel(self.tr("Synopsis"))
@@ -844,7 +845,7 @@ class GuiOutlineDetails(QScrollArea):
self.synopValue = QLabel("")
self.synopValue.setWordWrap(True)
self.synopValue.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.synopValue.setAlignment(QtAlignLeftTop)
self.synopLWrap = QHBoxLayout()
self.synopLWrap.addWidget(self.synopValue, 1)
@@ -925,23 +926,20 @@ class GuiOutlineDetails(QScrollArea):
self.mainForm = QGridLayout()
self.mainGroup.setLayout(self.mainForm)
topLeft = Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignLeft
topRight = Qt.AlignmentFlag.AlignTop | Qt.AlignmentFlag.AlignRight
self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, topLeft)
self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, topLeft)
self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, topLeft)
self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, topRight)
self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, topLeft)
self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, topLeft)
self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, topLeft)
self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, topRight)
self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, topLeft)
self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, topLeft)
self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, topLeft)
self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, topRight)
self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, topLeft)
self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, topLeft)
self.mainForm.addWidget(self.titleLabel, 0, 0, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.titleValue, 0, 1, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.cCLabel, 0, 2, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.cCValue, 0, 3, 1, 1, QtAlignRightTop)
self.mainForm.addWidget(self.fileLabel, 1, 0, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.fileValue, 1, 1, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.wCLabel, 1, 2, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.wCValue, 1, 3, 1, 1, QtAlignRightTop)
self.mainForm.addWidget(self.itemLabel, 2, 0, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.itemValue, 2, 1, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.pCLabel, 2, 2, 1, 1, QtAlignLeftTop)
self.mainForm.addWidget(self.pCValue, 2, 3, 1, 1, QtAlignRightTop)
self.mainForm.addWidget(self.synopLabel, 3, 0, 1, 4, QtAlignLeftTop)
self.mainForm.addLayout(self.synopLWrap, 4, 0, 1, 4, QtAlignLeftTop)
self.mainForm.setColumnStretch(1, 1)
self.mainForm.setRowStretch(4, 1)
@@ -953,24 +951,24 @@ class GuiOutlineDetails(QScrollArea):
self.tagsForm = QGridLayout()
self.tagsGroup.setLayout(self.tagsForm)
self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, topLeft)
self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, topLeft)
self.tagsForm.addWidget(self.povKeyLabel, 0, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.povKeyLWrap, 0, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.focKeyLabel, 1, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.focKeyLWrap, 1, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.chrKeyLabel, 2, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.chrKeyLWrap, 2, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.pltKeyLabel, 3, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.pltKeyLWrap, 3, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.timKeyLabel, 4, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.timKeyLWrap, 4, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.wldKeyLabel, 5, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.wldKeyLWrap, 5, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.objKeyLabel, 6, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.objKeyLWrap, 6, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.entKeyLabel, 7, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.entKeyLWrap, 7, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.addWidget(self.cstKeyLabel, 8, 0, 1, 1, QtAlignLeftTop)
self.tagsForm.addLayout(self.cstKeyLWrap, 8, 1, 1, 1, QtAlignLeftTop)
self.tagsForm.setColumnStretch(1, 1)
self.tagsForm.setRowStretch(8, 1)
+5 -4
View File
@@ -54,6 +54,7 @@ from novelwriter.dialogs.projectsettings import GuiProjectSettings
from novelwriter.enum import nwDocMode, nwItemType, nwItemClass, nwItemLayout
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtAlignLeft, QtAlignRight
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -1585,10 +1586,10 @@ class GuiProjectTree(QTreeWidget):
newItem.setText(self.C_ACTIVE, "")
newItem.setText(self.C_STATUS, "")
newItem.setTextAlignment(self.C_NAME, Qt.AlignmentFlag.AlignLeft)
newItem.setTextAlignment(self.C_COUNT, Qt.AlignmentFlag.AlignRight)
newItem.setTextAlignment(self.C_ACTIVE, Qt.AlignmentFlag.AlignLeft)
newItem.setTextAlignment(self.C_STATUS, Qt.AlignmentFlag.AlignLeft)
newItem.setTextAlignment(self.C_NAME, QtAlignLeft)
newItem.setTextAlignment(self.C_COUNT, QtAlignRight)
newItem.setTextAlignment(self.C_ACTIVE, QtAlignLeft)
newItem.setTextAlignment(self.C_STATUS, QtAlignLeft)
newItem.setData(self.C_DATA, self.D_HANDLE, tHandle)
newItem.setData(self.C_DATA, self.D_WORDS, 0)
+3 -2
View File
@@ -38,6 +38,7 @@ from novelwriter import CONFIG, SHARED
from novelwriter.common import checkInt, cssCol
from novelwriter.core.coretools import DocSearch
from novelwriter.core.item import NWItem
from novelwriter.types import QtAlignMiddle, QtAlignRight
logger = logging.getLogger(__name__)
@@ -124,7 +125,7 @@ class GuiProjectSearch(QWidget):
# Assemble
self.headerBox = QHBoxLayout()
self.headerBox.addWidget(self.viewLabel, 1)
self.headerBox.addWidget(self.searchOpt, 0, Qt.AlignmentFlag.AlignVCenter)
self.headerBox.addWidget(self.searchOpt, 0, QtAlignMiddle)
self.headerBox.setContentsMargins(0, 0, 0, 0)
self.headerBox.setSpacing(0)
@@ -328,7 +329,7 @@ class GuiProjectSearch(QWidget):
tItem.setIcon(self.C_NAME, docIcon)
tItem.setData(self.C_NAME, self.D_HANDLE, tHandle)
tItem.setText(self.C_COUNT, f"({len(results):n}{ext})")
tItem.setTextAlignment(self.C_COUNT, Qt.AlignmentFlag.AlignRight)
tItem.setTextAlignment(self.C_COUNT, QtAlignRight)
tItem.setForeground(self.C_COUNT, self.palette().highlight())
index = self._map.get(tHandle, (self.searchResult.topLevelItemCount(), 0.0))[0]