2005-12-29 22:55:22 +01:00
|
|
|
/*
|
2007-08-06 13:20:02 +02:00
|
|
|
* Copyright 2005 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2007 by Riccardo Iaconelli <riccardo@kde.org>
|
2008-04-14 12:48:32 +02:00
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-09-14 21:06:18 +02:00
|
|
|
* 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.
|
2005-12-29 22:55:22 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
2006-01-23 12:37:31 +01:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-12-29 22:55:22 +01:00
|
|
|
*/
|
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "applet.h"
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "private/applet_p.h"
|
2007-05-30 18:47:36 +02:00
|
|
|
|
2007-08-05 16:24:24 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <limits>
|
|
|
|
|
2008-06-24 05:17:38 +02:00
|
|
|
#include <QAction>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QApplication>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QEvent>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <QFile>
|
2008-06-24 05:17:38 +02:00
|
|
|
#include <QGraphicsGridLayout>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsView>
|
|
|
|
#include <QLabel>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QList>
|
2008-06-24 05:17:38 +02:00
|
|
|
#include <QGraphicsLinearLayout>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <QPainter>
|
2005-12-29 22:55:22 +01:00
|
|
|
#include <QSize>
|
2007-07-26 01:42:43 +02:00
|
|
|
#include <QStyleOptionGraphicsItem>
|
2007-11-04 06:31:18 +01:00
|
|
|
#include <QTextDocument>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <QTimer>
|
|
|
|
#include <QUiLoader>
|
2005-12-29 22:55:22 +01:00
|
|
|
|
2008-06-01 04:13:53 +02:00
|
|
|
#include <KAction>
|
2007-07-26 01:42:43 +02:00
|
|
|
#include <KIcon>
|
2007-11-04 07:58:20 +01:00
|
|
|
#include <KColorScheme>
|
2007-07-30 18:00:29 +02:00
|
|
|
#include <KConfigDialog>
|
2007-07-12 20:34:53 +02:00
|
|
|
#include <KDialog>
|
2008-04-02 17:37:17 +02:00
|
|
|
#include <KIconLoader>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KPluginInfo>
|
2006-12-17 00:04:44 +01:00
|
|
|
#include <KStandardDirs>
|
2007-03-05 01:07:21 +01:00
|
|
|
#include <KService>
|
2007-05-24 22:01:12 +02:00
|
|
|
#include <KServiceTypeTrader>
|
2008-06-01 04:13:53 +02:00
|
|
|
#include <KShortcut>
|
2008-04-02 17:37:17 +02:00
|
|
|
#include <KWindowSystem>
|
2008-05-17 05:39:24 +02:00
|
|
|
#include <KActionCollection>
|
2008-07-19 05:00:36 +02:00
|
|
|
#include <KAuthorized>
|
2007-06-01 00:40:38 +02:00
|
|
|
|
2007-12-21 13:27:29 +01:00
|
|
|
#include <Solid/PowerManagement>
|
|
|
|
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "configxml.h"
|
|
|
|
#include "containment.h"
|
|
|
|
#include "corona.h"
|
|
|
|
#include "dataenginemanager.h"
|
2008-08-02 19:46:32 +02:00
|
|
|
#include "extender.h"
|
|
|
|
#include "extenderitem.h"
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "package.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
#include "scripting/appletscript.h"
|
|
|
|
#include "svg.h"
|
|
|
|
#include "panelsvg.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "view.h"
|
|
|
|
#include "widgets/label.h"
|
|
|
|
#include "widgets/pushbutton.h"
|
|
|
|
#include "tooltipmanager.h"
|
2008-08-05 17:27:48 +02:00
|
|
|
#include "wallpaper.h"
|
2008-07-30 22:35:42 +02:00
|
|
|
|
|
|
|
#include "private/containment_p.h"
|
|
|
|
#include "private/packages_p.h"
|
|
|
|
#include "private/toolbox_p.h"
|
2006-04-13 02:11:16 +02:00
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
//#define DYNAMIC_SHADOWS
|
2005-12-29 22:55:22 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
Applet::Applet(QGraphicsItem *parent,
|
|
|
|
const QString& serviceID,
|
2007-07-12 20:34:53 +02:00
|
|
|
uint appletId)
|
2008-04-14 18:02:23 +02:00
|
|
|
: QGraphicsWidget(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(serviceID), appletId, this))
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-11-27 07:01:06 +01:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
2008-04-28 17:41:18 +02:00
|
|
|
d->init();
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
Applet::Applet(QObject* parentObject, const QVariantList& args)
|
2008-04-14 18:02:23 +02:00
|
|
|
: QGraphicsWidget(0),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new AppletPrivate(KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()),
|
2008-04-28 17:41:18 +02:00
|
|
|
args.count() > 1 ? args[1].toInt() : 0, this))
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2008-05-25 20:38:07 +02:00
|
|
|
// now remove those first two items since those are managed by Applet and subclasses shouldn't
|
|
|
|
// need to worry about them. yes, it violates the constness of this var, but it lets us add
|
|
|
|
// or remove items later while applets can just pretend that their args always start at 0
|
|
|
|
QVariantList &mutableArgs = const_cast<QVariantList&>(args);
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
|
|
|
|
if (!mutableArgs.isEmpty()) {
|
|
|
|
mutableArgs.removeFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 18:29:23 +02:00
|
|
|
setParent(parentObject);
|
2007-11-27 07:01:06 +01:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
2008-04-28 17:41:18 +02:00
|
|
|
d->init();
|
2008-04-24 18:29:23 +02:00
|
|
|
|
2007-09-28 07:46:37 +02:00
|
|
|
// the brain damage seen in the initialization list is due to the
|
2007-06-20 08:45:08 +02:00
|
|
|
// inflexibility of KService::createInstance
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
Applet::~Applet()
|
|
|
|
{
|
2008-04-14 11:42:57 +02:00
|
|
|
if (d->transient) {
|
2008-05-01 05:24:20 +02:00
|
|
|
d->resetConfigurationObject();
|
2008-04-14 11:42:57 +02:00
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-02-26 05:08:51 +01:00
|
|
|
PackageStructure::Ptr Applet::packageStructure()
|
2008-02-15 11:35:00 +01:00
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
if (!AppletPrivate::packageStructure) {
|
|
|
|
AppletPrivate::packageStructure = new PlasmoidPackage();
|
2008-02-26 05:08:51 +01:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
return AppletPrivate::packageStructure;
|
2008-02-15 11:35:00 +01:00
|
|
|
}
|
|
|
|
|
2007-09-13 19:00:57 +02:00
|
|
|
void Applet::init()
|
|
|
|
{
|
2008-01-25 01:08:25 +01:00
|
|
|
if (d->script && !d->script->init()) {
|
2008-02-29 09:11:45 +01:00
|
|
|
setFailedToLaunch(true, i18n("Script initialization failed"));
|
2008-01-25 01:08:25 +01:00
|
|
|
}
|
2007-09-13 19:00:57 +02:00
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
uint Applet::id() const
|
|
|
|
{
|
|
|
|
return d->appletId;
|
|
|
|
}
|
|
|
|
|
2008-07-07 04:16:08 +02:00
|
|
|
void Applet::save(KConfigGroup &g) const
|
2007-09-18 23:22:45 +02:00
|
|
|
{
|
2008-07-07 04:16:08 +02:00
|
|
|
KConfigGroup group = g;
|
|
|
|
if (!group.isValid()) {
|
|
|
|
group = *d->mainConfigGroup();
|
|
|
|
}
|
|
|
|
|
2007-12-07 06:02:54 +01:00
|
|
|
// we call the dptr member directly for locked since isImmutable()
|
|
|
|
// also checks kiosk and parent containers
|
2008-05-22 17:53:48 +02:00
|
|
|
group.writeEntry("immutability", (int)d->immutability);
|
|
|
|
group.writeEntry("plugin", pluginName());
|
2007-10-26 03:04:56 +02:00
|
|
|
//FIXME: for containments, we need to have some special values here w/regards to
|
|
|
|
// screen affinity (e.g. "bottom of screen 0")
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << pluginName() << "geometry is" << geometry() << "pos is" << pos() << "bounding rect is" << boundingRect();
|
2008-05-22 17:53:48 +02:00
|
|
|
group.writeEntry("geometry", geometry());
|
|
|
|
group.writeEntry("zvalue", zValue());
|
2007-09-18 23:22:45 +02:00
|
|
|
|
2007-11-19 10:21:11 +01:00
|
|
|
if (transform() == QTransform()) {
|
2008-05-22 17:53:48 +02:00
|
|
|
group.deleteEntry("transform");
|
2007-11-19 10:21:11 +01:00
|
|
|
} else {
|
|
|
|
QList<qreal> m;
|
|
|
|
QTransform t = transform();
|
|
|
|
m << t.m11() << t.m12() << t.m13() << t.m21() << t.m22() << t.m23() << t.m31() << t.m32() << t.m33();
|
2008-05-22 17:53:48 +02:00
|
|
|
group.writeEntry("transform", m);
|
|
|
|
//group.writeEntry("transform", transformToString(transform()));
|
2007-11-19 10:21:11 +01:00
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
KConfigGroup appletConfigGroup(&group, "Configuration");
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
if (extender()) {
|
2008-08-03 14:16:41 +02:00
|
|
|
//This would probably be nicer if it was located in extender. But in it's dtor, this won't
|
|
|
|
//work since when that get's called, the applet's config() isn't accesible anymore. (same
|
|
|
|
//problem with calling saveState(). Doing this in saveState() might be a possibility, but
|
|
|
|
//that would require every extender savestate implementation to call it's parent function,
|
|
|
|
//which isn't very nice.
|
|
|
|
foreach (ExtenderItem *item, extender()->attachedItems()) {
|
2008-08-25 17:17:54 +02:00
|
|
|
if (!item->isDetached() || item->autoExpireDelay()) {
|
|
|
|
//destroy temporary extender items, or items that aren't detached, so their
|
|
|
|
//configuration won't linger after a plasma restart.
|
2008-08-03 14:16:41 +02:00
|
|
|
item->destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
extender()->saveState();
|
|
|
|
}
|
|
|
|
|
2008-01-02 03:05:47 +01:00
|
|
|
//FIXME: we need a global save state too
|
2008-05-22 17:53:48 +02:00
|
|
|
saveState(appletConfigGroup);
|
2008-06-01 05:03:43 +02:00
|
|
|
|
|
|
|
if (d->activationAction) {
|
|
|
|
KConfigGroup shortcutConfig(&group, "Shortcuts");
|
|
|
|
shortcutConfig.writeEntry("global", d->activationAction->globalShortcut().toString());
|
|
|
|
}
|
2007-09-18 23:22:45 +02:00
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
void Applet::restore(KConfigGroup &group)
|
2008-02-13 02:52:02 +01:00
|
|
|
{
|
2008-05-22 17:53:48 +02:00
|
|
|
QList<qreal> m = group.readEntry("transform", QList<qreal>());
|
2008-02-13 02:52:02 +01:00
|
|
|
if (m.count() == 9) {
|
|
|
|
QTransform t(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]);
|
|
|
|
setTransform(t);
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
qreal z = group.readEntry("zvalue", 0);
|
2008-02-13 02:52:02 +01:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (z >= AppletPrivate::s_maxZValue) {
|
|
|
|
AppletPrivate::s_maxZValue = z;
|
2008-02-13 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2008-06-01 04:53:50 +02:00
|
|
|
if (z > 0) {
|
|
|
|
setZValue(z);
|
|
|
|
}
|
2008-02-13 02:52:02 +01:00
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
2008-05-12 23:49:55 +02:00
|
|
|
|
2008-06-01 04:13:53 +02:00
|
|
|
QRectF geom = group.readEntry("geometry", QRectF());
|
2008-05-13 21:42:17 +02:00
|
|
|
if (geom.isValid()) {
|
2008-05-12 23:49:55 +02:00
|
|
|
setGeometry(geom);
|
|
|
|
}
|
2008-06-01 04:13:53 +02:00
|
|
|
|
|
|
|
KConfigGroup shortcutConfig(&group, "Shortcuts");
|
2008-09-03 17:06:02 +02:00
|
|
|
QString shortcutText = shortcutConfig.readEntryUntranslated("global", QString());
|
2008-06-01 04:13:53 +02:00
|
|
|
if (!shortcutText.isEmpty()) {
|
2008-06-01 04:53:50 +02:00
|
|
|
setGlobalShortcut(KShortcut(shortcutText));
|
2008-06-01 04:13:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// local shortcut, if any
|
|
|
|
//TODO: implement; the shortcut will need to be registered with the containment
|
|
|
|
/*
|
2008-09-03 17:06:02 +02:00
|
|
|
shortcutText = shortcutConfig.readEntryUntranslated("local", QString());
|
2008-06-01 04:13:53 +02:00
|
|
|
if (!shortcutText.isEmpty()) {
|
2008-08-05 17:27:48 +02:00
|
|
|
//TODO: implement; the shortcut
|
2008-06-01 04:13:53 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::setFocus()
|
2008-06-01 04:13:53 +02:00
|
|
|
{
|
|
|
|
kDebug() << "setting focus";
|
|
|
|
q->setFocus(Qt::ShortcutFocusReason);
|
2008-02-13 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2008-04-18 18:05:20 +02:00
|
|
|
void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
|
|
|
{
|
|
|
|
if (d->failed == failed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->failed = failed;
|
|
|
|
prepareGeometryChange();
|
|
|
|
|
|
|
|
qDeleteAll(QGraphicsItem::children());
|
|
|
|
setLayout(0);
|
|
|
|
|
|
|
|
if (failed) {
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(d->backgroundHints|StandardBackground);
|
2008-04-18 18:05:20 +02:00
|
|
|
|
2008-08-23 19:21:55 +02:00
|
|
|
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout(this);
|
2008-04-18 18:05:20 +02:00
|
|
|
failureLayout->setContentsMargins(0, 0, 0, 0);
|
2008-05-19 07:25:16 +02:00
|
|
|
Label *failureWidget = new Plasma::Label(this);
|
|
|
|
failureWidget->setText(d->visibleFailureText(reason));
|
|
|
|
QLabel *label = failureWidget->nativeWidget();
|
2008-04-18 18:05:20 +02:00
|
|
|
label->setWordWrap(true);
|
|
|
|
failureLayout->addItem(failureWidget);
|
|
|
|
setLayout(failureLayout);
|
2008-04-30 00:57:08 +02:00
|
|
|
resize(300,250);
|
2008-05-19 07:25:16 +02:00
|
|
|
setMinimumSize(failureWidget->size());
|
|
|
|
//resize(label->size());
|
2008-04-30 00:57:08 +02:00
|
|
|
d->background->resizePanel(geometry().size());
|
2008-04-18 18:05:20 +02:00
|
|
|
}
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
void Applet::saveState(KConfigGroup &group) const
|
2007-09-18 23:22:45 +02:00
|
|
|
{
|
2008-05-22 17:53:48 +02:00
|
|
|
if (group.config()->name() != config().config()->name()) {
|
2008-01-02 03:05:47 +01:00
|
|
|
// we're being saved to a different file!
|
|
|
|
// let's just copy the current values in our configuration over
|
|
|
|
KConfigGroup c = config();
|
2008-05-22 17:53:48 +02:00
|
|
|
c.copyTo(&group);
|
2008-01-02 03:05:47 +01:00
|
|
|
}
|
2007-09-18 23:22:45 +02:00
|
|
|
}
|
|
|
|
|
2007-11-25 00:38:37 +01:00
|
|
|
KConfigGroup Applet::config(const QString &group) const
|
2007-07-12 21:14:23 +02:00
|
|
|
{
|
|
|
|
KConfigGroup cg = config();
|
2007-11-25 00:38:37 +01:00
|
|
|
return KConfigGroup(&cg, group);
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::config() const
|
|
|
|
{
|
2008-04-27 21:05:06 +02:00
|
|
|
if (d->isContainment) {
|
2008-04-28 17:41:18 +02:00
|
|
|
return *(d->mainConfigGroup());
|
2007-11-25 00:38:37 +01:00
|
|
|
}
|
|
|
|
|
2008-04-28 17:41:18 +02:00
|
|
|
return KConfigGroup(d->mainConfigGroup(), "Configuration");
|
2007-07-12 21:14:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup Applet::globalConfig() const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-11-25 00:38:37 +01:00
|
|
|
KConfigGroup globalAppletConfig;
|
2008-04-29 02:49:10 +02:00
|
|
|
const Containment *c = containment();
|
2008-04-27 21:05:06 +02:00
|
|
|
QString group = isContainment() ? "ContainmentGlobals" : "AppletGlobals";
|
2008-01-11 19:21:53 +01:00
|
|
|
|
|
|
|
if (c && c->corona()) {
|
|
|
|
KSharedConfig::Ptr coronaConfig = c->corona()->config();
|
|
|
|
globalAppletConfig = KConfigGroup(coronaConfig, group);
|
2007-11-25 00:38:37 +01:00
|
|
|
} else {
|
2008-01-11 19:21:53 +01:00
|
|
|
globalAppletConfig = KConfigGroup(KGlobal::config(), group);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-04-28 18:22:01 +02:00
|
|
|
return KConfigGroup(&globalAppletConfig, d->globalName());
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-08-05 11:39:32 +02:00
|
|
|
void Applet::destroy()
|
|
|
|
{
|
2008-07-07 00:43:53 +02:00
|
|
|
if (immutability() != Mutable || d->transient) {
|
2008-05-09 06:43:21 +02:00
|
|
|
return; //don't double delete
|
|
|
|
}
|
2008-07-07 00:43:53 +02:00
|
|
|
|
2008-05-09 06:43:21 +02:00
|
|
|
d->transient = true;
|
2008-07-07 00:43:53 +02:00
|
|
|
|
|
|
|
if (isContainment()) {
|
|
|
|
d->cleanUpAndDelete();
|
|
|
|
} else {
|
|
|
|
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
|
|
|
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
|
|
|
Animator::self()->animateItem(this, Animator::DisappearAnimation);
|
|
|
|
}
|
2008-05-09 06:43:21 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
2008-05-09 06:43:21 +02:00
|
|
|
{
|
|
|
|
if (anim != Animator::DisappearAnimation || item != q) {
|
|
|
|
return; //it's not our time yet
|
|
|
|
}
|
2008-06-04 21:04:34 +02:00
|
|
|
|
|
|
|
cleanUpAndDelete();
|
|
|
|
}
|
|
|
|
|
2008-07-07 00:43:53 +02:00
|
|
|
void AppletPrivate::selectItemToDestroy()
|
|
|
|
{
|
|
|
|
//FIXME: this will not work nicely with multiple screens and being zoomed out!
|
|
|
|
if (q->isContainment() &&
|
|
|
|
q->view() && q->view()->transform().isScaling() &&
|
|
|
|
q->scene()->focusItem() != q) {
|
|
|
|
QGraphicsItem *focus = q->scene()->focusItem();
|
|
|
|
|
|
|
|
if (focus) {
|
|
|
|
Containment *toDestroy = dynamic_cast<Containment*>(focus->topLevelItem());
|
|
|
|
|
|
|
|
if (toDestroy) {
|
|
|
|
toDestroy->destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q->destroy();
|
|
|
|
}
|
|
|
|
|
2008-08-05 17:27:48 +02:00
|
|
|
void AppletPrivate::updateRect(const QRectF& rect)
|
|
|
|
{
|
|
|
|
q->update(rect);
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::cleanUpAndDelete()
|
2008-06-04 21:04:34 +02:00
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "???????????????? DESTROYING APPLET" << name() << " ???????????????????????????";
|
2008-05-09 06:43:21 +02:00
|
|
|
QGraphicsWidget *parent = dynamic_cast<QGraphicsWidget *>(q->parentItem());
|
|
|
|
//it probably won't matter, but right now if there are applethandles, *they* are the parent.
|
|
|
|
//not the containment.
|
2008-05-09 01:30:29 +02:00
|
|
|
|
2008-05-08 22:26:56 +02:00
|
|
|
//is the applet in a containment and is the containment have a layout? if yes, we remove the applet in the layout
|
2008-05-09 06:43:21 +02:00
|
|
|
if (parent && parent->layout()) {
|
|
|
|
QGraphicsLayout *l = parent->layout();
|
2008-05-09 01:30:29 +02:00
|
|
|
for (int i = 0; i < l->count(); ++i) {
|
2008-05-09 06:43:21 +02:00
|
|
|
if (q == l->itemAt(i)) {
|
2008-05-09 01:30:29 +02:00
|
|
|
l->removeAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-05-08 22:26:56 +02:00
|
|
|
}
|
2008-05-21 06:37:10 +02:00
|
|
|
|
2008-05-09 06:43:21 +02:00
|
|
|
if (configXml) {
|
|
|
|
configXml->setDefaults();
|
2007-08-05 11:39:32 +02:00
|
|
|
}
|
2008-05-21 06:37:10 +02:00
|
|
|
|
2008-05-19 21:19:47 +02:00
|
|
|
q->scene()->removeItem(q);
|
2008-05-09 06:43:21 +02:00
|
|
|
q->deleteLater();
|
2007-08-05 11:39:32 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 04:28:35 +02:00
|
|
|
ConfigXml* Applet::configScheme() const
|
2007-07-30 18:19:07 +02:00
|
|
|
{
|
|
|
|
return d->configXml;
|
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
DataEngine* Applet::dataEngine(const QString& name) const
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-06-02 19:29:39 +02:00
|
|
|
int index = d->loadedEngines.indexOf(name);
|
|
|
|
if (index != -1) {
|
2008-04-23 21:05:47 +02:00
|
|
|
return DataEngineManager::self()->engine(name);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:04:53 +02:00
|
|
|
DataEngine* engine = DataEngineManager::self()->loadEngine(name);
|
2007-07-11 03:24:43 +02:00
|
|
|
if (engine->isValid()) {
|
2007-06-02 19:29:39 +02:00
|
|
|
d->loadedEngines.append(name);
|
2006-04-13 02:11:16 +02:00
|
|
|
}
|
|
|
|
|
2007-07-11 03:24:43 +02:00
|
|
|
return engine;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2007-07-20 05:34:20 +02:00
|
|
|
const Package* Applet::package() const
|
|
|
|
{
|
|
|
|
return d->package;
|
|
|
|
}
|
|
|
|
|
2008-04-14 16:50:02 +02:00
|
|
|
QGraphicsView *Applet::view() const
|
|
|
|
{
|
|
|
|
// It's assumed that we won't be visible on more than one view here.
|
|
|
|
// Anything that actually needs view() should only really care about
|
|
|
|
// one of them anyway though.
|
|
|
|
if (!scene()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-17 01:48:41 +02:00
|
|
|
QGraphicsView *found = 0;
|
2008-04-14 16:50:02 +02:00
|
|
|
foreach (QGraphicsView *view, scene()->views()) {
|
|
|
|
if (view->sceneRect().intersects(sceneBoundingRect()) ||
|
|
|
|
view->sceneRect().contains(scenePos())) {
|
2008-07-17 01:48:41 +02:00
|
|
|
if (!found || view->isActiveWindow()) {
|
|
|
|
found = view;
|
|
|
|
}
|
2008-04-14 16:50:02 +02:00
|
|
|
}
|
|
|
|
}
|
2008-07-17 01:48:41 +02:00
|
|
|
return found;
|
2008-04-14 16:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Applet::mapFromView(const QGraphicsView *view, const QRect &rect) const
|
|
|
|
{
|
2008-06-08 00:51:51 +02:00
|
|
|
// Why is this adjustment needed? Qt calculation error?
|
|
|
|
return mapFromScene(view->mapToScene(rect)).boundingRect().adjusted(0, 0, 1, 1);;
|
2008-04-14 16:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect Applet::mapToView(const QGraphicsView *view, const QRectF &rect) const
|
|
|
|
{
|
2008-06-08 00:51:51 +02:00
|
|
|
// Why is this adjustment needed? Qt calculation error?
|
|
|
|
return view->mapFromScene(mapToScene(rect)).boundingRect().adjusted(0, 0, -1, -1);;
|
2008-04-14 16:50:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QPoint Applet::popupPosition(const QSize &s) const
|
|
|
|
{
|
2008-07-17 01:48:41 +02:00
|
|
|
return Plasma::popupPosition(this, s);
|
2008-04-14 16:50:02 +02:00
|
|
|
}
|
|
|
|
|
2007-10-02 01:24:38 +02:00
|
|
|
void Applet::updateConstraints(Plasma::Constraints constraints)
|
2007-08-05 10:41:55 +02:00
|
|
|
{
|
2008-04-28 17:41:18 +02:00
|
|
|
d->scheduleConstraintsUpdate(constraints);
|
2007-08-05 10:41:55 +02:00
|
|
|
}
|
|
|
|
|
2008-04-27 13:04:43 +02:00
|
|
|
void Applet::constraintsEvent(Plasma::Constraints constraints)
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2008-02-04 21:09:45 +01:00
|
|
|
//NOTE: do NOT put any code in here that reacts to constraints updates
|
2008-04-27 13:04:43 +02:00
|
|
|
// as it will not get called for any applet that reimplements constraintsEvent
|
2008-02-04 21:09:45 +01:00
|
|
|
// without calling the Applet:: version as well, which it shouldn't need to.
|
2008-04-26 19:13:59 +02:00
|
|
|
// INSTEAD put such code into flushPendingConstraintsEvents
|
2007-11-03 03:52:45 +01:00
|
|
|
Q_UNUSED(constraints)
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << constraints << "constraints are FormFactor: " << formFactor() << ", Location: " << location();
|
2008-03-02 22:36:59 +01:00
|
|
|
if (d->script) {
|
2008-04-27 13:23:09 +02:00
|
|
|
d->script->constraintsEvent(constraints);
|
2008-03-02 22:36:59 +01:00
|
|
|
}
|
2007-06-01 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
void Applet::initExtenderItem(ExtenderItem *item)
|
|
|
|
{
|
|
|
|
Q_UNUSED(item)
|
|
|
|
item->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
Extender *Applet::extender() const
|
|
|
|
{
|
|
|
|
return d->extender;
|
|
|
|
}
|
|
|
|
|
2007-06-21 20:24:05 +02:00
|
|
|
QString Applet::name() const
|
2007-06-05 21:31:48 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-07-18 00:26:18 +02:00
|
|
|
return i18n("Unknown Applet");
|
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
return d->appletDescription.name();
|
2007-06-05 21:31:48 +02:00
|
|
|
}
|
|
|
|
|
2008-04-14 17:15:26 +02:00
|
|
|
QFont Applet::font() const
|
|
|
|
{
|
|
|
|
return QApplication::font();
|
|
|
|
}
|
|
|
|
|
2007-07-23 08:12:38 +02:00
|
|
|
QString Applet::icon() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.icon();
|
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
QString Applet::pluginName() const
|
|
|
|
{
|
|
|
|
if (!d->appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->appletDescription.pluginName();
|
|
|
|
}
|
|
|
|
|
2007-12-21 13:27:29 +01:00
|
|
|
bool Applet::shouldConserveResources() const
|
|
|
|
{
|
|
|
|
return Solid::PowerManagement::appShouldConserveResources();
|
|
|
|
}
|
|
|
|
|
2007-07-12 15:24:35 +02:00
|
|
|
QString Applet::category() const
|
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!d->appletDescription.isValid()) {
|
2007-08-05 15:01:09 +02:00
|
|
|
return i18n("Miscellaneous");
|
2007-07-18 00:26:18 +02:00
|
|
|
}
|
|
|
|
|
2007-08-05 15:01:09 +02:00
|
|
|
return d->appletDescription.category();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2007-07-23 01:10:53 +02:00
|
|
|
QString Applet::category(const KPluginInfo& applet)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
return applet.property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Applet::category(const QString& appletName)
|
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
|
|
|
if (offers.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
2007-07-17 23:30:27 +02:00
|
|
|
return offers.first()->property("X-KDE-PluginInfo-Category").toString();
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
ImmutabilityType Applet::immutability() const
|
2007-06-21 20:24:05 +02:00
|
|
|
{
|
2008-04-24 20:24:11 +02:00
|
|
|
//Returning the more strict immutability between the applet immutability and Corona one
|
2008-05-08 06:26:52 +02:00
|
|
|
ImmutabilityType coronaImmutability = Mutable;
|
2007-12-04 05:15:21 +01:00
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
if (dynamic_cast<Corona*>(scene())) {
|
|
|
|
coronaImmutability = static_cast<Corona*>(scene())->immutability();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coronaImmutability == SystemImmutable) {
|
|
|
|
return SystemImmutable;
|
|
|
|
} else if (coronaImmutability == UserImmutable && d->immutability != SystemImmutable) {
|
|
|
|
return UserImmutable;
|
|
|
|
} else {
|
|
|
|
return d->immutability;
|
|
|
|
}
|
2007-06-21 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
void Applet::setImmutability(const ImmutabilityType immutable)
|
2007-06-21 20:24:05 +02:00
|
|
|
{
|
2008-04-24 20:24:11 +02:00
|
|
|
if (d->immutability == immutable) {
|
2007-12-05 21:24:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
d->immutability = immutable;
|
2007-12-05 21:24:40 +01:00
|
|
|
updateConstraints(ImmutableConstraint);
|
2007-06-21 20:24:05 +02:00
|
|
|
}
|
|
|
|
|
2008-04-26 11:13:57 +02:00
|
|
|
Applet::BackgroundHints Applet::backgroundHints() const
|
2007-06-22 22:28:42 +02:00
|
|
|
{
|
2008-04-26 11:13:57 +02:00
|
|
|
return d->backgroundHints;
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
|
|
|
|
2008-04-26 11:13:57 +02:00
|
|
|
void Applet::setBackgroundHints(const BackgroundHints hints)
|
2007-06-22 22:28:42 +02:00
|
|
|
{
|
2008-04-26 11:13:57 +02:00
|
|
|
d->backgroundHints = hints;
|
|
|
|
|
|
|
|
//Draw the standard background?
|
2008-05-27 12:57:09 +02:00
|
|
|
if ((hints & StandardBackground) || (hints & TranslucentBackground)) {
|
2007-06-22 22:28:42 +02:00
|
|
|
if (!d->background) {
|
2008-08-23 19:21:55 +02:00
|
|
|
d->background = new Plasma::PanelSvg(this);
|
2008-05-27 12:57:09 +02:00
|
|
|
}
|
|
|
|
|
2008-07-21 21:36:47 +02:00
|
|
|
if ((hints & TranslucentBackground) &&
|
|
|
|
Plasma::Theme::defaultTheme()->currentThemeHasImage("widgets/translucentbackground")) {
|
2008-05-27 12:57:09 +02:00
|
|
|
d->background->setImagePath("widgets/translucentbackground");
|
|
|
|
} else {
|
|
|
|
d->background->setImagePath("widgets/background");
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
2008-05-27 12:57:09 +02:00
|
|
|
|
|
|
|
d->background->setEnabledBorders(Plasma::PanelSvg::AllBorders);
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
setContentsMargins(left, right, top, bottom);
|
|
|
|
QSizeF fitSize(left + right, top + bottom);
|
|
|
|
if (minimumSize().expandedTo(fitSize) != minimumSize()) {
|
|
|
|
setMinimumSize(minimumSize().expandedTo(fitSize));
|
|
|
|
}
|
|
|
|
d->background->resizePanel(boundingRect().size());
|
2007-07-30 18:00:29 +02:00
|
|
|
} else if (d->background) {
|
2008-05-01 11:49:30 +02:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
2008-04-17 19:49:33 +02:00
|
|
|
//Setting a minimum size of 0,0 would result in the panel to be only
|
|
|
|
//on the first virtual desktop
|
2008-06-17 00:20:49 +02:00
|
|
|
setMinimumSize(qMax(minimumSize().width() - left - right, qreal(1.0)),
|
|
|
|
qMax(minimumSize().height() - top - bottom, qreal(1.0)));
|
2008-04-17 19:49:33 +02:00
|
|
|
|
2007-06-22 22:28:42 +02:00
|
|
|
delete d->background;
|
|
|
|
d->background = 0;
|
2008-04-13 15:23:39 +02:00
|
|
|
setContentsMargins(0, 0, 0, 0);
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:15:38 +02:00
|
|
|
bool Applet::hasFailedToLaunch() const
|
2007-07-12 20:34:53 +02:00
|
|
|
{
|
|
|
|
return d->failed;
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
void Applet::paintWindowFrame(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
|
2008-04-13 15:23:39 +02:00
|
|
|
{
|
2008-04-14 12:48:32 +02:00
|
|
|
//Here come the code for the window frame
|
2008-06-04 20:20:58 +02:00
|
|
|
//kDebug() << windowFrameGeometry();
|
|
|
|
//painter->drawRoundedRect(windowFrameGeometry(), 5, 5);
|
2008-04-13 15:23:39 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 04:34:21 +02:00
|
|
|
bool Applet::configurationRequired() const
|
2007-08-03 17:23:56 +02:00
|
|
|
{
|
2008-04-01 00:06:35 +02:00
|
|
|
return d->needsConfigOverlay != 0;
|
2007-08-03 17:23:56 +02:00
|
|
|
}
|
|
|
|
|
2008-06-24 05:17:38 +02:00
|
|
|
void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
2007-08-03 17:23:56 +02:00
|
|
|
{
|
2008-04-01 00:06:35 +02:00
|
|
|
if ((d->needsConfigOverlay != 0) == needsConfig) {
|
2007-08-03 17:23:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
if (d->needsConfigOverlay) {
|
|
|
|
delete d->needsConfigOverlay;
|
|
|
|
d->needsConfigOverlay = 0;
|
|
|
|
return;
|
2007-08-03 17:23:56 +02:00
|
|
|
}
|
|
|
|
|
2008-04-30 23:50:43 +02:00
|
|
|
d->needsConfigOverlay = new AppletOverlayWidget(this);
|
2008-05-30 08:16:37 +02:00
|
|
|
d->needsConfigOverlay->resize(contentsRect().size());
|
2008-06-24 05:17:38 +02:00
|
|
|
d->needsConfigOverlay->setPos(contentsRect().topLeft());
|
2008-04-01 00:06:35 +02:00
|
|
|
|
2008-04-01 02:20:28 +02:00
|
|
|
int zValue = 100;
|
|
|
|
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
|
|
|
if (child->zValue() > zValue) {
|
|
|
|
zValue = child->zValue() + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d->needsConfigOverlay->setZValue(zValue);
|
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
qDeleteAll(d->needsConfigOverlay->QGraphicsItem::children());
|
2008-06-24 05:17:38 +02:00
|
|
|
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(d->needsConfigOverlay);
|
2008-04-14 00:01:18 +02:00
|
|
|
configLayout->setContentsMargins(0, 0, 0, 0);
|
2008-06-24 05:17:38 +02:00
|
|
|
|
|
|
|
// configLayout->addStretch();
|
|
|
|
configLayout->setColumnStretchFactor(0, 10);
|
|
|
|
configLayout->setColumnStretchFactor(2, 10);
|
|
|
|
configLayout->setRowStretchFactor(0, 10);
|
|
|
|
configLayout->setRowStretchFactor(3, 10);
|
|
|
|
|
|
|
|
int row = 1;
|
|
|
|
if (!reason.isEmpty()) {
|
|
|
|
Label *explanation = new Label(d->needsConfigOverlay);
|
|
|
|
explanation->setText(reason);
|
|
|
|
configLayout->addItem(explanation, row, 1);
|
|
|
|
configLayout->setColumnStretchFactor(1, 10);
|
|
|
|
++row;
|
|
|
|
//configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
|
|
|
|
}
|
|
|
|
|
2008-06-14 00:12:23 +02:00
|
|
|
PushButton *configWidget = new PushButton(d->needsConfigOverlay);
|
2008-05-30 08:16:37 +02:00
|
|
|
configWidget->setText(i18n("Configure..."));
|
|
|
|
connect(configWidget, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
|
2008-06-24 05:17:38 +02:00
|
|
|
configLayout->addItem(configWidget, row, 1);
|
|
|
|
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
|
|
|
|
//configLayout->addStretch();
|
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
d->needsConfigOverlay->show();
|
2007-08-03 17:23:56 +02:00
|
|
|
}
|
|
|
|
|
2008-04-26 19:13:59 +02:00
|
|
|
void Applet::flushPendingConstraintsEvents()
|
2007-10-26 03:04:56 +02:00
|
|
|
{
|
|
|
|
if (d->pendingConstraints == NoConstraint) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-09 01:30:29 +02:00
|
|
|
if (d->constraintsTimerId) {
|
|
|
|
killTimer(d->constraintsTimerId);
|
|
|
|
d->constraintsTimerId = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "fushing constraints: " << d->pendingConstraints << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
|
2007-10-26 03:04:56 +02:00
|
|
|
Plasma::Constraints c = d->pendingConstraints;
|
|
|
|
d->pendingConstraints = NoConstraint;
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
if (c & Plasma::StartupCompletedConstraint) {
|
|
|
|
//common actions
|
|
|
|
bool unlocked = immutability() == Mutable;
|
2008-05-20 06:02:36 +02:00
|
|
|
//FIXME desktop containments can't be removed while in use.
|
|
|
|
//it's kinda silly to have a keyboard shortcut for something that can only be used when the
|
|
|
|
//shortcut isn't active.
|
2008-07-17 22:52:04 +02:00
|
|
|
QAction* closeApplet = new QAction(this);
|
2008-05-17 05:39:24 +02:00
|
|
|
closeApplet->setIcon(KIcon("edit-delete"));
|
|
|
|
closeApplet->setEnabled(unlocked);
|
|
|
|
closeApplet->setVisible(unlocked);
|
2008-08-02 01:25:24 +02:00
|
|
|
closeApplet->setShortcutContext(Qt::WidgetShortcut); //don't clash with other views
|
2008-06-04 20:20:58 +02:00
|
|
|
if (isContainment()) {
|
2008-07-17 22:52:04 +02:00
|
|
|
closeApplet->setText(i18n("Remove this %1 Activity", name()));
|
2008-05-20 06:02:36 +02:00
|
|
|
closeApplet->setShortcut(QKeySequence("ctrl+shift+r"));
|
2008-06-04 20:20:58 +02:00
|
|
|
} else {
|
2008-07-17 22:52:04 +02:00
|
|
|
closeApplet->setText(i18n("Remove this %1", name()));
|
2008-06-04 20:20:58 +02:00
|
|
|
closeApplet->setShortcut(QKeySequence("ctrl+r"));
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
2008-07-07 00:43:53 +02:00
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(selectItemToDestroy()));
|
2008-05-17 05:39:24 +02:00
|
|
|
d->actions.addAction("remove", closeApplet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c & Plasma::ImmutableConstraint) {
|
|
|
|
bool unlocked = immutability() == Mutable;
|
|
|
|
QAction *action = d->actions.action("remove");
|
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}
|
2008-07-19 05:00:36 +02:00
|
|
|
if (!KAuthorized::authorize("PlasmaAllowConfigureWhenLocked")) {
|
|
|
|
action = d->actions.action("configure");
|
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
if (c & Plasma::SizeConstraint && d->needsConfigOverlay) {
|
2008-08-19 22:00:40 +02:00
|
|
|
d->needsConfigOverlay->setGeometry(QRectF(QPointF(0,0), geometry().size()));
|
|
|
|
|
2008-05-29 10:49:40 +02:00
|
|
|
QGraphicsItem *button = 0;
|
|
|
|
QList<QGraphicsItem*> children = d->needsConfigOverlay->QGraphicsItem::children();
|
|
|
|
|
|
|
|
if (!children.isEmpty()) {
|
|
|
|
button = children.first();
|
|
|
|
}
|
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
if (button) {
|
|
|
|
QSizeF s = button->boundingRect().size();
|
|
|
|
button->setPos(d->needsConfigOverlay->boundingRect().width() / 2 - s.width() / 2,
|
|
|
|
d->needsConfigOverlay->boundingRect().height() / 2 - s.height() / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 20:20:33 +01:00
|
|
|
if (c & Plasma::FormFactorConstraint) {
|
|
|
|
FormFactor f = formFactor();
|
2008-04-27 21:05:06 +02:00
|
|
|
if (!isContainment() && f != Vertical && f != Horizontal) {
|
2008-07-29 18:52:44 +02:00
|
|
|
setBackgroundHints(d->backgroundHints | StandardBackground);
|
|
|
|
} else if(d->backgroundHints & StandardBackground) {
|
|
|
|
setBackgroundHints(d->backgroundHints ^ StandardBackground);
|
|
|
|
} else if(d->backgroundHints & TranslucentBackground) {
|
|
|
|
setBackgroundHints(d->backgroundHints ^ TranslucentBackground);
|
2008-04-26 11:13:57 +02:00
|
|
|
}
|
2007-11-19 02:21:41 +01:00
|
|
|
}
|
|
|
|
|
2008-05-19 21:34:13 +02:00
|
|
|
//enforce square size in panels
|
2008-06-04 20:58:38 +02:00
|
|
|
if ((c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) &&
|
2008-06-23 20:49:10 +02:00
|
|
|
aspectRatioMode() == Plasma::Square) {
|
2008-05-19 21:34:13 +02:00
|
|
|
if (formFactor() == Horizontal) {
|
2008-06-23 20:49:10 +02:00
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
|
2008-05-19 21:34:13 +02:00
|
|
|
} else if (formFactor() == Vertical) {
|
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
|
|
|
|
}
|
2008-06-04 20:58:38 +02:00
|
|
|
|
2008-06-23 20:49:10 +02:00
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
//enforce a constrained square size in panels
|
|
|
|
if ((c & Plasma::SizeConstraint || c & Plasma::FormFactorConstraint) &&
|
|
|
|
aspectRatioMode() == Plasma::ConstrainedSquare) {
|
2008-06-04 20:58:38 +02:00
|
|
|
if (formFactor() == Horizontal) {
|
2008-08-18 20:49:04 +02:00
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Expanding));
|
2008-06-04 20:58:38 +02:00
|
|
|
} else if (formFactor() == Vertical) {
|
2008-06-23 20:49:10 +02:00
|
|
|
setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
|
2008-06-04 20:58:38 +02:00
|
|
|
}
|
2008-05-19 21:34:13 +02:00
|
|
|
|
2008-06-23 20:49:10 +02:00
|
|
|
updateGeometry();
|
|
|
|
}
|
2008-06-04 20:58:38 +02:00
|
|
|
|
|
|
|
|
2008-02-13 02:52:02 +01:00
|
|
|
Containment* containment = qobject_cast<Plasma::Containment*>(this);
|
2008-04-27 21:05:06 +02:00
|
|
|
if (isContainment() && containment) {
|
2008-04-27 13:13:43 +02:00
|
|
|
containment->d->containmentConstraintsEvent(c);
|
2007-11-07 20:20:33 +01:00
|
|
|
}
|
|
|
|
|
2008-04-27 13:04:43 +02:00
|
|
|
constraintsEvent(c);
|
2007-10-26 03:04:56 +02:00
|
|
|
|
|
|
|
if (layout()) {
|
2007-11-20 00:45:56 +01:00
|
|
|
layout()->updateGeometry();
|
2007-10-26 03:04:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-23 00:01:10 +02:00
|
|
|
int Applet::type() const
|
|
|
|
{
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2008-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> Applet::contextualActions()
|
2007-07-31 02:20:19 +02:00
|
|
|
{
|
2008-02-09 04:41:57 +01:00
|
|
|
//kDebug() << "empty context actions";
|
2008-04-25 21:55:24 +02:00
|
|
|
return d->script ? d->script->contextualActions() : QList<QAction*>();
|
2007-07-31 02:20:19 +02:00
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
QAction* Applet::action(QString name) const
|
|
|
|
{
|
|
|
|
return d->actions.action(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::addAction(QString name, QAction *action)
|
|
|
|
{
|
|
|
|
d->actions.addAction(name, action);
|
|
|
|
}
|
|
|
|
|
2008-04-14 16:50:02 +02:00
|
|
|
void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-06-22 22:28:42 +02:00
|
|
|
{
|
2008-05-11 15:56:35 +02:00
|
|
|
QPainter *p;
|
2008-05-11 19:21:55 +02:00
|
|
|
//FIXME: we should probably set the pixmap to screenSize(), but that breaks stuff atm.
|
2008-09-03 01:29:54 +02:00
|
|
|
QPixmap *pixmap = 0;
|
2008-05-11 15:56:35 +02:00
|
|
|
|
2008-06-16 21:10:38 +02:00
|
|
|
QGraphicsView* qgv = qobject_cast<QGraphicsView*>(widget ? widget->parent() : 0);
|
2008-05-11 15:56:35 +02:00
|
|
|
bool ghost = (qgv && (qgv == d->ghostView));
|
|
|
|
|
|
|
|
if (ghost) {
|
|
|
|
// The applet has to be displayed semi transparent. Create a pixmap and a painter on
|
|
|
|
// that pixmap where the applet can draw on so we can draw the result transparently
|
|
|
|
// at the end.
|
|
|
|
kDebug() << "Painting ghosted...";
|
2008-09-03 01:29:54 +02:00
|
|
|
pixmap = new QPixmap(boundingRect().size().toSize());
|
|
|
|
pixmap->fill(Qt::transparent);
|
2008-05-11 15:56:35 +02:00
|
|
|
|
|
|
|
p = new QPainter();
|
2008-09-03 01:29:54 +02:00
|
|
|
p->begin(pixmap);
|
2008-05-11 15:56:35 +02:00
|
|
|
} else {
|
|
|
|
p = painter;
|
|
|
|
}
|
|
|
|
|
|
|
|
p->save();
|
2008-04-15 04:38:48 +02:00
|
|
|
|
2007-11-19 10:21:11 +01:00
|
|
|
if (transform().isRotating()) {
|
2008-05-11 15:56:35 +02:00
|
|
|
p->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
p->setRenderHint(QPainter::Antialiasing);
|
2007-11-19 10:21:11 +01:00
|
|
|
}
|
2008-04-27 22:09:20 +02:00
|
|
|
|
2008-02-06 19:50:25 +01:00
|
|
|
if (d->background &&
|
|
|
|
formFactor() != Plasma::Vertical &&
|
|
|
|
formFactor() != Plasma::Horizontal) {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "option rect is" << option->rect;
|
2008-07-27 19:20:27 +02:00
|
|
|
d->background->paintPanel(p);
|
2007-11-19 10:21:11 +01:00
|
|
|
}
|
2008-04-27 22:09:20 +02:00
|
|
|
|
2008-04-01 00:06:35 +02:00
|
|
|
if (!d->failed) {
|
2008-05-02 00:39:18 +02:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
getContentsMargins(&left, &top, &right, &bottom);
|
2008-09-03 01:29:54 +02:00
|
|
|
QRectF contentsRect = QRectF(QPointF(0,0), boundingRect().size())
|
|
|
|
.adjusted(left, top, -right, -bottom);
|
|
|
|
|
|
|
|
if (!ghost) {
|
|
|
|
// only paint the bare minimum when not ghosting
|
|
|
|
contentsRect = option->exposedRect.intersected(contentsRect);
|
|
|
|
}
|
|
|
|
|
2008-09-03 06:25:24 +02:00
|
|
|
QRect exposed = contentsRect.toRect();
|
2008-09-03 01:29:54 +02:00
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
if (widget && isContainment()) {
|
2007-11-19 10:21:11 +01:00
|
|
|
// note that the widget we get is actually the viewport of the view, not the view itself
|
|
|
|
View* v = qobject_cast<Plasma::View*>(widget->parent());
|
2008-08-21 04:56:41 +02:00
|
|
|
|
2008-04-18 19:40:57 +02:00
|
|
|
if (!v || v->isWallpaperEnabled()) {
|
2008-08-05 17:27:48 +02:00
|
|
|
Containment* c = qobject_cast<Plasma::Containment*>(this);
|
|
|
|
if (c && c->drawWallpaper() && c->wallpaper()) {
|
2008-09-03 01:29:54 +02:00
|
|
|
c->wallpaper()->paint(p, exposed);
|
2008-08-05 17:27:48 +02:00
|
|
|
}
|
2008-08-21 04:56:41 +02:00
|
|
|
|
|
|
|
Containment::StyleOption coption(*option);
|
|
|
|
coption.view = v;
|
2008-09-03 01:29:54 +02:00
|
|
|
paintInterface(p, &coption, exposed);
|
2007-11-19 10:21:11 +01:00
|
|
|
}
|
2008-08-21 04:56:41 +02:00
|
|
|
|
2008-05-11 15:56:35 +02:00
|
|
|
p->restore();
|
2008-02-23 00:41:44 +01:00
|
|
|
return;
|
2007-07-26 01:42:43 +02:00
|
|
|
}
|
2007-06-22 22:28:42 +02:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "paint interface of" << (QObject*) this;
|
2008-09-03 01:29:54 +02:00
|
|
|
paintInterface(p, option, exposed);
|
2008-05-11 15:56:35 +02:00
|
|
|
}
|
|
|
|
p->restore();
|
|
|
|
|
|
|
|
if (ghost) {
|
|
|
|
// Lets display the pixmap that we've just drawn... transparently.
|
|
|
|
p->setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
2008-09-03 01:29:54 +02:00
|
|
|
p->fillRect(pixmap->rect(), QColor(0, 0, 0, (0.3 * 255)));
|
2008-05-11 15:56:35 +02:00
|
|
|
p->end();
|
|
|
|
delete p;
|
|
|
|
|
2008-09-03 01:29:54 +02:00
|
|
|
painter->drawPixmap(0, 0, *pixmap);
|
|
|
|
delete pixmap;
|
2008-04-12 16:07:44 +02:00
|
|
|
}
|
2007-06-22 22:28:42 +02:00
|
|
|
}
|
|
|
|
|
2007-07-24 23:04:31 +02:00
|
|
|
void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
|
|
const QRect & contentsRect)
|
2007-06-20 08:45:08 +02:00
|
|
|
{
|
2008-01-25 01:08:25 +01:00
|
|
|
if (d->script) {
|
|
|
|
d->script->paintInterface(painter, option, contentsRect);
|
2007-07-24 23:04:31 +02:00
|
|
|
} else {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "Applet::paintInterface() default impl";
|
2007-07-23 11:21:45 +02:00
|
|
|
}
|
2007-06-20 08:45:08 +02:00
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
FormFactor Applet::formFactor() const
|
|
|
|
{
|
2007-09-18 23:22:45 +02:00
|
|
|
Containment* c = containment();
|
2008-04-29 02:49:10 +02:00
|
|
|
return c ? c->d->formFactor : Plasma::Planar;
|
2007-09-18 23:22:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment* Applet::containment() const
|
|
|
|
{
|
2008-04-29 02:49:10 +02:00
|
|
|
if (isContainment()) {
|
|
|
|
Containment *c = dynamic_cast<Containment*>(const_cast<Applet*>(this));
|
|
|
|
if (c) {
|
|
|
|
return c;
|
|
|
|
}
|
2008-01-11 19:21:53 +01:00
|
|
|
}
|
|
|
|
|
2008-02-29 18:50:57 +01:00
|
|
|
QGraphicsItem *parent = parentItem();
|
2007-12-04 05:15:21 +01:00
|
|
|
Containment *c = 0;
|
2008-01-11 19:21:53 +01:00
|
|
|
|
2007-11-15 12:01:17 +01:00
|
|
|
while (parent) {
|
2008-04-29 02:49:10 +02:00
|
|
|
Containment *possibleC = dynamic_cast<Containment*>(parent);
|
2008-04-27 21:05:06 +02:00
|
|
|
if (possibleC && possibleC->isContainment()) {
|
2008-01-11 19:21:53 +01:00
|
|
|
c = possibleC;
|
2007-11-15 12:01:17 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-02-29 18:50:57 +01:00
|
|
|
parent = parent->parentItem();
|
2007-11-15 12:01:17 +01:00
|
|
|
}
|
2008-01-11 19:21:53 +01:00
|
|
|
|
2007-12-04 05:15:21 +01:00
|
|
|
return c;
|
2007-06-01 00:40:38 +02:00
|
|
|
}
|
|
|
|
|
2008-06-01 04:53:50 +02:00
|
|
|
void Applet::setGlobalShortcut(const KShortcut &shortcut)
|
|
|
|
{
|
|
|
|
if (!d->activationAction) {
|
|
|
|
d->activationAction = new KAction(this);
|
2008-07-17 20:40:11 +02:00
|
|
|
d->activationAction->setText(i18n("Activate %1 Widget", name()));
|
2008-07-17 20:25:50 +02:00
|
|
|
d->activationAction->setObjectName(QString("activate widget %1").arg(name())); // NO I18N
|
2008-06-01 04:53:50 +02:00
|
|
|
connect(d->activationAction, SIGNAL(triggered()), this, SIGNAL(activate()));
|
|
|
|
connect(this, SIGNAL(activate()), this, SLOT(setFocus()));
|
2008-06-03 02:24:51 +02:00
|
|
|
|
|
|
|
QList<QWidget *> widgets = d->actions.associatedWidgets();
|
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
w->addAction(d->activationAction);
|
|
|
|
}
|
2008-06-01 04:53:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d->activationAction->setGlobalShortcut(shortcut);
|
|
|
|
}
|
|
|
|
|
|
|
|
KShortcut Applet::globalShortcut() const
|
|
|
|
{
|
|
|
|
if (d->activationAction) {
|
|
|
|
return d->activationAction->globalShortcut();
|
|
|
|
}
|
|
|
|
|
|
|
|
return KShortcut();
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
void Applet::addAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
d->actions.addAssociatedWidget(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::removeAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
d->actions.removeAssociatedWidget(widget);
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:40:38 +02:00
|
|
|
Location Applet::location() const
|
|
|
|
{
|
2007-09-18 23:22:45 +02:00
|
|
|
Containment* c = containment();
|
2008-04-29 02:49:10 +02:00
|
|
|
return c ? c->d->location : Plasma::Desktop;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-09-05 02:22:42 +02:00
|
|
|
Context* Applet::context() const
|
2008-08-18 16:04:30 +02:00
|
|
|
{
|
|
|
|
Containment *c = containment();
|
2008-09-05 02:22:42 +02:00
|
|
|
Q_ASSERT(c);
|
|
|
|
return c->d->context();
|
2008-08-18 16:04:30 +02:00
|
|
|
}
|
|
|
|
|
2008-05-01 00:13:27 +02:00
|
|
|
Plasma::AspectRatioMode Applet::aspectRatioMode() const
|
2008-01-10 20:02:05 +01:00
|
|
|
{
|
|
|
|
return d->aspectRatioMode;
|
|
|
|
}
|
|
|
|
|
2008-05-01 00:13:27 +02:00
|
|
|
void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode)
|
2008-01-10 20:02:05 +01:00
|
|
|
{
|
|
|
|
d->aspectRatioMode = mode;
|
|
|
|
}
|
|
|
|
|
2008-08-04 10:00:07 +02:00
|
|
|
void Applet::registerAsDragHandle(QGraphicsItem *item)
|
2008-02-21 11:26:40 +01:00
|
|
|
{
|
2008-04-30 17:04:49 +02:00
|
|
|
if (!item) {
|
2008-02-21 11:26:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-30 17:04:49 +02:00
|
|
|
int index = d->registeredAsDragHandle.indexOf(item);
|
2008-06-30 23:05:16 +02:00
|
|
|
|
2008-04-30 17:04:49 +02:00
|
|
|
if (index == -1) {
|
|
|
|
d->registeredAsDragHandle.append(item);
|
|
|
|
item->installSceneEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-02 17:12:52 +02:00
|
|
|
void Applet::unregisterAsDragHandle(QGraphicsItem *item)
|
2008-04-30 17:04:49 +02:00
|
|
|
{
|
|
|
|
if (!item) {
|
|
|
|
return;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
2008-04-30 17:04:49 +02:00
|
|
|
|
|
|
|
int index = d->registeredAsDragHandle.indexOf(item);
|
|
|
|
if (index != -1) {
|
|
|
|
d->registeredAsDragHandle.removeAt(index);
|
|
|
|
item->removeSceneEventFilter(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Applet::isRegisteredAsDragHandle( QGraphicsItem * item )
|
|
|
|
{
|
|
|
|
return (d->registeredAsDragHandle.indexOf(item) != -1);
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-04-16 23:15:38 +02:00
|
|
|
bool Applet::hasConfigurationInterface() const
|
2007-07-02 12:47:34 +02:00
|
|
|
{
|
|
|
|
return d->hasConfigurationInterface;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::setHasConfigurationInterface(bool hasInterface)
|
|
|
|
{
|
2008-05-17 05:39:24 +02:00
|
|
|
if (d->hasConfigurationInterface == hasInterface) {
|
|
|
|
return;
|
|
|
|
}
|
2008-08-18 16:04:30 +02:00
|
|
|
|
2007-07-02 12:47:34 +02:00
|
|
|
d->hasConfigurationInterface = hasInterface;
|
2008-05-17 05:39:24 +02:00
|
|
|
//config action
|
|
|
|
//TODO respect security when it's implemented (4.2)
|
|
|
|
QAction *configAction = d->actions.action("configure");
|
|
|
|
if (hasInterface) {
|
|
|
|
if (! configAction) { //should be always true
|
|
|
|
configAction = new QAction(i18n("%1 Settings", name()), this);
|
|
|
|
configAction->setIcon(KIcon("configure"));
|
2008-08-02 01:25:24 +02:00
|
|
|
configAction->setShortcutContext(Qt::WidgetShortcut); //don't clash with other views
|
2008-05-17 05:39:24 +02:00
|
|
|
if (isContainment()) {
|
|
|
|
//kDebug() << "I am a containment";
|
|
|
|
configAction->setShortcut(QKeySequence("ctrl+shift+s"));
|
|
|
|
} else {
|
|
|
|
configAction->setShortcut(QKeySequence("ctrl+s"));
|
|
|
|
}
|
|
|
|
//TODO how can we handle configuration of the shortcut in a way that spans all applets?
|
|
|
|
connect(configAction, SIGNAL(triggered(bool)),
|
|
|
|
this, SLOT(showConfigurationInterface()));
|
|
|
|
d->actions.addAction("configure", configAction);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
d->actions.removeAction(configAction);
|
|
|
|
}
|
2007-07-02 12:47:34 +02:00
|
|
|
}
|
|
|
|
|
2007-03-03 02:41:27 +01:00
|
|
|
bool Applet::eventFilter( QObject *o, QEvent * e )
|
2005-12-29 22:55:22 +01:00
|
|
|
{
|
2007-05-24 22:01:12 +02:00
|
|
|
return QObject::eventFilter(o, e);
|
|
|
|
}
|
|
|
|
|
2008-02-21 11:26:40 +01:00
|
|
|
bool Applet::sceneEventFilter( QGraphicsItem * watched, QEvent * event )
|
|
|
|
{
|
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::GraphicsSceneMouseMove: {
|
2008-08-04 10:00:07 +02:00
|
|
|
// don't move when the containment is not mutable,
|
|
|
|
// in the rare case the containment doesn't exists consider it as mutable
|
|
|
|
if ((!containment() || containment()->immutability() == Mutable) &&
|
|
|
|
d->registeredAsDragHandle.contains(watched)) {
|
2008-02-21 11:26:40 +01:00
|
|
|
mouseMoveEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsItem::sceneEventFilter(watched, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-06-30 23:05:16 +02:00
|
|
|
if (immutability() == Mutable && formFactor() == Plasma::Planar) {
|
2008-02-21 11:26:40 +01:00
|
|
|
QGraphicsItem *parent = parentItem();
|
|
|
|
Plasma::Applet *applet = qgraphicsitem_cast<Plasma::Applet*>(parent);
|
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
if (applet && applet->isContainment()) {
|
2008-02-21 11:26:40 +01:00
|
|
|
// our direct parent is a containment. just move ourselves.
|
|
|
|
QPointF curPos = event->pos();
|
|
|
|
QPointF lastPos = event->lastPos();
|
|
|
|
QPointF delta = curPos-lastPos;
|
|
|
|
|
|
|
|
moveBy(delta.x(),delta.y());
|
|
|
|
} else if (parent) {
|
|
|
|
//don't move the icon as well because our parent (usually an appletHandle) will do it for us
|
|
|
|
//parent->moveBy(delta.x(),delta.y());
|
|
|
|
QPointF curPos = parent->transform().map(event->pos());
|
|
|
|
QPointF lastPos = parent->transform().map(event->lastPos());
|
|
|
|
QPointF delta = curPos-lastPos;
|
|
|
|
|
|
|
|
parent->setPos(parent->pos() + delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
void Applet::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-07-07 00:43:53 +02:00
|
|
|
setFocus(Qt::MouseFocusReason);
|
2008-04-14 23:50:41 +02:00
|
|
|
QGraphicsWidget::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Applet::focusInEvent(QFocusEvent * event)
|
|
|
|
{
|
2008-07-07 00:43:53 +02:00
|
|
|
if (!isContainment() && containment()) {
|
2008-05-17 05:39:24 +02:00
|
|
|
//focusing an applet may trigger this event again, but we won't be here more than twice
|
2008-07-07 00:43:53 +02:00
|
|
|
containment()->d->focusApplet(this);
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
2008-06-01 04:13:53 +02:00
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
QGraphicsWidget::focusInEvent(event);
|
|
|
|
}
|
2008-02-21 11:26:40 +01:00
|
|
|
|
2008-06-01 04:13:53 +02:00
|
|
|
void Applet::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsWidget::resizeEvent(event);
|
|
|
|
|
|
|
|
if (d->background) {
|
|
|
|
d->background->resizePanel(boundingRect().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConstraints(Plasma::SizeConstraint);
|
2008-06-07 12:52:34 +02:00
|
|
|
emit geometryChanged();
|
2008-06-01 04:13:53 +02:00
|
|
|
}
|
|
|
|
|
2007-07-02 12:58:03 +02:00
|
|
|
void Applet::showConfigurationInterface()
|
2007-07-02 12:47:34 +02:00
|
|
|
{
|
2008-04-02 17:37:17 +02:00
|
|
|
if (!hasConfigurationInterface()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-07-19 05:22:41 +02:00
|
|
|
if (immutability() != Mutable && !KAuthorized::authorize("PlasmaAllowConfigureWhenLocked")) {
|
|
|
|
return;
|
|
|
|
}
|
2008-04-02 17:37:17 +02:00
|
|
|
|
|
|
|
const QString dialogId = QString("%1settings%2").arg(id()).arg(name());
|
|
|
|
KConfigDialog * dlg = KConfigDialog::exists(dialogId);
|
|
|
|
|
|
|
|
if (dlg) {
|
|
|
|
KWindowSystem::setOnDesktop(dlg->winId(), KWindowSystem::currentDesktop());
|
|
|
|
dlg->show();
|
|
|
|
KWindowSystem::activateWindow(dlg->winId());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString windowTitle = i18nc("@title:window", "%1 Settings", name());
|
2007-07-30 18:00:29 +02:00
|
|
|
if (d->package && d->configXml) {
|
|
|
|
QString uiFile = d->package->filePath("mainconfigui");
|
|
|
|
if (uiFile.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-02 17:37:17 +02:00
|
|
|
KConfigDialog *dialog = new KConfigDialog(0, dialogId, d->configXml);
|
|
|
|
dialog->setWindowTitle(windowTitle);
|
2007-07-30 18:00:29 +02:00
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
QUiLoader loader;
|
2008-01-25 15:53:12 +01:00
|
|
|
QFile f(uiFile);
|
2007-07-30 18:00:29 +02:00
|
|
|
if (!f.open(QIODevice::ReadOnly)) {
|
|
|
|
delete dialog;
|
2008-05-09 01:30:29 +02:00
|
|
|
|
|
|
|
if (d->script) {
|
|
|
|
d->script->showConfigurationInterface();
|
|
|
|
}
|
2007-07-30 18:00:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *w = loader.load(&f);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
dialog->addPage(w, i18n("Settings"), icon(), i18n("%1 Settings", name()));
|
|
|
|
dialog->show();
|
2008-04-02 17:37:17 +02:00
|
|
|
} else if (d->script) {
|
2008-05-08 19:46:28 +02:00
|
|
|
d->script->showConfigurationInterface();
|
2008-04-02 17:37:17 +02:00
|
|
|
} else {
|
|
|
|
KConfigSkeleton *nullManager = new KConfigSkeleton(0);
|
|
|
|
KConfigDialog *dialog = new KConfigDialog(0, dialogId, nullManager);
|
|
|
|
dialog->setFaceType(KPageDialog::Auto);
|
|
|
|
dialog->setWindowTitle(windowTitle);
|
|
|
|
dialog->setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
createConfigurationInterface(dialog);
|
|
|
|
//TODO: would be nice to not show dialog if there are no pages added?
|
|
|
|
connect(dialog, SIGNAL(finished()), nullManager, SLOT(deleteLater()));
|
2008-05-31 23:26:49 +02:00
|
|
|
//TODO: Apply button does not correctly work for now, so do not show it
|
|
|
|
dialog->showButton( KDialog::Apply, false );
|
2008-04-02 17:37:17 +02:00
|
|
|
dialog->show();
|
2008-03-02 22:36:59 +01:00
|
|
|
}
|
2008-04-25 19:21:24 +02:00
|
|
|
|
2008-04-29 04:28:35 +02:00
|
|
|
emit releaseVisualFocus();
|
2007-07-02 12:47:34 +02:00
|
|
|
}
|
|
|
|
|
2008-04-02 17:37:17 +02:00
|
|
|
void Applet::createConfigurationInterface(KConfigDialog *parent)
|
|
|
|
{
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
// virtual method reimplemented by subclasses.
|
|
|
|
// do not put anything here ...
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:15:38 +02:00
|
|
|
KPluginInfo::List Applet::listAppletInfo(const QString &category,
|
2007-07-17 23:30:27 +02:00
|
|
|
const QString &parentApp)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint;
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
|
|
|
}
|
|
|
|
|
2007-07-18 00:26:18 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
2007-08-05 15:01:09 +02:00
|
|
|
if (category == "Miscellaneous") {
|
2007-07-18 00:26:18 +02:00
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2007-07-17 23:30:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2008-04-16 23:15:38 +02:00
|
|
|
//kDebug() << "Applet::listAppletInfo constraint was '" << constraint << "' which got us " << offers.count() << " matches";
|
2007-05-24 22:01:12 +02:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:15:38 +02:00
|
|
|
KPluginInfo::List Applet::listAppletInfoForMimetype(const QString &mimetype)
|
2007-07-31 12:52:05 +02:00
|
|
|
{
|
2008-05-24 09:47:20 +02:00
|
|
|
QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimetype);
|
2008-04-16 23:15:38 +02:00
|
|
|
//kDebug() << "listAppletInfoForMimetype with" << mimetype << constraint;
|
2007-07-31 12:52:05 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2008-04-16 23:15:38 +02:00
|
|
|
QStringList Applet::listCategories(const QString &parentApp, bool visibleOnly)
|
2007-07-12 15:24:35 +02:00
|
|
|
{
|
2007-07-17 23:30:27 +02:00
|
|
|
QString constraint = "exist [X-KDE-PluginInfo-Category]";
|
|
|
|
|
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append(" and not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append(" and [X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
2007-07-12 15:24:35 +02:00
|
|
|
QStringList categories;
|
2008-04-26 18:19:00 +02:00
|
|
|
foreach (const KService::Ptr &applet, offers) {
|
2007-07-17 23:30:27 +02:00
|
|
|
QString appletCategory = applet->property("X-KDE-PluginInfo-Category").toString();
|
2007-11-19 17:37:46 +01:00
|
|
|
if (visibleOnly && applet->noDisplay()) {
|
2007-11-19 10:46:52 +01:00
|
|
|
// we don't want to show the hidden category
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << " and we have " << appletCategory;
|
2007-07-17 23:30:27 +02:00
|
|
|
if (appletCategory.isEmpty()) {
|
2007-08-05 15:01:09 +02:00
|
|
|
if (!categories.contains(i18n("Miscellaneous"))) {
|
|
|
|
categories << i18n("Miscellaneous");
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
} else if (!categories.contains(appletCategory)) {
|
|
|
|
categories << appletCategory;
|
2007-07-12 15:24:35 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-17 23:30:27 +02:00
|
|
|
|
|
|
|
categories.sort();
|
2007-07-12 15:24:35 +02:00
|
|
|
return categories;
|
|
|
|
}
|
|
|
|
|
2008-02-26 02:48:52 +01:00
|
|
|
Applet* Applet::load(const QString& appletName, uint appletId, const QVariantList& args)
|
2007-05-24 22:01:12 +02:00
|
|
|
{
|
|
|
|
if (appletName.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
|
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
bool isContainment = false;
|
2007-05-24 22:01:12 +02:00
|
|
|
if (offers.isEmpty()) {
|
|
|
|
//TODO: what would be -really- cool is offer to try and download the applet
|
|
|
|
// from the network at this point
|
2008-03-05 22:12:33 +01:00
|
|
|
offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
2008-04-27 21:05:06 +02:00
|
|
|
isContainment = true;
|
2008-03-05 22:19:48 +01:00
|
|
|
if (offers.isEmpty()) {
|
2008-03-05 22:12:33 +01:00
|
|
|
kDebug() << "offers is empty for " << appletName;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-26 03:06:03 +02:00
|
|
|
} /* else if (offers.count() > 1) {
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "hey! we got more than one! let's blindly take the first one";
|
2007-10-26 03:06:03 +02:00
|
|
|
} */
|
2007-05-24 22:01:12 +02:00
|
|
|
|
2007-11-29 21:38:13 +01:00
|
|
|
KService::Ptr offer = offers.first();
|
|
|
|
|
2007-05-24 22:01:12 +02:00
|
|
|
if (appletId == 0) {
|
2008-07-01 20:56:43 +02:00
|
|
|
appletId = ++AppletPrivate::s_maxAppletId;
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 18:24:14 +02:00
|
|
|
if (!offer->property("X-Plasma-API").toString().isEmpty()) {
|
|
|
|
kDebug() << "we have a script using the" << offer->property("X-Plasma-API").toString() << "API";
|
2008-04-27 21:05:06 +02:00
|
|
|
if (isContainment) {
|
2008-03-05 22:12:33 +01:00
|
|
|
return new Containment(0, offer->storageId(), appletId);
|
|
|
|
}
|
|
|
|
return new Applet(0, offer->storageId(), appletId);
|
2007-11-29 21:38:13 +01:00
|
|
|
}
|
|
|
|
|
2008-07-17 03:11:25 +02:00
|
|
|
KPluginLoader plugin(*offer);
|
|
|
|
|
2008-07-17 03:27:43 +02:00
|
|
|
if (!Plasma::isPluginVersionCompatible(plugin.pluginVersion())) {
|
2008-07-17 03:11:25 +02:00
|
|
|
return 0;
|
2008-07-17 03:27:43 +02:00
|
|
|
}
|
2008-07-17 03:11:25 +02:00
|
|
|
|
2007-08-29 04:33:22 +02:00
|
|
|
QVariantList allArgs;
|
2007-11-29 21:38:13 +01:00
|
|
|
allArgs << offer->storageId() << appletId << args;
|
2007-08-29 04:33:22 +02:00
|
|
|
QString error;
|
2007-11-29 21:38:13 +01:00
|
|
|
Applet* applet = offer->createInstance<Plasma::Applet>(0, allArgs, &error);
|
2007-05-24 22:01:12 +02:00
|
|
|
|
|
|
|
if (!applet) {
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "Couldn't load applet \"" << appletName << "\"! reason given: " << error;
|
2007-05-24 22:01:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return applet;
|
2005-12-29 22:55:22 +01:00
|
|
|
}
|
|
|
|
|
2008-02-26 02:48:52 +01:00
|
|
|
Applet* Applet::load(const KPluginInfo& info, uint appletId, const QVariantList& args)
|
2007-05-24 22:51:59 +02:00
|
|
|
{
|
2007-07-23 01:10:53 +02:00
|
|
|
if (!info.isValid()) {
|
2007-05-24 22:51:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-26 02:48:52 +01:00
|
|
|
return load(info.pluginName(), appletId, args);
|
2007-05-24 22:51:59 +02:00
|
|
|
}
|
|
|
|
|
2007-08-05 10:41:55 +02:00
|
|
|
QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2008-08-19 19:37:53 +02:00
|
|
|
QVariant ret = QGraphicsWidget::itemChange(change, value);
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
//kDebug() << change;
|
2007-08-05 10:41:55 +02:00
|
|
|
switch (change) {
|
2008-03-03 19:15:49 +01:00
|
|
|
case ItemSceneHasChanged: {
|
2007-08-05 10:41:55 +02:00
|
|
|
QGraphicsScene *newScene = qvariant_cast<QGraphicsScene*>(value);
|
|
|
|
if (newScene) {
|
2008-04-28 17:41:18 +02:00
|
|
|
d->checkImmutability();
|
2007-11-27 07:01:06 +01:00
|
|
|
}
|
2007-08-05 10:41:55 +02:00
|
|
|
}
|
|
|
|
break;
|
2008-06-01 04:13:53 +02:00
|
|
|
case ItemPositionHasChanged:
|
|
|
|
emit geometryChanged();
|
|
|
|
break;
|
2007-08-05 10:41:55 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
2008-08-19 19:37:53 +02:00
|
|
|
return ret;
|
2007-08-05 10:41:55 +02:00
|
|
|
}
|
|
|
|
|
2008-06-25 02:33:46 +02:00
|
|
|
QPainterPath Applet::shape() const
|
|
|
|
{
|
|
|
|
if (d->script) {
|
|
|
|
return d->script->shape();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QGraphicsWidget::shape();
|
|
|
|
}
|
|
|
|
|
2008-04-29 22:31:18 +02:00
|
|
|
QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
|
|
|
{
|
|
|
|
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
|
|
|
|
2008-06-23 20:49:10 +02:00
|
|
|
//in panels make sure that the contents won't exit from the panel
|
|
|
|
if (formFactor() == Horizontal && which == Qt::MinimumSize) {
|
|
|
|
hint.setHeight(0);
|
|
|
|
} else if (formFactor() == Vertical && which == Qt::MinimumSize) {
|
|
|
|
hint.setWidth(0);
|
|
|
|
}
|
2008-07-07 04:16:08 +02:00
|
|
|
|
2008-06-23 20:49:10 +02:00
|
|
|
// enforce a square size in panels
|
2008-04-29 22:31:18 +02:00
|
|
|
if (d->aspectRatioMode == Plasma::Square) {
|
|
|
|
if (formFactor() == Horizontal) {
|
2008-06-23 20:49:10 +02:00
|
|
|
hint.setWidth(size().height());
|
|
|
|
} else if (formFactor() == Vertical) {
|
|
|
|
hint.setHeight(size().width());
|
|
|
|
}
|
|
|
|
} else if (d->aspectRatioMode == Plasma::ConstrainedSquare) {
|
|
|
|
//enforce a size not wider than tall
|
|
|
|
if (formFactor() == Horizontal && (which == Qt::MaximumSize || size().height() <= KIconLoader::SizeLarge)) {
|
|
|
|
hint.setWidth(size().height());
|
|
|
|
//enforce a size not taller than wide
|
|
|
|
} else if (formFactor() == Vertical && (which == Qt::MaximumSize || size().width() <= KIconLoader::SizeLarge)) {
|
|
|
|
hint.setHeight(size().width());
|
2008-04-29 22:31:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hint;
|
|
|
|
}
|
|
|
|
|
2008-05-09 01:30:29 +02:00
|
|
|
void Applet::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == d->constraintsTimerId) {
|
2008-05-09 04:35:29 +02:00
|
|
|
killTimer(d->constraintsTimerId);
|
2008-05-09 01:30:29 +02:00
|
|
|
d->constraintsTimerId = 0;
|
|
|
|
flushPendingConstraintsEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-11 19:21:55 +02:00
|
|
|
QRect Applet::screenRect() const
|
|
|
|
{
|
|
|
|
QPointF bottomRight = pos();
|
|
|
|
bottomRight.setX(bottomRight.x() + size().width());
|
|
|
|
bottomRight.setY(bottomRight.y() + size().height());
|
|
|
|
|
2008-05-23 19:21:14 +02:00
|
|
|
Containment *c;
|
|
|
|
c = containment();
|
2008-05-11 19:21:55 +02:00
|
|
|
|
2008-05-23 19:21:14 +02:00
|
|
|
if (c) {
|
|
|
|
QGraphicsView *v;
|
|
|
|
v = c->view();
|
|
|
|
|
|
|
|
if (v) {
|
|
|
|
QPoint tL = v->mapToGlobal(v->mapFromScene(pos()));
|
|
|
|
QPoint bR = v->mapToGlobal(v->mapFromScene(bottomRight));
|
|
|
|
|
|
|
|
return QRect(QPoint(tL.x(), tL.y()), QSize(bR.x() - tL.x(), bR.y() - tL.y()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//The applet isn't in any containment, or in a containment that doesn't have a view on it.
|
|
|
|
//So a screenRect isn't relevant.
|
|
|
|
return QRect(QPoint(0, 0), QSize(0, 0));
|
2008-05-11 19:21:55 +02:00
|
|
|
}
|
|
|
|
|
2008-02-13 02:52:02 +01:00
|
|
|
void Applet::raise()
|
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
setZValue(++AppletPrivate::s_maxZValue);
|
2008-02-13 02:52:02 +01:00
|
|
|
}
|
|
|
|
|
2008-04-23 22:27:44 +02:00
|
|
|
void Applet::lower()
|
|
|
|
{
|
2008-07-01 20:56:43 +02:00
|
|
|
setZValue(--AppletPrivate::s_minZValue);
|
2008-04-23 22:27:44 +02:00
|
|
|
}
|
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
void Applet::setIsContainment(bool isContainment)
|
2007-11-15 10:39:46 +01:00
|
|
|
{
|
2008-04-27 21:05:06 +02:00
|
|
|
if (d->isContainment == isContainment) {
|
2008-04-24 18:29:23 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
d->isContainment = isContainment;
|
2008-04-24 18:29:23 +02:00
|
|
|
|
|
|
|
Containment *c = qobject_cast<Containment*>(this);
|
|
|
|
if (c) {
|
2008-07-06 12:03:10 +02:00
|
|
|
if (isContainment) {
|
|
|
|
// set up the toolbox
|
|
|
|
c->d->createToolBox();
|
|
|
|
} else {
|
|
|
|
delete c->d->toolBox;
|
|
|
|
c->d->toolBox = 0;
|
|
|
|
}
|
2008-04-24 18:29:23 +02:00
|
|
|
}
|
2007-11-15 10:39:46 +01:00
|
|
|
}
|
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
bool Applet::isContainment() const
|
2007-11-15 10:39:46 +01:00
|
|
|
{
|
2008-04-27 21:05:06 +02:00
|
|
|
return d->isContainment;
|
2007-11-15 10:39:46 +01:00
|
|
|
}
|
|
|
|
|
2008-04-30 23:50:43 +02:00
|
|
|
|
|
|
|
// PRIVATE CLASS IMPLEMENTATION
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet)
|
2008-04-30 23:50:43 +02:00
|
|
|
: appletId(uniqueID),
|
|
|
|
q(applet),
|
2008-08-02 13:48:56 +02:00
|
|
|
extender(0),
|
2008-07-01 20:56:43 +02:00
|
|
|
backgroundHints(Applet::StandardBackground),
|
2008-04-30 23:50:43 +02:00
|
|
|
appletDescription(service),
|
|
|
|
package(0),
|
|
|
|
needsConfigOverlay(0),
|
|
|
|
background(0),
|
|
|
|
script(0),
|
|
|
|
configXml(0),
|
|
|
|
mainConfig(0),
|
|
|
|
pendingConstraints(NoConstraint),
|
2008-05-01 00:13:27 +02:00
|
|
|
aspectRatioMode(Plasma::KeepAspectRatio),
|
Initialise variable.
Valgrind rationale:
==18955== Conditional jump or move depends on uninitialised value(s)
==18955== at 0x40E2295: Plasma::Applet::paint(QPainter*, QStyleOptionGraphicsItem const*, QWidget*) (applet.cpp:765)
==18955== by 0x65259FF: _ZL12_q_paintItemP13QGraphicsItemP8QPainterPK24QStyleOptionGraphicsItemP7QWidgetb (qgraphicsscene.cpp:3766)
==18955== by 0x6525AE3: QGraphicsScenePrivate::drawItemHelper(QGraphicsItem*, QPainter*, QStyleOptionGraphicsItem const*, QWidget*) (qgraphicsscene.cpp:3790)
==18955== by 0x652B61E: QGraphicsScene::drawItems(QPainter*, int, QGraphicsItem**, QStyleOptionGraphicsItem const*, QWidget*) (qgraphicsscene.cpp:4015)
==18955== by 0x6541637: QGraphicsView::drawItems(QPainter*, int, QGraphicsItem**, QStyleOptionGraphicsItem const*) (qgraphicsview.cpp:3294)
==18955== by 0x6546C08: QGraphicsView::paintEvent(QPaintEvent*) (qgraphicsview.cpp:3042)
==18955== by 0x5EDD149: QWidget::event(QEvent*) (qwidget.cpp:7082)
==18955== by 0x62D12B1: QFrame::event(QEvent*) (qframe.cpp:627)
==18955== by 0x63804C8: QAbstractScrollArea::viewportEvent(QEvent*) (qabstractscrollarea.cpp:914)
==18955== by 0x6544410: QGraphicsView::viewportEvent(QEvent*) (qgraphicsview.cpp:2299)
==18955== by 0x6383611: QAbstractScrollAreaPrivate::viewportEvent(QEvent*) (qabstractscrollarea_p.h:72)
==18955== by 0x638363F: QAbstractScrollAreaFilter::eventFilter(QObject*, QEvent*) (qabstractscrollarea_p.h:83)
svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=811619
2008-05-23 16:41:55 +02:00
|
|
|
ghostView(0),
|
2008-05-08 06:26:52 +02:00
|
|
|
immutability(Mutable),
|
2008-05-17 05:39:24 +02:00
|
|
|
actions(applet),
|
2008-06-01 04:13:53 +02:00
|
|
|
activationAction(0),
|
2008-05-09 01:30:29 +02:00
|
|
|
constraintsTimerId(0),
|
2008-04-30 23:50:43 +02:00
|
|
|
hasConfigurationInterface(false),
|
|
|
|
failed(false),
|
|
|
|
isContainment(false),
|
|
|
|
transient(false)
|
|
|
|
{
|
|
|
|
if (appletId == 0) {
|
|
|
|
appletId = ++s_maxAppletId;
|
|
|
|
} else if (appletId > s_maxAppletId) {
|
|
|
|
s_maxAppletId = appletId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
AppletPrivate::~AppletPrivate()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
2008-07-29 18:52:44 +02:00
|
|
|
foreach (const QString& engine, loadedEngines) {
|
2008-04-30 23:50:43 +02:00
|
|
|
DataEngineManager::self()->unloadEngine( engine );
|
|
|
|
}
|
|
|
|
delete package;
|
|
|
|
delete configXml;
|
|
|
|
delete mainConfig;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::init()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
2008-07-01 20:56:43 +02:00
|
|
|
q->setCacheMode(Applet::DeviceCoordinateCache);
|
2008-04-30 23:50:43 +02:00
|
|
|
q->setAcceptsHoverEvents(true);
|
|
|
|
q->setFlag(QGraphicsItem::ItemIsFocusable, true);
|
2008-06-09 02:03:25 +02:00
|
|
|
// FIXME: adding here because nothing seems to be doing it in QGraphicsView,
|
|
|
|
// but it doesn't actually work anyways =/
|
|
|
|
q->setLayoutDirection(qApp->layoutDirection());
|
2008-04-30 23:50:43 +02:00
|
|
|
|
|
|
|
if (!appletDescription.isValid()) {
|
2008-06-22 19:29:59 +02:00
|
|
|
kDebug() << "Check your constructor! You probably want to be passing in a Service::Ptr or a QVariantList with a valid storageid as arg[0].";
|
2008-04-30 23:50:43 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString api = appletDescription.property("X-Plasma-API").toString();
|
|
|
|
|
|
|
|
// we have a scripted plasmoid
|
|
|
|
if (!api.isEmpty()) {
|
|
|
|
// find where the Package is
|
|
|
|
QString path = KStandardDirs::locate("data",
|
2008-07-03 07:46:25 +02:00
|
|
|
"plasma/plasmoids/" + appletDescription.pluginName() + "/");
|
2008-04-30 23:50:43 +02:00
|
|
|
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
q->setFailedToLaunch(true, i18n("Could not locate the %1 package required for the %2 widget.",
|
2008-07-03 07:46:25 +02:00
|
|
|
appletDescription.pluginName(), appletDescription.name()));
|
2008-04-30 23:50:43 +02:00
|
|
|
} else {
|
|
|
|
// create the package and see if we have something real
|
|
|
|
//kDebug() << "trying for" << path;
|
|
|
|
PackageStructure::Ptr structure = Plasma::packageStructure(api, Plasma::AppletComponent);
|
|
|
|
structure->setPath(path);
|
|
|
|
package = new Package(path, structure);
|
|
|
|
|
|
|
|
if (package->isValid()) {
|
|
|
|
// now we try and set up the script engine.
|
|
|
|
// it will be parented to this applet and so will get
|
|
|
|
// deleted when the applet does
|
|
|
|
|
|
|
|
script = Plasma::loadScriptEngine(api, q);
|
|
|
|
if (!script) {
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
q->setFailedToLaunch(true, i18n("Could not create a %1 ScriptEngine for the %2 widget.",
|
|
|
|
api, appletDescription.name()));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
q->setFailedToLaunch(true, i18n("Could not open the %1 package required for the %2 widget.",
|
|
|
|
appletDescription.pluginName(), appletDescription.name()));
|
|
|
|
delete package;
|
|
|
|
package = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (package) {
|
|
|
|
setupScriptSupport();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
q->setBackgroundHints(Applet::DefaultBackground);
|
2008-04-30 23:50:43 +02:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
QObject::connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), q, SLOT(themeChanged()));
|
2008-04-30 23:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// put all setup routines for script here. at this point we can assume that
|
|
|
|
// package exists and that we have a script engin
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::setupScriptSupport()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
Q_ASSERT(package);
|
|
|
|
QString xmlPath = package->filePath("mainconfigxml");
|
|
|
|
if (!xmlPath.isEmpty()) {
|
|
|
|
QFile file(xmlPath);
|
|
|
|
// FIXME: KConfigSkeleton doesn't play well with KConfigGroup =/
|
|
|
|
KConfigGroup config = q->config();
|
|
|
|
configXml = new ConfigXml(&config, &file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!package->filePath("mainconfigui").isEmpty()) {
|
|
|
|
q->setHasConfigurationInterface(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
QString AppletPrivate::globalName() const
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletDescription.service()->library();
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
QString AppletPrivate::instanceName()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
if (!appletDescription.isValid()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return appletDescription.service()->library() + QString::number(appletId);
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::scheduleConstraintsUpdate(Plasma::Constraints c)
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
2008-08-19 23:36:52 +02:00
|
|
|
// Don't start up a timer if we're just starting up
|
|
|
|
// flushPendingConstraints will be called by Corona
|
|
|
|
if (!constraintsTimerId && !(c & Plasma::StartupCompletedConstraint)) {
|
2008-05-09 01:30:29 +02:00
|
|
|
constraintsTimerId = q->startTimer(0);
|
2008-04-30 23:50:43 +02:00
|
|
|
}
|
|
|
|
pendingConstraints |= c;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
KConfigGroup* AppletPrivate::mainConfigGroup()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
if (mainConfig) {
|
|
|
|
return mainConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isContainment) {
|
|
|
|
const Containment *asContainment = qobject_cast<Containment*>(const_cast<Applet*>(q));
|
|
|
|
Q_ASSERT(asContainment);
|
|
|
|
|
|
|
|
KConfigGroup containmentConfig;
|
|
|
|
//kDebug() << "got a corona, baby?" << (QObject*)asContainment->corona();
|
|
|
|
if (asContainment->corona()) {
|
|
|
|
containmentConfig = KConfigGroup(asContainment->corona()->config(), "Containments");
|
|
|
|
} else {
|
|
|
|
containmentConfig = KConfigGroup(KGlobal::config(), "Containments");
|
|
|
|
}
|
|
|
|
|
|
|
|
mainConfig = new KConfigGroup(&containmentConfig, QString::number(appletId));
|
|
|
|
} else {
|
|
|
|
KConfigGroup appletConfig;
|
|
|
|
if (q->containment()) {
|
|
|
|
appletConfig = q->containment()->config();
|
|
|
|
appletConfig = KConfigGroup(&appletConfig, "Applets");
|
|
|
|
} else {
|
|
|
|
kWarning() << "requesting config for" << q->name() << "without a containment!";
|
|
|
|
appletConfig = KConfigGroup(KGlobal::config(), "Applets");
|
|
|
|
}
|
|
|
|
|
|
|
|
mainConfig = new KConfigGroup(&appletConfig, QString::number(appletId));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mainConfig;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
QString AppletPrivate::visibleFailureText(const QString& reason)
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
QString text;
|
|
|
|
|
|
|
|
if (reason.isEmpty()) {
|
|
|
|
text = i18n("This object could not be created.");
|
|
|
|
} else {
|
|
|
|
text = i18n("This object could not be created for the following reason:<p><b>%1</b></p>", reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::checkImmutability()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
|
|
|
const bool systemImmutable = q->globalConfig().isImmutable() || q->config().isImmutable() ||
|
|
|
|
((!isContainment && q->containment()) &&
|
|
|
|
q->containment()->immutability() == SystemImmutable) ||
|
|
|
|
(dynamic_cast<Corona*>(q->scene()) && static_cast<Corona*>(q->scene())->immutability() == SystemImmutable);
|
|
|
|
|
|
|
|
if (systemImmutable) {
|
|
|
|
q->updateConstraints(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::themeChanged()
|
2008-04-30 23:50:43 +02:00
|
|
|
{
|
2008-05-24 17:58:40 +02:00
|
|
|
if (background) {
|
2008-05-27 12:57:09 +02:00
|
|
|
//do again the translucent background fallback
|
|
|
|
q->setBackgroundHints(backgroundHints);
|
|
|
|
|
2008-05-24 17:58:40 +02:00
|
|
|
qreal left;
|
|
|
|
qreal right;
|
|
|
|
qreal top;
|
|
|
|
qreal bottom;
|
|
|
|
background->getMargins(left, top, right, bottom);
|
|
|
|
q->setContentsMargins(left, right, top, bottom);
|
|
|
|
}
|
2008-04-30 23:50:43 +02:00
|
|
|
q->update();
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void AppletPrivate::resetConfigurationObject()
|
2008-05-01 05:24:20 +02:00
|
|
|
{
|
|
|
|
mainConfigGroup()->deleteGroup();
|
|
|
|
delete mainConfig;
|
|
|
|
mainConfig = 0;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
uint AppletPrivate::s_maxAppletId = 0;
|
|
|
|
uint AppletPrivate::s_maxZValue = 0;
|
|
|
|
uint AppletPrivate::s_minZValue = 0;
|
|
|
|
PackageStructure::Ptr AppletPrivate::packageStructure(0);
|
2008-04-30 23:50:43 +02:00
|
|
|
|
|
|
|
AppletOverlayWidget::AppletOverlayWidget(QGraphicsWidget *parent)
|
|
|
|
: QGraphicsWidget(parent)
|
|
|
|
{
|
|
|
|
resize(parent->size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppletOverlayWidget::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
painter->save();
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
QColor wash = Plasma::Theme::defaultTheme()->color(Theme::BackgroundColor);
|
|
|
|
wash.setAlphaF(.6);
|
2008-08-19 22:00:40 +02:00
|
|
|
|
|
|
|
Applet *applet = qobject_cast<Applet *>(parentWidget());
|
|
|
|
|
|
|
|
if (applet->backgroundHints() & Applet::StandardBackground) {
|
|
|
|
painter->fillRect(parentWidget()->contentsRect(), wash);
|
|
|
|
} else {
|
|
|
|
painter->fillPath(parentItem()->shape(), wash);
|
|
|
|
}
|
|
|
|
|
2008-04-30 23:50:43 +02:00
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:55:22 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
|
|
|
#include "applet.moc"
|