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

« back to all changes in this revision

Viewing changes to libs/plasmagenericshell/scripting/widget.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 2009 Aaron Seigo <aseigo@kde.org>
 
3
 *
 
4
 *   This program is free software; you can redistribute it and/or modify
 
5
 *   it under the terms of the GNU Library General Public License as
 
6
 *   published by the Free Software Foundation; either version 2, or
 
7
 *   (at your option) any later version.
 
8
 *
 
9
 *   This program is distributed in the hope that it will be useful,
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *   GNU General Public License for more details
 
13
 *
 
14
 *   You should have received a copy of the GNU Library General Public
 
15
 *   License along with this program; if not, write to the
 
16
 *   Free Software Foundation, Inc.,
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "widget.h"
 
21
 
 
22
#include <QAction>
 
23
#include <QGraphicsLinearLayout>
 
24
 
 
25
#include <Plasma/Applet>
 
26
#include <Plasma/Containment>
 
27
#include <Plasma/Corona>
 
28
 
 
29
namespace WorkspaceScripting
 
30
{
 
31
 
 
32
class Widget::Private
 
33
{
 
34
public:
 
35
    Private()
 
36
    {
 
37
    }
 
38
 
 
39
    QWeakPointer<Plasma::Applet> applet;
 
40
};
 
41
 
 
42
Widget::Widget(Plasma::Applet *applet, QObject *parent)
 
43
    : Applet(parent),
 
44
      d(new Widget::Private)
 
45
{
 
46
    d->applet = applet;
 
47
    setCurrentConfigGroup(QStringList());
 
48
    setCurrentGlobalConfigGroup(QStringList());
 
49
}
 
50
 
 
51
Widget::~Widget()
 
52
{
 
53
    reloadConfigIfNeeded();
 
54
    delete d;
 
55
}
 
56
 
 
57
uint Widget::id() const
 
58
{
 
59
    if (d->applet) {
 
60
        return d->applet.data()->id();
 
61
    }
 
62
 
 
63
    return 0;
 
64
}
 
65
 
 
66
QString Widget::type() const
 
67
{
 
68
    if (d->applet) {
 
69
        return d->applet.data()->pluginName();
 
70
    }
 
71
 
 
72
    return QString();
 
73
}
 
74
 
 
75
void Widget::remove()
 
76
{
 
77
    if (d->applet) {
 
78
        d->applet.data()->destroy();
 
79
        d->applet.clear();
 
80
    }
 
81
}
 
82
 
 
83
void Widget::setGlobalShortcut(const QString &shortcut)
 
84
{
 
85
    if (d->applet) {
 
86
        d->applet.data()->setGlobalShortcut(KShortcut(shortcut));
 
87
    }
 
88
}
 
89
 
 
90
QString Widget::globalShorcut() const
 
91
{
 
92
    if (d->applet) {
 
93
        return d->applet.data()->globalShortcut().toString();
 
94
    }
 
95
 
 
96
    return QString();
 
97
}
 
98
 
 
99
Plasma::Applet *Widget::applet() const
 
100
{
 
101
    return d->applet.data();
 
102
}
 
103
 
 
104
int Widget::index() const
 
105
{
 
106
    if (!d->applet) {
 
107
        return -1;
 
108
    }
 
109
 
 
110
    Plasma::Applet *applet = d->applet.data();
 
111
    Plasma::Containment *c = applet->containment();
 
112
    if (!c) {
 
113
        return -1;
 
114
    }
 
115
 
 
116
    QGraphicsLayout *layout = c->layout();
 
117
    if (!layout) {
 
118
        return - 1;
 
119
    }
 
120
 
 
121
    for (int i = 0; i < layout->count(); ++i) {
 
122
        if (layout->itemAt(i) == applet) {
 
123
            return i;
 
124
        }
 
125
    }
 
126
 
 
127
    return -1;
 
128
}
 
129
 
 
130
void Widget::setIndex(int index)
 
131
{
 
132
    if (!d->applet) {
 
133
        return;
 
134
    }
 
135
 
 
136
    Plasma::Applet *applet = d->applet.data();
 
137
    Plasma::Containment *c = applet->containment();
 
138
    if (!c) {
 
139
        return;
 
140
    }
 
141
 
 
142
    //FIXME: this is hackish. would be nice to define this for gridlayouts too
 
143
    QGraphicsLinearLayout *layout = dynamic_cast<QGraphicsLinearLayout *>(c->layout());
 
144
    if (!layout) {
 
145
        return;
 
146
    }
 
147
 
 
148
    layout->insertItem(index, applet);
 
149
}
 
150
 
 
151
QRectF Widget::geometry() const
 
152
{
 
153
    if (d->applet) {
 
154
        return d->applet.data()->geometry();
 
155
    }
 
156
 
 
157
    return QRectF();
 
158
}
 
159
 
 
160
void Widget::setGeometry(const QRectF &geometry)
 
161
{
 
162
    if (d->applet) {
 
163
        d->applet.data()->setGeometry(geometry);
 
164
    }
 
165
}
 
166
 
 
167
void Widget::showConfigurationInterface()
 
168
{
 
169
    if (d->applet) {
 
170
        d->applet.data()->showConfigurationInterface();
 
171
    }
 
172
}
 
173
 
 
174
}
 
175
 
 
176
#include "widget.moc"
 
177