Restyle completion to be dark

This commit is contained in:
Florian Bruhin 2014-05-09 19:47:20 +02:00
parent 6417c7d875
commit 5f1cb2ede3
2 changed files with 43 additions and 15 deletions

View File

@ -669,44 +669,52 @@ DATA = OrderedDict([
('colors', sect.KeyValue(
('completion.fg',
SettingValue(types.Color(), 'white'),
"Text color of the completion widget."),
('completion.bg',
SettingValue(types.Color(), '#333333'),
"Text color of the completion widget."),
('completion.item.bg',
SettingValue(types.Color(), 'white'),
SettingValue(types.Color(), '${completion.bg}'),
"Background color of completion widget items."),
('completion.category.fg',
SettingValue(types.Color(), '#e6bd00'),
"Foreground color of completion widget category headers."),
('completion.category.bg',
SettingValue(types.Color(), 'qlineargradient(x1:0, y1:0, x2:0, y2:1, '
'stop:0 #e4e4e4, stop:1 #dbdbdb)'),
'stop:0 #888888, stop:1 #505050)'),
"Background color of the completion widget category headers."),
('completion.category.border.top',
SettingValue(types.Color(), '#808080'),
SettingValue(types.Color(), 'black'),
"Top border color of the completion widget category headers."),
('completion.category.border.bottom',
SettingValue(types.Color(), '#bbbbbb'),
SettingValue(types.Color(), '${completion.category.border.top}'),
"Bottom border color of the completion widget category headers."),
('completion.item.selected.fg',
SettingValue(types.Color(), '#333333'),
SettingValue(types.Color(), 'black'),
"Foreground color of the selected completion item."),
('completion.item.selected.bg',
SettingValue(types.Color(), '#ffec8b'),
SettingValue(types.Color(), '#e8c000'),
"Background color of the selected completion item."),
('completion.item.selected.border.top',
SettingValue(types.Color(), '#f2f2c0'),
SettingValue(types.Color(), '#bbbb00'),
"Top border color of the completion widget category headers."),
('completion.item.selected.border.bottom',
SettingValue(types.Color(), '#ffec8b'),
SettingValue(types.Color(), '${completion.item.selected.border.top}'),
"Bottom border color of the selected completion item."),
('completion.match.fg',
SettingValue(types.Color(), 'red'),
SettingValue(types.Color(), '#ff4444'),
"Foreground color of the matched text in the completion."),
('statusbar.bg',

View File

@ -29,7 +29,7 @@ from PyQt5.QtWidgets import (QStyle, QStyleOptionViewItem, QTreeView,
from PyQt5.QtCore import (pyqtSlot, pyqtSignal, Qt, QRectF, QSize,
QItemSelectionModel)
from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
QTextCursor)
QTextCursor, QColor, QAbstractTextDocumentLayout)
import qutebrowser.config.config as config
import qutebrowser.commands.utils as cmdutils
@ -75,7 +75,6 @@ class CompletionView(QTreeView):
STYLESHEET = """
QTreeView {{
{font[completion]}
{color[completion.fg]}
{color[completion.bg]}
outline: 0;
}}
@ -103,6 +102,8 @@ class CompletionView(QTreeView):
"""
COLUMN_WIDTHS = [20, 70, 10]
# FIXME style scrollbar
change_completed_part = pyqtSignal(str)
def __init__(self, parent=None):
@ -474,14 +475,33 @@ class _CompletionItemDelegate(QStyledItemDelegate):
self._draw_textdoc(text_rect)
self._painter.restore()
def _draw_textdoc(self, text_rect):
def _draw_textdoc(self, rect):
"""Draw the QTextDocument of an item.
Args:
text_rect: The QRect to clip the drawing to.
rect: The QRect to clip the drawing to.
"""
clip = QRectF(0, 0, text_rect.width(), text_rect.height())
self._doc.drawContents(self._painter, clip)
# We can't use drawContents because then the color would be ignored.
# See: https://qt-project.org/forums/viewthread/21492
clip = QRectF(0, 0, rect.width(), rect.height())
self._painter.save()
if self._opt.state & QStyle.State_Selected:
option = 'completion.item.selected.fg'
elif not self._opt.state & QStyle.State_Enabled:
option = 'completion.category.fg'
else:
option = 'completion.fg'
try:
self._painter.setPen(QColor(config.get('colors', option)))
except config.NoOptionError:
self._painter.setPen(QColor(config.get('colors', 'completion.fg')))
ctx = QAbstractTextDocumentLayout.PaintContext()
ctx.palette.setColor(QPalette.Text, self._painter.pen().color())
if clip.isValid():
self._painter.setClipRect(clip)
ctx.clip = clip
self._doc.documentLayout().draw(self._painter, ctx)
self._painter.restore()
def _get_textdoc(self, index):
"""Create the QTextDocument of an item.