Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kdm / kfrontend / themer / kdmbutton.cpp
blob30dc50cc6fa96307a85f45954eef97811b335e12
1 /*
2 * Copyright (C) 2003 by Unai Garro <ugarro@users.sourceforge.net>
3 * Copyright (C) 2007 by Oswald Buddenhagen <ossi@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "kdmbutton.h"
22 #include "kdmthemer.h"
23 #include "kdmlabel.h"
25 #include <kglobal.h>
26 #include <klocale.h>
28 #include <QPushButton>
30 KdmButton::KdmButton( QObject *parent, const QDomNode &node )
31 : KdmItem( parent, node )
33 itemType = "button";
34 if (!isVisible())
35 return;
37 const QString locale = KGlobal::locale()->language();
39 // Read LABEL TAGS
40 QDomNodeList childList = node.childNodes();
41 bool stockUsed = false;
42 for (int nod = 0; nod < childList.count(); nod++) {
43 QDomNode child = childList.item( nod );
44 QDomElement el = child.toElement();
45 QString tagName = el.tagName();
47 if (tagName == "text" && el.attributes().count() == 0 && !stockUsed) {
48 text = el.text();
49 } else if (tagName == "text" && !stockUsed) {
50 QString lang = el.attribute( "xml:lang", "" );
51 if (lang == locale)
52 text = el.text();
53 } else if (tagName == "stock") {
54 text = KdmLabel::lookupStock( el.attribute( "type", "" ) );
55 stockUsed = true;
59 text.replace( '\n', ' ' ).replace( '_', '&' );
62 void
63 KdmButton::doPlugActions( bool )
65 QWidget *w = themer()->widget();
66 if (w) {
67 if (!myWidget) {
68 QPushButton *btn = new QPushButton( text, w );
69 btn->setAutoDefault( false );
70 myWidget = btn;
71 myWidget->hide(); // yes, really
72 setWidgetAttribs( myWidget );
73 connect( myWidget, SIGNAL(destroyed()), SLOT(widgetGone()) );
74 connect( myWidget, SIGNAL(clicked()), SLOT(activate()) );
75 emit needPlacement();
77 } else {
78 if (myWidget)
79 delete myWidget;
83 void
84 KdmButton::widgetGone()
86 myWidget = 0;
88 emit needPlacement();
91 void
92 KdmButton::activate()
94 emit activated( objectName() );
97 void
98 KdmButton::drawContents( QPainter *, const QRect & )
102 #include "kdmbutton.moc"