2007-09-18 23:16:17 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
2008-04-14 11:36:55 +02:00
|
|
|
* Copyright 2008 by Ménard Alexis <darktears31@gmail.com>
|
2007-09-18 23:16:17 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "containment.h"
|
2008-04-25 20:44:09 +02:00
|
|
|
#include "containment_p.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
|
|
|
|
#include <QAction>
|
|
|
|
#include <QDesktopWidget>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QGraphicsSceneContextMenuEvent>
|
2007-12-27 16:03:50 +01:00
|
|
|
#include <QGraphicsView>
|
2007-09-23 20:03:37 +02:00
|
|
|
#include <QMimeData>
|
2007-09-18 23:16:17 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QStyleOptionGraphicsItem>
|
2008-04-13 15:23:39 +02:00
|
|
|
#include <QGraphicsLayout>
|
|
|
|
#include <QGraphicsLinearLayout>
|
2007-09-18 23:16:17 +02:00
|
|
|
|
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"
|
2008-04-25 05:23:31 +02:00
|
|
|
#include "animator.h"
|
2007-12-21 02:14:32 +01:00
|
|
|
#include "desktoptoolbox_p.h"
|
2008-04-14 15:05:49 +02:00
|
|
|
#include "paneltoolbox_p.h"
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "svg.h"
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-02-23 00:41:44 +01:00
|
|
|
Containment::StyleOption::StyleOption()
|
|
|
|
: QStyleOptionGraphicsItem(),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(0)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const Containment::StyleOption & other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(other.view)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment::StyleOption::StyleOption(const QStyleOptionGraphicsItem &other)
|
|
|
|
: QStyleOptionGraphicsItem(other),
|
2008-04-24 18:01:09 +02:00
|
|
|
view(0)
|
2008-02-23 00:41:44 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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);
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(DefaultBackground);
|
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);
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(NoBackground);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Containment::~Containment()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::init()
|
|
|
|
{
|
2008-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
|
|
|
|
2008-04-25 05:11:59 +02:00
|
|
|
//TODO: would be nice to not do this on init, as it causes Animator to init
|
|
|
|
connect(Animator::self(), SIGNAL(animationFinished(QGraphicsItem*,Plasma::Animator::Animation)),
|
|
|
|
this, SLOT(appletAnimationComplete(QGraphicsItem*,Plasma::Animator::Animation)));
|
2007-11-19 03:14:18 +01:00
|
|
|
|
2007-11-29 01:20:37 +01:00
|
|
|
if (d->type == NoContainmentType) {
|
|
|
|
setContainmentType(DesktopContainment);
|
2007-11-19 02:19:58 +01:00
|
|
|
}
|
2008-03-06 01:40:09 +01:00
|
|
|
|
|
|
|
Applet::init();
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 00:18:07 +02:00
|
|
|
// helper function for sorting the list of applets
|
|
|
|
bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2)
|
|
|
|
{
|
|
|
|
QPointF p1 = c1.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
QPointF p2 = c2.readEntry("geometry", QRectF()).topLeft();
|
|
|
|
if (p1.x() != p2.x()) {
|
|
|
|
return p1.x() < p2.x();
|
|
|
|
}
|
|
|
|
return p1.y() < p2.y();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::loadContainment(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);*/
|
2008-03-22 19:56:59 +01:00
|
|
|
|
|
|
|
QRectF geo = group->readEntry("geometry", geometry());
|
|
|
|
//override max/min
|
|
|
|
if (geo.size() != geo.size().boundedTo(maximumSize())) {
|
|
|
|
setMaximumSize(maximumSize().expandedTo(geo.size()));
|
|
|
|
}
|
|
|
|
if (geo.size() != geo.size().expandedTo(minimumSize())) {
|
|
|
|
setMinimumSize(minimumSize().boundedTo(geo.size()));
|
|
|
|
}
|
|
|
|
setGeometry(geo);
|
|
|
|
|
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));
|
2008-04-25 00:18:07 +02:00
|
|
|
|
|
|
|
flushUpdatedConstraints();
|
|
|
|
//kDebug() << "Containment" << id() << "geometry is" << geometry() << "config'd with" << appletConfig.name();
|
|
|
|
KConfigGroup applets(group, "Applets");
|
|
|
|
|
|
|
|
// Sort the applet configs in order of geometry to ensure that applets
|
|
|
|
// are added from left to right or top to bottom for a panel containment
|
|
|
|
QList<KConfigGroup> appletConfigs;
|
|
|
|
foreach (const QString &appletGroup, applets.groupList()) {
|
|
|
|
//kDebug() << "reading from applet group" << appletGroup;
|
|
|
|
KConfigGroup appletConfig(&applets, appletGroup);
|
|
|
|
appletConfigs.append(appletConfig);
|
|
|
|
}
|
|
|
|
qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan);
|
|
|
|
|
|
|
|
foreach (KConfigGroup appletConfig, appletConfigs) {
|
|
|
|
int appId = appletConfig.name().toUInt();
|
|
|
|
//kDebug() << "the name is" << appletConfig.name();
|
|
|
|
QString plugin = appletConfig.readEntry("plugin", QString());
|
|
|
|
|
|
|
|
if (plugin.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = d->addApplet(plugin, QVariantList(), appletConfig.readEntry("geometry", QRectF()), appId, true);
|
|
|
|
applet->restore(&appletConfig);
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 00:18:07 +02:00
|
|
|
void Containment::saveContainment(KConfigGroup* group) const
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
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: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
|
|
|
|
2008-04-13 15:23:39 +02:00
|
|
|
if (isContainment() && type == DesktopContainment) {
|
2008-04-25 20:44:09 +02:00
|
|
|
if (!d->toolBox) {
|
2008-04-14 00:01:18 +02:00
|
|
|
QGraphicsWidget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
|
2008-04-25 04:53:35 +02:00
|
|
|
connect(addWidgetTool, SIGNAL(clicked()), this, SLOT(triggerShowAddWidgets()));
|
2008-01-01 20:57:40 +01:00
|
|
|
|
2008-04-14 00:01:18 +02:00
|
|
|
QGraphicsWidget *zoomInTool = addToolBoxTool("zoomIn", "zoom-in", i18n("Zoom In"));
|
2008-04-13 15:23:39 +02:00
|
|
|
connect(zoomInTool, SIGNAL(clicked()), this, SLOT(zoomIn()));
|
2008-01-01 20:57:40 +01:00
|
|
|
|
2008-04-14 00:01:18 +02:00
|
|
|
QGraphicsWidget *zoomOutTool = addToolBoxTool("zoomOut", "zoom-out", i18n("Zoom Out"));
|
2008-04-25 21:08:49 +02:00
|
|
|
connect(zoomOutTool, SIGNAL(clicked()), this, SLOT(zoomOut()));
|
2008-04-13 10:18:46 +02:00
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
if (immutability() != SystemImmutable) {
|
2008-04-14 00:01:18 +02:00
|
|
|
QGraphicsWidget *lockTool = addToolBoxTool("lockWidgets", "object-locked",
|
2008-04-24 20:24:11 +02:00
|
|
|
immutability() == UserImmutable ? i18n("Unlock Widgets") :
|
2008-04-13 15:23:39 +02:00
|
|
|
i18n("Lock Widgets"));
|
|
|
|
connect(lockTool, SIGNAL(clicked()), this, SLOT(toggleDesktopImmutability()));
|
|
|
|
}
|
2008-04-14 11:23:35 +02:00
|
|
|
|
2008-04-14 11:36:55 +02:00
|
|
|
QGraphicsWidget *activityTool = addToolBoxTool("addSiblingContainment", "list-add", i18n("Add Activity"));
|
2008-04-14 11:23:35 +02:00
|
|
|
connect(activityTool, SIGNAL(clicked()), this, SLOT(addSiblingContainment()));
|
2008-04-13 15:23:39 +02:00
|
|
|
}
|
2008-04-14 23:26:40 +02:00
|
|
|
|
2008-04-14 23:09:15 +02:00
|
|
|
} else if (isContainment() && type == PanelContainment) {
|
2008-04-25 20:44:09 +02:00
|
|
|
if (!d->toolBox) {
|
|
|
|
d->createToolBox();
|
|
|
|
d->toolBox->setSize(22);
|
|
|
|
d->toolBox->setIconSize(QSize(16, 16));
|
2008-04-18 18:05:20 +02:00
|
|
|
}
|
2008-04-13 15:23:39 +02:00
|
|
|
} else {
|
2008-04-25 20:44:09 +02:00
|
|
|
delete d->toolBox;
|
|
|
|
d->toolBox = 0;
|
2008-04-13 15:23:39 +02:00
|
|
|
}
|
2007-10-09 18:33:52 +02:00
|
|
|
}
|
|
|
|
|
2007-11-09 01:44:35 +01:00
|
|
|
Corona* Containment::corona() const
|
|
|
|
{
|
|
|
|
return dynamic_cast<Corona*>(scene());
|
|
|
|
}
|
|
|
|
|
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-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> actions = applet->contextualActions();
|
2008-01-25 02:41:16 +01:00
|
|
|
if (!actions.isEmpty()) {
|
|
|
|
foreach(QAction* action, actions) {
|
|
|
|
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-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> containmentActions = contextualActions();
|
2008-03-30 01:57:36 +01:00
|
|
|
if (!containmentActions.isEmpty()) {
|
2008-03-07 13:43:17 +01:00
|
|
|
if (hasEntries) {
|
|
|
|
desktopMenu.addSeparator();
|
|
|
|
}
|
2008-02-05 19:27:01 +01:00
|
|
|
hasEntries = true;
|
|
|
|
QMenu *containmentActionMenu = &desktopMenu;
|
|
|
|
|
2008-03-30 01:57:36 +01:00
|
|
|
if (!actions.isEmpty() && containmentActions.count() > 2) {
|
2008-02-05 19:27:01 +01:00
|
|
|
containmentActionMenu = new KMenu(i18n("%1 Options", name()), &desktopMenu);
|
|
|
|
desktopMenu.addMenu(containmentActionMenu);
|
|
|
|
}
|
|
|
|
|
2008-02-23 19:02:42 +01:00
|
|
|
foreach(QAction* action, containmentActions) {
|
2008-02-05 19:27:01 +01:00
|
|
|
containmentActionMenu->addAction(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-24 20:24:11 +02:00
|
|
|
if (scene() && !static_cast<Corona*>(scene())->immutability() != NotImmutable) {
|
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"));
|
2008-04-25 04:53:35 +02:00
|
|
|
connect(closeApplet, SIGNAL(triggered(bool)), this, SLOT(destroyApplet()));
|
2007-11-22 06:11:06 +01:00
|
|
|
desktopMenu.addAction(closeApplet);
|
|
|
|
hasEntries = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasEntries) {
|
2007-12-27 16:19:01 +01:00
|
|
|
Applet::contextMenuEvent(event);
|
2008-01-08 02:25:09 +01:00
|
|
|
kDebug() << "no entries";
|
2007-11-22 06:11:06 +01:00
|
|
|
return;
|
2007-11-18 23:02:01 +01:00
|
|
|
}
|
2008-01-25 02:41:16 +01:00
|
|
|
} else {
|
2008-04-24 20:24:11 +02:00
|
|
|
if (!scene() || (static_cast<Corona*>(scene())->immutability() != NotImmutable && !KAuthorized::authorizeKAction("unlock_desktop"))) {
|
2008-01-25 02:41:16 +01:00
|
|
|
//kDebug() << "immutability";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-04-25 21:55:24 +02:00
|
|
|
QList<QAction*> actions = contextualActions();
|
2008-01-25 02:41:16 +01:00
|
|
|
|
|
|
|
if (actions.count() < 1) {
|
|
|
|
//kDebug() << "no applet, but no actions";
|
|
|
|
Applet::contextMenuEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionPanel(true);
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
|
2008-04-13 15:23:39 +02:00
|
|
|
QGraphicsLayout *lay = layout();
|
|
|
|
QGraphicsLinearLayout * linearLay = dynamic_cast<QGraphicsLinearLayout *>(lay);
|
|
|
|
if (linearLay) {
|
2008-03-14 18:05:37 +01:00
|
|
|
foreach (Applet* applet, d->applets) {
|
|
|
|
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-04-13 15:23:39 +02:00
|
|
|
//setLayout(new QGraphicsLinearLayout());
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
case Horizontal: {
|
2008-04-17 17:29:28 +02:00
|
|
|
if
|
|
|
|
(!layout())
|
|
|
|
{
|
|
|
|
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
|
|
|
|
lay->setOrientation(Qt::Horizontal);
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(4);
|
|
|
|
lay->setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding));
|
|
|
|
setLayout(lay);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsLayout *lay = layout();
|
|
|
|
QGraphicsLinearLayout * linearLay = dynamic_cast<QGraphicsLinearLayout *>(lay);
|
|
|
|
if (linearLay) {
|
|
|
|
linearLay->setOrientation(Qt::Horizontal);
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
case Vertical: {
|
2008-04-17 17:29:28 +02:00
|
|
|
if
|
|
|
|
(!layout())
|
|
|
|
{
|
|
|
|
QGraphicsLinearLayout *lay = new QGraphicsLinearLayout();
|
|
|
|
lay->setOrientation(Qt::Vertical);
|
|
|
|
lay->setContentsMargins(0, 0, 0, 0);
|
|
|
|
lay->setSpacing(4);
|
|
|
|
setLayout(lay);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QGraphicsLayout *lay = layout();
|
|
|
|
QGraphicsLinearLayout * linearLay = dynamic_cast<QGraphicsLinearLayout *>(lay);
|
|
|
|
if (linearLay) {
|
|
|
|
linearLay->setOrientation(Qt::Vertical);
|
|
|
|
}
|
|
|
|
}
|
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-04-13 15:23:39 +02: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-04-14 11:23:35 +02:00
|
|
|
void Containment::addSiblingContainment()
|
|
|
|
{
|
|
|
|
emit addSiblingContainment(this);
|
|
|
|
}
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
void Containment::clearApplets()
|
|
|
|
{
|
|
|
|
qDeleteAll(d->applets);
|
|
|
|
d->applets.clear();
|
|
|
|
}
|
|
|
|
|
2008-04-25 00:18:07 +02:00
|
|
|
Applet* Containment::addApplet(const QString& name, const QVariantList& args, const QRectF &appletGeometry)
|
2007-09-18 23:16:17 +02:00
|
|
|
{
|
2008-04-25 00:18:07 +02:00
|
|
|
return d->addApplet(name, args, appletGeometry);
|
|
|
|
}
|
|
|
|
|
2008-02-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-04-24 20:24:11 +02:00
|
|
|
if (!delayInit && immutability() != NotImmutable) {
|
2008-02-18 00:02:09 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "adding null applet!?!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Containment *currentContainment = applet->containment();
|
|
|
|
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
//panels don't want backgrounds, which is important when setting geometry
|
2008-04-26 11:13:57 +02:00
|
|
|
setBackgroundHints(NoBackground);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentContainment && currentContainment != this) {
|
|
|
|
applet->removeSceneEventFilter(currentContainment);
|
|
|
|
KConfigGroup oldConfig = applet->config();
|
|
|
|
currentContainment->d->applets.removeAll(applet);
|
2008-04-15 04:38:48 +02:00
|
|
|
applet->setParentItem(this);
|
2008-02-29 18:50:57 +01:00
|
|
|
|
2008-02-03 14:09:21 +01:00
|
|
|
// now move the old config to the new location
|
|
|
|
KConfigGroup c = config().group("Applets").group(QString::number(applet->id()));
|
|
|
|
oldConfig.reparent(&c);
|
2008-03-23 22:36:33 +01:00
|
|
|
applet->resetConfigurationObject();
|
2008-02-03 14:09:21 +01:00
|
|
|
} else {
|
2008-04-14 18:02:23 +02:00
|
|
|
applet->setParentItem(this);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->applets << applet;
|
|
|
|
|
2008-04-25 01:07:21 +02:00
|
|
|
connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*)));
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 01:07:21 +02:00
|
|
|
if (pos != QPointF(-1, -1)) {
|
|
|
|
applet->setPos(pos);
|
2008-02-03 14:09:21 +01:00
|
|
|
}
|
2008-02-18 00:02:09 +01:00
|
|
|
|
2007-11-28 00:19:02 +01:00
|
|
|
if (delayInit) {
|
2008-03-20 00:26:21 +01:00
|
|
|
if (containmentType() == DesktopContainment) {
|
2007-11-28 00:23:38 +01:00
|
|
|
applet->installSceneEventFilter(this);
|
|
|
|
}
|
2007-11-28 00:19:02 +01:00
|
|
|
} else {
|
2007-09-18 23:16:17 +02:00
|
|
|
applet->init();
|
2008-04-25 05:11:59 +02:00
|
|
|
Animator::self()->animateItem(applet, Animator::AppearAnimation);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-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
|
|
|
}
|
2008-04-25 01:07:21 +02:00
|
|
|
|
|
|
|
emit appletAdded(applet, pos);
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Applet::List Containment::applets() const
|
|
|
|
{
|
|
|
|
return d->applets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::setScreen(int screen)
|
|
|
|
{
|
2007-10-26 01:09:02 +02:00
|
|
|
// screen of -1 means no associated screen.
|
2008-04-24 18:16:50 +02:00
|
|
|
if (containmentType() == DesktopContainment || containmentType() >= CustomContainment) {
|
2008-04-01 18:24:15 +02:00
|
|
|
#ifndef Q_OS_WIN
|
2008-03-05 08:08:32 +01:00
|
|
|
// we want to listen to changes in work area if our screen changes
|
|
|
|
if (d->screen < 0 && screen > -1) {
|
2008-04-26 05:33:41 +02:00
|
|
|
connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2008-03-05 08:08:32 +01:00
|
|
|
} else if (screen < 0) {
|
2008-04-26 05:33:41 +02:00
|
|
|
disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(positionToolBox()));
|
2008-03-05 08:08:32 +01:00
|
|
|
}
|
2008-04-01 18:24:15 +02:00
|
|
|
#endif
|
2008-03-05 08:08:32 +01:00
|
|
|
if (screen > -1 && corona()) {
|
2008-03-12 16:23:33 +01:00
|
|
|
// sanity check to make sure someone else doesn't have this screen already!
|
2008-03-05 08:08:32 +01:00
|
|
|
Containment* currently = corona()->containmentForScreen(screen);
|
|
|
|
if (currently && currently != this) {
|
|
|
|
//kDebug() << "currently is on screen" << currently->screen() << "and is" << currently->name() << (QObject*)currently << (QObject*)this;
|
|
|
|
currently->setScreen(-1);
|
|
|
|
}
|
2007-11-17 21:50:57 +01:00
|
|
|
}
|
|
|
|
}
|
2007-10-26 01:09:02 +02:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "setting screen to" << screen << "and we are a" << containmentType();
|
2007-11-09 01:44:35 +01:00
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
int numScreens = desktop->numScreens();
|
2007-11-27 09:47:46 +01:00
|
|
|
if (screen < -1) {
|
2007-09-18 23:16:17 +02:00
|
|
|
screen = -1;
|
|
|
|
}
|
2008-03-03 15:40:02 +01:00
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "setting screen to " << screen << "and type is" << containmentType();
|
2007-11-27 09:47:46 +01:00
|
|
|
if (screen < numScreens && screen > -1) {
|
2008-03-12 16:23:33 +01:00
|
|
|
if (containmentType() == DesktopContainment ||
|
2008-04-24 18:16:50 +02:00
|
|
|
containmentType() >= CustomContainment) {
|
2008-03-14 18:05:37 +01:00
|
|
|
resize(desktop->screenGeometry(screen).size());
|
2007-10-26 01:09:02 +02:00
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-03-12 21:41:03 +01:00
|
|
|
int oldScreen = d->screen;
|
2007-09-18 23:16:17 +02:00
|
|
|
d->screen = screen;
|
2007-10-02 01:24:38 +02:00
|
|
|
updateConstraints(Plasma::ScreenConstraint);
|
2008-03-16 08:20:42 +01:00
|
|
|
if (oldScreen != screen) {
|
|
|
|
emit screenChanged(oldScreen, screen, this);
|
|
|
|
}
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
int Containment::screen() const
|
2008-03-14 18:05:37 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
return d->screen;
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
QPoint Containment::effectiveScreenPos() const
|
|
|
|
{
|
|
|
|
if (d->screen < 0) {
|
|
|
|
return QPoint();
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
QRect r = QApplication::desktop()->screenGeometry(d->screen);
|
|
|
|
if (containmentType() == PanelContainment) {
|
|
|
|
QRectF p = geometry();
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
switch (d->location) {
|
|
|
|
case TopEdge:
|
|
|
|
return QPoint(r.left() + p.x(), r.top());
|
|
|
|
break;
|
|
|
|
case BottomEdge:
|
|
|
|
return QPoint(r.left() + p.x(), r.bottom() - p.height());
|
|
|
|
break;
|
|
|
|
case LeftEdge:
|
|
|
|
return QPoint(r.left(), r.top() + (p.bottom() + INTER_CONTAINMENT_MARGIN));
|
|
|
|
break;
|
|
|
|
case RightEdge:
|
|
|
|
return QPoint(r.right() - p.width(), r.top() + (p.bottom() + INTER_CONTAINMENT_MARGIN));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//FIXME: implement properly for Floating!
|
|
|
|
return p.topLeft().toPoint();
|
|
|
|
break;
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
} else {
|
|
|
|
//NOTE: if we ever support non-origin'd desktop containments
|
|
|
|
// this assumption here will have to change
|
|
|
|
return r.topLeft();
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
2008-04-25 20:44:09 +02:00
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KPluginInfo::List Containment::listContainments(const QString &category,
|
|
|
|
const QString &parentApp)
|
|
|
|
{
|
|
|
|
QString constraint;
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
if (parentApp.isEmpty()) {
|
|
|
|
constraint.append("not exist [X-KDE-ParentApp]");
|
|
|
|
} else {
|
|
|
|
constraint.append("[X-KDE-ParentApp] == '").append(parentApp).append("'");
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
if (!category.isEmpty()) {
|
|
|
|
if (!constraint.isEmpty()) {
|
|
|
|
constraint.append(" and ");
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
constraint.append("[X-KDE-PluginInfo-Category] == '").append(category).append("'");
|
|
|
|
if (category == "Miscellaneous") {
|
|
|
|
constraint.append(" or (not exist [X-KDE-PluginInfo-Category] or [X-KDE-PluginInfo-Category] == '')");
|
2008-03-14 18:05:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
//kDebug() << "constraint was" << constraint << "which got us" << offers.count() << "matches";
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2008-03-14 18:05:37 +01:00
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
KPluginInfo::List Containment::listContainmentsForMimetype(const QString &mimetype)
|
|
|
|
{
|
|
|
|
QString constraint = QString("'%1' in MimeTypes").arg(mimetype);
|
|
|
|
//kDebug() << mimetype << constraint;
|
|
|
|
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
|
|
|
|
return KPluginInfo::fromServices(offers);
|
|
|
|
}
|
2007-09-20 20:30:40 +02:00
|
|
|
|
2007-09-23 20:03:37 +02:00
|
|
|
void Containment::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
2008-04-24 23:33:16 +02:00
|
|
|
//kDebug() << event->mimeData()->text();
|
2007-09-23 20:03:37 +02:00
|
|
|
|
|
|
|
QString mimetype(static_cast<Corona*>(scene())->appletMimeType());
|
|
|
|
|
|
|
|
if (event->mimeData()->hasFormat(mimetype) && scene()) {
|
|
|
|
QString plasmoidName;
|
|
|
|
plasmoidName = event->mimeData()->data(mimetype);
|
2007-10-27 14:37:05 +02:00
|
|
|
QRectF geom(mapFromScene(event->scenePos()), QSize(0, 0));
|
2008-04-25 00:18:07 +02:00
|
|
|
addApplet(plasmoidName, QVariantList(), geom);
|
2007-09-23 20:03:37 +02:00
|
|
|
event->acceptProposedAction();
|
|
|
|
} else if (KUrl::List::canDecode(event->mimeData())) {
|
2008-03-12 16:23:33 +01:00
|
|
|
//TODO: collect the mimetypes of available script engines and offer
|
|
|
|
// to create widgets out of the matching URLs, if any
|
2007-10-03 17:46:40 +02:00
|
|
|
KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
|
2007-09-23 20:03:37 +02:00
|
|
|
foreach (const KUrl& url, urls) {
|
|
|
|
KMimeType::Ptr mime = KMimeType::findByUrl(url);
|
|
|
|
QString mimeName = mime->name();
|
|
|
|
QRectF geom(event->scenePos(), QSize(0, 0));
|
|
|
|
QVariantList args;
|
|
|
|
args << url.url();
|
2008-01-08 02:25:09 +01:00
|
|
|
// kDebug() << mimeName;
|
2008-04-16 23:15:38 +02:00
|
|
|
KPluginInfo::List appletList = Applet::listAppletInfoForMimetype(mimeName);
|
2007-09-23 20:03:37 +02:00
|
|
|
|
|
|
|
if (appletList.isEmpty()) {
|
2007-10-03 17:46:40 +02:00
|
|
|
// no special applet associated with this mimetype, let's
|
2008-04-25 00:18:07 +02:00
|
|
|
addApplet("icon", args, geom);
|
2007-09-23 20:03:37 +02:00
|
|
|
} else {
|
|
|
|
//TODO: should we show a dialog here to choose which plasmoid load if
|
2008-03-30 01:57:36 +01:00
|
|
|
//!appletList.isEmpty()
|
2008-04-25 00:18:07 +02:00
|
|
|
addApplet(appletList.first().pluginName(), args, geom);
|
2007-09-23 20:03:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2008-04-14 23:50:41 +02:00
|
|
|
void Containment::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
kDebug() << "keyPressEvent with" << event->key() << "and hoping and wishing for a" << Qt::Key_Tab;
|
|
|
|
if (event->key() == Qt::Key_Tab) { // && event->modifiers() == 0) {
|
|
|
|
kDebug() << "let's give focus to...." << (QObject*)d->applets.first();
|
|
|
|
if (!d->applets.isEmpty()) {
|
|
|
|
d->applets.first()->setFocus(Qt::TabFocusReason);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-04-24 20:24:11 +02:00
|
|
|
//kDebug() << "got hoverenterEvent" << immutability() << " " << applet->immutability();
|
|
|
|
if (immutability() == NotImmutable && applet->immutability() == NotImmutable) {
|
2008-01-10 00:43:49 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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:
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionPanel();
|
2008-03-14 18:05:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-25 04:53:35 +02:00
|
|
|
d->positionContainment();
|
2008-03-14 18:05:37 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Applet::itemChange(change, value);
|
|
|
|
}
|
|
|
|
|
2008-04-14 00:01:18 +02:00
|
|
|
QGraphicsWidget * 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-04-13 15:23:39 +02:00
|
|
|
tool->resize(tool->size());
|
2008-01-01 20:57:40 +01:00
|
|
|
|
2008-04-25 20:44:09 +02: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-04-25 20:44:09 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->enableTool(toolname, enable);
|
2008-03-17 00:58:12 +01:00
|
|
|
}
|
2007-12-19 03:41:45 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:49:27 +02:00
|
|
|
bool Containment::isToolBoxToolEnabled(const QString &toolname) const
|
2007-12-19 03:41:45 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
return d->toolBox->isToolEnabled(toolname);
|
2008-03-17 00:58:12 +01:00
|
|
|
}
|
|
|
|
return false;
|
2007-09-18 23:16:17 +02:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:49:27 +02:00
|
|
|
void Containment::setToolBoxOpen(bool open)
|
|
|
|
{
|
|
|
|
if (open) {
|
|
|
|
openToolBox();
|
|
|
|
} else {
|
|
|
|
closeToolBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::openToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->showToolbox();
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:49:27 +02:00
|
|
|
void Containment::closeToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
if (d->toolBox) {
|
|
|
|
d->toolBox->hideToolbox();
|
2008-03-12 16:23:33 +01:00
|
|
|
}
|
2008-01-21 16:10:19 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
|
|
|
|
// Private class implementation
|
|
|
|
|
2008-04-25 21:15:50 +02:00
|
|
|
void Containment::Private::toggleDesktopImmutability()
|
|
|
|
{
|
|
|
|
if (q->corona()) {
|
|
|
|
if (q->corona()->immutability() == NotImmutable) {
|
|
|
|
q->corona()->setImmutability(UserImmutable);
|
|
|
|
} else if (q->corona()->immutability() == UserImmutable) {
|
|
|
|
q->corona()->setImmutability(NotImmutable);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (q->immutability() == NotImmutable) {
|
|
|
|
q->setImmutability(UserImmutable);
|
|
|
|
} else if (q->immutability() == UserImmutable) {
|
|
|
|
q->setImmutability(NotImmutable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setLockToolText();
|
|
|
|
}
|
|
|
|
|
2008-04-25 21:08:49 +02:00
|
|
|
void Containment::Private::zoomIn()
|
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::zoomOut()
|
|
|
|
{
|
|
|
|
emit q->zoomRequested(q, Plasma::ZoomOut);
|
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
Toolbox* Containment::Private::createToolBox()
|
|
|
|
{
|
|
|
|
if (!toolBox) {
|
|
|
|
switch (type) {
|
|
|
|
case PanelContainment:
|
|
|
|
toolBox = new PanelToolbox(q);
|
|
|
|
break;
|
|
|
|
//defaults to DesktopContainment right now
|
|
|
|
default:
|
|
|
|
toolBox = new DesktopToolbox(q);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
positionToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
return toolBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::positionToolBox()
|
|
|
|
{
|
|
|
|
if (!toolBox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF r;
|
|
|
|
if (screen < 0) {
|
|
|
|
r = q->geometry();
|
|
|
|
} else {
|
|
|
|
QDesktopWidget *desktop = QApplication::desktop();
|
|
|
|
r = desktop->availableGeometry(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
toolBox->setPos(QPointF(r.right(), r.y()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::triggerShowAddWidgets()
|
|
|
|
{
|
|
|
|
emit q->showAddWidgetsInterface(QPointF());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::handleDisappeared(AppletHandle *handle)
|
2008-03-05 08:08:32 +01:00
|
|
|
{
|
2008-04-25 20:44:09 +02:00
|
|
|
handles.remove(handle->applet());
|
|
|
|
handle->deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::setLockToolText()
|
|
|
|
{
|
|
|
|
if (!toolBox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Icon *icon = dynamic_cast<Plasma::Icon*>(toolBox->tool("lockWidgets"));
|
|
|
|
if (icon) {
|
|
|
|
// we know it's an icon becase we made it
|
|
|
|
icon->setText(q->immutability() != NotImmutable ? i18n("Unlock Widgets") :
|
|
|
|
i18n("Lock Widgets"));
|
|
|
|
QSizeF iconSize = icon->sizeFromIconSize(22);
|
|
|
|
icon->setMinimumSize(iconSize);
|
|
|
|
icon->setMaximumSize(iconSize);
|
|
|
|
icon->resize(icon->size());
|
2008-03-05 08:08:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 20:44:09 +02:00
|
|
|
void Containment::Private::containmentConstraintsUpdated(Plasma::Constraints constraints)
|
|
|
|
{
|
|
|
|
if (!q->isContainment()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << "got containmentConstraintsUpdated" << constraints << (QObject*)toolBox;
|
|
|
|
if (constraints & Plasma::ImmutableConstraint) {
|
|
|
|
setLockToolText();
|
|
|
|
|
|
|
|
// tell the applets too
|
|
|
|
foreach (Applet *a, applets) {
|
|
|
|
a->constraintsUpdated(ImmutableConstraint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((constraints & Plasma::SizeConstraint || constraints & Plasma::ScreenConstraint) &&
|
|
|
|
toolBox) {
|
|
|
|
//The placement assumes that the geometry width/height is no more than the screen
|
|
|
|
if (type == PanelContainment) {
|
|
|
|
if (q->formFactor() == Vertical) {
|
|
|
|
toolBox->setOrientation(Qt::Vertical);
|
|
|
|
toolBox->setPos(q->geometry().width()/2 - toolBox->boundingRect().width()/2, q->geometry().height());
|
|
|
|
//defaulting to Horizontal right now
|
|
|
|
} else {
|
|
|
|
toolBox->setOrientation(Qt::Horizontal);
|
|
|
|
toolBox->setPos(q->geometry().width(), q->geometry().height()/2 - toolBox->boundingRect().height()/2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
toolBox->setPos(q->geometry().right() - qAbs(toolBox->boundingRect().width()), 0);
|
|
|
|
}
|
|
|
|
toolBox->enableTool("addwidgets", q->immutability() == NotImmutable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints & Plasma::FormFactorConstraint && toolBox) {
|
|
|
|
if (q->formFactor() == Vertical) {
|
|
|
|
toolBox->setOrientation(Qt::Vertical);
|
|
|
|
//defaults to horizontal
|
|
|
|
} else {
|
|
|
|
toolBox->setOrientation(Qt::Horizontal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (constraints & Plasma::SizeConstraint) {
|
|
|
|
switch (q->containmentType()) {
|
|
|
|
case PanelContainment:
|
|
|
|
positionPanel();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
positionContainment();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::destroyApplet()
|
|
|
|
{
|
|
|
|
QAction *action = qobject_cast<QAction*>(q->sender());
|
|
|
|
|
|
|
|
if (!action) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *applet = qobject_cast<Applet*>(action->data().value<QObject*>());
|
|
|
|
Animator::self()->animateItem(applet, Animator::DisappearAnimation);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet* Containment::Private::addApplet(const QString& name, const QVariantList& args,
|
|
|
|
const QRectF& appletGeometry, uint id, bool delayInit)
|
|
|
|
{
|
|
|
|
if (!delayInit && q->immutability() != NotImmutable) {
|
|
|
|
kDebug() << "addApplet for" << name << "requested, but we're currently immutable!";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *v = q->view();
|
|
|
|
if (v) {
|
|
|
|
v->setCursor(Qt::BusyCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet* applet = Applet::load(name, id, args);
|
|
|
|
if (v) {
|
|
|
|
v->unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!applet) {
|
|
|
|
kDebug() << "Applet" << name << "could not be loaded.";
|
|
|
|
applet = new Applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
|
|
|
|
|
|
|
|
connect(applet, SIGNAL(configNeedsSaving()), q, SIGNAL(configNeedsSaving()));
|
|
|
|
connect(applet, SIGNAL(launchActivated()), q, SIGNAL(launchActivated()));
|
|
|
|
q->addApplet(applet, appletGeometry.topLeft(), delayInit);
|
|
|
|
return applet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Containment::Private::regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet) const
|
|
|
|
{
|
|
|
|
foreach (Applet *applet, applets) {
|
|
|
|
if (applet != ignoredApplet && applet->geometry().intersects(region)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::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);
|
|
|
|
applets.removeAll(applet);
|
|
|
|
emit q->appletRemoved(applet);
|
|
|
|
emit q->configNeedsSaving();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::appletAnimationComplete(QGraphicsItem *item, Plasma::Animator::Animation anim)
|
|
|
|
{
|
|
|
|
if (anim == Animator::DisappearAnimation) {
|
|
|
|
QGraphicsItem *parent = item->parentItem();
|
|
|
|
|
|
|
|
while (parent) {
|
|
|
|
if (parent == q) {
|
|
|
|
Applet *applet = qgraphicsitem_cast<Applet*>(item);
|
|
|
|
|
|
|
|
if (applet) {
|
|
|
|
applet->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = parent->parentItem();
|
|
|
|
}
|
|
|
|
} else if (anim == Animator::AppearAnimation) {
|
|
|
|
if (q->containmentType() == DesktopContainment &&
|
|
|
|
item->parentItem() == q &&
|
|
|
|
qgraphicsitem_cast<Applet*>(item)) {
|
|
|
|
item->installSceneEventFilter(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::positionContainment()
|
|
|
|
{
|
|
|
|
Corona *c = q->corona();
|
|
|
|
if (!c) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<Containment*> containments = c->containments();
|
|
|
|
QMutableListIterator<Containment*> it(containments);
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
if (containment == q ||
|
|
|
|
containment->containmentType() == PanelContainment) {
|
|
|
|
// weed out all containments we don't care about at all
|
|
|
|
// e.g. Panels and ourself
|
|
|
|
it.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (q->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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//this magic number (4) is the number of columns to try before going to the next row
|
|
|
|
width = (width + INTER_CONTAINMENT_MARGIN) * 4;
|
|
|
|
height += INTER_CONTAINMENT_MARGIN;
|
|
|
|
|
|
|
|
// a mildly naive "find the first slot" approach
|
|
|
|
QRectF r = q->boundingRect();
|
|
|
|
QPointF topLeft(0, 0);
|
|
|
|
q->setPos(topLeft);
|
|
|
|
|
|
|
|
positioning = true;
|
|
|
|
while (true) {
|
|
|
|
it.toFront();
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
Containment *containment = it.next();
|
|
|
|
if (q->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;
|
|
|
|
q->setPos(topLeft);
|
|
|
|
//kDebug() << collidingItems().count() << collidingItems()[0] << (QGraphicsItem*)this;
|
|
|
|
}
|
|
|
|
|
|
|
|
positioning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Containment::Private::positionPanel(bool force)
|
|
|
|
{
|
|
|
|
if (!q->scene()) {
|
|
|
|
kDebug() << "no scene yet";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we position panels in negative coordinates, and stack all horizontal
|
|
|
|
// and all vertical panels with each other.
|
|
|
|
|
|
|
|
const QPointF p = q->pos();
|
|
|
|
|
|
|
|
if (!force &&
|
|
|
|
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
|
|
|
|
q->scene()->collidingItems(q).isEmpty()) {
|
|
|
|
// already positioned and not running into any other panels
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
|
|
|
|
bool horiz = q->formFactor() == Plasma::Horizontal;
|
|
|
|
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
|
|
|
|
qreal lastHeight = 0;
|
|
|
|
|
|
|
|
// 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, q->corona()->containments()) {
|
|
|
|
if (other == q ||
|
|
|
|
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 - q->size().height());
|
|
|
|
newPos = QPointF(0, bottom - q->size().height());
|
|
|
|
} else {
|
|
|
|
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
|
|
|
|
//TODO: fix y position for non-flush-top panels
|
|
|
|
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
|
|
|
|
}
|
|
|
|
|
|
|
|
positioning = true;
|
|
|
|
if (p != newPos) {
|
|
|
|
q->setPos(newPos);
|
|
|
|
emit q->geometryChanged();
|
|
|
|
}
|
|
|
|
positioning = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-19 02:19:58 +01:00
|
|
|
} // Plasma namespace
|
|
|
|
|
2007-09-18 23:16:17 +02:00
|
|
|
#include "containment.moc"
|
2007-11-19 02:19:58 +01:00
|
|
|
|