~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/kfrontend/themer/kdmbutton.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) 2003 by Unai Garro <ugarro@users.sourceforge.net>
 
3
 *  Copyright (C) 2007 by Oswald Buddenhagen <ossi@kde.org>
 
4
 *
 
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.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 */
 
19
 
 
20
#include "kdmbutton.h"
 
21
 
 
22
#include "kdmthemer.h"
 
23
#include "kdmlabel.h"
 
24
 
 
25
#include <kglobal.h>
 
26
#include <klocale.h>
 
27
 
 
28
#include <QPushButton>
 
29
 
 
30
KdmButton::KdmButton(QObject *parent, const QDomNode &node)
 
31
    : KdmItem(parent, node)
 
32
{
 
33
    itemType = "button";
 
34
    if (!isVisible())
 
35
        return;
 
36
 
 
37
    const QString locale = KGlobal::locale()->language();
 
38
 
 
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();
 
46
 
 
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;
 
56
        }
 
57
    }
 
58
 
 
59
    text.replace('\n', ' ').replace('_', '&');
 
60
}
 
61
 
 
62
void
 
63
KdmButton::doPlugActions(bool)
 
64
{
 
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();
 
76
        }
 
77
    } else {
 
78
        delete myWidget;
 
79
    }
 
80
}
 
81
 
 
82
void
 
83
KdmButton::widgetGone()
 
84
{
 
85
    myWidget = 0;
 
86
 
 
87
    emit needPlacement();
 
88
}
 
89
 
 
90
void
 
91
KdmButton::activate()
 
92
{
 
93
    emit activated(objectName());
 
94
}
 
95
 
 
96
void
 
97
KdmButton::drawContents(QPainter *, const QRect &)
 
98
{
 
99
}
 
100
 
 
101
#include "kdmbutton.moc"