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 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.
22
#include "kdmthemer.h"
24
#include "kdmpixmap.h"
29
#include <kdm_greet.h>
36
#include <QMouseEvent>
37
#include <QPaintEvent>
45
* KdmThemer. The main theming interface
47
KdmThemer::KdmThemer( const QString &_filename, const QString &mode,
48
const QMap<QString, bool> &showTypes, QWidget *w )
50
, m_currentMode( mode )
51
, m_showTypes( showTypes )
53
, m_geometryOutdated( true )
54
, m_geometryInvalid( true )
57
// read the XML file and create DOM tree
58
QString filename = _filename;
59
if (!::access( QFile::encodeName( filename + "/KdmGreeterTheme.desktop" ), R_OK )) {
60
KConfig _cfg( filename + "/KdmGreeterTheme.desktop", KConfig::OnlyLocal );
61
KConfigGroup cfg( &_cfg, "KdmGreeterTheme" );
62
filename += '/' + cfg.readEntry( "Greeter" );
64
QFile opmlFile( filename );
65
if (!opmlFile.open( QIODevice::ReadOnly )) {
66
FDialog::box( w, errorbox, i18n( "Cannot open theme file %1" , filename) );
70
if (!domTree.setContent( &opmlFile )) {
71
FDialog::box( w, errorbox, i18n( "Cannot parse theme file %1" , filename) );
74
// generate all the items defined in the theme
75
const QDomElement &theme = domTree.documentElement();
76
// Get its tag, and check it's correct ("greeter")
77
if (theme.tagName() != "greeter") {
78
FDialog::box( w, errorbox, i18n( "%1 does not seem to be a correct theme file" , filename) );
82
// Set the root (screen) item
83
rootItem = new KdmRect( this, theme );
85
basedir = QFileInfo( filename ).absolutePath();
87
generateItems( rootItem, theme );
88
rootItem->updateVisible();
92
QTimer *time = new QTimer( this );
94
connect( time, SIGNAL(timeout()), SLOT(update()) )
98
KdmThemer::~KdmThemer()
103
KdmThemer::setWidget( QWidget *w )
105
if ((m_widget = w)) {
106
setWidgetAttribs( m_widget, rootItem->style );
107
rootItem->plugActions();
112
KdmThemer::findNode( const QString &item ) const
114
return rootItem->findChild<KdmItem *>( item );
118
KdmThemer::slotNeedPlacement()
120
m_geometryOutdated = m_geometryInvalid = true;
126
KdmThemer::slotNeedPlugging()
129
rootItem->plugActions();
133
KdmThemer::update( int x, int y, int w, int h )
136
widget()->update( x, y, w, h );
139
// BEGIN other functions
142
KdmThemer::widgetEvent( QEvent *e )
147
case QEvent::MouseMove:
149
QMouseEvent *me = static_cast<QMouseEvent *>(e);
150
rootItem->mouseEvent( me->x(), me->y() );
153
case QEvent::MouseButtonPress:
155
QMouseEvent *me = static_cast<QMouseEvent *>(e);
156
rootItem->mouseEvent( me->x(), me->y(), true );
159
case QEvent::MouseButtonRelease:
161
QMouseEvent *me = static_cast<QMouseEvent *>(e);
162
rootItem->mouseEvent( me->x(), me->y(), false, true );
166
m_geometryOutdated = true;
170
if (m_geometryOutdated) {
171
debug() << "==== updating geometry ====" << endl;
173
QRect rect( QPoint( 0, 0 ), widget()->size() );
174
rootItem->setGeometry( ps, rect, m_geometryInvalid );
175
if (debugLevel & DEBUG_THEMING)
177
m_geometryOutdated = m_geometryInvalid = false;
180
QRect paintRect = static_cast<QPaintEvent *>(e)->rect();
181
//kDebug() << "paint on: " << paintRect;
183
QPainter p( widget() );
184
rootItem->paint( &p, paintRect );
185
rootItem->showWidget();
194
KdmThemer::paintBackground( QPaintDevice *dev )
196
if (KdmItem *bg = findNode( "background" )) {
197
debug() << "==== setting background geometry ====" << endl;
198
QRect rect( 0, 0, dev->width(), dev->height() );
200
bg->setGeometry( ps, rect, true );
202
bg->paint( &p, rect );
207
KdmThemer::generateItems( KdmItem *parent, const QDomNode &node )
210
* Go through each of the child nodes
212
const QDomNodeList &subnodeList = node.childNodes();
213
for (int nod = 0; nod < subnodeList.count(); nod++) {
214
QDomNode subnode = subnodeList.item( nod );
215
QDomElement el = subnode.toElement();
216
QString tagName = el.tagName();
218
if (tagName == "item") {
220
bool showTypeInvert = false;
222
QDomNode showNode = subnode.namedItem( "show" );
223
if (!showNode.isNull()) {
224
QDomElement sel = showNode.toElement();
226
QString modes = sel.attribute( "modes" );
227
if (!modes.isNull() &&
228
(modes == "nowhere" ||
229
(modes != "everywhere" &&
230
!modes.split( ",", QString::SkipEmptyParts ).contains(
234
showType = sel.attribute( "type" );
235
if (!showType.isNull()) {
236
if (showType[0] == '!') {
237
showType.remove( 0, 1 );
238
showTypeInvert = true;
240
if (!showType.startsWith( "plugin-" ) &&
241
m_showTypes.contains( showType ) == showTypeInvert)
246
QString type = el.attribute( "type" );
249
newItem = new KdmLabel( parent, subnode );
250
else if (type == "pixmap")
251
newItem = new KdmPixmap( parent, subnode );
252
else if (type == "rect")
253
newItem = new KdmRect( parent, subnode );
254
else if (type == "entry") {
255
//newItem = new KdmEntry( parent, subnode );
256
newItem = new KdmRect( parent, subnode );
257
newItem->setType( type );
258
} else if (type=="list")
259
newItem = new KdmList( parent, subnode );
260
else if (type == "svg")
261
newItem = new KdmPixmap( parent, subnode );
264
newItem->setIsButton( el.attribute( "button", "false" ) == "true" );
265
newItem->setShowType( showType, showTypeInvert );
266
connect( newItem, SIGNAL(needUpdate( int, int, int, int )),
267
SLOT(update( int, int, int, int )) );
268
connect( newItem, SIGNAL(needPlacement()),
269
SLOT(slotNeedPlacement()) );
270
connect( newItem, SIGNAL(needPlugging()),
271
SLOT(slotNeedPlugging()) );
272
connect( newItem, SIGNAL(activated( const QString & )),
273
SIGNAL(activated( const QString & )) );
274
generateItems( newItem, subnode );
275
} else if (tagName == "box") {
276
parent->setBoxLayout( subnode );
277
generateItems( parent, subnode );
278
} else if (tagName == "fixed") {
279
parent->setFixedLayout( subnode );
280
generateItems( parent, subnode );
286
KdmThemer::showStructure()
288
kDebug() << "======= item tree =======";
289
rootItem->showStructure( QString() );
293
KdmThemer::setTypeVisible( const QString &t, bool show )
295
m_showTypes[t] = show;
296
rootItem->updateVisible();
299
#include "kdmthemer.moc"