From 45d35b283e36129327f0c6fb8163b13c0870ee50 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 3 Jun 2012 12:42:46 +0530 Subject: [PATCH] Fix focus highlighting obsucring text in listviews --- session.vim | 8 +++++++- setup/extensions.py | 23 ++++------------------- src/calibre/gui2/__init__.py | 8 ++++---- src/qtcurve/config.h | 12 ++++++++++++ src/qtcurve/style/qtcurve.cpp | 4 ++++ src/qtcurve/test_rendering.py | 28 ++++++++++++++++++++++++++++ 6 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 src/qtcurve/config.h create mode 100644 src/qtcurve/test_rendering.py diff --git a/session.vim b/session.vim index 185e51ae0d..bbacc4e0ec 100644 --- a/session.vim +++ b/session.vim @@ -2,7 +2,13 @@ let $PYFLAKES_BUILTINS = "_,dynamic_property,__,P,I,lopen,icu_lower,icu_upper,icu_title,ngettext" " Include directories for C++ modules -let g:syntastic_cpp_include_dirs = [ '/usr/include/podofo', '/usr/include/qt4/QtCore', '/usr/include/qt4/QtGui', '/usr/include/qt4'] +let g:syntastic_cpp_include_dirs = [ + \'/usr/include/podofo', + \'/usr/include/qt4/QtCore', + \'/usr/include/qt4/QtGui', + \'/usr/include/qt4', + \'src/qtcurve/common', 'src/qtcurve', + \] fun! CalibreLog() " Setup buffers to edit the calibre changelog and version info prior to diff --git a/setup/extensions.py b/setup/extensions.py index a264885a8b..586c43fe7a 100644 --- a/setup/extensions.py +++ b/setup/extensions.py @@ -368,7 +368,8 @@ class Build(Command): self.info('\n####### Building calibre style', '#'*7) sdir = self.j(self.SRC, 'qtcurve') def path(x): - return '"%s"'%self.j(sdir, x).replace(os.sep, '/') + if x: x=self.j(sdir, x) + return ('"%s"'%x).replace(os.sep, '/') headers = [ "common/colorutils.h", "common/common.h", @@ -404,7 +405,7 @@ class Build(Command): DESTDIR = . TARGET = calibre QT *= svg - INCLUDEPATH *= . {inc} + INCLUDEPATH *= {conf} {inc} win32-msvc*:DEFINES *= _CRT_SECURE_NO_WARNINGS # Force C++ language @@ -412,7 +413,7 @@ class Build(Command): *msvc*:QMAKE_CFLAGS *= -TP *msvc*:QMAKE_CXXFLAGS += /MP - ''').format(inc=path('common')) + ''').format(conf=path(''), inc=path('common')) if isosx: pro += '\nCONFIG += x86 x86_64\n' else: @@ -422,18 +423,6 @@ class Build(Command): pro += 'HEADERS += %s\n'%path(x) for x in sources: pro += 'SOURCES += %s\n'%path(x) - config = textwrap.dedent(''' - #pragma once - - /* #define VERSION "1.5.3" */ - #define KDE3PREFIX "/usr" - #define KDE4PREFIX "/usr" - - #define QTC_QT_ONLY - /* #undef QTC_OLD_NVIDIA_ARROW_FIX */ - #undef QTC_STYLE_SUPPORT - /* #undef QTC_KWIN_MAX_BUTTON_HACK */ - ''') odir = self.j(self.d(self.SRC), 'build', 'qtcurve') if not os.path.exists(odir): os.makedirs(odir) @@ -444,10 +433,6 @@ class Build(Command): 'rb').read() != pro): with open('qtcurve.pro', 'wb') as f: f.write(pro) - if not os.path.exists('config.h') or (open('config.h', - 'rb').read() != config): - with open('config.h', 'wb') as f: - f.write(config) qmc = [QMAKE, '-o', 'Makefile'] if iswindows: qmc += ['-spec', 'win32-msvc2008'] diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index a0fbab7bbc..1295118290 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -720,7 +720,7 @@ gui_thread = None qt_app = None class Application(QApplication): - def __init__(self, args): + def __init__(self, args, force_calibre_style=False): self.file_event_hook = None qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args] QApplication.__init__(self, qargs) @@ -731,7 +731,7 @@ class Application(QApplication): qt_app = self self._file_open_paths = [] self._file_open_lock = RLock() - self.setup_styles() + self.setup_styles(force_calibre_style) def load_calibre_style(self): # On OS X QtCurve resets the palette, so we preserve it explicitly @@ -743,7 +743,7 @@ class Application(QApplication): pi.load_style(path, 'Calibre') self.setPalette(orig_pal) - def setup_styles(self): + def setup_styles(self, force_calibre_style): self.original_font = QFont(QApplication.font()) fi = gprefs['font'] if fi is not None: @@ -753,7 +753,7 @@ class Application(QApplication): font.setStretch(s) QApplication.setFont(font) - if gprefs['widget_style'] != 'system': + if force_calibre_style or gprefs['widget_style'] != 'system': self.load_calibre_style() else: st = self.style() diff --git a/src/qtcurve/config.h b/src/qtcurve/config.h new file mode 100644 index 0000000000..19ce0bf25c --- /dev/null +++ b/src/qtcurve/config.h @@ -0,0 +1,12 @@ +#pragma once + +/* #define VERSION "1.5.3" */ +#define KDE3PREFIX "/usr" +#define KDE4PREFIX "/usr" + +#define QTC_QT_ONLY +/* #undef QTC_OLD_NVIDIA_ARROW_FIX */ +#undef QTC_STYLE_SUPPORT +/* #undef QTC_KWIN_MAX_BUTTON_HACK */ + + diff --git a/src/qtcurve/style/qtcurve.cpp b/src/qtcurve/style/qtcurve.cpp index dea39b343f..2d186c63e7 100644 --- a/src/qtcurve/style/qtcurve.cpp +++ b/src/qtcurve/style/qtcurve.cpp @@ -4986,6 +4986,10 @@ void Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option, if(widget && ::qobject_cast(widget)) r2.adjust(0, 2, 0, 0); + // Added by Kovid so that the highlight does not cover the text + if(widget && ::qobject_cast(widget)) + r2.adjust(0, 0, 0, 2); + if(FOCUS_STANDARD==opts.focus) { // Taken from QWindowsStyle... diff --git a/src/qtcurve/test_rendering.py b/src/qtcurve/test_rendering.py new file mode 100644 index 0000000000..7196412b74 --- /dev/null +++ b/src/qtcurve/test_rendering.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2012, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2 import Application +from PyQt4.Qt import (QDialog, QGridLayout, QListWidget, QDialogButtonBox) + +app = Application([], force_calibre_style=True) + +d = QDialog() +d.l = l = QGridLayout() +d.setLayout(l) +lw = QListWidget() +lw.addItem('Some text guy') +l.addWidget(lw, 0, 0, 2, 1) +bb = QDialogButtonBox() +bb.setStandardButtons(bb.Close) +bb.accepted.connect(d.accept) +bb.rejected.connect(d.reject) +l.addWidget(bb, 2, 0, 1, 2) + +d.exec_() +