2010-03-17 19:00:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "widget.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
|
|
|
|
#include <Plasma/Applet>
|
|
|
|
#include <Plasma/Containment>
|
|
|
|
#include <Plasma/Corona>
|
|
|
|
|
2010-04-25 21:35:51 +02:00
|
|
|
class Widget::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QWeakPointer<Plasma::Applet> applet;
|
|
|
|
};
|
|
|
|
|
2010-03-17 19:00:07 +01:00
|
|
|
Widget::Widget(Plasma::Applet *applet, QObject *parent)
|
|
|
|
: Applet(parent),
|
2010-04-25 21:35:51 +02:00
|
|
|
d(new Widget::Private)
|
2010-03-17 19:00:07 +01:00
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
d->applet = applet;
|
2010-03-17 19:00:07 +01:00
|
|
|
setCurrentConfigGroup(QStringList());
|
2010-04-25 21:35:51 +02:00
|
|
|
setCurrentGlobalConfigGroup(QStringList());
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget::~Widget()
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
delete d;
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint Widget::id() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
return d->applet.data()->id();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Widget::type() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
return d->applet.data()->pluginName();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::remove()
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
d->applet.data()->destroy();
|
|
|
|
d->applet.clear();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setGlobalShortcut(const QString &shortcut)
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
d->applet.data()->setGlobalShortcut(KShortcut(shortcut));
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Widget::globalShorcut() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
return d->applet.data()->globalShortcut().toString();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Applet *Widget::applet() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
return d->applet.data();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Widget::index() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (!d->applet) {
|
2010-03-17 19:00:07 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-04-25 21:35:51 +02:00
|
|
|
Plasma::Applet *applet = d->applet.data();
|
2010-03-17 19:00:07 +01:00
|
|
|
Plasma::Containment *c = applet->containment();
|
|
|
|
if (!c) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsLayout *layout = c->layout();
|
|
|
|
if (!layout) {
|
|
|
|
return - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < layout->count(); ++i) {
|
|
|
|
if (layout->itemAt(i) == applet) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setIndex(int index)
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (!d->applet) {
|
2010-03-17 19:00:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-25 21:35:51 +02:00
|
|
|
Plasma::Applet *applet = d->applet.data();
|
2010-03-17 19:00:07 +01:00
|
|
|
Plasma::Containment *c = applet->containment();
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: this is hackish. would be nice to define this for gridlayouts too
|
|
|
|
QGraphicsLinearLayout *layout = dynamic_cast<QGraphicsLinearLayout *>(c->layout());
|
|
|
|
if (!layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
layout->insertItem(index, applet);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Widget::geometry() const
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
return d->applet.data()->geometry();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setGeometry(const QRectF &geometry)
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
d->applet.data()->setGeometry(geometry);
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::showConfigurationInterface()
|
|
|
|
{
|
2010-04-25 21:35:51 +02:00
|
|
|
if (d->applet) {
|
|
|
|
d->applet.data()->showConfigurationInterface();
|
2010-03-17 19:00:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "widget.moc"
|
|
|
|
|