Add styling of new hints

This also removes the hints -> opacity setting, as this is now set by
using an rgba(...) color.
This commit is contained in:
Florian Bruhin 2016-08-16 17:44:48 +02:00
parent c033ed9edb
commit eac30fc84b
4 changed files with 67 additions and 29 deletions

View File

@ -178,7 +178,6 @@
|==============
|Setting|Description
|<<hints-border,border>>|CSS border value for hints.
|<<hints-opacity,opacity>>|Opacity for hints.
|<<hints-mode,mode>>|Mode to use for hints.
|<<hints-chars,chars>>|Chars used for hint strings.
|<<hints-min-chars,min-chars>>|Minimum number of chars used for hint strings.
@ -248,7 +247,7 @@
|<<colors-tabs.indicator.error,tabs.indicator.error>>|Color for the tab indicator on errors..
|<<colors-tabs.indicator.system,tabs.indicator.system>>|Color gradient interpolation system for the tab indicator.
|<<colors-hints.fg,hints.fg>>|Font color for hints.
|<<colors-hints.bg,hints.bg>>|Background color for hints.
|<<colors-hints.bg,hints.bg>>|Background color for hints. Note that you can use a `rgba(...)` value for transparency.
|<<colors-hints.fg.match,hints.fg.match>>|Font color for the matched part of hints.
|<<colors-downloads.bg.bar,downloads.bg.bar>>|Background color for the download bar.
|<<colors-downloads.fg.start,downloads.fg.start>>|Color gradient start for download text.
@ -1601,12 +1600,6 @@ CSS border value for hints.
Default: +pass:[1px solid #E3BE23]+
[[hints-opacity]]
=== opacity
Opacity for hints.
Default: +pass:[0.7]+
[[hints-mode]]
=== mode
Mode to use for hints.
@ -2052,9 +2045,9 @@ Default: +pass:[black]+
[[colors-hints.bg]]
=== hints.bg
Background color for hints.
Background color for hints. Note that you can use a `rgba(...)` value for transparency.
Default: +pass:[-webkit-gradient(linear, left top, left bottom, color-stop(0%,#FFF785), color-stop(100%,#FFC542))]+
Default: +pass:[qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 rgba(255, 247, 133, 0.8), stop:1 rgba(255, 197, 66, 0.8))]+
[[colors-hints.fg.match]]
=== hints.fg.match

View File

@ -32,7 +32,7 @@ from PyQt5.QtGui import QMouseEvent
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWebKitWidgets import QWebPage
from qutebrowser.config import config
from qutebrowser.config import config, style
from qutebrowser.keyinput import modeman, modeparsers
from qutebrowser.browser import webelem
from qutebrowser.commands import userscripts, cmdexc, cmdutils, runners
@ -65,22 +65,30 @@ class HintLabel(QLabel):
_context: The current hinting context.
"""
STYLESHEET = """
QLabel {
background-color: {{ color['hints.bg'] }};
color: {{ color['hints.fg'] }};
font: {{ font['hints'] }};
border: {{ config.get('hints', 'border') }};
padding-left: -3px;
padding-right: -3px;
}
"""
def __init__(self, elem, context):
super().__init__(parent=context.tab)
self._context = context
self.elem = elem
self.setAttribute(Qt.WA_StyledBackground, True)
style.set_register_stylesheet(self)
self._context.tab.contents_size_changed.connect(
self._on_contents_size_changed)
self._move_to_elem()
self.show()
# FIXME styling
# ('color', config.get('colors', 'hints.fg') + ' !important'),
# ('background', config.get('colors', 'hints.bg') + ' !important'),
# ('font', config.get('fonts', 'hints') + ' !important'),
# ('border', config.get('hints', 'border') + ' !important'),
# ('opacity', str(config.get('hints', 'opacity')) + ' !important'),
def update_text(self, matched, unmatched):
"""Set the text for the hint.
@ -99,6 +107,7 @@ class HintLabel(QLabel):
match_color = html.escape(config.get('colors', 'hints.fg.match'))
self.setText('<font color="{}">{}</font>{}'.format(
match_color, matched, unmatched))
self.adjustSize()
def _move_to_elem(self):
"""Reposition the label to its element."""

View File

@ -24,6 +24,7 @@ are fundamentally different. This is why nothing inherits from configparser,
but we borrow some methods and classes from there where it makes sense.
"""
import re
import os
import sys
import os.path
@ -34,6 +35,7 @@ import collections
import collections.abc
from PyQt5.QtCore import pyqtSignal, QObject, QUrl, QSettings
from PyQt5.QtGui import QColor
from qutebrowser.config import configdata, configexc, textwrapper
from qutebrowser.config.parsers import keyconf
@ -286,6 +288,40 @@ def _transform_position(val):
return val
def _transform_hint_color(val):
"""Transformer for hint colors."""
log.config.debug("Transforming hint value {}".format(val))
def to_rgba(qcolor):
"""Convert a QColor to a rgba() value."""
return 'rgba({}, {}, {}, 0.8)'.format(qcolor.red(), qcolor.green(),
qcolor.blue())
if val.startswith('-webkit-gradient'):
pattern = re.compile(r'-webkit-gradient\(linear, left top, '
r'left bottom, '
r'color-stop\(0%, *(#[a-fA-F0-9]{3,6})\), '
r'color-stop\(100%, *(#[a-fA-F0-9]{3,6})\)')
match = pattern.match(val)
if match:
log.config.debug('Color groups: {}'.format(match.groups()))
start_color = QColor(match.group(1))
stop_color = QColor(match.group(2))
qtutils.ensure_valid(start_color)
qtutils.ensure_valid(stop_color)
return ('qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 {}, '
'stop:1 {})'.format(to_rgba(start_color),
to_rgba(stop_color)))
else:
return None
elif val.startswith('-'): # Custom CSS stuff?
return None
else: # Already transformed or a named color.
return val
class ConfigManager(QObject):
"""Configuration manager for qutebrowser.
@ -353,6 +389,7 @@ class ConfigManager(QObject):
('ui', 'display-statusbar-messages'),
('ui', 'hide-mouse-cursor'),
('general', 'wrap-search'),
('hints', 'opacity'),
]
CHANGED_OPTIONS = {
('content', 'cookies-accept'):
@ -367,6 +404,9 @@ class ConfigManager(QObject):
_get_value_transformer({'false': '*', 'true': ''}),
('hints', 'auto-follow'):
_get_value_transformer({'false': 'never', 'true': 'unique-match'}),
('colors', 'hints.bg'): _transform_hint_color,
('colors', 'hints.fg'): _transform_hint_color,
('colors', 'hints.fg.match'): _transform_hint_color,
}
changed = pyqtSignal(str, str)

View File

@ -897,10 +897,6 @@ def data(readonly=False):
SettingValue(typ.String(), '1px solid #E3BE23'),
"CSS border value for hints."),
('opacity',
SettingValue(typ.Float(minval=0.0, maxval=1.0), '0.7'),
"Opacity for hints."),
('mode',
SettingValue(typ.String(
valid_values=typ.ValidValues(
@ -1209,18 +1205,18 @@ def data(readonly=False):
"Color gradient interpolation system for the tab indicator."),
('hints.fg',
SettingValue(typ.CssColor(), 'black'),
SettingValue(typ.QssColor(), 'black'),
"Font color for hints."),
('hints.bg',
SettingValue(
typ.CssColor(), '-webkit-gradient(linear, left top, '
'left bottom, color-stop(0%,#FFF785), '
'color-stop(100%,#FFC542))'),
"Background color for hints."),
SettingValue(typ.QssColor(), 'qlineargradient(x1:0, y1:0, x2:1, '
'y2:1, stop:0 rgba(255, 247, 133, 0.8), '
'stop:1 rgba(255, 197, 66, 0.8))'),
"Background color for hints. Note that you can use a `rgba(...)` "
"value for transparency."),
('hints.fg.match',
SettingValue(typ.CssColor(), 'green'),
SettingValue(typ.QssColor(), 'green'),
"Font color for the matched part of hints."),
('downloads.bg.bar',