summaryrefslogtreecommitdiff
path: root/qutebrowser/completion
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-08-26 16:47:12 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-08-26 16:47:12 +0200
commitac9d67cce0dbecdde14c474db855243e9746ba04 (patch)
treeb564440308dc40b8ae40209a33cb1c47c95e17c6 /qutebrowser/completion
parentba30ac2af0860a8c92503179f6867ab0b46e3d31 (diff)
downloadqutebrowser-ac9d67cce0dbecdde14c474db855243e9746ba04.tar.gz
qutebrowser-ac9d67cce0dbecdde14c474db855243e9746ba04.zip
Automatically rewrite enums
See #5904
Diffstat (limited to 'qutebrowser/completion')
-rw-r--r--qutebrowser/completion/completiondelegate.py72
-rw-r--r--qutebrowser/completion/completionwidget.py8
-rw-r--r--qutebrowser/completion/models/completionmodel.py14
-rw-r--r--qutebrowser/completion/models/filepathcategory.py4
-rw-r--r--qutebrowser/completion/models/listcategory.py2
5 files changed, 50 insertions, 50 deletions
diff --git a/qutebrowser/completion/completiondelegate.py b/qutebrowser/completion/completiondelegate.py
index 1ab389e0d..4e9d14d1a 100644
--- a/qutebrowser/completion/completiondelegate.py
+++ b/qutebrowser/completion/completiondelegate.py
@@ -45,7 +45,7 @@ class _Highlighter(QSyntaxHighlighter):
words.sort(key=len, reverse=True)
pat = "|".join(re.escape(word) for word in words)
self._expression = QRegularExpression(
- pat, QRegularExpression.CaseInsensitiveOption
+ pat, QRegularExpression.PatternOption.CaseInsensitiveOption
)
qtutils.ensure_valid(self._expression)
@@ -109,12 +109,12 @@ class CompletionItemDelegate(QStyledItemDelegate):
# be displayed.
return
- mode = QIcon.Normal
- if not self._opt.state & QStyle.State_Enabled:
- mode = QIcon.Disabled
- elif self._opt.state & QStyle.State_Selected:
- mode = QIcon.Selected
- state = QIcon.On if self._opt.state & QStyle.State_Open else QIcon.Off
+ mode = QIcon.Mode.Normal
+ if not self._opt.state & QStyle.StateFlag.State_Enabled:
+ mode = QIcon.Mode.Disabled
+ elif self._opt.state & QStyle.StateFlag.State_Selected:
+ mode = QIcon.Mode.Selected
+ state = QIcon.State.On if self._opt.state & QStyle.StateFlag.State_Open else QIcon.State.Off
self._opt.icon.paint(self._painter, icon_rect,
self._opt.decorationAlignment, mode, state)
@@ -136,7 +136,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
text_rect_ = self._style.subElementRect(
self._style.SE_ItemViewItemText, self._opt, self._opt.widget)
qtutils.ensure_valid(text_rect_)
- margin = self._style.pixelMetric(QStyle.PM_FocusFrameHMargin,
+ margin = self._style.pixelMetric(QStyle.PixelMetric.PM_FocusFrameHMargin,
self._opt, self._opt.widget) + 1
# remove width padding
text_rect = text_rect_.adjusted(margin, 0, -margin, 0)
@@ -148,24 +148,24 @@ class CompletionItemDelegate(QStyledItemDelegate):
text_rect.adjust(0, -2, 0, -2)
self._painter.save()
state = self._opt.state
- if state & QStyle.State_Enabled and state & QStyle.State_Active:
- cg = QPalette.Normal
- elif state & QStyle.State_Enabled:
- cg = QPalette.Inactive
+ if state & QStyle.StateFlag.State_Enabled and state & QStyle.StateFlag.State_Active:
+ cg = QPalette.ColorGroup.Normal
+ elif state & QStyle.StateFlag.State_Enabled:
+ cg = QPalette.ColorGroup.Inactive
else:
- cg = QPalette.Disabled
+ cg = QPalette.ColorGroup.Disabled
- if state & QStyle.State_Selected:
+ if state & QStyle.StateFlag.State_Selected:
self._painter.setPen(self._opt.palette.color(
- cg, QPalette.HighlightedText))
+ cg, QPalette.ColorRole.HighlightedText))
# This is a dirty fix for the text jumping by one pixel for
# whatever reason.
text_rect.adjust(0, -1, 0, 0)
else:
- self._painter.setPen(self._opt.palette.color(cg, QPalette.Text))
+ self._painter.setPen(self._opt.palette.color(cg, QPalette.ColorRole.Text))
- if state & QStyle.State_Editing:
- self._painter.setPen(self._opt.palette.color(cg, QPalette.Text))
+ if state & QStyle.StateFlag.State_Editing:
+ self._painter.setPen(self._opt.palette.color(cg, QPalette.ColorRole.Text))
self._painter.drawRect(text_rect_.adjusted(0, 0, -1, -1))
self._painter.translate(text_rect.left(), text_rect.top())
@@ -187,9 +187,9 @@ class CompletionItemDelegate(QStyledItemDelegate):
clip = QRectF(0, 0, rect.width(), rect.height())
self._painter.save()
- if self._opt.state & QStyle.State_Selected:
+ if self._opt.state & QStyle.StateFlag.State_Selected:
color = config.cache['colors.completion.item.selected.fg']
- elif not self._opt.state & QStyle.State_Enabled:
+ elif not self._opt.state & QStyle.StateFlag.State_Enabled:
color = config.cache['colors.completion.category.fg']
else:
colors = config.cache['colors.completion.fg']
@@ -198,7 +198,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
self._painter.setPen(color)
ctx = QAbstractTextDocumentLayout.PaintContext()
- ctx.palette.setColor(QPalette.Text, self._painter.pen().color())
+ ctx.palette.setColor(QPalette.ColorRole.Text, self._painter.pen().color())
if clip.isValid():
self._painter.setClipRect(clip)
ctx.clip = clip
@@ -216,10 +216,10 @@ class CompletionItemDelegate(QStyledItemDelegate):
# qcommonstyle.cpp:viewItemDrawText
# https://github.com/qutebrowser/qutebrowser/issues/118
text_option = QTextOption()
- if self._opt.features & QStyleOptionViewItem.WrapText:
- text_option.setWrapMode(QTextOption.WordWrap)
+ if self._opt.features & QStyleOptionViewItem.ViewItemFeature.WrapText:
+ text_option.setWrapMode(QTextOption.WrapMode.WordWrap)
else:
- text_option.setWrapMode(QTextOption.ManualWrap)
+ text_option.setWrapMode(QTextOption.WrapMode.ManualWrap)
text_option.setTextDirection(self._opt.direction)
text_option.setAlignment(QStyle.visualAlignment(
self._opt.direction, self._opt.displayAlignment))
@@ -236,7 +236,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
pattern = view.pattern
columns_to_filter = index.model().columns_to_filter(index)
if index.column() in columns_to_filter and pattern:
- if self._opt.state & QStyle.State_Selected:
+ if self._opt.state & QStyle.StateFlag.State_Selected:
color = config.val.colors.completion.item.selected.match.fg
else:
color = config.val.colors.completion.match.fg
@@ -253,23 +253,23 @@ class CompletionItemDelegate(QStyledItemDelegate):
assert self._opt is not None
assert self._style is not None
state = self._opt.state
- if not state & QStyle.State_HasFocus:
+ if not state & QStyle.StateFlag.State_HasFocus:
return
o = self._opt
o.rect = self._style.subElementRect(
self._style.SE_ItemViewItemFocusRect, self._opt, self._opt.widget)
- o.state |= int(QStyle.State_KeyboardFocusChange | QStyle.State_Item)
+ o.state |= int(QStyle.StateFlag.State_KeyboardFocusChange | QStyle.StateFlag.State_Item)
qtutils.ensure_valid(o.rect)
- if state & QStyle.State_Enabled:
- cg = QPalette.Normal
+ if state & QStyle.StateFlag.State_Enabled:
+ cg = QPalette.ColorGroup.Normal
else:
- cg = QPalette.Disabled
- if state & QStyle.State_Selected:
- role = QPalette.Highlight
+ cg = QPalette.ColorGroup.Disabled
+ if state & QStyle.StateFlag.State_Selected:
+ role = QPalette.ColorRole.Highlight
else:
- role = QPalette.Window
+ role = QPalette.ColorRole.Window
o.backgroundColor = self._opt.palette.color(cg, role)
- self._style.drawPrimitive(QStyle.PE_FrameFocusRect, o, self._painter,
+ self._style.drawPrimitive(QStyle.PrimitiveElement.PE_FrameFocusRect, o, self._painter,
self._opt.widget)
def sizeHint(self, option, index):
@@ -285,7 +285,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
Return:
A QSize with the recommended size.
"""
- value = index.data(Qt.SizeHintRole)
+ value = index.data(Qt.ItemDataRole.SizeHintRole)
if value is not None:
return value
self._opt = QStyleOptionViewItem(option)
@@ -296,7 +296,7 @@ class CompletionItemDelegate(QStyledItemDelegate):
assert self._doc is not None
docsize = self._doc.size().toSize()
- size = self._style.sizeFromContents(QStyle.CT_ItemViewItem, self._opt,
+ size = self._style.sizeFromContents(QStyle.ContentsType.CT_ItemViewItem, self._opt,
docsize, self._opt.widget)
qtutils.ensure_valid(size)
return size + QSize(10, 3) # type: ignore[operator]
diff --git a/qutebrowser/completion/completionwidget.py b/qutebrowser/completion/completionwidget.py
index a559531ec..c7af2c37b 100644
--- a/qutebrowser/completion/completionwidget.py
+++ b/qutebrowser/completion/completionwidget.py
@@ -126,14 +126,14 @@ class CompletionView(QTreeView):
self.setItemDelegate(self._delegate)
self.setStyle(QStyleFactory.create('Fusion'))
stylesheet.set_register(self)
- self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
+ self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
self.setHeaderHidden(True)
self.setAlternatingRowColors(True)
self.setIndentation(0)
self.setItemsExpandable(False)
self.setExpandsOnDoubleClick(False)
self.setAnimated(False)
- self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
+ self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
# WORKAROUND
# This is a workaround for weird race conditions with invalid
# item indexes leading to segfaults in Qt.
@@ -327,8 +327,8 @@ class CompletionView(QTreeView):
selmodel.setCurrentIndex(
idx,
- QItemSelectionModel.ClearAndSelect | # type: ignore[arg-type]
- QItemSelectionModel.Rows)
+ QItemSelectionModel.SelectionFlag.ClearAndSelect | # type: ignore[arg-type]
+ QItemSelectionModel.SelectionFlag.Rows)
# if the last item is focused, try to fetch more
next_idx = self.indexBelow(idx)
diff --git a/qutebrowser/completion/models/completionmodel.py b/qutebrowser/completion/models/completionmodel.py
index 1499cd352..ad156cd2f 100644
--- a/qutebrowser/completion/models/completionmodel.py
+++ b/qutebrowser/completion/models/completionmodel.py
@@ -63,7 +63,7 @@ class CompletionModel(QAbstractItemModel):
"""Add a completion category to the model."""
self._categories.append(cat)
- def data(self, index, role=Qt.DisplayRole):
+ def data(self, index, role=Qt.ItemDataRole.DisplayRole):
"""Return the item data for index.
Override QAbstractItemModel::data.
@@ -73,7 +73,7 @@ class CompletionModel(QAbstractItemModel):
Return: The item data, or None on an invalid index.
"""
- if role != Qt.DisplayRole:
+ if role != Qt.ItemDataRole.DisplayRole:
return None
cat = self._cat_from_idx(index)
if cat:
@@ -93,17 +93,17 @@ class CompletionModel(QAbstractItemModel):
Override QAbstractItemModel::flags.
- Return: The item flags, or Qt.NoItemFlags on error.
+ Return: The item flags, or Qt.ItemFlag.NoItemFlags on error.
"""
if not index.isValid():
- return Qt.NoItemFlags
+ return Qt.ItemFlag.NoItemFlags
if index.parent().isValid():
# item
- return (Qt.ItemIsEnabled | Qt.ItemIsSelectable |
- Qt.ItemNeverHasChildren)
+ return (Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable |
+ Qt.ItemFlag.ItemNeverHasChildren)
else:
# category
- return Qt.NoItemFlags
+ return Qt.ItemFlag.NoItemFlags
def index(self, row, col, parent=QModelIndex()):
"""Get an index into the model.
diff --git a/qutebrowser/completion/models/filepathcategory.py b/qutebrowser/completion/models/filepathcategory.py
index bcbf881d7..baf97903b 100644
--- a/qutebrowser/completion/models/filepathcategory.py
+++ b/qutebrowser/completion/models/filepathcategory.py
@@ -100,9 +100,9 @@ class FilePathCategory(QAbstractListModel):
paths = self._glob(expanded)
self._paths = sorted(self._contract_user(val, path) for path in paths)
- def data(self, index: QModelIndex, role: int = Qt.DisplayRole) -> Optional[str]:
+ def data(self, index: QModelIndex, role: int = Qt.ItemDataRole.DisplayRole) -> Optional[str]:
"""Implement abstract method in QAbstractListModel."""
- if role == Qt.DisplayRole and index.column() == 0:
+ if role == Qt.ItemDataRole.DisplayRole and index.column() == 0:
return self._paths[index.row()]
return None
diff --git a/qutebrowser/completion/models/listcategory.py b/qutebrowser/completion/models/listcategory.py
index 1098928eb..385a146ec 100644
--- a/qutebrowser/completion/models/listcategory.py
+++ b/qutebrowser/completion/models/listcategory.py
@@ -66,7 +66,7 @@ class ListCategory(QSortFilterProxyModel):
val = re.sub(r' +', r' ', val) # See #1919
val = re.escape(val)
val = val.replace(r'\ ', '.*')
- rx = QRegularExpression(val, QRegularExpression.CaseInsensitiveOption)
+ rx = QRegularExpression(val, QRegularExpression.PatternOption.CaseInsensitiveOption)
qtutils.ensure_valid(rx)
self.setFilterRegularExpression(rx)
self.invalidate()