2
* Copyright (C) 2003 by Unai Garro <ugarro@users.sourceforge.net>
3
* Copyright (C) 2004 by Enrico Ros <rosenric@dei.unipd.it>
4
* Copyright (C) 2004 by Stephan Kulow <coolo@kde.org>
5
* Copyright (C) 2004,2006 by Oswald Buddenhagen <ossi@kde.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include <kdm_greet.h>
26
#include <KGlobalSettings>
27
#include <KStandardDirs>
30
#include <QDomElement>
34
#include <QStyleFactory>
38
parseSize(const QString &s, DataPoint &pt)
44
if (s == "box") { // box value
47
} else if (s == "scale") {
50
} else if ((p = s.indexOf('%')) >= 0) { // percent value
55
while ((p = sCopy.indexOf('^')) >= 0) {
59
sCopy.replace(',', '.');
60
pt.val = (int)sCopy.toDouble();
64
if (sCopy.at(0) == '-') {
68
sCopy.replace(',', '.');
69
pt.val = (int)sCopy.toDouble();
77
int splitAt = rs.lastIndexOf(' ') + 1;
78
QString s(rs.mid(splitAt));
79
rs.truncate(splitAt - 1);
84
parseFont(const QString &is, FontType &ft)
88
QString rs(is.simplified());
89
if ((ft.present = !rs.isEmpty())) {
90
QString s(getword(rs));
92
if (s.endsWith("px")) {
93
int ps = s.left(s.length() - 2).toInt(&ok);
95
ft.font.setPixelSize(ps);
99
double ps = s.toDouble(&ok);
101
ft.font.setPointSizeF(ps);
106
QString ss(s.toLower());
108
ft.font.setStyle(QFont::StyleOblique);
109
else if (ss == "italic")
110
ft.font.setStyle(QFont::StyleItalic);
111
else if (ss == "ultra-light")
112
ft.font.setWeight(13);
113
else if (ss == "light")
114
ft.font.setWeight(QFont::Light);
115
else if (ss == "medium")
116
ft.font.setWeight(50);
117
else if (ss == "semi-bold")
118
ft.font.setWeight(QFont::DemiBold);
119
else if (ss == "bold")
120
ft.font.setWeight(QFont::Bold);
121
else if (ss == "ultra-bold")
122
ft.font.setWeight(QFont::Black);
123
else if (ss == "heavy")
124
ft.font.setWeight(99);
125
else if (ss == "ultra-condensed")
126
ft.font.setStretch(QFont::UltraCondensed);
127
else if (ss == "extra-condensed")
128
ft.font.setStretch(QFont::ExtraCondensed);
129
else if (ss == "condensed")
130
ft.font.setStretch(QFont::Condensed);
131
else if (ss == "semi-condensed")
132
ft.font.setStretch(QFont::SemiCondensed);
133
else if (ss == "semi-expanded")
134
ft.font.setStretch(QFont::SemiExpanded);
135
else if (ss == "expanded")
136
ft.font.setStretch(QFont::Expanded);
137
else if (ss == "extra-expanded")
138
ft.font.setStretch(QFont::ExtraExpanded);
139
else if (ss == "ultra-expanded")
140
ft.font.setStretch(QFont::UltraExpanded);
141
else if (ss == "normal" || // no-op
142
ss == "small-caps" || // this and following ignored
143
ss == "not-rotated" || ss == "south" || ss == "upside-down" ||
145
ss == "rotated-left" || ss == "east" ||
146
ss == "rotated-right" || ss == "west")
153
rs.append(' ').append(s);
156
QStringList ffs = rs.split(QRegExp(" ?, ?"), QString::SkipEmptyParts);
157
if (!ffs.isEmpty()) {
158
foreach (const QString& ff, ffs) {
159
ft.font.setFamily(ff);
160
if (ft.font.exactMatch())
163
ft.font.setFamily(ffs.first());
166
// don't inherit settings from parent widgets
167
ft.font.setFamily(ft.font.family());
168
if (ft.font.pixelSize() > 0)
169
ft.font.setPixelSize(ft.font.pixelSize());
171
ft.font.setPointSize(ft.font.pointSize());
172
ft.font.setStyle(ft.font.style());
173
ft.font.setStretch(ft.font.stretch());
174
ft.font.setWeight(ft.font.weight());
178
parseFont(const QDomElement &el, FontType &ft)
180
parseFont(el.attribute("font", QString()), ft);
185
parseColor(const QString &s, const QString &a, QColor &color)
188
if (s.startsWith('#')) {
189
uint hexColor = s.mid(1).toUInt(&ok, 16);
192
color.setRgba(hexColor);
194
color.setRgb(hexColor);
198
} else if (!s.isNull() && s.isEmpty()) {
203
float fltAlpha = a.toFloat(&ok);
205
color.setAlphaF(fltAlpha);
211
parseColor(const QDomElement &el, QColor &color)
213
parseColor(el.attribute("color"), el.attribute("alpha"), color);
218
parsePalEnt(const QDomElement &el, const QString &pfx, const QString &core,
219
QPalette &pal, QPalette::ColorGroup cg, QPalette::ColorRole cr)
221
QColor col = pal.color(cg, cr);
222
if (parseColor(el.attribute(pfx + core + "-color"),
223
el.attribute(pfx + core + "-alpha"), col))
224
pal.setColor(cg, cr, col);
228
parsePalEnt(const QDomElement &el, const QString &core,
229
QPalette &pal, QPalette::ColorRole cr)
231
parsePalEnt(el, "all-", core, pal, QPalette::Active, cr);
232
parsePalEnt(el, "all-", core, pal, QPalette::Inactive, cr);
233
parsePalEnt(el, "all-", core, pal, QPalette::Disabled, cr);
234
parsePalEnt(el, QString(), core, pal, QPalette::Active, cr);
235
parsePalEnt(el, QString(), core, pal, QPalette::Inactive, cr);
236
parsePalEnt(el, "active-", core, pal, QPalette::Active, cr);
237
parsePalEnt(el, "inactive-", core, pal, QPalette::Inactive, cr);
238
parsePalEnt(el, "disabled-", core, pal, QPalette::Disabled, cr);
242
parseStyle(const QDomElement &el, StyleType &style)
244
parseFont(el, style.font);
245
parseFont(el.attribute("edit-font", QString()), style.editfont);
246
QString colorscheme = el.attribute("colorscheme", QString());
247
if (!colorscheme.isNull()) {
248
colorscheme = KStandardDirs::locate("data", "color-schemes/" + colorscheme + ".colors");
249
if (!colorscheme.isEmpty()) {
250
KSharedConfigPtr config = KSharedConfig::openConfig(colorscheme, KConfig::SimpleConfig);
251
style.palette = KGlobalSettings::createApplicationPalette(config);
254
parsePalEnt(el, "window", style.palette, QPalette::Window);
255
parsePalEnt(el, "window-text", style.palette, QPalette::WindowText);
256
parsePalEnt(el, "base", style.palette, QPalette::Base);
257
parsePalEnt(el, "alternate-base", style.palette, QPalette::AlternateBase);
258
parsePalEnt(el, "text", style.palette, QPalette::Text);
259
parsePalEnt(el, "highlight", style.palette, QPalette::Highlight);
260
parsePalEnt(el, "highlighted-text", style.palette, QPalette::HighlightedText);
261
parsePalEnt(el, "button", style.palette, QPalette::Button);
262
parsePalEnt(el, "button-text", style.palette, QPalette::ButtonText);
263
parsePalEnt(el, "bright-text", style.palette, QPalette::BrightText);
264
QString frame = el.attribute("frame", QString());
266
style.frame = frame == "true";
267
QString guistyle = el.attribute("guistyle", QString());
268
if (!guistyle.isNull())
269
style.guistyle = QStyleFactory::create(guistyle);
273
setWidgetAttribs(QWidget *widget, const StyleType &style, bool frame)
276
(style.editfont.present &&
277
(qobject_cast<QLineEdit *>(widget) ||
278
qobject_cast<QComboBox *>(widget) ||
279
widget->objectName() == "edit")) ?
280
style.editfont.font : style.font.font);
283
if (QFrame *frm = qobject_cast<QFrame *>(widget)) {
284
if ((widget->windowFlags() & Qt::WindowType_Mask) == Qt::Widget)
285
frm->setFrameStyle(QFrame::NoFrame);
286
} else if (QLineEdit *le = qobject_cast<QLineEdit *>(widget)) {
288
} else if (QComboBox *cb = qobject_cast<QComboBox *>(widget)) {
293
foreach (QObject *child, widget->children())
294
if (QWidget *cw = qobject_cast<QWidget *>(child))
295
setWidgetAttribs(cw, style, frame ||
296
(widget->testAttribute(Qt::WA_OpaquePaintEvent) ||
297
(widget->autoFillBackground() &&
298
!widget->testAttribute(Qt::WA_NoSystemBackground) &&
299
widget->palette().brush(widget->backgroundRole()).isOpaque())));
302
static QString prefix;
303
static QStack<QString> prefixes;
305
#define dbgs ((debugLevel & DEBUG_THEMING) ? QDebug(QtDebugMsg) : kDebugDevNull())
308
enter(const char *fct)
310
prefixes.push(prefix);
311
prefix.replace('-', ' ').append(" |-");
312
if (prefixes.top().isEmpty())
314
return dbgs << (qPrintable(prefixes.top()) + 1) << fct;
320
if (prefix.isEmpty())
322
return dbgs << (qPrintable(prefix) + 1);
328
prefix[prefix.length() - 2] = '\\';
329
QString nprefix(prefix);
330
prefix = prefixes.pop();
331
return dbgs << (qPrintable(nprefix) + 1);