2007-09-18 23:16:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "containment.h"
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
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>
|
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>
|
2007-09-18 23:16:17 +02:00
|
|
|
|
2007-11-12 20:27:21 +01:00
|
|
|
#include "applethandle_p.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "corona.h"
|
|
|
|
#include "phase.h"
|
2007-12-21 02:14:32 +01:00
|
|
|
#include "desktoptoolbox_p.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "svg.h"
|
|
|
|
|
2007-11-19 23:42:56 +01:00
|
|
|
#include "layouts/freelayout.h"
|
|
|
|
#include "layouts/boxlayout.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2007-10-23 17:56:40 +02:00
|
|
|
static const int INTER_CONTAINMENT_MARGIN = 6;
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
class Containment::Private
|
|
|
|
{
|
|
|
|
public:
|
2007-12-19 03:41:45 +01:00
|
|
|
Private(Containment* c)
|
|
|
|
: q(c),
|
|
|
|
formFactor(Planar),
|
2007-09-18 23:16:17 +02:00
|
|
|
location(Floating),
|
2007-11-27 00:28:03 +01:00
|
|
|
screen(-1),
|
2007-11-28 22:46:17 +01:00
|
|
|
toolbox(0),
|
2007-11-29 01:20:37 +01:00
|
|
|
type(Containment::NoContainmentType)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Private()
|
|
|
|
{
|
|
|
|
qDeleteAll(applets);
|
|
|
|
applets.clear();
|
|
|
|
}
|
|
|
|
|
2007-12-19 03:41:45 +01:00
|
|
|
DesktopToolbox* createToolbox()
|
2007-12-14 07:34:26 +01:00
|
|
|
{
|
|
|
|
if (!toolbox) {
|
2007-12-19 03:41:45 +01:00
|
|
|
toolbox = new DesktopToolbox(q);
|
|
|
|
toolbox->setPos(q->geometry().width() - toolbox->boundingRect().width(), 0);
|
2007-12-14 07:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return toolbox;
|
|
|
|
}
|
|
|
|
|
2007-12-19 03:41:45 +01:00
|
|
|
Containment *q;
|
2007-09-18 23:16:17 +02:00
|
|
|
FormFactor formFactor;
|
|
|
|
Location location;
|
|
|
|
Applet::List applets;
|
2007-11-12 20:27:21 +01:00
|
|
|
QMap<Applet*, AppletHandle*> handles;
|
2007-09-18 23:16:17 +02:00
|
|
|
int screen;
|
2007-11-19 02:19:58 +01:00
|
|
|
DesktopToolbox *toolbox;
|
2007-11-28 22:46:17 +01:00
|
|
|
Containment::Type type;
|
2007-09-18 23:16:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Containment::Containment(QGraphicsItem* parent,
|
|
|
|
const QString& serviceId,
|
|
|
|
uint containmentId)
|
|
|
|
: Applet(parent, serviceId, containmentId),
|
2007-12-19 03:41:45 +01:00
|
|
|
d(new Private(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
|
2007-11-26 19:32:25 +01:00
|
|
|
setDrawStandardBackground(false);
|
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),
|
2007-12-19 03:41:45 +01:00
|
|
|
d(new Private(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
|
2007-11-17 04:31:25 +01:00
|
|
|
setDrawStandardBackground(false);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::~Containment()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::init()
|
|
|
|
{
|
2008-02-15 07:51:37 +01:00
|
|
|
setCacheMode(NoCache);
|
2007-09-18 23:16:17 +02:00
|
|
|
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
|
|
|
|
2007-10-24 04:10:10 +02:00
|
|
|
//TODO: would be nice to not do this on init, as it causes Phase to init
|
|
|
|
connect(Phase::self(), SIGNAL(animationComplete(QGraphicsItem*,Plasma::Phase::Animation)),
|
2007-11-12 20:27:21 +01:00
|
|
|
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Phase::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
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2007-11-17 04:31:25 +01:00
|
|
|
void Containment::loadConstraints(KConfigGroup* group)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2008-01-08 02:25:09 +01: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);*/
|
2007-10-26 03:11:27 +02:00
|
|
|
setGeometry(group->readEntry("geometry", geometry()));
|
2007-11-11 00:19:05 +01:00
|
|
|
setLocation((Plasma::Location)group->readEntry("location", (int)d->location));
|
2007-10-26 03:11:27 +02:00
|
|
|
setFormFactor((Plasma::FormFactor)group->readEntry("formfactor", (int)d->formFactor));
|
|
|
|
setScreen(group->readEntry("screen", d->screen));
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::saveConstraints(KConfigGroup* group) const
|
|
|
|
{
|
2007-12-07 06:02:54 +01:00
|
|
|
// locking is saved in Applet::save
|
2007-09-18 23:16:17 +02:00
|
|
|
group->writeEntry("screen", d->screen);
|
|
|
|
group->writeEntry("formfactor", (int)d->formFactor);
|
|
|
|
group->writeEntry("location", (int)d->location);
|
|
|
|
}
|
|
|
|
|
2007-11-19 02:19:58 +01:00
|
|
|
void Containment::containmentConstraintsUpdated(Plasma::Constraints constraints)
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "got containmentConstraintsUpdated" << constraints << (QObject*)d->toolbox;
|
2007-12-05 21:26:23 +01:00
|
|
|
if (d->toolbox) {
|
|
|
|
if (constraints & Plasma::ScreenConstraint) {
|
|
|
|
d->toolbox->setPos(geometry().width() - d->toolbox->boundingRect().width(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints & Plasma::ImmutableConstraint) {
|
|
|
|
d->toolbox->enableTool("addwidgets", !isImmutable());
|
|
|
|
}
|
2007-11-19 02:19:58 +01: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)
|
|
|
|
{
|
|
|
|
d->type = type;
|
2007-11-29 01:20:37 +01:00
|
|
|
|
|
|
|
if (isContainment() && type == DesktopContainment) {
|
|
|
|
if (!d->toolbox) {
|
2008-01-02 22:52:31 +01:00
|
|
|
Plasma::Widget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
|
2008-01-01 20:57:40 +01:00
|
|
|
connect(addWidgetTool, SIGNAL(clicked()), this, SIGNAL(showAddWidgets()));
|
|
|
|
|
|
|
|
Plasma::Widget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
|
|
|
|
connect(zoomInTool, SIGNAL(clicked()), this, SIGNAL(zoomIn()));
|
|
|
|
|
|
|
|
Plasma::Widget *zoomOutTool = addToolBoxTool("zoomOut", "zoom-out", i18n("Zoom Out"));
|
|
|
|
connect(zoomOutTool, SIGNAL(clicked()), this, SIGNAL(zoomOut()));
|
2007-11-29 01:20:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete d->toolbox;
|
|
|
|
d->toolbox = 0;
|
|
|
|
}
|
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());
|
|
|
|
}
|
|
|
|
|
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-01-08 05:01:42 +01: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-01-08 05:01:42 +01: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-01-25 02:41:16 +01:00
|
|
|
QList<QAction*> actions = applet->contextActions();
|
|
|
|
if (!actions.isEmpty()) {
|
|
|
|
foreach(QAction* action, actions) {
|
|
|
|
desktopMenu.addAction(action);
|
|
|
|
}
|
|
|
|
hasEntries = true;
|
2007-10-07 23:53:20 +02:00
|
|
|
}
|
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
if (applet->hasConfigurationInterface()) {
|
2008-01-04 17:53:55 +01:00
|
|
|
QAction* configureApplet = new QAction(i18n("%1 Settings", applet->name()), &desktopMenu);
|
2007-12-04 03:17:21 +01:00
|
|
|
configureApplet->setIcon(KIcon("configure"));
|
2007-11-22 06:11:06 +01:00
|
|
|
connect(configureApplet, SIGNAL(triggered(bool)),
|
|
|
|
applet, SLOT(showConfigurationInterface()));
|
|
|
|
desktopMenu.addAction(configureApplet);
|
|
|
|
hasEntries = true;
|
|
|
|
}
|
|
|
|
|
2008-02-05 19:27:01 +01:00
|
|
|
actions = contextActions();
|
|
|
|
if (actions.count() > 0) {
|
|
|
|
hasEntries = true;
|
|
|
|
QMenu *containmentActionMenu = &desktopMenu;
|
|
|
|
|
2008-02-13 03:29:45 +01:00
|
|
|
if (actions.count() > 2) {
|
2008-02-05 19:27:01 +01:00
|
|
|
containmentActionMenu = new KMenu(i18n("%1 Options", name()), &desktopMenu);
|
|
|
|
desktopMenu.addMenu(containmentActionMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(QAction* action, actions) {
|
|
|
|
containmentActionMenu->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
if (scene() && !static_cast<Corona*>(scene())->isImmutable()) {
|
2008-01-25 02:41:16 +01:00
|
|
|
if (hasEntries) {
|
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
QAction* closeApplet = new QAction(i18n("Remove this %1", applet->name()), &desktopMenu);
|
|
|
|
QVariant appletV;
|
|
|
|
appletV.setValue((QObject*)applet);
|
|
|
|
closeApplet->setData(appletV);
|
2007-12-04 03:17:21 +01:00
|
|
|
closeApplet->setIcon(KIcon("edit-delete"));
|
2007-11-22 06:11:06 +01:00
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)),
|
|
|
|
this, SLOT(destroyApplet()));
|
|
|
|
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 {
|
|
|
|
if (!scene() || (static_cast<Corona*>(scene())->isImmutable() && !KAuthorized::authorizeKAction("unlock_desktop"))) {
|
|
|
|
//kDebug() << "immutability";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QAction*> actions = contextActions();
|
|
|
|
|
|
|
|
if (actions.count() < 1) {
|
|
|
|
//kDebug() << "no applet, but no actions";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(QAction* action, actions) {
|
|
|
|
desktopMenu.addAction(action);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
void Containment::destroyApplet()
|
|
|
|
{
|
|
|
|
QAction *action = qobject_cast<QAction*>(sender());
|
|
|
|
|
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
|
|
|
|
Phase::self()->animateItem(applet, Phase::Disappear);
|
|
|
|
}
|
|
|
|
|
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;
|
2007-09-18 23:16:17 +02:00
|
|
|
d->formFactor = formFactor;
|
2008-02-07 01:18:22 +01:00
|
|
|
Layout *lay = 0;
|
|
|
|
//note: setting a new layout autodeletes the old one
|
|
|
|
//and creating a layout calls setLayout on the parent
|
2007-09-18 23:16:17 +02:00
|
|
|
|
|
|
|
switch (d->formFactor) {
|
|
|
|
case Planar:
|
2007-11-11 00:19:05 +01:00
|
|
|
lay = new FreeLayout(this);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
case Horizontal:
|
2007-11-11 00:19:05 +01:00
|
|
|
lay = new BoxLayout(BoxLayout::LeftToRight, this);
|
2008-02-18 00:02:09 +01:00
|
|
|
lay->setMargins(0, 0, 0, 0);
|
2007-11-20 01:44:29 +01:00
|
|
|
lay->setSpacing(4);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
case Vertical:
|
2007-11-11 00:19:05 +01:00
|
|
|
lay = new BoxLayout(BoxLayout::TopToBottom, this);
|
2008-02-18 00:02:09 +01:00
|
|
|
lay->setMargins(0, 0, 0, 0);
|
2007-11-20 01:44:29 +01:00
|
|
|
lay->setSpacing(4);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
case MediaCenter:
|
|
|
|
//FIXME: need a layout type here!
|
2008-02-07 01:18:22 +01:00
|
|
|
setLayout(0); //auto-delete
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
default:
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "This can't be happening! Or... can it? ;)" << d->formFactor;
|
2008-02-07 01:18:22 +01:00
|
|
|
setLayout(0); //auto-delete
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-11-11 00:19:05 +01:00
|
|
|
if (lay) {
|
|
|
|
foreach (Applet* applet, d->applets) {
|
|
|
|
lay->addItem(applet);
|
|
|
|
applet->updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
2007-10-02 01:24:38 +02:00
|
|
|
|
|
|
|
updateConstraints(Plasma::FormFactorConstraint);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FormFactor Containment::formFactor() const
|
|
|
|
{
|
2007-12-13 07:27:23 +01:00
|
|
|
if (isContainment()) {
|
|
|
|
return d->formFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Applet::formFactor();
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setLocation(Location location)
|
|
|
|
{
|
|
|
|
if (d->location == location) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2007-11-09 01:44:35 +01:00
|
|
|
setScreen(screen());
|
2007-10-02 01:24:38 +02:00
|
|
|
updateConstraints(Plasma::LocationConstraint);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Location Containment::location() const
|
|
|
|
{
|
|
|
|
return d->location;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::clearApplets()
|
|
|
|
{
|
|
|
|
qDeleteAll(d->applets);
|
|
|
|
d->applets.clear();
|
|
|
|
}
|
|
|
|
|
2007-11-11 00:19:05 +01:00
|
|
|
Applet* Containment::addApplet(const QString& name, const QVariantList& args, uint id, const QRectF& appletGeometry, bool delayInit)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2008-02-18 00:02:09 +01:00
|
|
|
if (!delayInit && isImmutable()) {
|
|
|
|
kDebug() << "addApplet for" << name << "requested, but we're currently immutable!";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-27 16:03:50 +01:00
|
|
|
QGraphicsView *v = view();
|
|
|
|
if (v) {
|
|
|
|
v->setCursor(Qt::BusyCursor);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
Applet* applet = Applet::loadApplet(name, id, args);
|
2007-12-27 16:03:50 +01:00
|
|
|
if (v) {
|
|
|
|
v->unsetCursor();
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
if (!applet) {
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "Applet" << name << "could not be loaded.";
|
2007-09-18 23:16:17 +02:00
|
|
|
applet = new Applet;
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
addApplet(applet, appletGeometry.topLeft(), delayInit);
|
2007-10-07 09:28:24 +02:00
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
if (containmentType() != PanelContainment) {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid();
|
2007-12-24 08:49:33 +01:00
|
|
|
if (appletGeometry.isValid()) {
|
|
|
|
applet->setGeometry(appletGeometry);
|
|
|
|
} else if (appletGeometry.x() != -1 && appletGeometry.y() != -1) {
|
|
|
|
// yes, this means we can't have items start -1, -1
|
|
|
|
applet->setGeometry(QRectF(appletGeometry.topLeft(),
|
|
|
|
applet->sizeHint()));
|
|
|
|
} else if (geometry().isValid()) {
|
|
|
|
applet->setGeometry(geometryForApplet(applet));
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
2007-09-30 20:06:08 +02:00
|
|
|
|
2008-01-01 23:44:56 +01:00
|
|
|
Corona *c = corona();
|
|
|
|
if (c) {
|
2008-01-01 23:54:33 +01:00
|
|
|
connect(applet, SIGNAL(configNeedsSaving()), corona(), SLOT(scheduleConfigSync()));
|
2008-01-01 23:44:56 +01:00
|
|
|
}
|
|
|
|
|
2007-12-29 17:26:36 +01:00
|
|
|
emit appletAdded(applet);
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
//pos must be relative to the containment already. use mapfromscene.
|
|
|
|
//what we're trying to do here for panels is make the applet go to the requested position,
|
|
|
|
//or somewhere close to it, and get integrated properly into the containment as if it were created
|
|
|
|
//there.
|
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-02-18 00:02:09 +01:00
|
|
|
if (!delayInit && isImmutable()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "adding null applet!?!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment *currentContainment = applet->containment();
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
//panels don't want backgrounds, which is important when setting geometry
|
|
|
|
applet->setDrawStandardBackground(false);
|
|
|
|
|
|
|
|
// Calculate where the user wants the applet to go before adding it
|
|
|
|
//so long as this isn't a new applet with a delayed init
|
2008-02-18 00:02:09 +01:00
|
|
|
if (! delayInit || (currentContainment && currentContainment != this)) {
|
2008-02-03 14:09:21 +01:00
|
|
|
index = indexAt(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentContainment && currentContainment != this) {
|
|
|
|
applet->removeSceneEventFilter(currentContainment);
|
|
|
|
KConfigGroup oldConfig = applet->config();
|
|
|
|
applet->resetConfigurationObject();
|
|
|
|
currentContainment->d->applets.removeAll(applet);
|
|
|
|
addChild(applet);
|
|
|
|
|
|
|
|
// now move the old config to the new location
|
|
|
|
KConfigGroup c = config().group("Applets").group(QString::number(applet->id()));
|
|
|
|
oldConfig.reparent(&c);
|
|
|
|
} else {
|
|
|
|
addChild(applet);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->applets << applet;
|
|
|
|
|
|
|
|
connect(applet, SIGNAL(destroyed(QObject*)),
|
|
|
|
this, SLOT(appletDestroyed(QObject*)));
|
|
|
|
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
// Reposition the applet after adding has been done
|
|
|
|
if (index != -1) {
|
|
|
|
BoxLayout *l = dynamic_cast<BoxLayout *>(layout());
|
|
|
|
l->insertItem(index, l->takeAt(l->indexOf(applet)));
|
|
|
|
d->applets.removeAll(applet);
|
|
|
|
d->applets.insert(index, applet);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//FIXME if it came from a panel its bg was disabled
|
|
|
|
//maybe we should expect the applet to handle that on a constraint update?
|
|
|
|
|
|
|
|
//should we really do this? hell, do we have any business playing with the geometry of
|
|
|
|
//non-panel applets at all?
|
|
|
|
if (pos != QPointF(-1, -1)) {
|
|
|
|
applet->setPos(pos);
|
|
|
|
}
|
|
|
|
}
|
2008-02-18 00:02:09 +01:00
|
|
|
|
|
|
|
prepareApplet(applet, delayInit); //must at least flush constraints
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//containment-relative pos... right?
|
|
|
|
int Containment::indexAt(const QPointF &pos) const
|
|
|
|
{
|
|
|
|
if (pos == QPointF(-1, -1)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
BoxLayout *l = dynamic_cast<BoxLayout *>(layout());
|
|
|
|
if (l) {
|
|
|
|
foreach (Applet *existingApplet, d->applets) {
|
|
|
|
if (formFactor() == Horizontal) {
|
|
|
|
qreal middle = (existingApplet->geometry().left() +
|
|
|
|
existingApplet->geometry().right()) / 2.0;
|
|
|
|
// Applets are checked in order so there is no need to check
|
|
|
|
// if the position is equal to or greater than the applet's
|
|
|
|
// leftmost point. This also allows for dropping in the gap
|
|
|
|
// between applets.
|
|
|
|
if (pos.x() < middle) {
|
|
|
|
return l->indexOf(existingApplet);
|
|
|
|
} else if (pos.x() <= existingApplet->geometry().right()) {
|
|
|
|
return l->indexOf(existingApplet) + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qreal middle = (existingApplet->geometry().top() +
|
|
|
|
existingApplet->geometry().bottom()) / 2.0;
|
|
|
|
if (pos.y() < middle) {
|
|
|
|
return l->indexOf(existingApplet);
|
|
|
|
} else if (pos.y() <= existingApplet->geometry().bottom()) {
|
|
|
|
return l->indexOf(existingApplet) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-12-29 17:26:36 +01:00
|
|
|
void Containment::prepareApplet(Applet *applet, bool delayInit)
|
|
|
|
{
|
2007-11-28 00:19:02 +01:00
|
|
|
if (delayInit) {
|
2007-11-28 00:36:10 +01:00
|
|
|
if (containmentType() == DesktopContainment) {
|
2007-11-28 00:23:38 +01:00
|
|
|
applet->installSceneEventFilter(this);
|
|
|
|
}
|
2007-11-28 00:19:02 +01:00
|
|
|
} else {
|
2007-09-18 23:16:17 +02:00
|
|
|
applet->init();
|
2007-11-28 00:19:02 +01:00
|
|
|
Phase::self()->animateItem(applet, Phase::Appear);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-02-13 03:29:45 +01:00
|
|
|
applet->updateConstraints(Plasma::AllConstraints | Plasma::StartupCompletedConstraint);
|
2007-12-29 17:26:36 +01:00
|
|
|
if (!delayInit) {
|
|
|
|
applet->flushUpdatedConstraints();
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2007-12-22 13:32:55 +01:00
|
|
|
QRectF Containment::geometryForApplet(Applet *applet) const
|
|
|
|
{
|
2007-12-22 17:42:09 +01:00
|
|
|
// The value part of these maps isn't used. Only sorted keys are needed.
|
|
|
|
QMap<qreal, bool> xPositions;
|
|
|
|
QMap<qreal, bool> yPositions;
|
|
|
|
|
|
|
|
// Add the top-left corner offset by the applet's border
|
|
|
|
QPointF offset = applet->boundingRect().topLeft();
|
|
|
|
xPositions[-offset.x()] = true;
|
|
|
|
yPositions[-offset.y()] = true;
|
|
|
|
|
|
|
|
QRectF placement(QPointF(0, 0), applet->sizeHint());
|
|
|
|
foreach (Applet *existingApplet, d->applets) {
|
|
|
|
QPointF bottomRight = existingApplet->geometry().bottomRight();
|
|
|
|
if (bottomRight.x() + placement.width() < geometry().width()) {
|
|
|
|
xPositions[bottomRight.x() + 1] = true;
|
2007-12-22 13:32:55 +01:00
|
|
|
}
|
2007-12-22 17:42:09 +01:00
|
|
|
if (bottomRight.y() + placement.height() < geometry().height()) {
|
|
|
|
yPositions[bottomRight.y() + 1] = true;
|
2007-12-22 13:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-22 17:42:09 +01:00
|
|
|
// Try to fit it in an empty space
|
|
|
|
foreach (qreal x, xPositions.keys()) {
|
|
|
|
foreach (qreal y, yPositions.keys()) {
|
|
|
|
placement.moveTo(x, y);
|
|
|
|
if (regionIsEmpty(placement, applet)) {
|
|
|
|
return placement;
|
|
|
|
}
|
2007-12-22 13:32:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise place it in the centre of the screen
|
2007-12-22 13:49:44 +01:00
|
|
|
placement.moveLeft(geometry().width() / 2 - placement.width() / 2);
|
|
|
|
placement.moveTop(geometry().height() / 2 - placement.height() / 2);
|
2007-12-22 13:32:55 +01:00
|
|
|
return placement;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet) const
|
|
|
|
{
|
|
|
|
foreach (Applet *applet, d->applets) {
|
|
|
|
if (applet != ignoredApplet && applet->geometry().intersects(region)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
void Containment::appletDestroyed(QObject* object)
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
Applet* applet = static_cast<Plasma::Applet*>(object);
|
2007-11-27 07:08:44 +01:00
|
|
|
d->applets.removeAll(applet);
|
2007-12-11 03:59:02 +01:00
|
|
|
emit appletRemoved(applet);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2007-11-12 20:27:21 +01:00
|
|
|
void Containment::appletAnimationComplete(QGraphicsItem *item, Plasma::Phase::Animation anim)
|
2007-10-24 04:10:10 +02:00
|
|
|
{
|
|
|
|
if (anim == Phase::Disappear) {
|
2007-11-22 06:11:06 +01:00
|
|
|
QGraphicsItem *parent = item->parentItem();
|
2007-10-24 04:10:10 +02:00
|
|
|
|
2007-11-22 06:11:06 +01:00
|
|
|
while (parent) {
|
|
|
|
if (parent == this) {
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
|
|
|
|
|
|
|
if (applet) {
|
|
|
|
applet->destroy();
|
|
|
|
}
|
2007-11-27 07:08:44 +01:00
|
|
|
|
|
|
|
break;
|
2007-10-24 04:10:10 +02:00
|
|
|
}
|
2007-11-22 06:11:06 +01:00
|
|
|
|
|
|
|
parent = parent->parentItem();
|
2007-10-24 04:10:10 +02:00
|
|
|
}
|
2007-11-12 20:27:21 +01:00
|
|
|
} else if (anim == Phase::Appear) {
|
2007-11-22 08:37:57 +01:00
|
|
|
if (containmentType() == DesktopContainment &&
|
|
|
|
item->parentItem() == this &&
|
2007-11-22 09:00:35 +01:00
|
|
|
qgraphicsitem_cast<Applet*>(item)) {
|
2007-11-22 08:37:57 +01:00
|
|
|
item->installSceneEventFilter(this);
|
2007-11-12 20:27:21 +01:00
|
|
|
}
|
2007-10-24 04:10:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2007-11-17 21:50:57 +01:00
|
|
|
// sanity check to make sure someone else doesn't have this screen already!
|
2007-11-27 00:28:03 +01:00
|
|
|
if (screen > -1 && containmentType() == DesktopContainment && corona()) {
|
2007-11-17 21:50:57 +01:00
|
|
|
Containment* currently = corona()->containmentForScreen(screen);
|
|
|
|
if (currently && currently != this) {
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "currently is on screen" << currently->screen() << "and is" << currently->name() << (QObject*)currently << (QObject*)this;
|
2007-11-17 21:50:57 +01:00
|
|
|
currently->setScreen(-1);
|
|
|
|
}
|
|
|
|
}
|
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-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) {
|
2007-11-09 01:44:35 +01:00
|
|
|
QRect r = desktop->screenGeometry(screen);
|
2007-10-26 01:31:20 +02:00
|
|
|
|
2007-11-19 03:14:18 +01:00
|
|
|
if (containmentType() == DesktopContainment) {
|
2007-10-30 00:32:55 +01:00
|
|
|
// we need to find how many screens are to our top and left
|
|
|
|
// to calculate the proper offsets for the margins.
|
|
|
|
int x = r.x();
|
|
|
|
int y = r.y();
|
|
|
|
int screensLeft = 0;
|
|
|
|
int screensAbove = 0;
|
|
|
|
for (int i = 0; i < numScreens; ++i) {
|
2007-11-09 01:44:35 +01:00
|
|
|
QRect otherScreen = desktop->screenGeometry(screen);
|
2007-10-30 00:32:55 +01:00
|
|
|
if (x > otherScreen.x()) {
|
|
|
|
++screensLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y > otherScreen.y()) {
|
|
|
|
++screensAbove;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
r.moveLeft(r.x() + INTER_CONTAINMENT_MARGIN * screensLeft);
|
|
|
|
r.moveTop(r.y() + INTER_CONTAINMENT_MARGIN * screensAbove);
|
2007-11-17 21:50:57 +01:00
|
|
|
|
|
|
|
// FIXME: positioning at this x,y will break if we switch between containments for a
|
|
|
|
// given screen! we should change the pos() on new containment setup.
|
2007-10-26 01:31:20 +02:00
|
|
|
setGeometry(r);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "setting geometry to" << desktop->screenGeometry(screen) << r << geometry();
|
2007-11-19 03:14:18 +01:00
|
|
|
} else if (containmentType() == PanelContainment) {
|
2007-11-09 01:44:35 +01:00
|
|
|
QRect r = desktop->screenGeometry(screen);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "we are a panel on" << r << ", let's move ourselves to a negative coordinate system" << -(r.y() * 2) - r.height() - INTER_CONTAINMENT_MARGIN;
|
2008-01-07 03:15:29 +01:00
|
|
|
// panels are moved into negative coords; we double the x() so that each screen get's
|
|
|
|
// it's own area for panels
|
2008-01-07 04:56:46 +01:00
|
|
|
int vertOffset = (r.y() * 2) + r.height() + INTER_CONTAINMENT_MARGIN;
|
2007-11-09 01:44:35 +01:00
|
|
|
translate(0, -vertOffset);
|
2007-10-26 01:09:02 +02:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d->screen = screen;
|
2007-10-02 01:24:38 +02:00
|
|
|
updateConstraints(Plasma::ScreenConstraint);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int Containment::screen() const
|
|
|
|
{
|
|
|
|
return d->screen;
|
|
|
|
}
|
|
|
|
|
2007-09-20 20:30:40 +02:00
|
|
|
KPluginInfo::List Containment::knownContainments(const QString &category,
|
|
|
|
const QString &parentApp)
|
|
|
|
{
|
|
|
|
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 ");
|
|
|
|
}
|
|
|
|
|
|
|
|
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] == '')");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "constraint was" << constraint << "which got us" << offers.count() << "matches";
|
2007-09-20 20:30:40 +02:00
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
|
|
|
KPluginInfo::List Containment::knownContainmentsForMimetype(const QString &mimetype)
|
|
|
|
{
|
|
|
|
QString constraint = QString("'%1' in MimeTypes").arg(mimetype);
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "knownContainmentsForMimetype with" << mimetype << constraint;
|
2007-09-20 20:30:40 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
|
|
|
|
2007-09-23 20:03:37 +02:00
|
|
|
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "drop event:" << event->mimeData()->text();
|
2007-09-23 20:03:37 +02:00
|
|
|
|
|
|
|
QString mimetype(static_cast<Corona*>(scene())->appletMimeType());
|
|
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimetype) && scene()) {
|
|
|
|
QString plasmoidName;
|
|
|
|
plasmoidName = event->mimeData()->data(mimetype);
|
2007-10-27 14:37:05 +02:00
|
|
|
QRectF geom(mapFromScene(event->scenePos()), QSize(0, 0));
|
2007-09-23 20:03:37 +02:00
|
|
|
addApplet(plasmoidName, QVariantList(), 0, geom);
|
|
|
|
event->acceptProposedAction();
|
|
|
|
} else if (KUrl::List::canDecode(event->mimeData())) {
|
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();
|
|
|
|
QRectF geom(event->scenePos(), QSize(0, 0));
|
|
|
|
QVariantList args;
|
|
|
|
args << url.url();
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << mimeName;
|
2007-09-23 20:03:37 +02:00
|
|
|
KPluginInfo::List appletList = Applet::knownAppletsForMimetype(mimeName);
|
|
|
|
|
|
|
|
if (appletList.isEmpty()) {
|
2007-10-03 17:46:40 +02:00
|
|
|
// no special applet associated with this mimetype, let's
|
2007-12-31 12:19:34 +01:00
|
|
|
addApplet("icon", args, 0, geom);
|
2007-09-23 20:03:37 +02:00
|
|
|
} else {
|
|
|
|
//TODO: should we show a dialog here to choose which plasmoid load if
|
|
|
|
//appletList.count() > 0?
|
|
|
|
addApplet(appletList.first().pluginName(), args, 0, geom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
event->acceptProposedAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-05 19:40:45 +01:00
|
|
|
void Containment::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
//FIXME Qt4.4 check to see if this is still necessary to avoid unecessary repaints
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
//FIXME Qt4.4 check to see if this is still necessary to avoid unecessary repaints
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
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...
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "got sceneEvent";
|
2007-11-12 20:27:21 +01:00
|
|
|
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
|
|
|
|
2007-11-13 16:49:28 +01:00
|
|
|
switch (event->type()) {
|
2007-11-12 20:27:21 +01:00
|
|
|
case QEvent::GraphicsSceneHoverEnter:
|
2008-01-10 00:43:49 +01:00
|
|
|
//kDebug() << "got hoverenterEvent" << isImmutable() << " " << applet->isImmutable();
|
|
|
|
if (!isImmutable() && !applet->isImmutable()) {
|
|
|
|
if (d->handles.contains(applet)) {
|
|
|
|
d->handles[applet]->startFading(AppletHandle::FadeIn);
|
|
|
|
} else {
|
|
|
|
//kDebug() << "generated applet handle";
|
|
|
|
//TODO: there should be a small delay on showing these. they pop up too quickly/easily
|
|
|
|
// right now
|
|
|
|
AppletHandle *handle = new AppletHandle(this, applet);
|
|
|
|
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;
|
2008-01-10 00:43:49 +01:00
|
|
|
case QEvent::GraphicsSceneHoverLeave:
|
|
|
|
//kDebug() << "got hoverLeaveEvent";
|
|
|
|
if (d->handles.contains(applet)) {
|
|
|
|
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent *>(event);
|
2008-01-10 09:21:37 +01:00
|
|
|
if (!d->handles[applet]->boundingRect().contains(d->handles[applet]->mapFromScene(he->scenePos()))) {
|
2008-01-10 00:43:49 +01:00
|
|
|
d->handles[applet]->startFading(AppletHandle::FadeOut);
|
|
|
|
}
|
|
|
|
}
|
2007-11-12 20:27:21 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::handleDisappeared(AppletHandle *handle)
|
|
|
|
{
|
|
|
|
d->handles.remove(handle->applet());
|
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
|
2007-11-15 12:06:33 +01:00
|
|
|
void Containment::emitLaunchActivated()
|
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug();
|
2007-11-15 12:06:33 +01:00
|
|
|
emit launchActivated();
|
|
|
|
}
|
|
|
|
|
2008-01-01 20:57:40 +01:00
|
|
|
Plasma::Widget * Containment::addToolBoxTool(const QString& toolName, const QString& iconName, const QString& iconText)
|
2007-11-19 02:19:58 +01:00
|
|
|
{
|
2008-01-01 20:57:40 +01:00
|
|
|
Plasma::Icon *tool = new Plasma::Icon(this);
|
|
|
|
|
2008-01-03 23:33:27 +01:00
|
|
|
tool->setDrawBackground(true);
|
2008-01-01 20:57:40 +01:00
|
|
|
tool->setIcon(KIcon(iconName));
|
|
|
|
tool->setText(iconText);
|
|
|
|
tool->setOrientation(Qt::Horizontal);
|
|
|
|
QSizeF iconSize = tool->sizeFromIconSize(22);
|
|
|
|
tool->setMinimumSize(iconSize);
|
|
|
|
tool->setMaximumSize(iconSize);
|
|
|
|
tool->resize(tool->sizeHint());
|
|
|
|
|
2007-12-19 03:41:45 +01:00
|
|
|
d->createToolbox()->addTool(tool, toolName);
|
2008-01-01 20:57:40 +01:00
|
|
|
|
|
|
|
return tool;
|
2007-12-14 07:34:26 +01:00
|
|
|
}
|
2007-11-19 02:19:58 +01:00
|
|
|
|
2007-12-14 07:34:26 +01:00
|
|
|
void Containment::enableToolBoxTool(const QString &toolname, bool enable)
|
|
|
|
{
|
2007-12-19 03:41:45 +01:00
|
|
|
d->createToolbox()->enableTool(toolname, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::isToolboxToolEnabled(const QString &toolname) const
|
|
|
|
{
|
|
|
|
return d->createToolbox()->isToolEnabled(toolname);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-01-21 16:10:19 +01:00
|
|
|
void Containment::showToolbox()
|
|
|
|
{
|
|
|
|
d->createToolbox()->showToolbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::hideToolbox()
|
|
|
|
{
|
|
|
|
d->createToolbox()->hideToolbox();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|