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>
27
#include <QDomElement>
34
parseSize( const QString &s, DataPoint &pt )
40
if (s == "box") { // box value
43
} else if (s == "scale") {
46
} else if ((p = s.indexOf( '%' )) >= 0) { // percent value
51
while ((p = sCopy.indexOf( '^' )) >= 0) {
55
sCopy.replace( ',', '.' );
56
pt.val = (int)sCopy.toDouble();
60
if (sCopy.at( 0 ) == '-') {
64
sCopy.replace( ',', '.' );
65
pt.val = (int)sCopy.toDouble();
71
getword( QString &rs )
73
int splitAt = rs.lastIndexOf( ' ' ) + 1;
74
QString s( rs.mid( splitAt ) );
75
rs.truncate( splitAt - 1 );
80
parseFont( const QString &is, FontType &ft )
84
QString rs( is.simplified() );
85
if ((ft.present = !rs.isEmpty())) {
86
QString s( getword( rs ) );
88
if (s.endsWith( "px" )) {
89
int ps = s.left( s.length() - 2 ).toInt( &ok );
91
ft.font.setPixelSize( ps );
95
double ps = s.toDouble( &ok );
97
ft.font.setPointSizeF( ps );
102
QString ss( s.toLower() );
104
ft.font.setStyle( QFont::StyleOblique );
105
else if (ss == "italic")
106
ft.font.setStyle( QFont::StyleItalic );
107
else if (ss == "ultra-light")
108
ft.font.setWeight( 13 );
109
else if (ss == "light")
110
ft.font.setWeight( QFont::Light );
111
else if (ss == "medium")
112
ft.font.setWeight( 50 );
113
else if (ss == "semi-bold")
114
ft.font.setWeight( QFont::DemiBold );
115
else if (ss == "bold")
116
ft.font.setWeight( QFont::Bold );
117
else if (ss == "ultra-bold")
118
ft.font.setWeight( QFont::Black );
119
else if (ss == "heavy")
120
ft.font.setWeight( 99 );
121
else if (ss == "ultra-condensed")
122
ft.font.setStretch( QFont::UltraCondensed );
123
else if (ss == "extra-condensed")
124
ft.font.setStretch( QFont::ExtraCondensed );
125
else if (ss == "condensed")
126
ft.font.setStretch( QFont::Condensed );
127
else if (ss == "semi-condensed")
128
ft.font.setStretch( QFont::SemiCondensed );
129
else if (ss == "semi-expanded")
130
ft.font.setStretch( QFont::SemiExpanded );
131
else if (ss == "expanded")
132
ft.font.setStretch( QFont::Expanded );
133
else if (ss == "extra-expanded")
134
ft.font.setStretch( QFont::ExtraExpanded );
135
else if (ss == "ultra-expanded")
136
ft.font.setStretch( QFont::UltraExpanded );
137
else if (ss == "normal" || // no-op
138
ss == "small-caps" || // this and following ignored
139
ss == "not-rotated" || ss == "south" || ss == "upside-down" ||
141
ss == "rotated-left" || ss == "east" ||
142
ss == "rotated-right" || ss == "west")
149
rs.append( ' ' ).append( s );
152
QStringList ffs = rs.split( QRegExp( " ?, ?" ), QString::SkipEmptyParts );
153
if (!ffs.isEmpty()) {
154
foreach (QString ff, ffs) {
155
ft.font.setFamily( ff );
156
if (ft.font.exactMatch())
159
ft.font.setFamily( ffs.first() );
162
// don't inherit settings from parent widgets
163
ft.font.setFamily( ft.font.family() );
164
if (ft.font.pixelSize() > 0)
165
ft.font.setPixelSize( ft.font.pixelSize() );
167
ft.font.setPointSize( ft.font.pointSize() );
168
ft.font.setStyle( ft.font.style() );
169
ft.font.setStretch( ft.font.stretch() );
170
ft.font.setWeight( ft.font.weight() );
174
parseFont( const QDomElement &el, FontType &ft )
176
parseFont( el.attribute( "font", QString() ), ft );
181
parseColor( const QString &s, const QString &a, QColor &color )
183
if (!s.length() || s.at( 0 ) != '#')
187
uint hexColor = sCopy.remove( 0, 1 ).toUInt( &ok, 16 );
189
if (sCopy.length() == 8)
190
color.setRgba( hexColor );
192
color.setRgb( hexColor );
194
color.setAlpha( int(a.toFloat() * 255) );
200
parseColor( const QDomElement &el, QColor &color )
202
parseColor( el.attribute( "color", QString() ),
203
el.attribute( "alpha", "1.0" ), color );
208
parsePalEnt( const QDomElement &el, const QString &core, QPalette &pal, QPalette::ColorRole cr )
211
parseColor( el.attribute( core + "-color", QString() ), el.attribute( core + "-alpha", "1.0" ), col );
213
pal.setColor( cr, col );
217
parseStyle( const QDomElement &el, StyleType &style )
219
parseFont( el, style.font );
220
parseFont( el.attribute( "edit-font", QString() ), style.editfont );
221
parsePalEnt( el, "window", style.palette, QPalette::Window );
222
parsePalEnt( el, "window-text", style.palette, QPalette::WindowText );
223
parsePalEnt( el, "base", style.palette, QPalette::Base );
224
parsePalEnt( el, "alternate-base", style.palette, QPalette::AlternateBase );
225
parsePalEnt( el, "text", style.palette, QPalette::Text );
226
parsePalEnt( el, "highlight", style.palette, QPalette::Highlight );
227
parsePalEnt( el, "highlighted-text", style.palette, QPalette::HighlightedText );
228
parsePalEnt( el, "button", style.palette, QPalette::Button );
229
parsePalEnt( el, "button-text", style.palette, QPalette::ButtonText );
230
parsePalEnt( el, "bright-text", style.palette, QPalette::BrightText );
231
QString frame = el.attribute( "frame", QString() );
233
style.frame = frame == "true";
237
setWidgetAttribs( QWidget *widget, const StyleType &style, bool frame )
240
(style.editfont.present &&
241
(qobject_cast<QLineEdit *>(widget) ||
242
qobject_cast<QComboBox *>(widget) ||
243
widget->objectName() == "edit")) ?
244
style.editfont.font : style.font.font );
247
if (QFrame *frm = qobject_cast<QFrame *>(widget)) {
248
if ((widget->windowFlags() & Qt::WindowType_Mask) == Qt::Widget)
249
frm->setFrameStyle( QFrame::NoFrame );
250
} else if (QLineEdit *le = qobject_cast<QLineEdit *>(widget))
251
le->setFrame( false );
252
else if (QComboBox *cb = qobject_cast<QComboBox *>(widget))
253
cb->setFrame( false );
256
foreach (QObject *child, widget->children())
257
if (QWidget *cw = qobject_cast<QWidget *>(child))
258
setWidgetAttribs( cw, style, frame ||
259
(widget->testAttribute( Qt::WA_OpaquePaintEvent ) ||
260
(widget->autoFillBackground() &&
261
!widget->testAttribute( Qt::WA_NoSystemBackground ) &&
262
widget->palette().brush( widget->backgroundRole() ).isOpaque() )));
266
setWidgetAttribs( QWidget *widget, const StyleType &style )
268
widget->setPalette( style.palette );
269
if (style.palette.isBrushSet( QPalette::Normal, QPalette::Window ))
270
widget->setAutoFillBackground( true );
271
setWidgetAttribs( widget, style, style.frame );
275
#ifndef KDE_NO_DEBUG_OUTPUT
276
static QString prefix;
277
static QStack<QString> prefixes;
279
# define dbgs kDebug( (debugLevel & DEBUG_THEMING) != 0 )
282
enter( const char *fct )
284
prefixes.push( prefix );
285
prefix.replace( '-', ' ' ).append( "|- " );
286
return dbgs << prefixes.top() << fct << " ";
292
return dbgs << prefix;
298
prefix[prefix.length() - 3] = '\\';
299
QString nprefix( prefix );
300
prefix = prefixes.pop();
301
return dbgs << nprefix;