2007-09-18 23:16:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
2008-04-14 11:36:55 +02:00
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2007-09-18 23:16:17 +02:00
|
|
|
*
|
|
|
|
* 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 "containment.h"
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "private/containment_p.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
2007-12-27 16:03:50 +01:00
|
|
|
#include <QGraphicsView>
|
2007-09-23 20:03:37 +02:00
|
|
|
#include <QMimeData>
|
2007-09-18 23:16:17 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
2008-04-13 15:23:39 +02:00
|
|
|
#include <QGraphicsLayout>
|
|
|
|
#include <QGraphicsLinearLayout>
|
2007-09-18 23:16:17 +02:00
|
|
|
|
2008-06-01 04:13:53 +02:00
|
|
|
#include <KAction>
|
2007-09-20 20:23:28 +02:00
|
|
|
#include <KApplication>
|
2007-09-18 23:16:17 +02:00
|
|
|
#include <KAuthorized>
|
2007-09-20 20:23:28 +02:00
|
|
|
#include <KIcon>
|
2007-09-18 23:16:17 +02:00
|
|
|
#include <KMenu>
|
2008-05-20 06:02:36 +02:00
|
|
|
#include <KMessageBox>
|
2007-09-23 20:03:37 +02:00
|
|
|
#include <KMimeType>
|
2007-09-18 23:16:17 +02:00
|
|
|
#include <KRun>
|
2007-09-20 20:30:40 +02:00
|
|
|
#include <KServiceTypeTrader>
|
2007-10-25 13:20:23 +02:00
|
|
|
#include <KStandardDirs>
|
2008-08-21 12:07:07 +02:00
|
|
|
#include <KTemporaryFile>
|
2008-03-05 08:08:32 +01:00
|
|
|
#include <KWindowSystem>
|
2007-09-18 23:16:17 +02:00
|
|
|
|
2008-04-25 05:23:31 +02:00
|
|
|
#include "animator.h"
|
2008-08-18 16:04:30 +02:00
|
|
|
#include "context.h"
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "corona.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "svg.h"
|
2008-08-05 17:27:48 +02:00
|
|
|
#include "wallpaper.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
|
2008-07-30 22:35:42 +02:00
|
|
|
#include "private/applet_p.h"
|
|
|
|
#include "private/applethandle_p.h"
|
|
|
|
#include "private/desktoptoolbox_p.h"
|
|
|
|
#include "private/paneltoolbox_p.h"
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-02-23 00:41:44 +01:00
|
|
|
Containment::StyleOption::StyleOption()
|
|
|
|
: QStyleOptionGraphicsItem(),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(0)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
2008-07-04 21:24:45 +02:00
|
|
|
version = Version;
|
|
|
|
type = Type;
|
2008-02-23 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const Containment::StyleOption & other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(other.view)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
2008-07-04 21:24:45 +02:00
|
|
|
version = Version;
|
|
|
|
type = Type;
|
2008-02-23 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const QStyleOptionGraphicsItem &other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(0)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
2008-07-04 21:24:45 +02:00
|
|
|
version = Version;
|
|
|
|
type = Type;
|
2008-02-23 00:41:44 +01:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
Containment::Containment(QGraphicsItem* parent,
|
|
|
|
const QString& serviceId,
|
|
|
|
uint containmentId)
|
|
|
|
: Applet(parent, serviceId, containmentId),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ContainmentPrivate(this))
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2007-11-27 07:08:44 +01:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
2008-03-14 18:05:37 +01:00
|
|
|
setPos(0, 0);
|
2008-04-27 22:35:23 +02:00
|
|
|
setBackgroundHints(NoBackground);
|
2007-11-29 01:20:37 +01:00
|
|
|
setContainmentType(CustomContainment);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::Containment(QObject* parent, const QVariantList& args)
|
|
|
|
: Applet(parent, args),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ContainmentPrivate(this))
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2007-11-27 07:08:44 +01:00
|
|
|
// WARNING: do not access config() OR globalConfig() in this method!
|
|
|
|
// that requires a scene, which is not available at this point
|
2008-03-14 18:05:37 +01:00
|
|
|
setPos(0, 0);
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(NoBackground);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::~Containment()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::init()
|
|
|
|
{
|
2008-08-21 09:49:46 +02:00
|
|
|
if (!isContainment()) {
|
|
|
|
return;
|
2008-06-16 21:10:38 +02:00
|
|
|
}
|
2008-08-21 09:49:46 +02:00
|
|
|
|
|
|
|
setCacheMode(NoCache);
|
|
|
|
setFlag(QGraphicsItem::ItemIsMovable, false);
|
2007-10-17 19:35:48 +02:00
|
|
|
setFlag(QGraphicsItem::ItemClipsChildrenToShape, false);
|
2007-09-23 20:03:37 +02:00
|
|
|
setAcceptDrops(true);
|
2007-11-09 01:44:35 +01:00
|
|
|
setAcceptsHoverEvents(true);
|
2007-10-09 18:33:52 +02:00
|
|
|
|
2008-04-25 05:11:59 +02:00
|
|
|
//TODO: would be nice to not do this on init, as it causes Animator to init
|
|
|
|
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
2008-05-24 19:13:19 +02:00
|
|
|
this, SLOT(containmentAppletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
2007-11-19 03:14:18 +01:00
|
|
|
|
2007-11-29 01:20:37 +01:00
|
|
|
if (d->type == NoContainmentType) {
|
|
|
|
setContainmentType(DesktopContainment);
|
2007-11-19 02:19:58 +01:00
|
|
|
}
|
2008-03-06 01:40:09 +01:00
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
//common actions
|
|
|
|
bool unlocked = immutability() == Mutable;
|
|
|
|
|
|
|
|
QAction *appletBrowserAction = new QAction(i18n("Add Widgets..."), this);
|
|
|
|
appletBrowserAction->setIcon(KIcon("list-add"));
|
|
|
|
appletBrowserAction->setVisible(unlocked);
|
|
|
|
appletBrowserAction->setEnabled(unlocked);
|
|
|
|
connect(appletBrowserAction, SIGNAL(triggered()), this, SLOT(triggerShowAddWidgets()));
|
2008-08-02 01:25:24 +02:00
|
|
|
appletBrowserAction->setShortcutContext(Qt::WidgetShortcut);
|
2008-05-17 05:39:24 +02:00
|
|
|
appletBrowserAction->setShortcut(QKeySequence("ctrl+a"));
|
|
|
|
d->actions().addAction("add widgets", appletBrowserAction);
|
|
|
|
|
|
|
|
QAction *action = new QAction(i18n("Next Applet"), this);
|
|
|
|
//no icon
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(focusNextApplet()));
|
2008-08-02 01:25:24 +02:00
|
|
|
action->setShortcutContext(Qt::WidgetShortcut);
|
2008-05-17 05:39:24 +02:00
|
|
|
action->setShortcut(QKeySequence("ctrl+n"));
|
|
|
|
d->actions().addAction("next applet", action);
|
|
|
|
|
|
|
|
action = new QAction(i18n("Previous Applet"), this);
|
|
|
|
//no icon
|
|
|
|
connect(action, SIGNAL(triggered()), this, SLOT(focusPreviousApplet()));
|
2008-08-02 01:25:24 +02:00
|
|
|
action->setShortcutContext(Qt::WidgetShortcut);
|
2008-05-17 05:39:24 +02:00
|
|
|
action->setShortcut(QKeySequence("ctrl+p"));
|
|
|
|
d->actions().addAction("previous applet", action);
|
|
|
|
|
|
|
|
if (immutability() != SystemImmutable) {
|
|
|
|
//FIXME I'm not certain this belongs in Containment
|
|
|
|
//but it sure is nice to have the keyboard shortcut in every containment by default
|
|
|
|
QAction *lockDesktopAction = new QAction(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets"), this);
|
2008-05-18 21:58:33 +02:00
|
|
|
lockDesktopAction->setIcon(KIcon(unlocked ? "object-locked" : "object-unlocked"));
|
2008-05-17 05:39:24 +02:00
|
|
|
connect(lockDesktopAction, SIGNAL(triggered(bool)), this, SLOT(toggleDesktopImmutability()));
|
2008-08-02 01:25:24 +02:00
|
|
|
lockDesktopAction->setShortcutContext(Qt::WidgetShortcut);
|
2008-05-17 05:39:24 +02:00
|
|
|
lockDesktopAction->setShortcut(QKeySequence("ctrl+l"));
|
|
|
|
d->actions().addAction("lock widgets", lockDesktopAction);
|
|
|
|
}
|
|
|
|
|
2008-07-06 11:49:23 +02:00
|
|
|
if (d->type != PanelContainment &&
|
|
|
|
d->type != CustomPanelContainment) {
|
2008-05-17 05:39:24 +02:00
|
|
|
QAction *zoomAction = new QAction(i18n("Zoom In"), this);
|
|
|
|
zoomAction->setIcon(KIcon("zoom-in"));
|
|
|
|
connect(zoomAction, SIGNAL(triggered(bool)), this, SLOT(zoomIn()));
|
2008-08-02 01:25:24 +02:00
|
|
|
zoomAction->setShortcutContext(Qt::WidgetShortcut);
|
2008-06-02 06:26:54 +02:00
|
|
|
//two shortcuts because I hate ctrl-+ but others expect it
|
|
|
|
QList<QKeySequence> keys;
|
|
|
|
keys << QKeySequence(QKeySequence::ZoomIn);
|
2008-06-30 16:41:31 +02:00
|
|
|
keys << QKeySequence("ctrl+=");
|
2008-06-02 06:26:54 +02:00
|
|
|
zoomAction->setShortcuts(keys);
|
2008-05-17 05:39:24 +02:00
|
|
|
d->actions().addAction("zoom in", zoomAction);
|
|
|
|
|
|
|
|
zoomAction = new QAction(i18n("Zoom Out"), this);
|
|
|
|
zoomAction->setIcon(KIcon("zoom-out"));
|
|
|
|
connect(zoomAction, SIGNAL(triggered(bool)), this, SLOT(zoomOut()));
|
2008-08-02 01:25:24 +02:00
|
|
|
zoomAction->setShortcutContext(Qt::WidgetShortcut);
|
2008-06-02 06:26:54 +02:00
|
|
|
zoomAction->setShortcut(QKeySequence(QKeySequence::ZoomOut));
|
2008-05-17 05:39:24 +02:00
|
|
|
d->actions().addAction("zoom out", zoomAction);
|
2008-05-24 03:48:36 +02:00
|
|
|
|
2008-05-24 06:34:27 +02:00
|
|
|
QAction *activityAction = new QAction(i18n("Add Activity"), this);
|
|
|
|
activityAction->setIcon(KIcon("list-add"));
|
|
|
|
activityAction->setVisible(unlocked);
|
|
|
|
activityAction->setEnabled(unlocked);
|
|
|
|
connect(activityAction, SIGNAL(triggered(bool)), this, SLOT(addSiblingContainment()));
|
2008-08-02 01:25:24 +02:00
|
|
|
activityAction->setShortcutContext(Qt::WidgetShortcut);
|
2008-05-24 06:34:27 +02:00
|
|
|
activityAction->setShortcut(QKeySequence("ctrl+shift+a"));
|
2008-07-01 20:23:39 +02:00
|
|
|
d->actions().addAction("add sibling containment", activityAction);
|
2008-05-24 06:34:27 +02:00
|
|
|
|
2008-07-22 22:46:34 +02:00
|
|
|
if (d->type == DesktopContainment && d->toolBox) {
|
2008-06-30 16:41:31 +02:00
|
|
|
d->toolBox->addTool(this->action("add widgets"));
|
|
|
|
d->toolBox->addTool(this->action("zoom in"));
|
|
|
|
d->toolBox->addTool(this->action("zoom out"));
|
|
|
|
if (immutability() != SystemImmutable) {
|
|
|
|
d->toolBox->addTool(this->action("lock widgets"));
|
|
|
|
}
|
2008-07-01 20:23:39 +02:00
|
|
|
d->toolBox->addTool(this->action("add sibling containment"));
|
2008-05-24 03:48:36 +02:00
|
|
|
}
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 00:18:07 +02:00
|
|
|
// helper function for sorting the list of applets
|
|
|
|
bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2)
|
|
|
|
{
|
|
|
|
QPointF p1 = c1.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
QPointF p2 = c2.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
if (p1.x() != p2.x()) {
|
|
|
|
return p1.x() < p2.x();
|
|
|
|
}
|
|
|
|
return p1.y() < p2.y();
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
void Containment::restore(KConfigGroup &group)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2008-05-22 17:53:48 +02:00
|
|
|
/*kDebug() << "!!!!!!!!!!!!initConstraints" << group.name() << containmentType();
|
|
|
|
kDebug() << " location:" << group.readEntry("location", (int)d->location);
|
|
|
|
kDebug() << " geom:" << group.readEntry("geometry", geometry());
|
|
|
|
kDebug() << " formfactor:" << group.readEntry("formfactor", (int)d->formFactor);
|
|
|
|
kDebug() << " screen:" << group.readEntry("screen", d->screen);*/
|
|
|
|
if (!isContainment()) {
|
|
|
|
Applet::restore(group);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-22 19:56:59 +01:00
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
QRectF geo = group.readEntry("geometry", geometry());
|
2008-03-22 19:56:59 +01:00
|
|
|
//override max/min
|
2008-05-22 04:23:33 +02:00
|
|
|
//this ensures panels are set to their saved size even when they have max & min set to prevent
|
|
|
|
//resizing
|
2008-03-22 19:56:59 +01:00
|
|
|
if (geo.size() != geo.size().boundedTo(maximumSize())) {
|
|
|
|
setMaximumSize(maximumSize().expandedTo(geo.size()));
|
|
|
|
}
|
|
|
|
if (geo.size() != geo.size().expandedTo(minimumSize())) {
|
|
|
|
setMinimumSize(minimumSize().boundedTo(geo.size()));
|
|
|
|
}
|
|
|
|
setGeometry(geo);
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
setLocation((Plasma::Location)group.readEntry("location", (int)d->location));
|
|
|
|
setFormFactor((Plasma::FormFactor)group.readEntry("formfactor", (int)d->formFactor));
|
|
|
|
setScreen(group.readEntry("screen", d->screen));
|
2008-08-20 15:13:31 +02:00
|
|
|
setActivity(group.readEntry("activity", QString()));
|
2008-04-25 00:18:07 +02:00
|
|
|
|
2008-04-26 19:13:59 +02:00
|
|
|
flushPendingConstraintsEvents();
|
2008-05-22 17:53:48 +02:00
|
|
|
restoreContents(group);
|
|
|
|
setImmutability((ImmutabilityType)group.readEntry("immutability", (int)Mutable));
|
2008-08-05 17:27:48 +02:00
|
|
|
|
2008-08-20 10:06:34 +02:00
|
|
|
setWallpaper(group.readEntry("wallpaperplugin", "image"),
|
|
|
|
group.readEntry("wallpaperpluginmode", "SingleImage"));
|
|
|
|
/*
|
|
|
|
kDebug() << "Containment" << id() <<
|
|
|
|
"screen" << screen() <<
|
|
|
|
"geometry is" << geometry() <<
|
|
|
|
"wallpaper" << ((d->wallpaper) ? d->wallpaper->pluginName() : QString()) <<
|
|
|
|
"wallpaper mode" << wallpaperMode() <<
|
|
|
|
"config entries" << group.entryMap();
|
|
|
|
*/
|
2008-05-22 17:53:48 +02:00
|
|
|
}
|
|
|
|
|
2008-07-07 04:16:08 +02:00
|
|
|
void Containment::save(KConfigGroup &g) const
|
2008-05-22 17:53:48 +02:00
|
|
|
{
|
2008-07-07 04:16:08 +02:00
|
|
|
KConfigGroup group = g;
|
|
|
|
if (!group.isValid()) {
|
|
|
|
group = config();
|
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
// locking is saved in Applet::save
|
|
|
|
Applet::save(group);
|
|
|
|
group.writeEntry("screen", d->screen);
|
|
|
|
group.writeEntry("formfactor", (int)d->formFactor);
|
|
|
|
group.writeEntry("location", (int)d->location);
|
2008-08-20 15:13:31 +02:00
|
|
|
group.writeEntry("activity", d->activity);
|
2008-08-20 14:45:19 +02:00
|
|
|
|
|
|
|
if (d->wallpaper) {
|
|
|
|
group.writeEntry("wallpaperplugin", d->wallpaper->pluginName());
|
|
|
|
group.writeEntry("wallpaperpluginmode", d->wallpaper->renderingMode().name());
|
2008-08-20 15:13:31 +02:00
|
|
|
KConfigGroup wallpaperConfig(&group, "Wallpaper");
|
|
|
|
d->wallpaper->save(wallpaperConfig);
|
2008-08-20 14:45:19 +02:00
|
|
|
}
|
|
|
|
|
2008-05-22 17:53:48 +02:00
|
|
|
saveContents(group);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::saveContents(KConfigGroup &group) const
|
|
|
|
{
|
|
|
|
KConfigGroup applets(&group, "Applets");
|
|
|
|
foreach (const Applet* applet, d->applets) {
|
|
|
|
KConfigGroup appletConfig(&applets, QString::number(applet->id()));
|
|
|
|
applet->save(appletConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::restoreContents(KConfigGroup &group)
|
|
|
|
{
|
|
|
|
KConfigGroup applets(&group, "Applets");
|
2008-04-25 00:18:07 +02:00
|
|
|
|
|
|
|
// Sort the applet configs in order of geometry to ensure that applets
|
|
|
|
// are added from left to right or top to bottom for a panel containment
|
|
|
|
QList<KConfigGroup> appletConfigs;
|
|
|
|
foreach (const QString &appletGroup, applets.groupList()) {
|
|
|
|
//kDebug() << "reading from applet group" << appletGroup;
|
|
|
|
KConfigGroup appletConfig(&applets, appletGroup);
|
|
|
|
appletConfigs.append(appletConfig);
|
|
|
|
}
|
|
|
|
qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
|
|
|
|
|
|
|
foreach (KConfigGroup appletConfig, appletConfigs) {
|
|
|
|
int appId = appletConfig.name().toUInt();
|
|
|
|
QString plugin = appletConfig.readEntry("plugin", QString());
|
|
|
|
|
|
|
|
if (plugin.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = d->addApplet(plugin, QVariantList(), appletConfig.readEntry("geometry", QRectF()), appId, true);
|
2008-05-22 17:53:48 +02:00
|
|
|
applet->restore(appletConfig);
|
2008-04-25 00:18:07 +02:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2007-11-19 02:35:10 +01:00
|
|
|
Containment::Type Containment::containmentType() const
|
2007-10-09 18:33:52 +02:00
|
|
|
{
|
2007-11-28 22:46:17 +01:00
|
|
|
return d->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setContainmentType(Containment::Type type)
|
|
|
|
{
|
2008-07-06 11:49:23 +02:00
|
|
|
if (d->type == type) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete d->toolBox;
|
|
|
|
d->toolBox = 0;
|
2007-11-28 22:46:17 +01:00
|
|
|
d->type = type;
|
2007-11-29 01:20:37 +01:00
|
|
|
|
2008-07-06 11:49:23 +02:00
|
|
|
if (!isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-06 12:03:10 +02:00
|
|
|
if ((type == DesktopContainment || type == PanelContainment)) {
|
|
|
|
d->createToolBox();
|
2008-04-13 15:23:39 +02:00
|
|
|
}
|
2007-10-09 18:33:52 +02:00
|
|
|
}
|
|
|
|
|
2007-11-09 01:44:35 +01:00
|
|
|
Corona* Containment::corona() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<Corona*>(scene());
|
|
|
|
}
|
|
|
|
|
2008-08-06 03:59:44 +02:00
|
|
|
void Containment::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->wallpaper) {
|
|
|
|
QGraphicsItem* item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
|
|
|
d->wallpaper->mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->wallpaper) {
|
|
|
|
QGraphicsItem* item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
|
|
|
d->wallpaper->mousePressEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::mousePressEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->wallpaper) {
|
|
|
|
QGraphicsItem* item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
|
|
|
d->wallpaper->mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::mouseReleaseEvent(event);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "let's see if we manage to get a context menu here, huh";
|
2008-04-27 21:05:06 +02:00
|
|
|
if (!isContainment() || !scene() || !KAuthorized::authorizeKAction("desktop_contextmenu")) {
|
2007-12-27 16:14:51 +01:00
|
|
|
Applet::contextMenuEvent(event);
|
2007-09-18 23:16:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF point = event->scenePos();
|
|
|
|
QGraphicsItem* item = scene()->itemAt(point);
|
|
|
|
if (item == this) {
|
|
|
|
item = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet* applet = 0;
|
|
|
|
|
|
|
|
while (item) {
|
|
|
|
applet = qgraphicsitem_cast<Applet*>(item);
|
2008-04-27 21:05:06 +02:00
|
|
|
if (applet && !applet->isContainment()) {
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-03 01:51:15 +01:00
|
|
|
// applet may have a value due to finding a containment!
|
|
|
|
applet = 0;
|
2007-09-18 23:16:17 +02:00
|
|
|
item = item->parentItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
KMenu desktopMenu;
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "context menu event " << (QObject*)applet;
|
2008-01-25 02:41:16 +01:00
|
|
|
if (applet) {
|
|
|
|
bool hasEntries = false;
|
2007-10-07 23:53:20 +02:00
|
|
|
|
2008-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> actions = applet->contextualActions();
|
2008-01-25 02:41:16 +01:00
|
|
|
if (!actions.isEmpty()) {
|
|
|
|
foreach(QAction* action, actions) {
|
2008-06-13 18:51:25 +02:00
|
|
|
if (action) {
|
|
|
|
desktopMenu.addAction(action);
|
|
|
|
}
|
2008-01-25 02:41:16 +01:00
|
|
|
}
|
|
|
|
hasEntries = true;
|
2007-10-07 23:53:20 +02:00
|
|
|
}
|
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
if (applet->hasConfigurationInterface()) {
|
2008-05-17 05:39:24 +02:00
|
|
|
QAction* configureApplet = applet->d->actions.action("configure");
|
|
|
|
if (configureApplet) {
|
|
|
|
desktopMenu.addAction(configureApplet);
|
|
|
|
hasEntries = true;
|
|
|
|
}
|
2007-11-22 06:11:06 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> containmentActions = contextualActions();
|
2008-03-30 01:57:36 +01:00
|
|
|
if (!containmentActions.isEmpty()) {
|
2008-03-07 13:43:17 +01:00
|
|
|
if (hasEntries) {
|
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
2008-06-13 18:51:25 +02:00
|
|
|
|
2008-02-05 19:27:01 +01:00
|
|
|
hasEntries = true;
|
|
|
|
QMenu *containmentActionMenu = &desktopMenu;
|
|
|
|
|
2008-03-30 01:57:36 +01:00
|
|
|
if (!actions.isEmpty() && containmentActions.count() > 2) {
|
2008-02-05 19:27:01 +01:00
|
|
|
containmentActionMenu = new KMenu(i18n("%1 Options", name()), &desktopMenu);
|
|
|
|
desktopMenu.addMenu(containmentActionMenu);
|
|
|
|
}
|
|
|
|
|
2008-06-13 18:51:25 +02:00
|
|
|
foreach (QAction* action, containmentActions) {
|
|
|
|
if (action) {
|
|
|
|
containmentActionMenu->addAction(action);
|
|
|
|
}
|
2008-02-05 19:27:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
if (scene() && static_cast<Corona*>(scene())->immutability() == Mutable) {
|
2008-01-25 02:41:16 +01:00
|
|
|
if (hasEntries) {
|
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
QAction* closeApplet = applet->d->actions.action("remove");
|
2008-06-04 20:20:58 +02:00
|
|
|
if (!closeApplet) { //unlikely but not impossible
|
2008-06-13 07:23:02 +02:00
|
|
|
kDebug() << "no remove action!!!!!!!!";
|
2008-05-17 05:39:24 +02:00
|
|
|
closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
|
|
|
|
closeApplet->setIcon(KIcon("edit-delete"));
|
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), applet, SLOT(destroy()));
|
|
|
|
}
|
2007-11-22 06:11:06 +01:00
|
|
|
desktopMenu.addAction(closeApplet);
|
|
|
|
hasEntries = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasEntries) {
|
2007-12-27 16:19:01 +01:00
|
|
|
Applet::contextMenuEvent(event);
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "no entries";
|
2007-11-22 06:11:06 +01:00
|
|
|
return;
|
2007-11-18 23:02:01 +01:00
|
|
|
}
|
2008-01-25 02:41:16 +01:00
|
|
|
} else {
|
2008-05-08 06:26:52 +02:00
|
|
|
if (!scene() || (static_cast<Corona*>(scene())->immutability() != Mutable && !KAuthorized::authorizeKAction("unlock_desktop"))) {
|
2008-01-25 02:41:16 +01:00
|
|
|
//kDebug() << "immutability";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> actions = contextualActions();
|
2008-01-25 02:41:16 +01:00
|
|
|
|
|
|
|
if (actions.count() < 1) {
|
|
|
|
//kDebug() << "no applet, but no actions";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-13 18:51:25 +02:00
|
|
|
foreach (QAction* action, actions) {
|
|
|
|
if (action) {
|
|
|
|
desktopMenu.addAction(action);
|
|
|
|
}
|
2008-01-25 02:41:16 +01:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "executing at" << event->screenPos();
|
2007-10-18 11:52:59 +02:00
|
|
|
desktopMenu.exec(event->screenPos());
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setFormFactor(FormFactor formFactor)
|
|
|
|
{
|
2007-11-11 00:19:05 +01:00
|
|
|
if (d->formFactor == formFactor && layout()) {
|
2007-09-18 23:16:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "switching FF to " << formFactor;
|
2008-03-12 16:23:33 +01:00
|
|
|
FormFactor was = d->formFactor;
|
2007-09-18 23:16:17 +02:00
|
|
|
d->formFactor = formFactor;
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-07-06 11:49:23 +02:00
|
|
|
if (isContainment() &&
|
|
|
|
was != formFactor &&
|
|
|
|
(d->type == PanelContainment ||
|
|
|
|
d->type == CustomPanelContainment)) {
|
2008-03-14 18:05:37 +01:00
|
|
|
// we are a panel and we have chaged our orientation
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionPanel(true);
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
void Containment::setLocation(Location location)
|
|
|
|
{
|
|
|
|
if (d->location == location) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-03-05 01:06:22 +01:00
|
|
|
bool emitGeomChange = false;
|
|
|
|
|
|
|
|
if ((location == TopEdge || location == BottomEdge) &&
|
|
|
|
(d->location == TopEdge || d->location == BottomEdge)) {
|
|
|
|
emitGeomChange = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((location == RightEdge || location == LeftEdge) &&
|
|
|
|
(d->location == RightEdge || d->location == LeftEdge)) {
|
|
|
|
emitGeomChange = true;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
d->location = location;
|
|
|
|
|
|
|
|
foreach (Applet* applet, d->applets) {
|
2007-10-02 01:24:38 +02:00
|
|
|
applet->updateConstraints(Plasma::LocationConstraint);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
2007-10-02 01:24:38 +02:00
|
|
|
|
2008-03-05 01:06:22 +01:00
|
|
|
if (emitGeomChange) {
|
|
|
|
// our geometry on the scene will not actually change,
|
|
|
|
// but for the purposes of views it has
|
|
|
|
emit geometryChanged();
|
|
|
|
}
|
|
|
|
|
2007-10-02 01:24:38 +02:00
|
|
|
updateConstraints(Plasma::LocationConstraint);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-14 11:23:35 +02:00
|
|
|
void Containment::addSiblingContainment()
|
|
|
|
{
|
|
|
|
emit addSiblingContainment(this);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
void Containment::clearApplets()
|
|
|
|
{
|
2008-06-04 21:04:34 +02:00
|
|
|
foreach (Applet *applet, d->applets) {
|
|
|
|
applet->d->cleanUpAndDelete();
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
d->applets.clear();
|
|
|
|
}
|
|
|
|
|
2008-04-25 00:18:07 +02:00
|
|
|
Applet* Containment::addApplet(const QString& name, const QVariantList& args, const QRectF &appletGeometry)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2008-04-25 00:18:07 +02:00
|
|
|
return d->addApplet(name, args, appletGeometry);
|
|
|
|
}
|
|
|
|
|
2008-02-18 00:02:09 +01:00
|
|
|
void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
2008-02-03 14:09:21 +01:00
|
|
|
{
|
2008-05-08 06:26:52 +02:00
|
|
|
if (!delayInit && immutability() != Mutable) {
|
2008-02-18 00:02:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "adding null applet!?!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-07 04:16:08 +02:00
|
|
|
if (d->applets.contains(applet)) {
|
|
|
|
kDebug() << "already have this applet!";
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
Containment *currentContainment = applet->containment();
|
|
|
|
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
//panels don't want backgrounds, which is important when setting geometry
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(NoBackground);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentContainment && currentContainment != this) {
|
2008-06-17 23:54:43 +02:00
|
|
|
emit currentContainment->appletRemoved(applet);
|
2008-02-03 14:09:21 +01:00
|
|
|
applet->removeSceneEventFilter(currentContainment);
|
|
|
|
KConfigGroup oldConfig = applet->config();
|
|
|
|
currentContainment->d->applets.removeAll(applet);
|
2008-05-19 18:20:27 +02:00
|
|
|
if (currentContainment->d->handles.contains(applet)) {
|
|
|
|
currentContainment->d->handles.remove(applet);
|
|
|
|
}
|
2008-04-15 04:38:48 +02:00
|
|
|
applet->setParentItem(this);
|
2008-02-29 18:50:57 +01:00
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
// now move the old config to the new location
|
|
|
|
KConfigGroup c = config().group("Applets").group(QString::number(applet->id()));
|
|
|
|
oldConfig.reparent(&c);
|
2008-05-01 05:24:20 +02:00
|
|
|
applet->d->resetConfigurationObject();
|
2008-02-03 14:09:21 +01:00
|
|
|
} else {
|
2008-05-19 18:20:27 +02:00
|
|
|
applet->setParentItem(this);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->applets << applet;
|
|
|
|
|
2008-07-07 04:16:08 +02:00
|
|
|
connect(applet, SIGNAL(configNeedsSaving()), this, SIGNAL(configNeedsSaving()));
|
|
|
|
connect(applet, SIGNAL(releaseVisualFocus()), this, SIGNAL(releaseVisualFocus()));
|
2008-04-25 01:07:21 +02:00
|
|
|
connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*)));
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 01:07:21 +02:00
|
|
|
if (pos != QPointF(-1, -1)) {
|
|
|
|
applet->setPos(pos);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
2008-02-18 00:02:09 +01:00
|
|
|
|
2007-11-28 00:19:02 +01:00
|
|
|
if (delayInit) {
|
2008-03-20 00:26:21 +01:00
|
|
|
if (containmentType() == DesktopContainment) {
|
2007-11-28 00:23:38 +01:00
|
|
|
applet->installSceneEventFilter(this);
|
2008-06-04 20:20:58 +02:00
|
|
|
//applet->setWindowFlags(Qt::Window);
|
2007-11-28 00:23:38 +01:00
|
|
|
}
|
2007-11-28 00:19:02 +01:00
|
|
|
} else {
|
2007-09-18 23:16:17 +02:00
|
|
|
applet->init();
|
2008-04-25 05:11:59 +02:00
|
|
|
Animator::self()->animateItem(applet, Animator::AppearAnimation);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-08-20 15:13:31 +02:00
|
|
|
applet->updateConstraints(Plasma::AllConstraints);
|
|
|
|
|
|
|
|
if (!currentContainment) {
|
|
|
|
applet->updateConstraints(Plasma::StartupCompletedConstraint);
|
|
|
|
}
|
|
|
|
|
2007-12-29 17:26:36 +01:00
|
|
|
if (!delayInit) {
|
2008-04-26 19:13:59 +02:00
|
|
|
applet->flushPendingConstraintsEvents();
|
2007-12-29 17:26:36 +01:00
|
|
|
}
|
2008-04-25 01:07:21 +02:00
|
|
|
|
|
|
|
emit appletAdded(applet, pos);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Applet::List Containment::applets() const
|
|
|
|
{
|
|
|
|
return d->applets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setScreen(int screen)
|
|
|
|
{
|
2007-10-26 01:09:02 +02:00
|
|
|
// screen of -1 means no associated screen.
|
2008-07-07 00:43:53 +02:00
|
|
|
if (d->type == DesktopContainment || d->type == CustomContainment) {
|
2008-04-01 18:24:15 +02:00
|
|
|
#ifndef Q_OS_WIN
|
2008-03-05 08:08:32 +01:00
|
|
|
// we want to listen to changes in work area if our screen changes
|
|
|
|
if (d->screen < 0 && screen > -1) {
|
2008-05-24 14:25:56 +02:00
|
|
|
connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2008-03-05 08:08:32 +01:00
|
|
|
} else if (screen < 0) {
|
2008-05-24 14:25:56 +02:00
|
|
|
disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2008-03-05 08:08:32 +01:00
|
|
|
}
|
2008-04-01 18:24:15 +02:00
|
|
|
#endif
|
2008-03-05 08:08:32 +01:00
|
|
|
if (screen > -1 && corona()) {
|
2008-03-12 16:23:33 +01:00
|
|
|
// sanity check to make sure someone else doesn't have this screen already!
|
2008-03-05 08:08:32 +01:00
|
|
|
Containment* currently = corona()->containmentForScreen(screen);
|
|
|
|
if (currently && currently != this) {
|
|
|
|
//kDebug() << "currently is on screen" << currently->screen() << "and is" << currently->name() << (QObject*)currently << (QObject*)this;
|
|
|
|
currently->setScreen(-1);
|
|
|
|
}
|
2007-11-17 21:50:57 +01:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 01:09:02 +02:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "setting screen to" << screen << "and we are a" << containmentType();
|
2007-11-09 01:44:35 +01:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
int numScreens = desktop->numScreens();
|
2007-11-27 09:47:46 +01:00
|
|
|
if (screen < -1) {
|
2007-09-18 23:16:17 +02:00
|
|
|
screen = -1;
|
|
|
|
}
|
2008-03-03 15:40:02 +01:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "setting screen to " << screen << "and type is" << containmentType();
|
2007-11-27 09:47:46 +01:00
|
|
|
if (screen < numScreens && screen > -1) {
|
2008-03-12 16:23:33 +01:00
|
|
|
if (containmentType() == DesktopContainment ||
|
2008-04-24 18:16:50 +02:00
|
|
|
containmentType() >= CustomContainment) {
|
2008-03-14 18:05:37 +01:00
|
|
|
resize(desktop->screenGeometry(screen).size());
|
2007-10-26 01:09:02 +02:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-03-12 21:41:03 +01:00
|
|
|
int oldScreen = d->screen;
|
2007-09-18 23:16:17 +02:00
|
|
|
d->screen = screen;
|
2007-10-02 01:24:38 +02:00
|
|
|
updateConstraints(Plasma::ScreenConstraint);
|
2008-03-16 08:20:42 +01:00
|
|
|
if (oldScreen != screen) {
|
|
|
|
emit screenChanged(oldScreen, screen, this);
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
int Containment::screen() const
|
2008-03-14 18:05:37 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
return d->screen;
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
QPoint Containment::effectiveScreenPos() const
|
|
|
|
{
|
|
|
|
if (d->screen < 0) {
|
|
|
|
return QPoint();
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
QRect r = QApplication::desktop()->screenGeometry(d->screen);
|
2008-07-06 11:49:23 +02:00
|
|
|
if (containmentType() == PanelContainment ||
|
|
|
|
containmentType() == CustomPanelContainment) {
|
2008-04-25 20:44:09 +02:00
|
|
|
QRectF p = geometry();
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
switch (d->location) {
|
|
|
|
case TopEdge:
|
|
|
|
return QPoint(r.left() + p.x(), r.top());
|
|
|
|
break;
|
|
|
|
case BottomEdge:
|
|
|
|
return QPoint(r.left() + p.x(), r.bottom() - p.height());
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
return QPoint(r.left(), r.top() + (p.bottom() + INTER_CONTAINMENT_MARGIN));
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
return QPoint(r.right() - p.width(), r.top() + (p.bottom() + INTER_CONTAINMENT_MARGIN));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//FIXME: implement properly for Floating!
|
|
|
|
return p.topLeft().toPoint();
|
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
} else {
|
|
|
|
//NOTE: if we ever support non-origin'd desktop containments
|
|
|
|
// this assumption here will have to change
|
|
|
|
return r.topLeft();
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KPluginInfo::List Containment::listContainments(const QString &category,
|
|
|
|
const QString &parentApp)
|
|
|
|
{
|
|
|
|
QString constraint;
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
|
|
|
if (category == "Miscellaneous") {
|
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
//kDebug() << "constraint was" << constraint << "which got us" << offers.count() << "matches";
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KPluginInfo::List Containment::listContainmentsForMimetype(const QString &mimetype)
|
|
|
|
{
|
2008-05-24 09:47:20 +02:00
|
|
|
QString constraint = QString("'%1' in [X-Plasma-DropMimeTypes]").arg(mimetype);
|
2008-04-25 20:44:09 +02:00
|
|
|
//kDebug() << mimetype << constraint;
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2007-09-20 20:30:40 +02:00
|
|
|
|
2008-06-13 18:21:59 +02:00
|
|
|
void Containment::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-06-13 18:51:25 +02:00
|
|
|
//kDebug() << immutability() << Mutable << (immutability() == Mutable);
|
2008-06-13 18:21:59 +02:00
|
|
|
event->setAccepted(immutability() == Mutable &&
|
|
|
|
(event->mimeData()->hasFormat(static_cast<Corona*>(scene())->appletMimeType()) ||
|
|
|
|
KUrl::List::canDecode(event->mimeData())));
|
2008-08-21 12:07:07 +02:00
|
|
|
|
|
|
|
if (!event->isAccepted()) {
|
|
|
|
// check to see if we have an applet that accepts the format.
|
|
|
|
QStringList formats = event->mimeData()->formats();
|
|
|
|
|
|
|
|
foreach (const QString &format, formats) {
|
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(format);
|
|
|
|
if (!appletList.isEmpty()) {
|
|
|
|
event->setAccepted(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-06-13 18:21:59 +02:00
|
|
|
}
|
|
|
|
|
2008-06-23 02:13:03 +02:00
|
|
|
void Containment::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
QGraphicsItem *item = scene()->itemAt(event->scenePos());
|
|
|
|
event->setAccepted(item == this || !item);
|
|
|
|
}
|
|
|
|
|
2007-09-23 20:03:37 +02:00
|
|
|
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-04-24 23:33:16 +02:00
|
|
|
//kDebug() << event->mimeData()->text();
|
2007-09-23 20:03:37 +02:00
|
|
|
|
|
|
|
QString mimetype(static_cast<Corona*>(scene())->appletMimeType());
|
|
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimetype) && scene()) {
|
2008-06-18 00:20:14 +02:00
|
|
|
QString data = event->mimeData()->data(mimetype);
|
|
|
|
QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
|
|
|
|
|
|
|
|
foreach (const QString &appletName, appletNames) {
|
|
|
|
//kDebug() << "doing" << appletName;
|
|
|
|
QRectF geom(mapFromScene(event->scenePos()), QSize(0, 0));
|
|
|
|
addApplet(appletName, QVariantList(), geom);
|
|
|
|
}
|
2007-09-23 20:03:37 +02:00
|
|
|
event->acceptProposedAction();
|
|
|
|
} else if (KUrl::List::canDecode(event->mimeData())) {
|
2008-03-12 16:23:33 +01:00
|
|
|
//TODO: collect the mimetypes of available script engines and offer
|
|
|
|
// to create widgets out of the matching URLs, if any
|
2007-10-03 17:46:40 +02:00
|
|
|
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
2007-09-23 20:03:37 +02:00
|
|
|
foreach (const KUrl& url, urls) {
|
|
|
|
KMimeType::Ptr mime = KMimeType::findByUrl(url);
|
|
|
|
QString mimeName = mime->name();
|
2008-06-09 06:09:11 +02:00
|
|
|
QRectF geom(event->pos(), QSize());
|
2007-09-23 20:03:37 +02:00
|
|
|
QVariantList args;
|
|
|
|
args << url.url();
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << mimeName;
|
2008-04-16 23:15:38 +02:00
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(mimeName);
|
2007-09-23 20:03:37 +02:00
|
|
|
|
2008-08-08 19:14:35 +02:00
|
|
|
if (!appletList.isEmpty()) {
|
2007-09-23 20:03:37 +02:00
|
|
|
//TODO: should we show a dialog here to choose which plasmoid load if
|
2008-03-30 01:57:36 +01:00
|
|
|
//!appletList.isEmpty()
|
2008-05-24 09:47:20 +02:00
|
|
|
QMenu choices;
|
|
|
|
QHash<QAction*, QString> actionsToPlugins;
|
|
|
|
foreach (const KPluginInfo &info, appletList) {
|
|
|
|
QAction *action;
|
|
|
|
if (!info.icon().isEmpty()) {
|
|
|
|
action = choices.addAction(KIcon(info.icon()), info.name());
|
|
|
|
} else {
|
|
|
|
action = choices.addAction(info.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
actionsToPlugins.insert(action, info.pluginName());
|
|
|
|
}
|
|
|
|
|
|
|
|
actionsToPlugins.insert(choices.addAction(i18n("Icon")), "icon");
|
|
|
|
QAction *choice = choices.exec(event->screenPos());
|
|
|
|
if (choice) {
|
|
|
|
addApplet(actionsToPlugins[choice], args, geom);
|
|
|
|
}
|
2008-08-08 19:14:35 +02:00
|
|
|
} else if (url.protocol() != "data") {
|
|
|
|
// We don't try to do anything with data: URIs
|
|
|
|
// no special applet associated with this mimetype, let's
|
|
|
|
addApplet("icon", args, geom);
|
2007-09-23 20:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
event->acceptProposedAction();
|
2008-08-21 12:07:07 +02:00
|
|
|
} else {
|
|
|
|
QStringList formats = event->mimeData()->formats();
|
|
|
|
QHash<QString, KPluginInfo> seenPlugins;
|
|
|
|
QHash<QString, QString> pluginFormats;
|
|
|
|
|
|
|
|
foreach (const QString &format, formats) {
|
|
|
|
KPluginInfo::List plugins = Applet::listAppletInfoForMimetype(format);
|
|
|
|
|
|
|
|
foreach (const KPluginInfo &plugin, plugins) {
|
|
|
|
if (seenPlugins.contains(plugin.pluginName())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
seenPlugins.insert(plugin.pluginName(), plugin);
|
|
|
|
pluginFormats.insert(plugin.pluginName(), format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString selectedPlugin;
|
|
|
|
|
|
|
|
if (seenPlugins.isEmpty()) {
|
|
|
|
// do nothing, we have no matches =/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seenPlugins.count() == 1) {
|
|
|
|
selectedPlugin = seenPlugins.constBegin().key();
|
|
|
|
} else {
|
|
|
|
QMenu choices;
|
|
|
|
QHash<QAction*, QString > actionsToPlugins;
|
|
|
|
foreach (const KPluginInfo &info, seenPlugins) {
|
|
|
|
QAction *action;
|
|
|
|
if (!info.icon().isEmpty()) {
|
|
|
|
action = choices.addAction(KIcon(info.icon()), info.name());
|
|
|
|
} else {
|
|
|
|
action = choices.addAction(info.name());
|
|
|
|
}
|
|
|
|
|
|
|
|
actionsToPlugins.insert(action, info.pluginName());
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *choice = choices.exec(event->screenPos());
|
|
|
|
if (choice) {
|
|
|
|
selectedPlugin = actionsToPlugins[choice];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedPlugin.isEmpty()) {
|
|
|
|
KTemporaryFile tempFile;
|
|
|
|
if (tempFile.open()) {
|
|
|
|
//TODO: what should we do with files after the applet is done with them??
|
|
|
|
tempFile.setAutoRemove(false);
|
|
|
|
|
|
|
|
{
|
|
|
|
QDataStream stream(&tempFile);
|
|
|
|
QByteArray data = event->mimeData()->data(pluginFormats[selectedPlugin]);
|
|
|
|
stream.writeRawData(data, data.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QRectF geom(event->pos(), QSize());
|
|
|
|
QVariantList args;
|
|
|
|
args << tempFile.fileName();
|
|
|
|
kDebug() << args;
|
|
|
|
tempFile.close();
|
|
|
|
|
|
|
|
addApplet(selectedPlugin, args, geom);
|
|
|
|
}
|
|
|
|
}
|
2007-09-23 20:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-05 17:27:48 +02:00
|
|
|
void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
|
|
|
Applet::resizeEvent(event);
|
|
|
|
if (d->wallpaper) {
|
|
|
|
d->wallpaper->setBoundingRect(geometry());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 19:40:45 +01:00
|
|
|
void Containment::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2008-05-09 07:32:15 +02:00
|
|
|
//FIXME Qt4.4 check to see if this is still necessary to avoid unnecessary repaints
|
2007-11-05 19:40:45 +01:00
|
|
|
// check with QT_FLUSH_PAINT=1 and mouse through applets that accept hover,
|
|
|
|
// applets that don't and system windows
|
|
|
|
if (event->spontaneous()) {
|
|
|
|
Applet::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2008-05-09 07:32:15 +02:00
|
|
|
//FIXME Qt4.4 check to see if this is still necessary to avoid unnecessary repaints
|
2007-11-05 19:40:45 +01:00
|
|
|
// check with QT_FLUSH_PAINT=1 and mouse through applets that accept hover,
|
|
|
|
// applets that don't and system windows
|
|
|
|
// Applet::hoverLeaveEvent(event);
|
|
|
|
Q_UNUSED(event)
|
|
|
|
}
|
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
void Containment::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
2008-06-13 07:23:02 +02:00
|
|
|
//kDebug() << "keyPressEvent with" << event->key() << "and hoping and wishing for a" << Qt::Key_Tab;
|
2008-04-14 23:50:41 +02:00
|
|
|
if (event->key() == Qt::Key_Tab) { // && event->modifiers() == 0) {
|
|
|
|
if (!d->applets.isEmpty()) {
|
2008-06-04 04:44:54 +02:00
|
|
|
kDebug() << "let's give focus to...." << (QObject*)d->applets.first();
|
2008-04-14 23:50:41 +02:00
|
|
|
d->applets.first()->setFocus(Qt::TabFocusReason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-06 03:22:05 +02:00
|
|
|
void Containment::wheelEvent(QGraphicsSceneWheelEvent *event)
|
|
|
|
{
|
|
|
|
if (containmentType() == DesktopContainment) {
|
|
|
|
QGraphicsItem* item = scene()->itemAt(event->scenePos());
|
|
|
|
if (item == this) {
|
|
|
|
int numDesktops = KWindowSystem::numberOfDesktops();
|
|
|
|
int currentDesktop = KWindowSystem::currentDesktop();
|
|
|
|
|
|
|
|
if (event->delta() > 0) {
|
|
|
|
KWindowSystem::setCurrentDesktop(currentDesktop % numDesktops + 1);
|
|
|
|
} else {
|
|
|
|
KWindowSystem::setCurrentDesktop((numDesktops + currentDesktop - 2) % numDesktops + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
event->accept();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet::wheelEvent(event);
|
|
|
|
}
|
|
|
|
|
2007-11-12 20:27:21 +01:00
|
|
|
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
|
|
|
|
|
|
|
|
// Otherwise we're watching something we shouldn't be...
|
|
|
|
Q_ASSERT(applet!=0);
|
2007-11-13 16:49:28 +01:00
|
|
|
if (!d->applets.contains(applet)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-12 20:27:21 +01:00
|
|
|
|
2008-06-13 07:23:02 +02:00
|
|
|
//kDebug() << "got sceneEvent";
|
2007-11-13 16:49:28 +01:00
|
|
|
switch (event->type()) {
|
2007-11-12 20:27:21 +01:00
|
|
|
case QEvent::GraphicsSceneHoverEnter:
|
2008-04-24 20:24:11 +02:00
|
|
|
//kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
|
2008-05-08 06:26:52 +02:00
|
|
|
if (immutability() == Mutable && applet->immutability() == Mutable) {
|
2008-07-10 03:35:51 +02:00
|
|
|
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent*>(event);
|
2008-07-29 02:07:57 +02:00
|
|
|
if (!d->handles.contains(applet)) {
|
2008-01-10 00:43:49 +01:00
|
|
|
//kDebug() << "generated applet handle";
|
2008-07-10 03:35:51 +02:00
|
|
|
AppletHandle *handle = new AppletHandle(this, applet, he->pos());
|
2008-01-10 00:43:49 +01:00
|
|
|
d->handles[applet] = handle;
|
|
|
|
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
|
|
|
this, SLOT(handleDisappeared(AppletHandle*)));
|
|
|
|
connect(applet, SIGNAL(geometryChanged()),
|
|
|
|
handle, SLOT(appletResized()));
|
|
|
|
}
|
2007-11-12 20:27:21 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-03-12 16:23:33 +01:00
|
|
|
QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
2008-05-17 05:39:24 +02:00
|
|
|
//FIXME if the applet is moved to another containment we need to unfocus it
|
2008-03-12 16:23:33 +01:00
|
|
|
|
2008-04-27 21:05:06 +02:00
|
|
|
if (isContainment() &&
|
2008-03-16 08:20:42 +01:00
|
|
|
(change == QGraphicsItem::ItemSceneHasChanged || change == QGraphicsItem::ItemPositionHasChanged) &&
|
2008-03-14 18:05:37 +01:00
|
|
|
!d->positioning) {
|
|
|
|
switch (containmentType()) {
|
|
|
|
case PanelContainment:
|
2008-07-06 11:49:23 +02:00
|
|
|
case CustomPanelContainment:
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionPanel();
|
2008-03-14 18:05:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionContainment();
|
2008-03-14 18:05:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Applet::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2008-05-24 03:48:36 +02:00
|
|
|
void Containment::enableAction(const QString &name, bool enable)
|
2007-11-19 02:19:58 +01:00
|
|
|
{
|
2008-05-24 03:48:36 +02:00
|
|
|
QAction *action = this->action(name);
|
|
|
|
if (action) {
|
|
|
|
action->setEnabled(enable);
|
|
|
|
action->setVisible(enable);
|
|
|
|
}
|
2007-12-14 07:34:26 +01:00
|
|
|
}
|
2007-11-19 02:19:58 +01:00
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void Containment::addToolBoxTool(QAction *action)
|
2007-12-14 07:34:26 +01:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->addTool(action);
|
2008-03-17 00:58:12 +01:00
|
|
|
}
|
2007-12-19 03:41:45 +01:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void Containment::removeToolBoxTool(QAction *action)
|
2007-12-19 03:41:45 +01:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->removeTool(action);
|
2008-03-17 00:58:12 +01:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void Containment::setToolBoxOpen(bool open)
|
2008-04-25 20:49:27 +02:00
|
|
|
{
|
|
|
|
if (open) {
|
2008-05-24 14:25:56 +02:00
|
|
|
openToolBox();
|
2008-04-25 20:49:27 +02:00
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
closeToolBox();
|
2008-04-25 20:49:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void Containment::openToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->showToolBox();
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void Containment::closeToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->hideToolBox();
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
void Containment::addAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
Applet::addAssociatedWidget(widget);
|
|
|
|
if (d->focusedApplet) {
|
|
|
|
d->focusedApplet->addAssociatedWidget(widget);
|
|
|
|
}
|
2008-06-01 04:13:53 +02:00
|
|
|
|
|
|
|
foreach (const Applet* applet, d->applets) {
|
|
|
|
if (applet->d->activationAction) {
|
|
|
|
widget->addAction(applet->d->activationAction);
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::removeAssociatedWidget(QWidget *widget)
|
|
|
|
{
|
|
|
|
Applet::removeAssociatedWidget(widget);
|
|
|
|
if (d->focusedApplet) {
|
|
|
|
d->focusedApplet->removeAssociatedWidget(widget);
|
|
|
|
}
|
2008-06-01 04:13:53 +02:00
|
|
|
|
|
|
|
foreach (const Applet* applet, d->applets) {
|
|
|
|
if (applet->d->activationAction) {
|
|
|
|
widget->removeAction(applet->d->activationAction);
|
|
|
|
}
|
|
|
|
}
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
|
|
|
|
2008-08-05 17:27:48 +02:00
|
|
|
void Containment::setDrawWallpaper(bool drawWallpaper)
|
|
|
|
{
|
|
|
|
d->drawWallpaper = drawWallpaper;
|
2008-08-20 10:06:34 +02:00
|
|
|
if (d->drawWallpaper) {
|
|
|
|
KConfigGroup cfg = config();
|
|
|
|
setWallpaper(cfg.readEntry("wallpaperplugin", "image"),
|
|
|
|
cfg.readEntry("wallpaperpluginmode", "SingleImage"));
|
|
|
|
} else if (!d->drawWallpaper && d->wallpaper) {
|
|
|
|
delete d->wallpaper;
|
|
|
|
d->wallpaper = 0;
|
|
|
|
}
|
2008-08-05 17:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::drawWallpaper()
|
|
|
|
{
|
|
|
|
return d->drawWallpaper;
|
|
|
|
}
|
|
|
|
|
2008-08-05 19:32:47 +02:00
|
|
|
void Containment::setWallpaper(const QString &pluginName, const QString &mode)
|
2008-08-05 17:27:48 +02:00
|
|
|
{
|
2008-08-20 10:06:34 +02:00
|
|
|
KConfigGroup cfg = config();
|
|
|
|
|
|
|
|
if (d->drawWallpaper) {
|
|
|
|
if (d->wallpaper && d->wallpaper->pluginName() != pluginName) {
|
|
|
|
delete d->wallpaper;
|
|
|
|
d->wallpaper = 0;
|
|
|
|
}
|
2008-08-20 14:45:19 +02:00
|
|
|
|
2008-08-20 10:06:34 +02:00
|
|
|
if (!pluginName.isEmpty() && !d->wallpaper) {
|
|
|
|
d->wallpaper = Plasma::Wallpaper::load(pluginName);
|
|
|
|
}
|
2008-08-20 14:45:19 +02:00
|
|
|
|
2008-08-05 17:27:48 +02:00
|
|
|
if (d->wallpaper) {
|
|
|
|
d->wallpaper->setBoundingRect(geometry());
|
2008-08-20 14:45:19 +02:00
|
|
|
d->wallpaper->restore(KConfigGroup(&cfg, "Wallpaper"), mode);
|
2008-08-05 17:27:48 +02:00
|
|
|
connect(d->wallpaper, SIGNAL(update(const QRectF&)),
|
|
|
|
this, SLOT(updateRect(const QRectF&)));
|
|
|
|
}
|
2008-08-20 14:45:19 +02:00
|
|
|
|
2008-08-20 10:06:34 +02:00
|
|
|
update();
|
2008-08-05 17:27:48 +02:00
|
|
|
}
|
2008-08-20 10:06:34 +02:00
|
|
|
cfg.writeEntry("wallpaperplugin", pluginName);
|
|
|
|
cfg.writeEntry("wallpaperpluginmode", mode);
|
2008-08-05 17:27:48 +02:00
|
|
|
}
|
|
|
|
|
2008-08-05 19:32:47 +02:00
|
|
|
Plasma::Wallpaper* Containment::wallpaper() const
|
2008-08-05 17:27:48 +02:00
|
|
|
{
|
|
|
|
return d->wallpaper;
|
|
|
|
}
|
|
|
|
|
2008-08-20 15:13:31 +02:00
|
|
|
void Containment::setActivity(const QString &activity)
|
2008-08-18 16:04:30 +02:00
|
|
|
{
|
2008-08-20 15:13:31 +02:00
|
|
|
if (d->activity != activity) {
|
|
|
|
d->activity = activity;
|
2008-08-18 16:04:30 +02:00
|
|
|
Context c;
|
2008-08-20 15:13:31 +02:00
|
|
|
QStringList activities = c.listActivities();
|
|
|
|
if (!activities.contains(activity)) {
|
|
|
|
c.createActivity(activity);
|
2008-08-18 16:04:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Applet *a, d->applets) {
|
|
|
|
a->updateConstraints(ContextConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 15:13:31 +02:00
|
|
|
QString Containment::activity() const
|
2008-08-18 16:04:30 +02:00
|
|
|
{
|
2008-08-20 15:13:31 +02:00
|
|
|
return d->activity;
|
2008-08-18 16:04:30 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
KActionCollection& ContainmentPrivate::actions()
|
2008-05-17 05:39:24 +02:00
|
|
|
{
|
|
|
|
return static_cast<Applet*>(q)->d->actions;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::focusApplet(Plasma::Applet *applet)
|
2008-05-17 05:39:24 +02:00
|
|
|
{
|
|
|
|
if (focusedApplet == applet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-21 08:16:45 +02:00
|
|
|
if (q->screen() == -1) {
|
|
|
|
//what's the point of having focus if you're not on screen? :)
|
|
|
|
//also, clicking a containment to switch to it makes the ZUI waay nicer.
|
|
|
|
emit q->focusRequested(q);
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
QList<QWidget *> widgets = actions().associatedWidgets();
|
|
|
|
if (focusedApplet) {
|
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
focusedApplet->removeAssociatedWidget(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//but what if applet isn't really one of our applets?
|
|
|
|
//FIXME should we really unfocus the old applet?
|
|
|
|
if (applets.contains(applet)) {
|
2008-06-30 16:41:31 +02:00
|
|
|
//kDebug() << "switching to" << applet->name();
|
2008-05-17 05:39:24 +02:00
|
|
|
focusedApplet = applet;
|
|
|
|
if (focusedApplet) {
|
|
|
|
foreach (QWidget *w, widgets) {
|
|
|
|
focusedApplet->addAssociatedWidget(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
applet->setFocus(Qt::ShortcutFocusReason);
|
|
|
|
} else {
|
|
|
|
focusedApplet = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::focusNextApplet()
|
|
|
|
{
|
|
|
|
if (d->applets.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int index = d->focusedApplet ? d->applets.indexOf(d->focusedApplet) + 1 : 0;
|
|
|
|
if (index >= d->applets.size()) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
kDebug() << "index" << index;
|
|
|
|
d->focusApplet(d->applets.at(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::focusPreviousApplet()
|
|
|
|
{
|
|
|
|
if (d->applets.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int index = d->focusedApplet ? d->applets.indexOf(d->focusedApplet) - 1 : -1;
|
|
|
|
if (index < 0) {
|
|
|
|
index = d->applets.size() - 1;
|
|
|
|
}
|
|
|
|
kDebug() << "index" << index;
|
|
|
|
d->focusApplet(d->applets.at(index));
|
|
|
|
}
|
|
|
|
|
2008-05-20 06:02:36 +02:00
|
|
|
void Containment::destroy()
|
2008-08-21 04:57:42 +02:00
|
|
|
{
|
|
|
|
destroy(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::destroy(bool confirm)
|
2008-05-20 06:02:36 +02:00
|
|
|
{
|
|
|
|
if (immutability() != Mutable) {
|
|
|
|
return;
|
|
|
|
}
|
2008-06-04 21:04:34 +02:00
|
|
|
|
2008-05-20 06:26:10 +02:00
|
|
|
if (isContainment()) {
|
2008-07-07 00:43:53 +02:00
|
|
|
//don't remove a desktop that's in use
|
|
|
|
//FIXME allow removal of containments for screens that don't currently exist
|
|
|
|
if (d->type != PanelContainment && d->type != CustomPanelContainment &&
|
|
|
|
(d->screen != -1 || d->screen >= QApplication::desktop()->numScreens())) {
|
|
|
|
kDebug() << (QObject*)this << "containment has a screen number?" << d->screen;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-20 06:26:10 +02:00
|
|
|
//FIXME maybe that %1 should be the containment type not the name
|
2008-08-21 12:07:07 +02:00
|
|
|
if (!confirm ||
|
|
|
|
KMessageBox::warningContinueCancel(view(), i18n("Do you really want to remove this %1?", name()),
|
2008-05-20 06:26:10 +02:00
|
|
|
i18n("Remove %1", name()), KStandardGuiItem::remove()) == KMessageBox::Continue ) {
|
2008-07-07 00:43:53 +02:00
|
|
|
//clearApplets();
|
|
|
|
Applet::destroy();
|
2008-05-20 06:26:10 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Applet::destroy();
|
2008-08-21 04:57:42 +02:00
|
|
|
}
|
2008-05-20 06:02:36 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
|
|
|
|
// Private class implementation
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::toggleDesktopImmutability()
|
2008-04-25 21:15:50 +02:00
|
|
|
{
|
|
|
|
if (q->corona()) {
|
2008-05-24 14:25:56 +02:00
|
|
|
if (q->corona()->immutability() == Mutable) {
|
2008-04-25 21:15:50 +02:00
|
|
|
q->corona()->setImmutability(UserImmutable);
|
2008-05-24 14:25:56 +02:00
|
|
|
} else if (q->corona()->immutability() == UserImmutable) {
|
2008-05-08 06:26:52 +02:00
|
|
|
q->corona()->setImmutability(Mutable);
|
2008-04-25 21:15:50 +02:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-08 06:26:52 +02:00
|
|
|
if (q->immutability() == Mutable) {
|
2008-04-25 21:15:50 +02:00
|
|
|
q->setImmutability(UserImmutable);
|
2008-05-24 14:25:56 +02:00
|
|
|
} else if (q->immutability() == UserImmutable) {
|
2008-05-08 06:26:52 +02:00
|
|
|
q->setImmutability(Mutable);
|
2008-04-25 21:15:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-14 02:22:11 +02:00
|
|
|
if (q->immutability() != Mutable) {
|
2008-07-16 19:51:58 +02:00
|
|
|
QMap<Applet*, AppletHandle*> h = handles;
|
|
|
|
handles.clear();
|
|
|
|
|
|
|
|
foreach (AppletHandle* handle, h) {
|
2008-07-17 07:56:52 +02:00
|
|
|
handle->disconnect(q);
|
2008-07-14 02:22:11 +02:00
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
//setLockToolText();
|
2008-04-25 21:15:50 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::zoomIn()
|
2008-04-25 21:08:49 +02:00
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomIn);
|
2008-07-19 20:51:22 +02:00
|
|
|
positionToolBox();
|
2008-04-25 21:08:49 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::zoomOut()
|
2008-04-25 21:08:49 +02:00
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomOut);
|
2008-07-19 20:51:22 +02:00
|
|
|
positionToolBox();
|
2008-04-25 21:08:49 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
ToolBox* ContainmentPrivate::createToolBox()
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (!toolBox) {
|
2008-04-25 20:44:09 +02:00
|
|
|
switch (type) {
|
2008-07-01 20:56:43 +02:00
|
|
|
case Containment::PanelContainment:
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox = new PanelToolBox(q);
|
2008-07-06 12:03:10 +02:00
|
|
|
toolBox->setSize(22);
|
|
|
|
toolBox->setIconSize(QSize(16, 16));
|
|
|
|
if (q->immutability() != Mutable) {
|
|
|
|
toolBox->hide();
|
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
break;
|
2008-07-06 11:49:23 +02:00
|
|
|
case Containment::DesktopContainment:
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox = new DesktopToolBox(q);
|
2008-04-25 20:44:09 +02:00
|
|
|
break;
|
2008-07-06 11:49:23 +02:00
|
|
|
default:
|
|
|
|
break;
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
2008-06-29 01:50:43 +02:00
|
|
|
|
2008-07-06 11:49:23 +02:00
|
|
|
if (toolBox) {
|
|
|
|
QObject::connect(toolBox, SIGNAL(toggled()), q, SIGNAL(toolBoxToggled()));
|
|
|
|
positionToolBox();
|
2008-06-29 01:50:43 +02:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
return toolBox;
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::positionToolBox()
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
2008-05-24 14:25:56 +02:00
|
|
|
if (!toolBox) {
|
2008-04-25 20:44:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-20 23:29:31 +02:00
|
|
|
//The placement assumes that the geometry width/height is no more than the screen
|
2008-07-01 20:56:43 +02:00
|
|
|
if (type == Containment::PanelContainment) {
|
2008-05-20 23:29:31 +02:00
|
|
|
if (q->formFactor() == Vertical) {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setOrientation(Qt::Vertical);
|
|
|
|
toolBox->setPos(q->geometry().width()/2 - toolBox->boundingRect().width()/2, q->geometry().height());
|
2008-05-20 23:29:31 +02:00
|
|
|
//defaulting to Horizontal right now
|
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setOrientation(Qt::Horizontal);
|
2008-05-20 23:29:31 +02:00
|
|
|
if (QApplication::layoutDirection() == Qt::RightToLeft) {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setPos(q->geometry().left(), q->geometry().height()/2 - toolBox->boundingRect().height()/2);
|
2008-05-20 23:29:31 +02:00
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setPos(q->geometry().width(), q->geometry().height()/2 - toolBox->boundingRect().height()/2);
|
2008-05-20 23:29:31 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
} else {
|
2008-05-22 22:22:28 +02:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
2008-06-24 05:16:33 +02:00
|
|
|
QRectF r = desktop->availableGeometry(screen);
|
2008-05-22 22:22:28 +02:00
|
|
|
if (q->view() && !q->view()->transform().isScaling()) {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setPos(r.topRight());
|
2008-05-22 22:22:28 +02:00
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setPos(q->mapFromScene(QPointF(q->geometry().topRight())));
|
2008-05-22 22:22:28 +02:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::triggerShowAddWidgets()
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
|
|
|
emit q->showAddWidgetsInterface(QPointF());
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::handleDisappeared(AppletHandle *handle)
|
2008-03-05 08:08:32 +01:00
|
|
|
{
|
2008-07-16 19:51:58 +02:00
|
|
|
if (handles.contains(handle->applet())) {
|
|
|
|
handles.remove(handle->applet());
|
2008-08-20 11:14:27 +02:00
|
|
|
handle->detachApplet();
|
2008-07-16 19:51:58 +02:00
|
|
|
handle->deleteLater();
|
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::containmentConstraintsEvent(Plasma::Constraints constraints)
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
2008-04-27 21:05:06 +02:00
|
|
|
if (!q->isContainment()) {
|
2008-04-25 20:44:09 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
//kDebug() << "got containmentConstraintsEvent" << constraints << (QObject*)toolBox;
|
2008-04-25 20:44:09 +02:00
|
|
|
if (constraints & Plasma::ImmutableConstraint) {
|
2008-05-17 05:39:24 +02:00
|
|
|
//update actions
|
|
|
|
bool unlocked = q->immutability() == Mutable;
|
2008-06-13 18:51:25 +02:00
|
|
|
q->setAcceptDrops(unlocked);
|
|
|
|
|
2008-05-17 05:39:24 +02:00
|
|
|
QAction *action = actions().action("add widgets");
|
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}
|
2008-05-24 06:34:27 +02:00
|
|
|
//FIXME immutability changes conflict with zoom changes
|
2008-07-01 20:23:39 +02:00
|
|
|
/*action = actions().action("add sibling containment");
|
2008-05-24 06:34:27 +02:00
|
|
|
if (action) {
|
|
|
|
action->setVisible(unlocked);
|
|
|
|
action->setEnabled(unlocked);
|
|
|
|
}*/
|
2008-05-17 05:39:24 +02:00
|
|
|
action = actions().action("lock widgets");
|
|
|
|
if (action) {
|
|
|
|
action->setText(unlocked ? i18n("Lock Widgets") : i18n("Unlock Widgets"));
|
2008-05-18 21:58:33 +02:00
|
|
|
action->setIcon(KIcon(unlocked ? "object-locked" : "object-unlocked"));
|
2008-05-17 05:39:24 +02:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
|
|
|
|
// tell the applets too
|
|
|
|
foreach (Applet *a, applets) {
|
2008-04-27 22:35:23 +02:00
|
|
|
a->updateConstraints(ImmutableConstraint);
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
2008-05-19 22:49:44 +02:00
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
if (q->isContainment() && type == Containment::PanelContainment) {
|
2008-05-19 22:49:44 +02:00
|
|
|
if (unlocked) {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->show();
|
2008-05-19 22:49:44 +02:00
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->hide();
|
2008-05-19 22:49:44 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((constraints & Plasma::SizeConstraint || constraints & Plasma::ScreenConstraint) &&
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox) {
|
|
|
|
positionToolBox();
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
2008-04-29 01:00:08 +02:00
|
|
|
if (constraints & Plasma::FormFactorConstraint) {
|
2008-05-24 14:25:56 +02:00
|
|
|
if (toolBox) {
|
2008-04-29 01:00:08 +02:00
|
|
|
if (q->formFactor() == Vertical) {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setOrientation(Qt::Vertical);
|
2008-04-29 01:00:08 +02:00
|
|
|
//defaults to horizontal
|
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
toolBox->setOrientation(Qt::Horizontal);
|
2008-04-29 01:00:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (Applet *applet, applets) {
|
|
|
|
applet->updateConstraints(Plasma::FormFactorConstraint);
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints & Plasma::SizeConstraint) {
|
|
|
|
switch (q->containmentType()) {
|
2008-07-01 20:56:43 +02:00
|
|
|
case Containment::PanelContainment:
|
2008-07-06 11:49:23 +02:00
|
|
|
case Containment::CustomPanelContainment:
|
2008-04-25 20:44:09 +02:00
|
|
|
positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
positionContainment();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
Applet* ContainmentPrivate::addApplet(const QString& name, const QVariantList& args,
|
2008-04-25 20:44:09 +02:00
|
|
|
const QRectF& appletGeometry, uint id, bool delayInit)
|
|
|
|
{
|
2008-05-08 06:26:52 +02:00
|
|
|
if (!delayInit && q->immutability() != Mutable) {
|
2008-04-25 20:44:09 +02:00
|
|
|
kDebug() << "addApplet for" << name << "requested, but we're currently immutable!";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *v = q->view();
|
|
|
|
if (v) {
|
|
|
|
v->setCursor(Qt::BusyCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet* applet = Applet::load(name, id, args);
|
|
|
|
if (v) {
|
|
|
|
v->unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "Applet" << name << "could not be loaded.";
|
2008-07-17 20:21:55 +02:00
|
|
|
applet = new Applet(0, QString(), id);
|
2008-08-04 13:40:06 +02:00
|
|
|
applet->setFailedToLaunch(true, i18n("Could not find requested component: %1", name));
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
|
|
|
|
|
|
|
q->addApplet(applet, appletGeometry.topLeft(), delayInit);
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
bool ContainmentPrivate::regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet) const
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
|
|
|
foreach (Applet *applet, applets) {
|
|
|
|
if (applet != ignoredApplet && applet->geometry().intersects(region)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::appletDestroyed(QObject* object)
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
|
|
|
// we do a static_cast here since it really isn't an Applet by this
|
|
|
|
// point anymore since we are in the qobject dtor. we don't actually
|
|
|
|
// try and do anything with it, we just need the value of the pointer
|
|
|
|
// so this unsafe looking code is actually just fine.
|
2008-07-16 23:58:36 +02:00
|
|
|
//
|
|
|
|
// NOTE: DO NOT USE THE applet VARIABLE FOR ANYTHING OTHER THAN COMPARING
|
|
|
|
// THE ADDRESS! ACTUALLY USING THE OBJECT WILL RESULT IN A CRASH!!!
|
2008-04-25 20:44:09 +02:00
|
|
|
Applet* applet = static_cast<Plasma::Applet*>(object);
|
|
|
|
applets.removeAll(applet);
|
2008-05-17 05:39:24 +02:00
|
|
|
if (focusedApplet == applet) {
|
|
|
|
focusedApplet = 0;
|
|
|
|
}
|
2008-08-20 10:06:34 +02:00
|
|
|
|
2008-08-11 15:16:46 +02:00
|
|
|
foreach (AppletHandle* handle, handles) {
|
|
|
|
if (handles.contains(applet)) {
|
|
|
|
handles.remove(handle->applet());
|
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
}
|
2008-08-20 10:06:34 +02:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
emit q->appletRemoved(applet);
|
|
|
|
emit q->configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::containmentAppletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
2008-06-04 20:20:58 +02:00
|
|
|
if (anim == Animator::AppearAnimation &&
|
2008-07-01 20:56:43 +02:00
|
|
|
q->containmentType() == Containment::DesktopContainment &&
|
2008-06-04 20:20:58 +02:00
|
|
|
item->parentItem() == q) {
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
|
|
|
|
|
|
|
if (applet) {
|
|
|
|
applet->installSceneEventFilter(q);
|
2008-07-10 22:20:37 +02:00
|
|
|
KConfigGroup *cg = applet->d->mainConfigGroup();
|
|
|
|
applet->save(*cg);
|
|
|
|
emit q->configNeedsSaving();
|
2008-06-04 20:20:58 +02:00
|
|
|
//applet->setWindowFlags(Qt::Window);
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::positionContainment()
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
|
|
|
Corona *c = q->corona();
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Containment*> containments = c->containments();
|
|
|
|
QMutableListIterator<Containment*> it(containments);
|
|
|
|
|
2008-06-09 05:15:40 +02:00
|
|
|
bool noCollissions = true;
|
2008-04-25 20:44:09 +02:00
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
if (containment == q ||
|
2008-07-06 11:49:23 +02:00
|
|
|
containment->containmentType() == Containment::PanelContainment ||
|
|
|
|
containment->containmentType() == Containment::CustomPanelContainment) {
|
2008-04-25 20:44:09 +02:00
|
|
|
// weed out all containments we don't care about at all
|
|
|
|
// e.g. Panels and ourself
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-06-09 05:15:40 +02:00
|
|
|
if (noCollissions && q->collidesWithItem(containment)) {
|
|
|
|
noCollissions = false;
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-09 05:15:40 +02:00
|
|
|
if (noCollissions) {
|
2008-04-25 20:44:09 +02:00
|
|
|
// we made it all the way through the list, we have no
|
|
|
|
// collisions
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
int numScreens = desktop->numScreens();
|
|
|
|
|
|
|
|
for (int i = 0; i < numScreens; ++i) {
|
|
|
|
QRect otherScreen = desktop->screenGeometry(i);
|
|
|
|
|
|
|
|
if (width < otherScreen.width()) {
|
|
|
|
width = otherScreen.width();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height < otherScreen.height()) {
|
|
|
|
height = otherScreen.height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//this magic number (4) is the number of columns to try before going to the next row
|
|
|
|
width = (width + INTER_CONTAINMENT_MARGIN) * 4;
|
|
|
|
height += INTER_CONTAINMENT_MARGIN;
|
|
|
|
|
|
|
|
// a mildly naive "find the first slot" approach
|
|
|
|
QRectF r = q->boundingRect();
|
|
|
|
QPointF topLeft(0, 0);
|
|
|
|
q->setPos(topLeft);
|
|
|
|
|
|
|
|
positioning = true;
|
|
|
|
while (true) {
|
|
|
|
it.toFront();
|
2008-06-07 11:34:50 +02:00
|
|
|
int shift = 0;
|
2008-04-25 20:44:09 +02:00
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
2008-06-09 05:15:40 +02:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
if (q->collidesWithItem(containment)) {
|
2008-06-13 07:23:02 +02:00
|
|
|
shift = containment->geometry().right();
|
|
|
|
/*kDebug() << (QObject*)q << "collides with" << (QObject*)containment
|
|
|
|
<< containment->geometry() << "so shift to: " << shift;*/
|
2008-06-09 05:15:40 +02:00
|
|
|
//TODO: is it safe to remove a containment once we've
|
|
|
|
// collided with it?
|
2008-04-25 20:44:09 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF pos = containment->pos();
|
|
|
|
if (pos.x() <= topLeft.x() && pos.y() <= topLeft.y()) {
|
|
|
|
// we don't colid with this containment, and it's above
|
|
|
|
// and to the left of us, so let's not bother checking
|
|
|
|
// it again if we go through this loop again
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-07 11:34:50 +02:00
|
|
|
if (shift == 0) {
|
2008-04-25 20:44:09 +02:00
|
|
|
// success! no collisions!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-06-07 11:34:50 +02:00
|
|
|
if (shift + r.width() + INTER_CONTAINMENT_MARGIN > width) {
|
2008-04-25 20:44:09 +02:00
|
|
|
// we ran out of width room, try another row
|
|
|
|
topLeft = QPoint(0, topLeft.y() + height);
|
|
|
|
} else {
|
2008-06-07 11:34:50 +02:00
|
|
|
topLeft.setX(shift + INTER_CONTAINMENT_MARGIN);
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
q->setPos(topLeft);
|
2008-06-13 07:23:02 +02:00
|
|
|
//kDebug() << "trying at" << topLeft << q->geometry();
|
2008-04-25 20:44:09 +02:00
|
|
|
//kDebug() << collidingItems().count() << collidingItems()[0] << (QGraphicsItem*)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioning = false;
|
|
|
|
}
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
void ContainmentPrivate::positionPanel(bool force)
|
2008-04-25 20:44:09 +02:00
|
|
|
{
|
|
|
|
if (!q->scene()) {
|
|
|
|
kDebug() << "no scene yet";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we position panels in negative coordinates, and stack all horizontal
|
|
|
|
// and all vertical panels with each other.
|
|
|
|
|
|
|
|
const QPointF p = q->pos();
|
|
|
|
|
|
|
|
if (!force &&
|
|
|
|
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
|
|
|
|
q->scene()->collidingItems(q).isEmpty()) {
|
|
|
|
// already positioned and not running into any other panels
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
|
|
|
|
bool horiz = q->formFactor() == Plasma::Horizontal;
|
|
|
|
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
|
|
|
qreal lastHeight = 0;
|
|
|
|
|
2008-07-06 11:49:23 +02:00
|
|
|
// this should be ok for small numbers of panels, but if we ever end
|
2008-04-25 20:44:09 +02:00
|
|
|
// up managing hundreds of them, this simplistic alogrithm will
|
|
|
|
// likely be too slow.
|
|
|
|
foreach (const Containment* other, q->corona()->containments()) {
|
|
|
|
if (other == q ||
|
2008-07-06 11:49:23 +02:00
|
|
|
(other->containmentType() != Containment::PanelContainment &&
|
|
|
|
other->containmentType() != Containment::CustomPanelContainment) ||
|
2008-04-25 20:44:09 +02:00
|
|
|
horiz != (other->formFactor() == Plasma::Horizontal)) {
|
|
|
|
// only line up with panels of the same orientation
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (horiz) {
|
|
|
|
qreal y = other->pos().y();
|
|
|
|
if (y < bottom) {
|
|
|
|
lastHeight = other->size().height();
|
|
|
|
bottom = y;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qreal width = other->size().width();
|
|
|
|
qreal x = other->pos().x() + width;
|
|
|
|
if (x > bottom) {
|
|
|
|
lastHeight = width;
|
|
|
|
bottom = x + lastHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kDebug() << "positioning" << (horiz ? "" : "non-") << "horizontal panel; forced?" << force;
|
|
|
|
// give a space equal to the height again of the last item so there is
|
|
|
|
// room to grow.
|
|
|
|
QPointF newPos;
|
|
|
|
if (horiz) {
|
|
|
|
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix x position for non-flush-left panels
|
|
|
|
kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
|
|
|
|
newPos = QPointF(0, bottom - q->size().height());
|
|
|
|
} else {
|
|
|
|
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix y position for non-flush-top panels
|
|
|
|
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
positioning = true;
|
|
|
|
if (p != newPos) {
|
|
|
|
q->setPos(newPos);
|
|
|
|
emit q->geometryChanged();
|
|
|
|
}
|
|
|
|
positioning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 02:19:58 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "containment.moc"
|
2007-11-19 02:19:58 +01:00
|
|
|
|