Lines 18-33
Link Here
|
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
19 |
***************************************************************************/ |
19 |
***************************************************************************/ |
20 |
|
20 |
|
|
|
21 |
#include <QDir> // This has to be above any GTK headers |
22 |
|
21 |
#include "utilities.h" |
23 |
#include "utilities.h" |
22 |
#include "rcproperties.h" |
24 |
#include "rcproperties.h" |
23 |
#include "engine.h" |
25 |
#include "engine.h" |
24 |
|
26 |
|
25 |
#include <QDebug> |
27 |
#include <QtDebug> |
26 |
#include <QToolTip> |
28 |
#include <QToolTip> |
27 |
#include <QFile> |
29 |
#include <QFile> |
28 |
#include <QSettings> |
30 |
#include <QSettings> |
29 |
#include <QFileInfo> |
31 |
#include <QFileInfo> |
30 |
|
32 |
|
|
|
33 |
#define INITDUMMY(className) \ |
34 |
dummy.setPalette(QApplication::palette()); \ |
35 |
dummy.setObjectName(className); \ |
36 |
Engine::instance()->m_qtStyle->polish(&dummy); |
37 |
|
38 |
#define WCOLOR(class, role) \ |
39 |
GtkQtUtilities::colorString(dummy.palette().color(QPalette::class, QPalette::role)) |
40 |
|
31 |
|
41 |
|
32 |
bool RcProperties::s_scrollBarHasBack1; |
42 |
bool RcProperties::s_scrollBarHasBack1; |
33 |
bool RcProperties::s_scrollBarHasForward1; |
43 |
bool RcProperties::s_scrollBarHasForward1; |
Lines 44-65
Link Here
|
44 |
{ |
54 |
{ |
45 |
GTK_QT_DEBUG_FUNC |
55 |
GTK_QT_DEBUG_FUNC |
46 |
|
56 |
|
|
|
57 |
initKdeSettings(); |
58 |
|
47 |
setWidgetProperties(); |
59 |
setWidgetProperties(); |
48 |
setColorProperties(); |
60 |
setColorProperties(); |
49 |
setIconProperties(); |
61 |
setIconProperties(); |
|
|
62 |
|
63 |
// KDE's "Apply colors to non-KDE apps" setting is broken. |
64 |
// It applies colors to the "*" class which overrides colors set by the style |
65 |
// We take the (rather extreme) measure of removing its gtkrc file |
66 |
|
67 |
char** rcFiles = gtk_rc_get_default_files(); |
68 |
while (*rcFiles != NULL) |
69 |
{ |
70 |
QString fileName(*(rcFiles++)); |
71 |
|
72 |
if (!fileName.endsWith("/share/config/gtkrc-2.0")) |
73 |
continue; |
74 |
|
75 |
// Open the file and check for a known string just to make |
76 |
// sure we're not accidentally deleting something else |
77 |
QFile file(fileName); |
78 |
if (!file.exists()) |
79 |
continue; |
80 |
|
81 |
file.open(QIODevice::ReadOnly); |
82 |
if (!file.readLine(20).startsWith("# created by KDE")) |
83 |
continue; |
84 |
|
85 |
file.close(); |
86 |
file.remove(); |
87 |
} |
50 |
} |
88 |
} |
51 |
|
89 |
|
52 |
void RcProperties::setWidgetProperties() |
90 |
void RcProperties::setWidgetProperties() |
53 |
{ |
91 |
{ |
54 |
const QStyle* qtStyle = Engine::instance()->m_qtStyle; |
92 |
const QStyle* qtStyle = Engine::instance()->m_qtStyle; |
55 |
|
93 |
|
|
|
94 |
// Buttons |
95 |
GtkQtUtilities::parseRcString("GtkButton::child_displacement_x = " + QString::number(qtStyle->pixelMetric(QStyle::PM_ButtonShiftHorizontal)), "*", GtkQtUtilities::WidgetClass); |
96 |
GtkQtUtilities::parseRcString("GtkButton::child_displacement_y = " + QString::number(qtStyle->pixelMetric(QStyle::PM_ButtonShiftVertical)), "*", GtkQtUtilities::WidgetClass); |
97 |
|
56 |
// Check boxes |
98 |
// Check boxes |
57 |
// We add 2 to the size to account for the box around the check indicator |
99 |
// We add 2 to the size to account for the box around the check indicator |
58 |
GtkQtUtilities::parseRcString("GtkCheckButton::indicator-size = " + QString::number(qtStyle->pixelMetric(QStyle::PM_IndicatorHeight) + 2), "*", GtkQtUtilities::WidgetClass); |
100 |
GtkQtUtilities::parseRcString("GtkCheckButton::indicator-size = " + QString::number(qtStyle->pixelMetric(QStyle::PM_IndicatorHeight) + 2), "*", GtkQtUtilities::WidgetClass); |
59 |
|
101 |
|
60 |
// Tabs |
102 |
// Tabs |
|
|
103 |
GtkQtUtilities::parseRcString("GtkButton::tab-curvature = 0", "*", GtkQtUtilities::WidgetClass); |
61 |
GtkQtUtilities::parseRcString("GtkNotebook::tab-overlap = " + QString::number(qtStyle->pixelMetric(QStyle::PM_TabBarTabOverlap)), "*", GtkQtUtilities::WidgetClass); |
104 |
GtkQtUtilities::parseRcString("GtkNotebook::tab-overlap = " + QString::number(qtStyle->pixelMetric(QStyle::PM_TabBarTabOverlap)), "*", GtkQtUtilities::WidgetClass); |
62 |
GtkQtUtilities::parseRcString("xthickness = 3", "*.GtkNotebook", GtkQtUtilities::WidgetClass); // Hardcode values that look good |
105 |
GtkQtUtilities::parseRcString("xthickness = 2", "*.GtkNotebook", GtkQtUtilities::WidgetClass); // Hardcode values that look good |
63 |
GtkQtUtilities::parseRcString("ythickness = 3", "*.GtkNotebook", GtkQtUtilities::WidgetClass); |
106 |
GtkQtUtilities::parseRcString("ythickness = 3", "*.GtkNotebook", GtkQtUtilities::WidgetClass); |
64 |
|
107 |
|
65 |
// Line edits |
108 |
// Line edits |
Lines 131-137
Link Here
|
131 |
|
174 |
|
132 |
int availableSize = 200 - qtStyle->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarGroove, scrollBar).width(); |
175 |
int availableSize = 200 - qtStyle->subControlRect(QStyle::CC_ScrollBar, &option, QStyle::SC_ScrollBarGroove, scrollBar).width(); |
133 |
s_scrollBarButtonCount = s_scrollBarHasForward1 + s_scrollBarHasBack1 + s_scrollBarHasForward2 + s_scrollBarHasBack2; // Evil |
176 |
s_scrollBarButtonCount = s_scrollBarHasForward1 + s_scrollBarHasBack1 + s_scrollBarHasForward2 + s_scrollBarHasBack2; // Evil |
134 |
s_scrollBarButtonSize = availableSize / s_scrollBarButtonCount; |
177 |
if (s_scrollBarButtonCount != 0) |
|
|
178 |
s_scrollBarButtonSize = availableSize / s_scrollBarButtonCount; |
179 |
} |
180 |
|
181 |
QString RcProperties::gtkPaletteString(const QPalette& pal, const QString& bgfg, QPalette::ColorRole role) |
182 |
{ |
183 |
return bgfg + "[NORMAL] = " + GtkQtUtilities::colorString(pal.color(QPalette::Inactive, role)) + "\n" |
184 |
+ bgfg + "[ACTIVE] = " + GtkQtUtilities::colorString(pal.color(QPalette::Active, role)) + "\n" |
185 |
+ bgfg + "[PRELIGHT] = " + GtkQtUtilities::colorString(pal.color(QPalette::Active, role)) + "\n" |
186 |
+ bgfg + "[INSENSITIVE] = " + GtkQtUtilities::colorString(pal.color(QPalette::Disabled, role)) + "\n"; |
135 |
} |
187 |
} |
136 |
|
188 |
|
137 |
void RcProperties::setColorProperties() |
189 |
void RcProperties::setColorProperties() |
Lines 167-190
Link Here
|
167 |
mapColor("base[INSENSITIVE]", QPalette::Disabled, QPalette::Base); |
219 |
mapColor("base[INSENSITIVE]", QPalette::Disabled, QPalette::Base); |
168 |
|
220 |
|
169 |
// Tooltips |
221 |
// Tooltips |
170 |
QString tooltipColor = GtkQtUtilities::colorString(QToolTip::palette().color(QPalette::Active, QPalette::Base)); |
222 |
QColor tooltipBg(convertColor(kdeConfigValue("/share/config/kdeglobals", "Colors:Tooltip/BackgroundNormal", QToolTip::palette().color(QPalette::Active, QPalette::Base), true).second)); |
171 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + tooltipColor, "*.tooltips.*.GtkToggleButton", GtkQtUtilities::WidgetClass); |
223 |
QColor tooltipFg(convertColor(kdeConfigValue("/share/config/kdeglobals", "Colors:Tooltip/ForegroundNormal", QToolTip::palette().color(QPalette::Active, QPalette::Text), true).second)); |
172 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + tooltipColor, "gtk-tooltips", GtkQtUtilities::Widget); |
224 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + GtkQtUtilities::colorString(tooltipBg), "gtk-tooltip*", GtkQtUtilities::Widget); |
173 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + tooltipColor, "gtk-tooltip", GtkQtUtilities::Widget); |
225 |
GtkQtUtilities::parseRcString("fg[NORMAL] = " + GtkQtUtilities::colorString(tooltipFg), "gtk-tooltip*", GtkQtUtilities::Widget); |
174 |
|
|
|
175 |
// Buttons |
176 |
QString buttonColor = GtkQtUtilities::colorString(QApplication::palette().color(QPalette::Active, QPalette::Button)); |
177 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + buttonColor, "GtkButton", GtkQtUtilities::Class); |
178 |
GtkQtUtilities::parseRcString("bg[ACTIVE] = " + buttonColor, "GtkButton", GtkQtUtilities::Class); |
179 |
GtkQtUtilities::parseRcString("bg[NORMAL] = " + buttonColor, "GtkOptionMenu", GtkQtUtilities::Class); |
180 |
GtkQtUtilities::parseRcString("bg[ACTIVE] = " + buttonColor, "GtkOptionMenu", GtkQtUtilities::Class); |
181 |
|
182 |
buttonColor = GtkQtUtilities::colorString(QApplication::palette().color(QPalette::Disabled, QPalette::Button)); |
183 |
GtkQtUtilities::parseRcString("bg[INSENSITIVE] = " + buttonColor, "GtkButton", GtkQtUtilities::Class); |
184 |
|
226 |
|
185 |
// Lists |
227 |
// Lists |
186 |
QString activeListColor = GtkQtUtilities::colorString(QApplication::palette().color(QPalette::Active, QPalette::HighlightedText)); |
228 |
QString activeListColor = GtkQtUtilities::colorString(QApplication::palette().color(QPalette::Active, QPalette::HighlightedText)); |
187 |
GtkQtUtilities::parseRcString("text[ACTIVE] = " + activeListColor, "GtkTreeView", GtkQtUtilities::Class); |
229 |
GtkQtUtilities::parseRcString("text[ACTIVE] = " + activeListColor, "GtkTreeView", GtkQtUtilities::Class); |
|
|
230 |
|
231 |
// Patch from Thomas Lübking: |
232 |
// Ask the Qt style for color settings of a (growing?) bunch of widget types. |
233 |
// We pass a dummy widget to QStyle::polish(QWidget*) with the widget's object |
234 |
// name reflecting (a faked) QObject::className alongside with the apps |
235 |
// default palette - if the style changes the palette, we add a gtk style |
236 |
// for the matching gtk widgets |
237 |
// NOTICE using a dummy widget objectName rather than a matching QWidget |
238 |
// here does not only allow us to skip couple of widget headers here for no |
239 |
// sense, but also is REQUIRED! because the Qt styles tend to do freaky things |
240 |
// on certain widget types, which we need to prevent... |
241 |
// |
242 |
// as the GTK and Qt palette models do not really fit, we'll translate |
243 |
// QPalette::Inactive -> GTK_STATE_NORMAL |
244 |
// QPalette::Active -> GTK_STATE_PRELIGHT |
245 |
// QPalette::Active -> GTK_STATE_ACTIVE |
246 |
// QPalette::Disabled -> GTK_STATE_INSENSITIVE |
247 |
|
248 |
QWidget dummy; |
249 |
|
250 |
INITDUMMY("QPushButton") |
251 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Button), "GtkButton", GtkQtUtilities::Class); |
252 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "fg", QPalette::ButtonText), "*.GtkButton*GtkLabel", GtkQtUtilities::WidgetClass); |
253 |
|
254 |
INITDUMMY("QComboBox") |
255 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Button), "GtkOptionMenu", GtkQtUtilities::Class); |
256 |
|
257 |
INITDUMMY("QCheckBox") |
258 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Button), "GtkCheckButton", GtkQtUtilities::Class); |
259 |
|
260 |
INITDUMMY("QRadioButton") |
261 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Button), "GtkRadioButton", GtkQtUtilities::Class); |
262 |
|
263 |
INITDUMMY("QTabBar") |
264 |
if (dummy.palette() != QApplication::palette()) |
265 |
{ |
266 |
// SIC! GTK thinks all tabs but the active are active... |
267 |
GtkQtUtilities::parseRcString( |
268 |
"fg[ACTIVE] = " + WCOLOR(Inactive, WindowText) + "\n" + |
269 |
"fg[NORMAL] = " + WCOLOR(Active, WindowText) + "\n" + |
270 |
"fg[PRELIGHT] = " + WCOLOR(Active, WindowText) + "\n" + |
271 |
"fg[INSENSITIVE] = " + WCOLOR(Disabled, WindowText), |
272 |
"*.GtkNotebook.GtkLabel", GtkQtUtilities::WidgetClass); |
273 |
} |
274 |
|
275 |
INITDUMMY("QMenu") |
276 |
if (dummy.palette() != QApplication::palette()) |
277 |
{ |
278 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Window), "GtkMenu", GtkQtUtilities::Class); |
279 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "fg", QPalette::WindowText), "*.GtkMenuItem.GtkLabel", GtkQtUtilities::Class); |
280 |
} |
281 |
|
282 |
INITDUMMY("QMenuBar") |
283 |
if (dummy.palette() != QApplication::palette()) |
284 |
{ |
285 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "bg", QPalette::Window), "GtkMenuBar", GtkQtUtilities::Class); |
286 |
GtkQtUtilities::parseRcString(gtkPaletteString(dummy.palette(), "fg", QPalette::WindowText), "*.GtkMenuBar.GtkMenuItem.GtkLabel", GtkQtUtilities::WidgetClass); |
287 |
} |
188 |
} |
288 |
} |
189 |
|
289 |
|
190 |
void RcProperties::mapColor(const QString& name, QPalette::ColorGroup group, QPalette::ColorRole role) |
290 |
void RcProperties::mapColor(const QString& name, QPalette::ColorGroup group, QPalette::ColorRole role) |
Lines 192-198
Link Here
|
192 |
QPalette palette(QApplication::palette()); |
292 |
QPalette palette(QApplication::palette()); |
193 |
QString color(GtkQtUtilities::colorString(palette.color(group, role))); |
293 |
QString color(GtkQtUtilities::colorString(palette.color(group, role))); |
194 |
|
294 |
|
195 |
GtkQtUtilities::parseRcString(name + " = " + color, "*", GtkQtUtilities::Class); |
295 |
GtkQtUtilities::parseRcString(name + " = " + color, "GtkWidget", GtkQtUtilities::Class); |
196 |
} |
296 |
} |
197 |
|
297 |
|
198 |
PathAndValue RcProperties::kdeConfigValue(const QString& file, const QString& key, const QVariant& def, bool searchAllFiles) |
298 |
PathAndValue RcProperties::kdeConfigValue(const QString& file, const QString& key, const QVariant& def, bool searchAllFiles) |
Lines 239-253
Link Here
|
239 |
s_kdeSearchPaths << kdeDir; |
339 |
s_kdeSearchPaths << kdeDir; |
240 |
s_kdeSearchPaths << settings.value("KDEPrefix").toString(); |
340 |
s_kdeSearchPaths << settings.value("KDEPrefix").toString(); |
241 |
|
341 |
|
|
|
342 |
s_kdeSearchPaths << QDir::homePath() + "/.kde4"; |
343 |
s_kdeSearchPaths << QDir::homePath() + "/.kde"; |
242 |
s_kdeSearchPaths << "/usr/local"; |
344 |
s_kdeSearchPaths << "/usr/local"; |
243 |
s_kdeSearchPaths << "/usr"; |
345 |
s_kdeSearchPaths << "/usr"; |
244 |
} |
346 |
} |
245 |
|
347 |
|
246 |
void RcProperties::setIconProperties() |
348 |
void RcProperties::setIconProperties() |
247 |
{ |
349 |
{ |
248 |
// Find the current KDE icon theme |
|
|
249 |
initKdeSettings(); |
250 |
|
251 |
// Get the theme's directory and those of its parents |
350 |
// Get the theme's directory and those of its parents |
252 |
QString iconThemeName(kdeConfigValue("/share/config/kdeglobals", "Icons/Theme", "oxygen", true).second.toString()); |
351 |
QString iconThemeName(kdeConfigValue("/share/config/kdeglobals", "Icons/Theme", "oxygen", true).second.toString()); |
253 |
traverseIconThemeDir(iconThemeName); |
352 |
traverseIconThemeDir(iconThemeName); |
Lines 352-358
Link Here
|
352 |
iconMappings += doIconMapping("gtk-zoom-fit", "actions/zoom-fit-best.png"); |
451 |
iconMappings += doIconMapping("gtk-zoom-fit", "actions/zoom-fit-best.png"); |
353 |
iconMappings += doIconMapping("gtk-zoom-in", "actions/zoom-in.png"); |
452 |
iconMappings += doIconMapping("gtk-zoom-in", "actions/zoom-in.png"); |
354 |
iconMappings += doIconMapping("gtk-zoom-out", "actions/zoom-out.png"); |
453 |
iconMappings += doIconMapping("gtk-zoom-out", "actions/zoom-out.png"); |
355 |
iconMappings += "} class \"*\" style \"KDE-icons\""; |
454 |
iconMappings += "} class \"GtkWidget\" style \"KDE-icons\""; |
356 |
|
455 |
|
357 |
GtkQtUtilities::parseRcString(iconMappings); |
456 |
GtkQtUtilities::parseRcString(iconMappings); |
358 |
} |
457 |
} |
Lines 422-424
Link Here
|
422 |
|
521 |
|
423 |
return "stock[\"" + stockName + "\"] = {" + lines.join(",") + "}\n"; |
522 |
return "stock[\"" + stockName + "\"] = {" + lines.join(",") + "}\n"; |
424 |
} |
523 |
} |
|
|
524 |
|
525 |
QColor RcProperties::convertColor(const QVariant& variant) |
526 |
{ |
527 |
if (variant.value<QColor>().isValid()) |
528 |
return variant.value<QColor>(); |
529 |
|
530 |
// KDE seems to store colors in its config files as QStringList(r, g, b), which you can't convert |
531 |
// with QVariant::value<QColor> |
532 |
QStringList list(variant.toStringList()); |
533 |
if (list.count() == 3) |
534 |
return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt()); |
535 |
else if (list.count() == 4) |
536 |
return QColor(list[0].toInt(), list[1].toInt(), list[2].toInt(), list[3].toInt()); |
537 |
return QColor(); |
538 |
} |
539 |
|