Add setting for the webpage bg color to use.

Fixes #719.
This commit is contained in:
Florian Bruhin 2015-06-01 22:27:15 +02:00
parent 131f345007
commit 1bf036d1ba
3 changed files with 19 additions and 0 deletions

View File

@ -37,6 +37,7 @@ Added
- New flag `-d`/`--detach` for `:spawn` to detach the spawned process so it's not closed when qutebrowser is. - New flag `-d`/`--detach` for `:spawn` to detach the spawned process so it's not closed when qutebrowser is.
- New (hidden) command `:follow-selected` (bound to `Enter`/`Ctrl-Enter` by default) to follow the link which is currently selected (e.g. after searching via `/`). - New (hidden) command `:follow-selected` (bound to `Enter`/`Ctrl-Enter` by default) to follow the link which is currently selected (e.g. after searching via `/`).
- New setting `ui -> modal-js-dialog` to use the standard modal dialogs for javascript questions instead of using the statusbar. - New setting `ui -> modal-js-dialog` to use the standard modal dialogs for javascript questions instead of using the statusbar.
- New setting `colors -> webpage.bg` to set the background color to use for websites which don't set one.
Changed Changed
~~~~~~~ ~~~~~~~

View File

@ -24,6 +24,7 @@ import itertools
import functools import functools
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QTimer, QUrl
from PyQt5.QtGui import QPalette
from PyQt5.QtWidgets import QApplication, QStyleFactory from PyQt5.QtWidgets import QApplication, QStyleFactory
from PyQt5.QtWebKit import QWebSettings from PyQt5.QtWebKit import QWebSettings
from PyQt5.QtWebKitWidgets import QWebView, QWebPage from PyQt5.QtWebKitWidgets import QWebView, QWebPage
@ -108,6 +109,7 @@ class WebView(QWebView):
self.search_flags = 0 self.search_flags = 0
self.selection_enabled = False self.selection_enabled = False
self.init_neighborlist() self.init_neighborlist()
self._set_bg_color()
cfg = objreg.get('config') cfg = objreg.get('config')
cfg.changed.connect(self.init_neighborlist) cfg.changed.connect(self.init_neighborlist)
# For some reason, this signal doesn't get disconnected automatically # For some reason, this signal doesn't get disconnected automatically
@ -181,6 +183,15 @@ class WebView(QWebView):
self.load_status = val self.load_status = val
self.load_status_changed.emit(val.name) self.load_status_changed.emit(val.name)
def _set_bg_color(self):
"""Set the webpage background color as configured."""
col = config.get('colors', 'webpage.bg')
palette = self.palette()
if col is None:
col = self.style().standardPalette().color(QPalette.Base)
palette.setColor(QPalette.Base, col)
self.setPalette(palette)
@pyqtSlot(str, str) @pyqtSlot(str, str)
def on_config_changed(self, section, option): def on_config_changed(self, section, option):
"""Reinitialize the zoom neighborlist if related config changed.""" """Reinitialize the zoom neighborlist if related config changed."""
@ -195,6 +206,8 @@ class WebView(QWebView):
self.setContextMenuPolicy(Qt.PreventContextMenu) self.setContextMenuPolicy(Qt.PreventContextMenu)
else: else:
self.setContextMenuPolicy(Qt.DefaultContextMenu) self.setContextMenuPolicy(Qt.DefaultContextMenu)
elif section == 'colors' and option == 'webpage.bg':
self._set_bg_color()
def init_neighborlist(self): def init_neighborlist(self):
"""Initialize the _zoom neighborlist.""" """Initialize the _zoom neighborlist."""

View File

@ -959,6 +959,11 @@ def data(readonly=False):
SettingValue(typ.QtColor(), 'red'), SettingValue(typ.QtColor(), 'red'),
"Background color for downloads with errors."), "Background color for downloads with errors."),
('webpage.bg',
SettingValue(typ.QtColor(none_ok=True), 'white'),
"Background color for webpages if unset (or empty to use the "
"theme's color)"),
readonly=readonly readonly=readonly
)), )),