Update Qt namespace flags

This commit is contained in:
Veronica Berglyd Olsen
2024-04-03 19:28:39 +02:00
parent f95bbb8760
commit 46c5f1c10d
33 changed files with 212 additions and 174 deletions
+8 -9
View File
@@ -64,7 +64,8 @@ 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
QtAlignCenterTop, QtAlignJustify, QtAlignLeft, QtAlignLeftTop,
QtAlignRight, QtModCtrl, QtMouseLeft, QtModeNone, QtModShift
)
if TYPE_CHECKING: # pragma: no cover
@@ -181,12 +182,12 @@ class GuiDocEditor(QPlainTextEdit):
self.keyContext.activated.connect(self._openContextFromCursor)
self.followTag1 = QShortcut(self)
self.followTag1.setKey(Qt.Key.Key_Return | Qt.KeyboardModifier.ControlModifier)
self.followTag1.setKey(Qt.Key.Key_Return | QtModCtrl)
self.followTag1.setContext(Qt.ShortcutContext.WidgetShortcut)
self.followTag1.activated.connect(self._processTag)
self.followTag2 = QShortcut(self)
self.followTag2.setKey(Qt.Key.Key_Enter | Qt.KeyboardModifier.ControlModifier)
self.followTag2.setKey(Qt.Key.Key_Enter | QtModCtrl)
self.followTag2.setContext(Qt.ShortcutContext.WidgetShortcut)
self.followTag2.activated.connect(self._processTag)
@@ -962,7 +963,7 @@ class GuiDocEditor(QPlainTextEdit):
super().keyPressEvent(event)
nPos = self.cursorRect().topLeft().y()
kMod = event.modifiers()
okMod = kMod in (Qt.KeyboardModifier.NoModifier, Qt.KeyboardModifier.ShiftModifier)
okMod = kMod in (QtModeNone, QtModShift)
okKey = event.key() not in self.MOVE_KEYS
if nPos != cPos and okMod and okKey:
mPos = CONFIG.autoScrollPos*0.01 * self.viewport().height()
@@ -991,7 +992,7 @@ class GuiDocEditor(QPlainTextEdit):
pressed, check if we're clicking on a tag, and trigger the
follow tag function.
"""
if QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier:
if QApplication.keyboardModifiers() == QtModCtrl:
self._processTag(self.cursorForPosition(event.pos()))
super().mouseReleaseEvent(event)
return
@@ -2713,9 +2714,7 @@ class GuiDocEditSearch(QFrame):
@pyqtSlot()
def _doSearch(self) -> None:
"""Call the search action function for the document editor."""
self.docEditor.findNext(goBack=(
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ShiftModifier)
)
self.docEditor.findNext(goBack=(QApplication.keyboardModifiers() == QtModShift))
return
@pyqtSlot()
@@ -3002,7 +3001,7 @@ class GuiDocEditHeader(QWidget):
"""Capture a click on the title and ensure that the item is
selected in the project tree.
"""
if event.button() == Qt.MouseButton.LeftButton:
if event.button() == QtMouseLeft:
self.docEditor.requestProjectItemSelected.emit(self._docHandle or "", True)
return
+3 -3
View File
@@ -402,16 +402,16 @@ class GuiDocHighlighter(QSyntaxHighlighter):
if style is not None:
styles = style.split(",")
if "bold" in styles:
charFormat.setFontWeight(QFont.Bold)
charFormat.setFontWeight(QFont.Weight.Bold)
if "italic" in styles:
charFormat.setFontItalic(True)
if "strike" in styles:
charFormat.setFontStrikeOut(True)
if "errline" in styles:
charFormat.setUnderlineColor(SHARED.theme.colError)
charFormat.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
charFormat.setUnderlineStyle(QTextCharFormat.UnderlineStyle.SpellCheckUnderline)
if "background" in styles and color is not None:
charFormat.setBackground(QBrush(color, Qt.SolidPattern))
charFormat.setBackground(QBrush(color, Qt.BrushStyle.SolidPattern))
if size is not None:
charFormat.setFontPointSize(int(round(size*CONFIG.textSize)))
+2 -2
View File
@@ -49,7 +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
from novelwriter.types import QtAlignCenterTop, QtAlignJustify, QtMouseLeft
logger = logging.getLogger(__name__)
@@ -826,7 +826,7 @@ class GuiDocViewHeader(QWidget):
"""Capture a click on the title and ensure that the item is
selected in the project tree.
"""
if event.button() == Qt.MouseButton.LeftButton:
if event.button() == QtMouseLeft:
self.docViewer.requestProjectItemSelected.emit(self._docHandle, True)
return
+5 -4
View File
@@ -40,6 +40,7 @@ from novelwriter.core.index import IndexHeading, IndexItem
from novelwriter.enum import nwDocMode, nwItemClass
from novelwriter.extensions.modified import NIconToolButton
from novelwriter.gui.theme import STYLES_FLAT_TABS, STYLES_MIN_TOOLBUTTON
from novelwriter.types import QtDecoration, QtUserRole
logger = logging.getLogger(__name__)
@@ -232,7 +233,7 @@ class _ViewPanelBackRefs(QTreeWidget):
C_VIEW = 2
C_TITLE = 3
D_HANDLE = Qt.ItemDataRole.UserRole
D_HANDLE = QtUserRole
def __init__(self, parent: GuiDocViewerPanel) -> None:
super().__init__(parent=parent)
@@ -349,7 +350,7 @@ class _ViewPanelBackRefs(QTreeWidget):
trItem.setToolTip(self.C_DOC, nwItem.itemName)
trItem.setIcon(self.C_EDIT, self._editIcon)
trItem.setIcon(self.C_VIEW, self._viewIcon)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec)
trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, hItem.title)
trItem.setToolTip(self.C_TITLE, hItem.title)
trItem.setData(self.C_DATA, self.D_HANDLE, tHandle)
@@ -374,7 +375,7 @@ class _ViewPanelKeyWords(QTreeWidget):
C_TITLE = 5
C_SHORT = 6
D_TAG = Qt.ItemDataRole.UserRole
D_TAG = QtUserRole
def __init__(self, parent: GuiDocViewerPanel, itemClass: nwItemClass) -> None:
super().__init__(parent=parent)
@@ -468,7 +469,7 @@ class _ViewPanelKeyWords(QTreeWidget):
trItem.setIcon(self.C_DOC, docIcon)
trItem.setText(self.C_DOC, nwItem.itemName)
trItem.setToolTip(self.C_DOC, nwItem.itemName)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec)
trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, hItem.title)
trItem.setToolTip(self.C_TITLE, hItem.title)
trItem.setText(self.C_SHORT, hItem.synopsis)
+10 -10
View File
@@ -31,8 +31,8 @@ from enum import Enum
from time import time
from typing import TYPE_CHECKING
from PyQt5.QtGui import QFocusEvent, QFont, QMouseEvent, QPalette, QResizeEvent
from PyQt5.QtCore import QModelIndex, QPoint, Qt, pyqtSlot, pyqtSignal
from PyQt5.QtGui import QFocusEvent, QFont, QMouseEvent, QPalette, QResizeEvent
from PyQt5.QtWidgets import (
QAbstractItemView, QActionGroup, QFrame, QHBoxLayout, QHeaderView,
QInputDialog, QMenu, QSizePolicy, QToolTip, QTreeWidget, QTreeWidgetItem,
@@ -47,7 +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
from novelwriter.types import QtAlignRight, QtDecoration, QtMouseLeft, QtMouseMiddle, QtUserRole
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -364,10 +364,10 @@ class GuiNovelTree(QTreeWidget):
C_EXTRA = 2
C_MORE = 3
D_HANDLE = Qt.ItemDataRole.UserRole
D_TITLE = Qt.ItemDataRole.UserRole + 1
D_KEY = Qt.ItemDataRole.UserRole + 2
D_EXTRA = Qt.ItemDataRole.UserRole + 3
D_HANDLE = QtUserRole
D_TITLE = QtUserRole + 1
D_KEY = QtUserRole + 2
D_EXTRA = QtUserRole + 3
def __init__(self, novelView: GuiNovelView) -> None:
super().__init__(parent=novelView)
@@ -583,12 +583,12 @@ class GuiNovelTree(QTreeWidget):
"""
super().mousePressEvent(event)
if event.button() == Qt.MouseButton.LeftButton:
if event.button() == QtMouseLeft:
selItem = self.indexAt(event.pos())
if not selItem.isValid():
self.clearSelection()
elif event.button() == Qt.MouseButton.MiddleButton:
elif event.button() == QtMouseMiddle:
selItem = self.itemAt(event.pos())
if not isinstance(selItem, QTreeWidgetItem):
return
@@ -697,11 +697,11 @@ class GuiNovelTree(QTreeWidget):
iLevel = nwHeaders.H_LEVEL.get(idxItem.level, 0)
hDec = SHARED.theme.getHeaderDecoration(iLevel)
trItem.setData(self.C_TITLE, Qt.ItemDataRole.DecorationRole, hDec)
trItem.setData(self.C_TITLE, QtDecoration, hDec)
trItem.setText(self.C_TITLE, idxItem.title)
trItem.setFont(self.C_TITLE, self._hFonts[iLevel])
trItem.setText(self.C_WORDS, f"{idxItem.wordCount:n}")
trItem.setData(self.C_MORE, Qt.ItemDataRole.DecorationRole, self._pMore)
trItem.setData(self.C_MORE, QtDecoration, self._pMore)
# Custom column
mW = int(self._lastColSize * self.viewport().width())
+7 -5
View File
@@ -48,7 +48,9 @@ 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
from novelwriter.types import (
QtAlignLeftTop, QtAlignRight, QtAlignRightTop, QtDecoration, QtUserRole
)
logger = logging.getLogger(__name__)
@@ -68,7 +70,7 @@ class GuiOutlineView(QWidget):
self.outlineBar = GuiOutlineToolBar(self)
self.outlineBar.setEnabled(False)
self.splitOutline = QSplitter(Qt.Vertical)
self.splitOutline = QSplitter(Qt.Orientation.Vertical)
self.splitOutline.addWidget(self.outlineTree)
self.splitOutline.addWidget(self.outlineData)
self.splitOutline.setOpaqueResize(False)
@@ -354,8 +356,8 @@ class GuiOutlineTree(QTreeWidget):
nwOutline.SYNOP: False,
}
D_HANDLE = Qt.ItemDataRole.UserRole
D_TITLE = Qt.ItemDataRole.UserRole + 1
D_HANDLE = QtUserRole
D_TITLE = QtUserRole + 1
hiddenStateChanged = pyqtSignal()
activeItemChanged = pyqtSignal(str, str)
@@ -692,7 +694,7 @@ class GuiOutlineTree(QTreeWidget):
trItem = QTreeWidgetItem()
hDec = SHARED.theme.getHeaderDecoration(iLevel)
trItem.setData(self._colIdx[nwOutline.TITLE], Qt.ItemDataRole.DecorationRole, hDec)
trItem.setData(self._colIdx[nwOutline.TITLE], QtDecoration, hDec)
trItem.setText(self._colIdx[nwOutline.TITLE], novIdx.title)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_HANDLE, tHandle)
trItem.setData(self._colIdx[nwOutline.TITLE], self.D_TITLE, sTitle)
+7 -7
View File
@@ -32,10 +32,10 @@ from enum import Enum
from time import time
from typing import TYPE_CHECKING
from PyQt5.QtCore import QPoint, QTimer, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtGui import (
QDragEnterEvent, QDragMoveEvent, QDropEvent, QIcon, QMouseEvent, QPalette
)
from PyQt5.QtCore import QPoint, QTimer, Qt, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import (
QAbstractItemView, QAction, QDialog, QFrame, QHBoxLayout, QHeaderView,
QLabel, QMenu, QShortcut, QSizePolicy, QTreeWidget, QTreeWidgetItem,
@@ -54,7 +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
from novelwriter.types import QtAlignLeft, QtAlignRight, QtMouseLeft, QtMouseMiddle, QtUserRole
if TYPE_CHECKING: # pragma: no cover
from novelwriter.guimain import GuiMain
@@ -487,8 +487,8 @@ class GuiProjectTree(QTreeWidget):
C_ACTIVE = 2
C_STATUS = 3
D_HANDLE = Qt.ItemDataRole.UserRole
D_WORDS = Qt.ItemDataRole.UserRole + 1
D_HANDLE = QtUserRole
D_WORDS = QtUserRole + 1
itemRefreshed = pyqtSignal(str, NWItem, QIcon)
@@ -1256,11 +1256,11 @@ class GuiProjectTree(QTreeWidget):
for viewing if the user middle-clicked.
"""
super().mousePressEvent(event)
if event.button() == Qt.MouseButton.LeftButton:
if event.button() == QtMouseLeft:
selItem = self.indexAt(event.pos())
if not selItem.isValid():
self.clearSelection()
elif event.button() == Qt.MouseButton.MiddleButton:
elif event.button() == QtMouseMiddle:
selItem = self.itemAt(event.pos())
if selItem:
tHandle = selItem.data(self.C_DATA, self.D_HANDLE)
@@ -1268,7 +1268,7 @@ class GuiProjectTree(QTreeWidget):
self.projView.openDocumentRequest.emit(tHandle, nwDocMode.VIEW, "", False)
return
def startDrag(self, dropAction: Qt.DropActions) -> None:
def startDrag(self, dropAction: Qt.DropAction) -> None:
"""Capture the drag and drop handling to pop alerts."""
super().startDrag(dropAction)
if self._popAlert:
+3 -3
View File
@@ -38,7 +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
from novelwriter.types import QtAlignMiddle, QtAlignRight, QtUserRole
logger = logging.getLogger(__name__)
@@ -49,8 +49,8 @@ class GuiProjectSearch(QWidget):
C_RESULT = 0
C_COUNT = 1
D_HANDLE = Qt.ItemDataRole.UserRole
D_RESULT = Qt.ItemDataRole.UserRole + 1
D_HANDLE = QtUserRole
D_RESULT = QtUserRole + 1
selectedItemChanged = pyqtSignal(str)
openDocumentSelectRequest = pyqtSignal(str, int, int, bool)