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>
|
2008-03-05 08:08:32 +01:00
|
|
|
#include <KWindowSystem>
|
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"
|
2008-02-29 18:50:57 +01:00
|
|
|
#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;
|
2008-03-12 16:23:33 +01:00
|
|
|
static const int VERTICAL_STACKING_OFFSET = 10000;
|
2007-10-23 17:56:40 +02:00
|
|
|
|
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),
|
2008-02-23 00:41:44 +01:00
|
|
|
screen(-1), // no screen
|
2007-11-28 22:46:17 +01:00
|
|
|
toolbox(0),
|
2008-03-14 18:05:37 +01:00
|
|
|
type(Containment::NoContainmentType),
|
|
|
|
positioning(false)
|
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);
|
2008-03-05 08:08:32 +01:00
|
|
|
positionToolbox();
|
2007-12-14 07:34:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return toolbox;
|
|
|
|
}
|
|
|
|
|
2008-03-05 08:08:32 +01:00
|
|
|
void positionToolbox()
|
|
|
|
{
|
|
|
|
QRectF r;
|
|
|
|
if (screen < 0) {
|
|
|
|
r = q->geometry();
|
|
|
|
} else {
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
r = desktop->availableGeometry(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
toolbox->setPos(QPointF(r.right() - toolbox->boundingRect().width(), r.y()));
|
|
|
|
}
|
|
|
|
|
2008-03-03 19:14:07 +01:00
|
|
|
void setLockToolText();
|
|
|
|
|
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;
|
2008-03-14 18:05:37 +01:00
|
|
|
bool positioning;
|
2007-09-18 23:16:17 +02:00
|
|
|
};
|
|
|
|
|
2008-03-03 19:14:07 +01:00
|
|
|
void Containment::Private::setLockToolText()
|
|
|
|
{
|
|
|
|
if (toolbox) {
|
|
|
|
Icon *icon = dynamic_cast<Plasma::Icon*>(toolbox->tool("lockWidgets"));
|
|
|
|
if (icon) {
|
|
|
|
// we know it's an icon becase we made it
|
|
|
|
icon->setText(q->isImmutable() ? i18n("Unlock Widgets") :
|
|
|
|
i18n("Lock Widgets"));
|
|
|
|
QSizeF iconSize = icon->sizeFromIconSize(22);
|
|
|
|
icon->setMinimumSize(iconSize);
|
|
|
|
icon->setMaximumSize(iconSize);
|
|
|
|
icon->resize(icon->sizeHint());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-23 00:41:44 +01:00
|
|
|
Containment::StyleOption::StyleOption()
|
|
|
|
: QStyleOptionGraphicsItem(),
|
|
|
|
desktop(-1)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const Containment::StyleOption & other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
|
|
|
desktop(other.desktop)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const QStyleOptionGraphicsItem &other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
|
|
|
desktop(-1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
2008-03-14 18:05:37 +01:00
|
|
|
setPos(0, 0);
|
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
|
2008-03-14 18:05:37 +01:00
|
|
|
setPos(0, 0);
|
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
|
|
|
}
|
2008-03-06 01:40:09 +01:00
|
|
|
|
|
|
|
Applet::init();
|
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-03-16 08:20:42 +01:00
|
|
|
if (!isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "got containmentConstraintsUpdated" << constraints << (QObject*)d->toolbox;
|
2008-02-29 23:17:55 +01:00
|
|
|
if (constraints & Plasma::ImmutableConstraint) {
|
2008-03-03 19:14:07 +01:00
|
|
|
d->setLockToolText();
|
|
|
|
|
2008-02-29 23:17:55 +01:00
|
|
|
// tell the applets too
|
|
|
|
foreach (Applet *a, d->applets) {
|
|
|
|
a->constraintsUpdated(ImmutableConstraint);
|
2007-12-05 21:26:23 +01:00
|
|
|
}
|
2008-02-29 23:17:55 +01:00
|
|
|
}
|
2007-12-05 21:26:23 +01:00
|
|
|
|
2008-02-29 23:17:55 +01:00
|
|
|
if (constraints & Plasma::ScreenConstraint && d->toolbox) {
|
|
|
|
d->toolbox->setPos(geometry().width() - d->toolbox->boundingRect().width(), 0);
|
|
|
|
d->toolbox->enableTool("addwidgets", !isImmutable());
|
2007-11-19 02:19:58 +01:00
|
|
|
}
|
2008-03-12 16:23:33 +01:00
|
|
|
|
2008-03-14 18:05:37 +01:00
|
|
|
if (constraints & Plasma::SizeConstraint) {
|
|
|
|
switch (containmentType()) {
|
|
|
|
case PanelContainment:
|
|
|
|
positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
positionContainment();
|
|
|
|
break;
|
|
|
|
}
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
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"));
|
2008-03-18 00:49:01 +01:00
|
|
|
connect(zoomInTool, SIGNAL(clicked()), this, SLOT(zoomIn()));
|
2008-01-01 20:57:40 +01:00
|
|
|
|
|
|
|
Plasma::Widget *zoomOutTool = addToolBoxTool("zoomOut", "zoom-out", i18n("Zoom Out"));
|
|
|
|
connect(zoomOutTool, SIGNAL(clicked()), this, SIGNAL(zoomOut()));
|
2008-03-03 12:44:40 +01:00
|
|
|
|
2008-03-03 19:14:07 +01:00
|
|
|
if (!isKioskImmutable()) {
|
|
|
|
Plasma::Widget *lockTool = addToolBoxTool("lockWidgets", "object-locked",
|
|
|
|
isImmutable() ? i18n("Unlock Widgets") :
|
|
|
|
i18n("Lock Widgets"));
|
|
|
|
connect(lockTool, SIGNAL(clicked()), this, SLOT(toggleDesktopImmutability()));
|
|
|
|
}
|
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-23 19:02:42 +01:00
|
|
|
QList<QAction*> containmentActions = contextActions();
|
|
|
|
if (containmentActions.count() > 0) {
|
2008-03-07 13:43:17 +01:00
|
|
|
if (hasEntries) {
|
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
2008-02-05 19:27:01 +01:00
|
|
|
hasEntries = true;
|
|
|
|
QMenu *containmentActionMenu = &desktopMenu;
|
|
|
|
|
2008-02-23 19:02:42 +01:00
|
|
|
if (actions.count() > 0 && containmentActions.count() > 2) {
|
2008-02-05 19:27:01 +01:00
|
|
|
containmentActionMenu = new KMenu(i18n("%1 Options", name()), &desktopMenu);
|
|
|
|
desktopMenu.addMenu(containmentActionMenu);
|
|
|
|
}
|
|
|
|
|
2008-02-23 19:02:42 +01:00
|
|
|
foreach(QAction* action, containmentActions) {
|
2008-02-05 19:27:01 +01:00
|
|
|
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;
|
2008-03-12 16:23:33 +01:00
|
|
|
FormFactor was = d->formFactor;
|
2008-03-14 18:05:37 +01:00
|
|
|
|
|
|
|
createLayout(formFactor);
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
d->formFactor = formFactor;
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-03-16 08:20:42 +01:00
|
|
|
if (isContainment() && containmentType() == PanelContainment && was != formFactor) {
|
2008-03-14 18:05:37 +01:00
|
|
|
// we are a panel and we have chaged our orientation
|
|
|
|
positionPanel(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
Layout *lay = layout();
|
|
|
|
if (lay) {
|
|
|
|
foreach (Applet* applet, d->applets) {
|
|
|
|
lay->addItem(applet);
|
|
|
|
applet->updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateConstraints(Plasma::FormFactorConstraint);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::createLayout(FormFactor formFactor)
|
|
|
|
{
|
2008-02-07 01:18:22 +01:00
|
|
|
//note: setting a new layout autodeletes the old one
|
|
|
|
//and creating a layout calls setLayout on the parent
|
2008-03-12 16:23:33 +01:00
|
|
|
switch (formFactor) {
|
2007-09-18 23:16:17 +02:00
|
|
|
case Planar:
|
2008-03-05 01:06:22 +01:00
|
|
|
case MediaCenter:
|
2008-03-14 18:05:37 +01:00
|
|
|
new FreeLayout(this);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
case Horizontal: {
|
|
|
|
BoxLayout *lay = new BoxLayout(BoxLayout::LeftToRight, this);
|
2008-02-29 18:50:57 +01:00
|
|
|
lay->setMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(4);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
case Vertical: {
|
|
|
|
BoxLayout *lay = new BoxLayout(BoxLayout::TopToBottom, this);
|
2008-02-29 18:50:57 +01:00
|
|
|
lay->setMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(4);
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
Location Containment::location() const
|
|
|
|
{
|
|
|
|
return d->location;
|
|
|
|
}
|
|
|
|
|
2008-03-03 12:44:40 +01:00
|
|
|
void Containment::toggleDesktopImmutability()
|
|
|
|
{
|
|
|
|
if (corona()) {
|
|
|
|
corona()->setImmutable(!corona()->isImmutable());
|
|
|
|
} else {
|
|
|
|
setImmutable(!isImmutable());
|
|
|
|
}
|
2008-03-03 19:14:07 +01:00
|
|
|
|
|
|
|
d->setLockToolText();
|
2008-03-03 12:44:40 +01:00
|
|
|
}
|
|
|
|
|
2008-03-18 00:49:01 +01:00
|
|
|
void Containment::zoomIn()
|
|
|
|
{
|
|
|
|
emit zoomIn(this);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-02-26 02:58:55 +01:00
|
|
|
Applet* applet = Applet::load(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-02-29 18:50:57 +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(),
|
2008-02-29 18:50:57 +01:00
|
|
|
applet->sizeHint()));
|
2007-12-24 08:49:33 +01:00
|
|
|
} 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);
|
2008-02-29 18:50:57 +01:00
|
|
|
addChild(applet);
|
|
|
|
|
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);
|
|
|
|
} else {
|
2008-02-29 18:50:57 +01:00
|
|
|
addChild(applet);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->applets << applet;
|
|
|
|
|
|
|
|
connect(applet, SIGNAL(destroyed(QObject*)),
|
|
|
|
this, SLOT(appletDestroyed(QObject*)));
|
|
|
|
|
2008-03-14 18:05:37 +01:00
|
|
|
Layout *lay = layout();
|
|
|
|
|
|
|
|
// Reposition the applet after adding has been done
|
|
|
|
if (index != -1) {
|
|
|
|
BoxLayout *l = dynamic_cast<BoxLayout *>(lay);
|
|
|
|
if (l) {
|
2008-02-29 18:50:57 +01:00
|
|
|
l->insertItem(index, l->takeAt(l->indexOf(applet)));
|
|
|
|
d->applets.removeAll(applet);
|
|
|
|
d->applets.insert(index, applet);
|
2008-03-14 18:05:37 +01:00
|
|
|
} else {
|
|
|
|
index = -1;
|
2008-02-29 18:50:57 +01:00
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2008-02-03 14:09:21 +01:00
|
|
|
|
2008-03-14 18:05:37 +01:00
|
|
|
if (index == -1) {
|
2008-02-03 14:09:21 +01:00
|
|
|
if (pos != QPointF(-1, -1)) {
|
|
|
|
applet->setPos(pos);
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
|
|
|
if (lay) {
|
|
|
|
lay->addItem(applet);
|
|
|
|
}
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
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;
|
|
|
|
}
|
2008-02-29 18:50:57 +01:00
|
|
|
BoxLayout *l = dynamic_cast<BoxLayout *>(layout());
|
2008-02-03 14:09:21 +01:00
|
|
|
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) {
|
2008-02-29 18:50:57 +01:00
|
|
|
return l->indexOf(existingApplet);
|
2008-02-03 14:09:21 +01:00
|
|
|
} else if (pos.x() <= existingApplet->geometry().right()) {
|
2008-02-29 18:50:57 +01:00
|
|
|
return l->indexOf(existingApplet) + 1;
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qreal middle = (existingApplet->geometry().top() +
|
|
|
|
existingApplet->geometry().bottom()) / 2.0;
|
|
|
|
if (pos.y() < middle) {
|
2008-02-29 18:50:57 +01:00
|
|
|
return l->indexOf(existingApplet);
|
2008-02-03 14:09:21 +01:00
|
|
|
} else if (pos.y() <= existingApplet->geometry().bottom()) {
|
2008-02-29 18:50:57 +01:00
|
|
|
return l->indexOf(existingApplet) + 1;
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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) {
|
2008-03-20 00:26:21 +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();
|
2008-03-02 10:04:04 +01:00
|
|
|
emit configNeedsSaving();
|
2007-12-29 17:26:36 +01:00
|
|
|
}
|
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;
|
|
|
|
|
2008-02-29 18:50:57 +01:00
|
|
|
QRectF placement(QPointF(0, 0), applet->sizeHint());
|
2007-12-22 17:42:09 +01:00
|
|
|
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);
|
2008-03-02 09:43:07 +01:00
|
|
|
emit configNeedsSaving();
|
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) {
|
2008-03-20 00:26:21 +01:00
|
|
|
if (containmentType() == DesktopContainment &&
|
2007-11-22 08:37:57 +01:00
|
|
|
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.
|
2008-03-12 16:23:33 +01:00
|
|
|
if (containmentType() == DesktopContainment || containmentType() == CustomContainment) {
|
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) {
|
|
|
|
connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(repositionToolbox()));
|
|
|
|
} else if (screen < 0) {
|
|
|
|
disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(repositionToolbox()));
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ||
|
|
|
|
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-03-14 18:05:37 +01:00
|
|
|
void Containment::positionContainment()
|
|
|
|
{
|
|
|
|
Corona *c = corona();
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Containment*> containments = c->containments();
|
|
|
|
QMutableListIterator<Containment*> it(containments);
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
2008-03-16 08:20:42 +01:00
|
|
|
if (containment == this ||
|
|
|
|
containment->containmentType() == PanelContainment) {
|
2008-03-14 18:05:37 +01:00
|
|
|
// weed out all containments we don't care about at all
|
2008-03-16 08:20:42 +01:00
|
|
|
// e.g. Panels and ourself
|
2008-03-14 18:05:37 +01:00
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collidesWithItem(containment)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!it.hasNext()) {
|
|
|
|
// we made it all the way through the list, we have no
|
|
|
|
// collisions
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we need to find how many screens are to our top and left
|
|
|
|
// to calculate the proper offsets for the margins.
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width = (width + INTER_CONTAINMENT_MARGIN) * 4;
|
|
|
|
height += INTER_CONTAINMENT_MARGIN;
|
|
|
|
|
|
|
|
// a mildly naive "find the first slot" approach
|
|
|
|
QRectF r = boundingRect();
|
|
|
|
QPointF topLeft(0, 0);
|
|
|
|
setPos(topLeft);
|
|
|
|
|
|
|
|
d->positioning = true;
|
|
|
|
while (true) {
|
|
|
|
it.toFront();
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
if (collidesWithItem(containment)) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!it.hasNext()) {
|
|
|
|
// success! no collisions!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (topLeft.x() + (r.width() * 2) + INTER_CONTAINMENT_MARGIN > width) {
|
|
|
|
// we ran out of width room, try another row
|
|
|
|
topLeft = QPoint(0, topLeft.y() + height);
|
|
|
|
} else {
|
|
|
|
topLeft.setX(topLeft.x() + r.width() + INTER_CONTAINMENT_MARGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
kDebug() << "trying at" << topLeft;
|
|
|
|
setPos(topLeft);
|
|
|
|
//kDebug() << collidingItems().count() << collidingItems()[0] << (QGraphicsItem*)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->positioning = false;
|
|
|
|
}
|
|
|
|
|
2008-03-12 16:23:33 +01:00
|
|
|
void Containment::positionPanel(bool force)
|
|
|
|
{
|
|
|
|
if (!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 = pos();
|
|
|
|
|
|
|
|
if (!force &&
|
|
|
|
p.y() + size().height() < -INTER_CONTAINMENT_MARGIN &&
|
|
|
|
scene()->collidingItems(this).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 = formFactor() == Plasma::Horizontal;
|
|
|
|
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
|
|
|
qreal lastHeight = 0;
|
|
|
|
|
|
|
|
// this should be ok for small numbers of panels, but we ever end
|
|
|
|
// up managing hundreds of them, this simplistic alogrithm will
|
|
|
|
// likely be too slow.
|
|
|
|
foreach (const Containment* other, corona()->containments()) {
|
|
|
|
if (other == this ||
|
|
|
|
other->containmentType() != PanelContainment ||
|
|
|
|
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 - size().height());
|
|
|
|
newPos = QPointF(0, bottom - size().height());
|
|
|
|
} else {
|
|
|
|
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix y position for non-flush-top panels
|
|
|
|
kDebug() << "moved to" << QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height());
|
|
|
|
newPos = QPointF(bottom + size().width(), -INTER_CONTAINMENT_MARGIN - size().height());
|
|
|
|
}
|
|
|
|
|
2008-03-14 18:05:37 +01:00
|
|
|
d->positioning = true;
|
2008-03-12 16:23:33 +01:00
|
|
|
if (p != newPos) {
|
|
|
|
setPos(newPos);
|
|
|
|
emit geometryChanged();
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
d->positioning = false;
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
int Containment::screen() const
|
|
|
|
{
|
|
|
|
return d->screen;
|
|
|
|
}
|
|
|
|
|
2008-03-14 18:05:37 +01:00
|
|
|
QPoint Containment::effectiveScreenPos() const
|
|
|
|
{
|
|
|
|
if (d->screen < 0) {
|
|
|
|
return QPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect r = QApplication::desktop()->screenGeometry(d->screen);
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
QRectF p = geometry();
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//NOTE: if we ever support non-origin'd desktop containments
|
|
|
|
// this assumption here will have to change
|
|
|
|
return r.topLeft();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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())) {
|
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();
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2008-03-12 16:23:33 +01:00
|
|
|
QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value)
|
|
|
|
{
|
|
|
|
Q_UNUSED(value)
|
|
|
|
|
2008-03-16 08:20:42 +01:00
|
|
|
if (isContainment() &&
|
|
|
|
(change == QGraphicsItem::ItemSceneHasChanged || change == QGraphicsItem::ItemPositionHasChanged) &&
|
2008-03-14 18:05:37 +01:00
|
|
|
!d->positioning) {
|
|
|
|
switch (containmentType()) {
|
|
|
|
case PanelContainment:
|
|
|
|
positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
positionContainment();
|
|
|
|
break;
|
|
|
|
}
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Applet::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
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);
|
2008-02-29 18:50:57 +01:00
|
|
|
tool->resize(tool->sizeHint());
|
2008-01-01 20:57:40 +01:00
|
|
|
|
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)
|
|
|
|
{
|
2008-03-17 00:58:12 +01:00
|
|
|
if (d->toolbox) {
|
|
|
|
d->toolbox->enableTool(toolname, enable);
|
|
|
|
}
|
2007-12-19 03:41:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::isToolboxToolEnabled(const QString &toolname) const
|
|
|
|
{
|
2008-03-17 00:58:12 +01:00
|
|
|
if (d->toolbox) {
|
|
|
|
return d->toolbox->isToolEnabled(toolname);
|
|
|
|
}
|
|
|
|
return false;
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-01-21 16:10:19 +01:00
|
|
|
void Containment::showToolbox()
|
|
|
|
{
|
2008-03-12 16:23:33 +01:00
|
|
|
if (d->toolbox) {
|
|
|
|
d->toolbox->showToolbox();
|
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::hideToolbox()
|
|
|
|
{
|
2008-03-12 16:23:33 +01:00
|
|
|
if (d->toolbox) {
|
|
|
|
d->toolbox->hideToolbox();
|
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
2008-03-05 08:08:32 +01:00
|
|
|
void Containment::repositionToolbox()
|
|
|
|
{
|
|
|
|
//kDebug() << "reposition" << d->screen << (QObject*)d->toolbox;
|
|
|
|
if (d->toolbox) {
|
|
|
|
d->positionToolbox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|