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"
28
#include "kdmbutton.h"
30
#include <kdm_greet.h> // debug stuff
31
#include <kfdialog.h> // kfmsgbox
35
#include <kconfiggroup.h>
38
#include <QMouseEvent>
39
#include <QPaintEvent>
47
* KdmThemer. The main theming interface
49
KdmThemer::KdmThemer(const QString &_filename,
50
const QMap<QString, bool> &showTypes, QWidget *w)
52
, m_showTypes(showTypes)
54
, m_geometryOutdated(true)
55
, m_geometryInvalid(true)
58
// read the XML file and create DOM tree
59
QString filename = _filename;
60
if (!::access(QFile::encodeName(filename + "/KdmGreeterTheme.desktop"), R_OK)) {
61
KConfig _cfg(filename + "/KdmGreeterTheme.desktop", KConfig::SimpleConfig);
62
KConfigGroup cfg(&_cfg, "KdmGreeterTheme");
63
filename += '/' + cfg.readEntry("Greeter");
65
QFile opmlFile(filename);
66
if (!opmlFile.open(QIODevice::ReadOnly)) {
67
KFMsgBox::box(w, errorbox, i18n("Cannot open theme file %1" , filename));
71
if (!domTree.setContent(&opmlFile)) {
72
KFMsgBox::box(w, errorbox, i18n("Cannot parse theme file %1" , filename));
75
// generate all the items defined in the theme
76
const QDomElement &theme = domTree.documentElement();
77
// Get its tag, and check it's correct ("greeter")
78
if (theme.tagName() != "greeter") {
79
KFMsgBox::box(w, errorbox, i18n("%1 does not seem to be a correct theme file" , filename));
83
// Set the root (screen) item
84
rootItem = new KdmRect(this, theme);
86
basedir = QFileInfo(filename).absolutePath();
88
generateItems(rootItem, theme);
91
KdmThemer::~KdmThemer()
96
KdmThemer::setWidget(QWidget *w)
99
rootItem->updateVisible();
100
m_widget->setStyle(rootItem->style.guistyle);
101
m_widget->setPalette(rootItem->style.palette);
102
m_widget->setFont(rootItem->style.font.font);
103
rootItem->plugActions();
108
KdmThemer::findNode(const QString &item) const
110
return rootItem->findChild<KdmItem *>(item);
114
KdmThemer::slotNeedPlacement()
116
m_geometryOutdated = m_geometryInvalid = true;
122
KdmThemer::slotNeedPlugging()
125
rootItem->plugActions();
129
KdmThemer::update(int x, int y, int w, int h)
132
widget()->update(x, y, w, h);
135
// BEGIN other functions
138
KdmThemer::widgetEvent(QEvent *e)
143
case QEvent::MouseMove: {
144
QMouseEvent *me = static_cast<QMouseEvent *>(e);
145
rootItem->mouseEvent(me->x(), me->y());
147
case QEvent::MouseButtonPress: {
148
QMouseEvent *me = static_cast<QMouseEvent *>(e);
149
rootItem->mouseEvent(me->x(), me->y(), true);
151
case QEvent::MouseButtonRelease: {
152
QMouseEvent *me = static_cast<QMouseEvent *>(e);
153
rootItem->mouseEvent(me->x(), me->y(), false, true);
156
m_geometryOutdated = true;
160
if (m_geometryOutdated) {
161
debug() << "==== updating geometry ====";
163
QRect rect(QPoint(0, 0), widget()->size());
164
rootItem->setGeometry(ps, rect, m_geometryInvalid);
165
if (debugLevel & DEBUG_THEMING)
167
m_geometryOutdated = m_geometryInvalid = false;
170
QRect paintRect = static_cast<QPaintEvent *>(e)->rect();
171
//kDebug() << "paint on: " << paintRect;
173
QPainter p(widget());
174
rootItem->paint(&p, paintRect, false, true);
175
rootItem->showWidget();
184
KdmThemer::paintBackground(QPainter *p, const QRect &rect, bool primaryScreen)
186
debug() << "==== setting background geometry ====";
188
rootItem->setGeometry(ps, rect, true);
189
rootItem->paint(p, rect, true, primaryScreen);
193
KdmThemer::generateItems(KdmItem *parent, const QDomNode &node)
196
* Go through each of the child nodes
198
const QDomNodeList &subnodeList = node.childNodes();
199
for (int nod = 0; nod < subnodeList.count(); nod++) {
200
QDomNode subnode = subnodeList.item(nod);
201
QDomElement el = subnode.toElement();
202
QString tagName = el.tagName();
204
if (tagName == "item") {
205
QString type = el.attribute("type");
207
if (type == "label") {
208
newItem = new KdmLabel(parent, subnode);
209
} else if (type == "button") {
210
newItem = new KdmButton(parent, subnode);
211
} else if (type == "pixmap") {
212
newItem = new KdmPixmap(parent, subnode);
213
} else if (type == "rect") {
214
newItem = new KdmRect(parent, subnode);
215
} else if (type == "entry") {
216
//newItem = new KdmEntry(parent, subnode);
217
newItem = new KdmRect(parent, subnode);
218
newItem->setType(type);
219
} else if (type == "list") {
220
newItem = new KdmList(parent, subnode);
221
} else if (type == "svg") {
222
newItem = new KdmPixmap(parent, subnode);
226
if (!newItem->isVisible()) {
230
connect(newItem, SIGNAL(needUpdate(int, int, int, int)),
231
SLOT(update(int, int, int, int)));
232
connect(newItem, SIGNAL(needPlacement()),
233
SLOT(slotNeedPlacement()));
234
connect(newItem, SIGNAL(needPlugging()),
235
SLOT(slotNeedPlugging()));
236
connect(newItem, SIGNAL(activated(const QString &)),
237
SIGNAL(activated(const QString &)));
238
generateLayouts(newItem, subnode);
244
KdmThemer::generateLayouts(KdmItem *parent, const QDomNode &node)
246
const QDomNodeList &subnodeList = node.childNodes();
247
for (int nod = 0; nod < subnodeList.count(); nod++) {
248
QDomNode subnode = subnodeList.item(nod);
249
QString tagName = subnode.toElement().tagName();
251
if (tagName == "box") {
252
parent->setBoxLayout(subnode);
253
generateItems(parent, subnode);
254
} else if (tagName == "fixed") {
255
parent->setFixedLayout(subnode);
256
generateItems(parent, subnode);
262
KdmThemer::showStructure()
264
QDebug(QtDebugMsg) << "======= item tree =======";
265
rootItem->showStructure(QString());
269
KdmThemer::setTypeVisible(const QString &t, bool show)
271
m_showTypes[t] = show;
272
rootItem->updateVisible();
275
#include "kdmthemer.moc"