Use calibre icons for qt standard pixmaps even when using the system theme

This commit is contained in:
Kovid Goyal 2022-07-19 22:20:10 +05:30
parent 135f03c36c
commit 876ab0b19f
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 17 additions and 13 deletions

View File

@ -1088,7 +1088,7 @@ class Application(QApplication):
args = [override_program_name] + args[1:]
self.palette_manager = PaletteManager(gprefs['color_palette'], gprefs['ui_style'], force_calibre_style, headless)
if headless:
args.extend(['-platformpluginpath', plugins_loc, '-platform', 'headless'])
args.extend(('-platformpluginpath', plugins_loc, '-platform', 'headless'))
else:
args.extend(self.palette_manager.args_to_qt)

View File

@ -5,7 +5,7 @@ import os
import sys
from contextlib import contextmanager
from qt.core import (
QAbstractNativeEventFilter, QApplication, QColor, QIcon, QPalette, QSettings,
QAbstractNativeEventFilter, QApplication, QColor, QIcon, QPalette, QSettings, QProxyStyle,
QStyle, Qt, QTimer, pyqtSlot, QObject, QDataStream, QByteArray, QIODeviceBase
)
@ -19,6 +19,15 @@ light_text_color = QColor(0,0,0)
light_link_color = QColor(0, 0, 255)
class UseCalibreIcons(QProxyStyle):
def standardIcon(self, standard_pixmap, option=None, widget=None):
ic = QApplication.instance().get_qt_standard_icon(standard_pixmap)
if ic.isNull():
return super().standardIcon(standard_pixmap, option, widget)
return ic
if iswindows:
import ctypes
@ -288,7 +297,7 @@ class PaletteManager(QObject):
# own dark mode implementation when using calibre style so
# prefer that and use darkmode=1
args.append('-platform')
args.append('windows:darkmode=' + '1' if self.using_calibre_style else '2')
args.append('windows:darkmode=' + ('1' if self.using_calibre_style else '2'))
self.args_to_qt = tuple(args)
if ismacos and not headless and self.has_fixed_palette:
from calibre_extensions.cocoa import set_appearance
@ -297,7 +306,7 @@ class PaletteManager(QObject):
def initialize(self):
app = QApplication.instance()
self.setParent(app)
if not self.using_calibre_style and self.style().objectName() == 'fusion':
if not self.using_calibre_style and app.style().objectName() == 'fusion':
# Since Qt is using the fusion style anyway, specialize it
self.using_calibre_style = True
self.original_palette = QPalette(app.palette())
@ -332,6 +341,10 @@ class PaletteManager(QObject):
print('Using calibre Qt style:', self.using_calibre_style, file=sys.stderr)
if self.using_calibre_style:
self.load_calibre_style()
else:
app = QApplication.instance()
self.native_proxy_style = UseCalibreIcons(app.style())
app.setStyle(self.native_proxy_style)
self.on_palette_change()
def get_qt_standard_icon(self, standard_pixmap):

View File

@ -55,11 +55,6 @@ def compile_icon_dir_as_themes(
path_to_dir, output_path, theme_name='calibre-default', inherits='',
for_theme='any', prefix='/icons',
):
aliases = {
# these names are use by Qt commonstyle for line edit clear icons. The
# windows system style inherits it from commonstyle
'clear_left.png': ('edit-clear-locationbar-ltr.png', 'edit-clear-locationbar-rtl.png')
}
with tempfile.TemporaryDirectory(dir=path_to_dir) as tdir, open(os.path.join(tdir, 'icons.qrc'), 'w') as qrc:
print('<RCC>', file=qrc)
print(f' <qresource prefix="{prefix}">', file=qrc)
@ -114,10 +109,6 @@ def compile_icon_dir_as_themes(
dest = theme_dir, 'images', (rp + dest_name)
safe_link(image_path, os.path.join(tdir, *dest))
file('/'.join(dest))
for alias in aliases.get(image_name, ()):
dest = theme_dir, 'images', (rp + alias)
safe_link(image_path, os.path.join(tdir, *dest))
file('/'.join(dest))
for dirpath, dirnames, filenames in os.walk(path_to_dir):
if 'textures' in dirnames: