2008-11-04 00:08:39 +01:00
|
|
|
/*
|
2009-03-12 18:19:45 +01:00
|
|
|
* Copyright 2008, 2009 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
2008-11-04 00:08:39 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "extenderitem.h"
|
|
|
|
|
|
|
|
#include <QAction>
|
2009-02-09 19:10:45 +01:00
|
|
|
#include <QApplication>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QBitmap>
|
2009-02-09 19:10:45 +01:00
|
|
|
#include <QDrag>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsSceneResizeEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsLinearLayout>
|
|
|
|
#include <QLayout>
|
2009-02-09 19:10:45 +01:00
|
|
|
#include <QMimeData>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QTimer>
|
|
|
|
|
2008-11-04 03:04:34 +01:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <kicon.h>
|
2009-02-15 17:35:52 +01:00
|
|
|
#include <kiconloader.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include "applet.h"
|
|
|
|
#include "containment.h"
|
|
|
|
#include "corona.h"
|
|
|
|
#include "dialog.h"
|
|
|
|
#include "extender.h"
|
2009-03-23 17:30:32 +01:00
|
|
|
#include "extendergroup.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "framesvg.h"
|
|
|
|
#include "popupapplet.h"
|
|
|
|
#include "theme.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "widgets/iconwidget.h"
|
|
|
|
|
|
|
|
#include "private/applethandle_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/extender_p.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "private/extenderapplet_p.h"
|
2009-03-25 14:03:04 +01:00
|
|
|
#include "private/extendergroup_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
#include "private/extenderitem_p.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
#include "private/extenderitemmimedata_p.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
|
|
|
|
: QGraphicsWidget(hostExtender),
|
|
|
|
d(new ExtenderItemPrivate(this, hostExtender))
|
|
|
|
{
|
|
|
|
Q_ASSERT(hostExtender);
|
|
|
|
|
|
|
|
//set the extenderId
|
|
|
|
if (extenderItemId) {
|
|
|
|
d->extenderItemId = extenderItemId;
|
|
|
|
ExtenderItemPrivate::s_maxExtenderItemId =
|
|
|
|
qMax(ExtenderItemPrivate::s_maxExtenderItemId, extenderItemId);
|
|
|
|
} else {
|
|
|
|
d->extenderItemId = ++ExtenderItemPrivate::s_maxExtenderItemId;
|
|
|
|
}
|
|
|
|
|
2009-01-19 17:03:20 +01:00
|
|
|
//create the toolbox.
|
|
|
|
d->toolbox = new QGraphicsWidget(this);
|
|
|
|
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
|
|
|
|
d->toolbox->setLayout(d->toolboxLayout);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//create items's configgroup
|
|
|
|
KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems");
|
|
|
|
KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId));
|
|
|
|
|
2010-04-01 11:18:00 +02:00
|
|
|
//create own layout
|
|
|
|
d->layout = new QGraphicsLinearLayout(Qt::Vertical, this);
|
|
|
|
d->layout->addItem(d->toolbox);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
uint sourceAppletId = dg.readEntry("sourceAppletId", 0);
|
|
|
|
|
|
|
|
//check if we're creating a new item or reinstantiating an existing one.
|
|
|
|
if (!sourceAppletId) {
|
|
|
|
//The item is new
|
|
|
|
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName());
|
|
|
|
dg.writeEntry("sourceAppletId", hostExtender->d->applet->id());
|
2008-11-28 18:06:00 +01:00
|
|
|
dg.writeEntry("extenderIconName", hostExtender->d->applet->icon());
|
2008-11-04 00:08:39 +01:00
|
|
|
d->sourceApplet = hostExtender->d->applet;
|
|
|
|
d->collapseIcon = new IconWidget(KIcon(hostExtender->d->applet->icon()), "", this);
|
|
|
|
} else {
|
|
|
|
//The item already exists.
|
|
|
|
d->name = dg.readEntry("extenderItemName", "");
|
|
|
|
d->title = dg.readEntry("extenderTitle", "");
|
2009-01-16 19:49:54 +01:00
|
|
|
setCollapsed(dg.readEntry("isCollapsed", false));
|
|
|
|
|
2008-11-28 18:06:00 +01:00
|
|
|
QString iconName = dg.readEntry("extenderIconName", "utilities-desktop-extra");
|
|
|
|
if (iconName.isEmpty()) {
|
|
|
|
iconName = "utilities-desktop-extra";
|
|
|
|
}
|
|
|
|
d->collapseIcon = new IconWidget(KIcon(iconName), "", this);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
//Find the group if it's already there.
|
|
|
|
QString groupName = dg.readEntry("group", "");
|
|
|
|
d->group = hostExtender->d->findGroup(groupName);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//Find the sourceapplet.
|
|
|
|
Corona *corona = hostExtender->d->applet->containment()->corona();
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
foreach (Applet *applet, containment->applets()) {
|
|
|
|
if (applet->id() == sourceAppletId &&
|
|
|
|
applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) {
|
|
|
|
d->sourceApplet = applet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//make sure we keep monitoring if the source applet still exists, so the return to source icon
|
|
|
|
//can be hidden if it is removed.
|
|
|
|
connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved()));
|
|
|
|
connect(d->collapseIcon, SIGNAL(clicked()), this, SLOT(toggleCollapse()));
|
|
|
|
|
|
|
|
//set the extender we want to move to.
|
|
|
|
setExtender(hostExtender);
|
|
|
|
|
|
|
|
//show or hide the return to source icon.
|
|
|
|
d->updateToolBox();
|
|
|
|
|
|
|
|
//set the image paths, image sizes and collapseIcon position.
|
|
|
|
d->themeChanged();
|
|
|
|
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
|
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeChanged()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderItem::~ExtenderItem()
|
|
|
|
{
|
2010-02-10 09:43:08 +01:00
|
|
|
emit destroyed(this);
|
2008-11-28 18:06:00 +01:00
|
|
|
//make sure the original mousepointer always get's restored.
|
|
|
|
if (d->mouseOver) {
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup ExtenderItem::config() const
|
|
|
|
{
|
|
|
|
KConfigGroup cg = d->extender->d->applet->config("ExtenderItems");
|
|
|
|
return KConfigGroup(&cg, QString::number(d->extenderItemId));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setTitle(const QString &title)
|
|
|
|
{
|
2009-09-01 13:00:10 +02:00
|
|
|
if (d->title != title) {
|
|
|
|
d->title = title;
|
|
|
|
config().writeEntry("extenderTitle", title);
|
|
|
|
update();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtenderItem::title() const
|
|
|
|
{
|
|
|
|
return d->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setName(const QString &name)
|
|
|
|
{
|
|
|
|
d->name = name;
|
|
|
|
config().writeEntry("extenderItemName", name);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtenderItem::name() const
|
|
|
|
{
|
|
|
|
return d->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setWidget(QGraphicsItem *widget)
|
|
|
|
{
|
2009-07-25 06:53:35 +02:00
|
|
|
if (d->widget) {
|
|
|
|
d->widget->removeSceneEventFilter(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!widget) {
|
|
|
|
d->widget = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
widget->setParentItem(this);
|
|
|
|
|
2010-04-01 11:18:00 +02:00
|
|
|
if (widget->isWidget()) {
|
|
|
|
if (d->widget && d->widget->isWidget()) {
|
|
|
|
d->layout->removeItem(static_cast<QGraphicsWidget *>(d->widget));
|
|
|
|
}
|
|
|
|
d->layout->addItem(static_cast<QGraphicsWidget *>(widget));
|
|
|
|
d->widget = widget;
|
|
|
|
} else {
|
|
|
|
widget->installSceneEventFilter(this);
|
|
|
|
|
|
|
|
QSizeF panelSize(QSizeF(size().width() - d->bgLeft - d->bgRight,
|
|
|
|
d->iconSize + d->dragTop + d->dragBottom));
|
|
|
|
widget->setPos(QPointF(d->bgLeft + d->dragLeft, panelSize.height() + d->bgTop));
|
|
|
|
d->widget = widget;
|
|
|
|
d->updateSizeHints();
|
|
|
|
}
|
|
|
|
|
2009-12-26 14:02:53 +01:00
|
|
|
d->widget->setVisible(!d->collapsed);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsItem *ExtenderItem::widget() const
|
|
|
|
{
|
|
|
|
return d->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setIcon(const QIcon &icon)
|
|
|
|
{
|
2009-09-01 13:00:10 +02:00
|
|
|
if (d->collapseIcon->icon().isNull() || icon.cacheKey() != d->collapseIcon->icon().cacheKey()) {
|
|
|
|
d->iconName.clear();
|
|
|
|
d->collapseIcon->setIcon(icon);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setIcon(const QString &icon)
|
|
|
|
{
|
2008-12-09 15:04:33 +01:00
|
|
|
if (icon != d->iconName) {
|
|
|
|
d->collapseIcon->setIcon(icon);
|
|
|
|
d->iconName = icon;
|
|
|
|
config().writeEntry("extenderIconName", icon);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QIcon ExtenderItem::icon() const
|
|
|
|
{
|
|
|
|
return d->collapseIcon->icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setExtender(Extender *extender, const QPointF &pos)
|
|
|
|
{
|
|
|
|
Q_ASSERT(extender);
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//themeChanged() has to now that by now, we're no longer dragging, even though the QDrag has not
|
|
|
|
//been entirely finished.
|
|
|
|
d->dragStarted = false;
|
|
|
|
|
2009-04-27 01:49:22 +02:00
|
|
|
ExtenderGroup *group = qobject_cast<ExtenderGroup*>(this);
|
|
|
|
QList<ExtenderItem*> childItems;
|
|
|
|
if (group) {
|
|
|
|
childItems = group->items();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (extender == d->extender) {
|
|
|
|
//We're not moving between extenders, so just insert this item back into the layout.
|
|
|
|
setParentItem(extender);
|
|
|
|
extender->d->addExtenderItem(this, pos);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//We are switching extender...
|
|
|
|
//first remove this item from the old extender.
|
|
|
|
d->extender->d->removeExtenderItem(this);
|
|
|
|
|
|
|
|
//move the configuration.
|
|
|
|
if (d->hostApplet() && (extender != d->extender)) {
|
|
|
|
KConfigGroup c = extender->d->applet->config("ExtenderItems");
|
|
|
|
config().reparent(&c);
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//and notify the applet of the item being detached, after the config has been moved.
|
|
|
|
emit d->extender->itemDetached(this);
|
|
|
|
|
2010-03-06 02:43:44 +01:00
|
|
|
setParentItem(extender);
|
|
|
|
setParent(extender);
|
2008-11-04 00:08:39 +01:00
|
|
|
d->extender = extender;
|
|
|
|
|
|
|
|
//change parent.
|
|
|
|
extender->d->addExtenderItem(this, pos);
|
|
|
|
|
|
|
|
//cancel the timer.
|
|
|
|
if (d->expirationTimer && isDetached()) {
|
|
|
|
d->expirationTimer->stop();
|
|
|
|
delete d->expirationTimer;
|
|
|
|
d->expirationTimer = 0;
|
|
|
|
}
|
|
|
|
|
2009-03-12 18:19:45 +01:00
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
|
|
|
KConfigGroup extenderItemGroup(corona->config(), "DetachedExtenderItems");
|
|
|
|
|
|
|
|
if (isDetached()) {
|
|
|
|
kDebug() << "detached, adding entry to the global group";
|
|
|
|
KConfigGroup itemConfig = extenderItemGroup.group(QString::number(d->extenderItemId));
|
|
|
|
itemConfig.writeEntry("sourceAppletPluginName",
|
|
|
|
config().readEntry("sourceAppletPluginName", ""));
|
|
|
|
itemConfig.writeEntry("sourceAppletId",
|
|
|
|
config().readEntry("sourceAppletId", 0));
|
|
|
|
itemConfig.writeEntry("extenderItemName",
|
|
|
|
config().readEntry("extenderItemName", ""));
|
|
|
|
} else if (extenderItemGroup.hasGroup(QString::number(d->extenderItemId))) {
|
|
|
|
kDebug() << "no longer detached, removing entry from the global group";
|
|
|
|
extenderItemGroup.deleteGroup(QString::number(d->extenderItemId));
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//we might have to enable or disable the returnToSource button.
|
|
|
|
d->updateToolBox();
|
2009-04-27 01:49:22 +02:00
|
|
|
|
|
|
|
//invoke setGroup on all items belonging to this group, to make sure all children move to the
|
|
|
|
//new extender together with the group.
|
|
|
|
if (group) {
|
|
|
|
foreach (ExtenderItem *item, childItems) {
|
|
|
|
item->setGroup(group);
|
|
|
|
}
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Extender *ExtenderItem::extender() const
|
|
|
|
{
|
|
|
|
return d->extender;
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
void ExtenderItem::setGroup(ExtenderGroup *group)
|
|
|
|
{
|
2009-04-26 19:03:15 +02:00
|
|
|
if (isGroup()) {
|
|
|
|
//nesting extender groups is just insane. I don't think we'd even want to support that.
|
|
|
|
kWarning() << "Nesting ExtenderGroups is not supported";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-23 17:30:32 +01:00
|
|
|
d->group = group;
|
2009-04-26 19:03:15 +02:00
|
|
|
|
|
|
|
if (group) {
|
|
|
|
config().writeEntry("group", group->name());
|
|
|
|
//TODO: move to another extender if the group we set is actually detached.
|
|
|
|
if (group->extender() != extender()) {
|
|
|
|
kDebug() << "moving to another extender because we're joining a detached group.";
|
|
|
|
setExtender(group->extender());
|
|
|
|
}
|
2009-04-04 18:42:59 +02:00
|
|
|
group->d->addItemToGroup(this);
|
2009-04-26 19:03:15 +02:00
|
|
|
} else {
|
|
|
|
config().deleteEntry("group");
|
2009-04-04 18:42:59 +02:00
|
|
|
}
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderGroup *ExtenderItem::group() const
|
|
|
|
{
|
|
|
|
return d->group;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::isGroup() const
|
|
|
|
{
|
|
|
|
return (config().readEntry("isGroup", false));
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
bool ExtenderItem::isCollapsed() const
|
|
|
|
{
|
2009-01-16 19:49:54 +01:00
|
|
|
return d->collapsed;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setAutoExpireDelay(uint time)
|
|
|
|
{
|
|
|
|
if (!time) {
|
|
|
|
if (d->expirationTimer) {
|
|
|
|
d->expirationTimer->stop();
|
|
|
|
delete d->expirationTimer;
|
|
|
|
d->expirationTimer = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDetached()) {
|
|
|
|
if (!d->expirationTimer) {
|
|
|
|
d->expirationTimer = new QTimer(this);
|
|
|
|
connect(d->expirationTimer, SIGNAL(timeout()), this, SLOT(destroy()));
|
|
|
|
}
|
|
|
|
|
|
|
|
d->expirationTimer->stop();
|
|
|
|
d->expirationTimer->setSingleShot(true);
|
|
|
|
d->expirationTimer->setInterval(time);
|
|
|
|
d->expirationTimer->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ExtenderItem::autoExpireDelay() const
|
|
|
|
{
|
|
|
|
if (d->expirationTimer) {
|
|
|
|
return d->expirationTimer->interval();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::isDetached() const
|
|
|
|
{
|
|
|
|
if (d->hostApplet()) {
|
|
|
|
return (d->sourceApplet != d->hostApplet());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::addAction(const QString &name, QAction *action)
|
|
|
|
{
|
|
|
|
Q_ASSERT(action);
|
2009-01-09 03:15:23 +01:00
|
|
|
if (d->actionsInOrder.contains(action)) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-12-11 03:55:28 +01:00
|
|
|
d->actions.insert(name, action);
|
2009-01-09 03:15:23 +01:00
|
|
|
d->actionsInOrder.append(action);
|
2008-11-04 00:08:39 +01:00
|
|
|
connect(action, SIGNAL(changed()), this, SLOT(updateToolBox()));
|
2009-01-09 03:15:23 +01:00
|
|
|
connect(action, SIGNAL(destroyed(QObject*)), this, SLOT(actionDestroyed(QObject*)));
|
2008-11-04 00:08:39 +01:00
|
|
|
d->updateToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *ExtenderItem::action(const QString &name) const
|
|
|
|
{
|
2008-12-11 03:55:28 +01:00
|
|
|
return d->actions.value(name, 0);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::showCloseButton()
|
|
|
|
{
|
|
|
|
if (d->destroyActionVisibility) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->destroyActionVisibility = true;
|
|
|
|
d->updateToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::hideCloseButton()
|
|
|
|
{
|
|
|
|
if (!d->destroyActionVisibility) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->destroyActionVisibility = false;
|
|
|
|
d->updateToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::destroy()
|
|
|
|
{
|
2009-02-09 19:10:45 +01:00
|
|
|
if (d->dragStarted) {
|
2008-11-04 00:08:39 +01:00
|
|
|
//avoid being destroyed while we're being dragged.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-03-12 18:19:45 +01:00
|
|
|
//remove global entry if needed.
|
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
|
|
|
KConfigGroup extenderItemGroup(corona->config(), "DetachedExtenderItems");
|
|
|
|
if (extenderItemGroup.hasGroup(QString::number(d->extenderItemId))) {
|
|
|
|
extenderItemGroup.deleteGroup(QString::number(d->extenderItemId));
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
d->hostApplet()->config("ExtenderItems").deleteGroup(QString::number(d->extenderItemId));
|
|
|
|
d->extender->d->removeExtenderItem(this);
|
2009-03-23 17:30:32 +01:00
|
|
|
emit d->extender->itemDetached(this);
|
2009-11-10 12:30:25 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setCollapsed(bool collapsed)
|
|
|
|
{
|
2009-01-16 19:49:54 +01:00
|
|
|
config().writeEntry("isCollapsed", collapsed);
|
|
|
|
d->collapsed = collapsed;
|
2009-02-09 19:10:45 +01:00
|
|
|
if (d->widget) {
|
|
|
|
d->widget->setVisible(!collapsed);
|
|
|
|
d->updateSizeHints();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::returnToSource()
|
|
|
|
{
|
2009-02-01 22:56:19 +01:00
|
|
|
if (!d || !d->sourceApplet) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
2010-03-06 02:43:44 +01:00
|
|
|
|
2009-02-01 22:56:19 +01:00
|
|
|
if (d->sourceApplet->d) {
|
2009-02-09 19:10:45 +01:00
|
|
|
setExtender(d->sourceApplet->extender());
|
2009-02-01 22:56:19 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option);
|
|
|
|
Q_UNUSED(widget);
|
|
|
|
|
|
|
|
painter->setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
|
|
|
|
if (d->background->enabledBorders() != (FrameSvg::LeftBorder | FrameSvg::RightBorder) &&
|
|
|
|
d->background->enabledBorders()) {
|
|
|
|
//Don't paint if only the left and right borders are enabled, we only use the left and right
|
|
|
|
//border in this situation to set the correct margins on this item.
|
|
|
|
d->background->paintFrame(painter, QPointF(0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
d->dragger->paintFrame(painter, QPointF(d->bgLeft, d->bgTop));
|
|
|
|
|
|
|
|
//We don't need to paint a title if there is no title.
|
|
|
|
if (d->title.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set the font for the title.
|
|
|
|
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
|
|
|
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
|
|
|
font.setWeight(QFont::Bold);
|
|
|
|
|
|
|
|
//create a pixmap with the title that is faded out at the right side of the titleRect.
|
2009-12-01 22:04:59 +01:00
|
|
|
QRectF rect;
|
|
|
|
if (option->direction == Qt::LeftToRight) {
|
|
|
|
rect = QRectF(d->titleRect().width() - 30, 0, 30, d->titleRect().height());
|
|
|
|
} else {
|
|
|
|
rect = QRectF(0, 0, 30, d->titleRect().height());
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
QPixmap pixmap(d->titleRect().size().toSize());
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter p(&pixmap);
|
|
|
|
p.setPen(theme->color(Plasma::Theme::TextColor));
|
|
|
|
p.setFont(font);
|
|
|
|
p.drawText(QRectF(QPointF(0, 0), d->titleRect().size()),
|
|
|
|
Qt::TextSingleLine | Qt::AlignVCenter | Qt::AlignLeft,
|
|
|
|
d->title);
|
|
|
|
|
|
|
|
// Create the alpha gradient for the fade out effect
|
|
|
|
QLinearGradient alphaGradient(0, 0, 1, 0);
|
|
|
|
alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
|
|
|
|
//TODO: correct handling of right to left text.
|
2009-12-01 22:04:59 +01:00
|
|
|
if (option->direction == Qt::LeftToRight) {
|
|
|
|
alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
|
|
|
|
alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
|
|
|
|
} else {
|
|
|
|
alphaGradient.setColorAt(1, QColor(0, 0, 0, 255));
|
|
|
|
alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
p.fillRect(rect, alphaGradient);
|
|
|
|
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
painter->drawPixmap(d->titleRect().topLeft(), pixmap);
|
|
|
|
}
|
|
|
|
|
2008-11-28 18:06:00 +01:00
|
|
|
void ExtenderItem::moveEvent(QGraphicsSceneMoveEvent *event)
|
|
|
|
{
|
2009-02-09 19:10:45 +01:00
|
|
|
Q_UNUSED(event)
|
|
|
|
//not needed anymore, but here for binary compatibility
|
2008-11-28 18:06:00 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ExtenderItem::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
2009-02-09 19:10:45 +01:00
|
|
|
Q_UNUSED(event)
|
|
|
|
d->themeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2008-12-15 17:50:47 +01:00
|
|
|
if (!(d->dragHandleRect().contains(event->pos())) ||
|
|
|
|
d->extender->d->applet->immutability() != Plasma::Mutable) {
|
2008-11-04 00:08:39 +01:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-28 18:06:00 +01:00
|
|
|
d->mousePos = event->pos().toPoint();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2009-02-09 19:10:45 +01:00
|
|
|
if ((event->pos().toPoint() - d->mousePos).manhattanLength()
|
|
|
|
< QApplication::startDragDistance()) {
|
2008-11-28 18:06:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//Start the drag:
|
|
|
|
d->dragStarted = true;
|
2009-03-11 15:41:37 +01:00
|
|
|
QPointF curPos = pos();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-11 15:41:37 +01:00
|
|
|
//remove item from the layout, and add it somewhere off screen so we can render it to a pixmap,
|
|
|
|
//without other widgets interefing.
|
|
|
|
d->extender->itemRemovedEvent(this);
|
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
|
|
|
corona->addOffscreenWidget(this);
|
|
|
|
|
|
|
|
//update the borders, since while dragging, we want all of theme.
|
2009-02-09 19:10:45 +01:00
|
|
|
d->themeChanged();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//create a view to render the ExtenderItem and it's contents to a pixmap and set up a painter on
|
|
|
|
//a pixmap.
|
|
|
|
QGraphicsView view(scene());
|
|
|
|
QSize screenSize(view.mapFromScene(sceneBoundingRect()).boundingRect().size());
|
|
|
|
QPixmap pixmap(screenSize);
|
|
|
|
pixmap.fill(Qt::transparent);
|
|
|
|
QPainter p(&pixmap);
|
2008-11-22 16:16:46 +01:00
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//the following is necesarry to avoid having an offset when rendering the widget into the
|
|
|
|
//pixmap.
|
|
|
|
view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
view.setFrameShape(QFrame::NoFrame);
|
|
|
|
|
|
|
|
//aim the view and render.
|
|
|
|
view.resize(screenSize);
|
|
|
|
view.setSceneRect(sceneBoundingRect());
|
|
|
|
view.render(&p, QRectF(QPointF(0, 0), pixmap.size()), QRect(QPoint(0, 0), screenSize));
|
|
|
|
|
|
|
|
//create the necesarry mimedata.
|
|
|
|
ExtenderItemMimeData *mimeData = new ExtenderItemMimeData();
|
|
|
|
mimeData->setExtenderItem(this);
|
2010-03-06 02:43:44 +01:00
|
|
|
mimeData->setPointerOffset(d->mousePos);
|
2009-02-09 19:10:45 +01:00
|
|
|
|
|
|
|
//Hide empty internal extender containers when we drag the last item away. Avoids having
|
|
|
|
//an ugly empty applet on the desktop temporarily.
|
|
|
|
ExtenderApplet *extenderApplet = qobject_cast<ExtenderApplet*>(d->extender->d->applet);
|
2009-03-11 15:41:37 +01:00
|
|
|
if (extenderApplet && d->extender->attachedItems().count() < 2 &&
|
|
|
|
extenderApplet->formFactor() != Plasma::Horizontal &&
|
|
|
|
extenderApplet->formFactor() != Plasma::Vertical) {
|
2009-02-09 19:10:45 +01:00
|
|
|
kDebug() << "leaving the internal extender container, so hide the applet and it's handle.";
|
|
|
|
extenderApplet->hide();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-04-26 19:03:15 +02:00
|
|
|
ExtenderGroup *group = qobject_cast<ExtenderGroup*>(this);
|
2009-05-10 18:12:20 +02:00
|
|
|
bool collapsedGroup = false;
|
2009-04-26 19:03:15 +02:00
|
|
|
if (isGroup()) {
|
|
|
|
collapsedGroup = group->d->collapsed;
|
|
|
|
group->collapseGroup();
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//and execute the drag.
|
|
|
|
QWidget *dragParent = extender()->d->applet->view();
|
|
|
|
QDrag *drag = new QDrag(dragParent);
|
|
|
|
drag->setPixmap(pixmap);
|
|
|
|
drag->setMimeData(mimeData);
|
|
|
|
drag->setHotSpot(d->mousePos);
|
2009-03-11 15:41:37 +01:00
|
|
|
Qt::DropAction action = drag->exec();
|
2008-12-10 18:29:40 +01:00
|
|
|
|
2009-03-11 15:41:37 +01:00
|
|
|
corona->removeOffscreenWidget(this);
|
2010-03-06 02:43:44 +01:00
|
|
|
d->dragStarted = false;
|
2009-03-11 15:41:37 +01:00
|
|
|
|
2009-03-31 20:45:30 +02:00
|
|
|
if (!action || !drag->target()) {
|
|
|
|
//we weren't moved, so reinsert the item in our current layout.
|
2010-03-06 02:43:44 +01:00
|
|
|
//TODO: make it into a stand-alone window?
|
|
|
|
d->themeChanged();
|
2009-03-11 15:41:37 +01:00
|
|
|
d->extender->itemAddedEvent(this, curPos);
|
2010-03-06 02:43:44 +01:00
|
|
|
if (extenderApplet) {
|
|
|
|
extenderApplet->show();
|
|
|
|
}
|
2009-03-11 15:41:37 +01:00
|
|
|
}
|
2008-12-10 18:29:40 +01:00
|
|
|
|
2009-04-26 19:03:15 +02:00
|
|
|
if (isGroup() && !collapsedGroup) {
|
|
|
|
group->expandGroup();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->titleRect().contains(event->pos())) {
|
|
|
|
d->toggleCollapse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-07 16:08:17 +01:00
|
|
|
bool ExtenderItem::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|
|
|
{
|
|
|
|
if (watched == d->widget && event->type() == QEvent::GraphicsSceneResize) {
|
2009-02-09 19:10:45 +01:00
|
|
|
d->updateSizeHints();
|
2009-02-07 16:08:17 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
void ExtenderItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
//not needed anymore, but here for binary compatibility
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void ExtenderItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2008-12-15 17:50:47 +01:00
|
|
|
if (d->titleRect().contains(event->pos()) &&
|
|
|
|
d->extender->d->applet->immutability() == Plasma::Mutable) {
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!d->mouseOver) {
|
|
|
|
QApplication::setOverrideCursor(Qt::OpenHandCursor);
|
|
|
|
d->mouseOver = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (d->mouseOver) {
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
d->mouseOver = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
if (d->mouseOver) {
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
d->mouseOver = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-28 15:24:20 +01:00
|
|
|
QSizeF ExtenderItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
|
{
|
2010-04-01 11:18:00 +02:00
|
|
|
if (d->widget->isWidget()) {
|
|
|
|
return QGraphicsWidget::sizeHint(which, constraint);
|
|
|
|
} else {
|
|
|
|
switch (which) {
|
|
|
|
case Qt::MinimumSize:
|
|
|
|
return d->minimumSize;
|
|
|
|
case Qt::MaximumSize:
|
|
|
|
return d->maximumSize;
|
|
|
|
case Qt::PreferredSize:
|
|
|
|
default:
|
|
|
|
return d->preferredSize;
|
|
|
|
}
|
2009-11-28 15:24:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
ExtenderItemPrivate::ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *hostExtender)
|
|
|
|
: q(extenderItem),
|
|
|
|
widget(0),
|
|
|
|
toolbox(0),
|
|
|
|
extender(hostExtender),
|
|
|
|
sourceApplet(0),
|
2009-03-23 17:30:32 +01:00
|
|
|
group(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
dragger(new FrameSvg(extenderItem)),
|
|
|
|
background(new FrameSvg(extenderItem)),
|
|
|
|
collapseIcon(0),
|
2009-11-10 23:13:00 +01:00
|
|
|
destroyButton(0),
|
2008-11-04 00:08:39 +01:00
|
|
|
title(QString()),
|
|
|
|
mouseOver(false),
|
2008-11-30 12:45:23 +01:00
|
|
|
dragStarted(false),
|
2008-11-04 00:08:39 +01:00
|
|
|
destroyActionVisibility(false),
|
2009-01-16 19:49:54 +01:00
|
|
|
collapsed(false),
|
2009-02-07 16:08:17 +01:00
|
|
|
expirationTimer(0),
|
|
|
|
iconSize(qreal(0))
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
dragLeft = dragTop = dragRight = dragBottom = 0;
|
|
|
|
bgLeft = bgTop = bgRight = bgBottom = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderItemPrivate::~ExtenderItemPrivate()
|
|
|
|
{
|
2008-11-18 22:22:55 +01:00
|
|
|
delete widget;
|
|
|
|
widget = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//returns a Rect containing the area of the detachable where the draghandle will be drawn.
|
|
|
|
QRectF ExtenderItemPrivate::dragHandleRect()
|
|
|
|
{
|
|
|
|
QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight,
|
2009-02-07 16:08:17 +01:00
|
|
|
iconSize + dragTop + dragBottom));
|
2008-11-04 00:08:39 +01:00
|
|
|
return QRectF(QPointF(bgLeft, bgTop), panelSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF ExtenderItemPrivate::titleRect()
|
|
|
|
{
|
|
|
|
return dragHandleRect().adjusted(dragLeft + collapseIcon->size().width() + 1, dragTop,
|
|
|
|
-toolbox->size().width() - dragRight, -dragBottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::toggleCollapse()
|
|
|
|
{
|
|
|
|
q->setCollapsed(!q->isCollapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::updateToolBox()
|
|
|
|
{
|
|
|
|
Q_ASSERT(toolbox);
|
|
|
|
Q_ASSERT(dragger);
|
|
|
|
Q_ASSERT(toolboxLayout);
|
|
|
|
|
|
|
|
//TODO: only delete items that actually have to be deleted, current performance is horrible.
|
|
|
|
while (toolboxLayout->count()) {
|
|
|
|
QGraphicsLayoutItem *icon = toolboxLayout->itemAt(0);
|
|
|
|
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget*>(icon);
|
|
|
|
widget->deleteLater();
|
|
|
|
toolboxLayout->removeAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//add the actions that are actually set to visible.
|
2010-03-16 19:35:07 +01:00
|
|
|
QAction *closeAction = actions.value("close");
|
2009-01-09 03:15:23 +01:00
|
|
|
foreach (QAction *action, actionsInOrder) {
|
2010-03-16 19:35:07 +01:00
|
|
|
if (action->isVisible() && action != closeAction) {
|
2008-11-04 00:08:39 +01:00
|
|
|
IconWidget *icon = new IconWidget(q);
|
|
|
|
icon->setAction(action);
|
2009-02-07 16:08:17 +01:00
|
|
|
QSizeF size = icon->sizeFromIconSize(iconSize);
|
|
|
|
icon->setMinimumSize(size);
|
|
|
|
icon->setMaximumSize(size);
|
2010-03-16 19:35:07 +01:00
|
|
|
toolboxLayout->addItem(icon);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//add the returntosource icon if we are detached, and have a source applet.
|
|
|
|
if (q->isDetached() && sourceApplet) {
|
|
|
|
IconWidget *returnToSource = new IconWidget(q);
|
|
|
|
returnToSource->setSvg("widgets/configuration-icons", "return-to-source");
|
2009-02-07 16:08:17 +01:00
|
|
|
QSizeF size = returnToSource->sizeFromIconSize(iconSize);
|
|
|
|
returnToSource->setMinimumSize(size);
|
|
|
|
returnToSource->setMaximumSize(size);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
toolboxLayout->addItem(returnToSource);
|
|
|
|
QObject::connect(returnToSource, SIGNAL(clicked()), q, SLOT(returnToSource()));
|
|
|
|
}
|
|
|
|
|
|
|
|
//add the close icon if desired.
|
|
|
|
if (destroyActionVisibility) {
|
2009-11-10 23:13:00 +01:00
|
|
|
destroyButton = new IconWidget(q);
|
2010-03-16 19:35:07 +01:00
|
|
|
if (!closeAction) {
|
|
|
|
closeAction = new QAction(q);
|
|
|
|
actions.insert("close", closeAction);
|
|
|
|
QObject::connect(closeAction, SIGNAL(triggered()), q, SLOT(destroy()));
|
2009-11-10 23:13:00 +01:00
|
|
|
}
|
2010-03-16 19:35:07 +01:00
|
|
|
destroyButton->setAction(closeAction);
|
2009-11-10 23:13:00 +01:00
|
|
|
destroyButton->setSvg("widgets/configuration-icons", "close");
|
|
|
|
QSizeF size = destroyButton->sizeFromIconSize(iconSize);
|
|
|
|
destroyButton->setMinimumSize(size);
|
|
|
|
destroyButton->setMaximumSize(size);
|
|
|
|
toolboxLayout->addItem(destroyButton);
|
2010-03-16 19:35:07 +01:00
|
|
|
} else if (closeAction) {
|
2009-11-10 23:13:00 +01:00
|
|
|
actions.remove("close");
|
2010-03-16 19:35:07 +01:00
|
|
|
closeAction->deleteLater();
|
|
|
|
closeAction = 0;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
toolboxLayout->updateGeometry();
|
|
|
|
|
|
|
|
//position the toolbox correctly.
|
|
|
|
QSizeF minimum = toolboxLayout->minimumSize();
|
|
|
|
toolbox->resize(minimum);
|
|
|
|
repositionToolbox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::repositionToolbox()
|
|
|
|
{
|
|
|
|
QSizeF minimum = toolboxLayout->minimumSize();
|
|
|
|
toolbox->setPos(q->size().width() - minimum.width() - bgRight,
|
|
|
|
(dragHandleRect().height()/2) -
|
|
|
|
(minimum.height()/2) + bgTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *ExtenderItemPrivate::hostApplet() const
|
|
|
|
{
|
|
|
|
if (extender) {
|
|
|
|
return extender->d->applet;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::themeChanged()
|
|
|
|
{
|
2009-04-08 19:25:50 +02:00
|
|
|
if (dragStarted) {
|
|
|
|
background->setImagePath("opaque/widgets/extender-background");
|
2008-11-04 00:08:39 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
} else {
|
2010-03-06 02:43:44 +01:00
|
|
|
background->setImagePath("widgets/extender-background");
|
2008-11-04 00:08:39 +01:00
|
|
|
background->setEnabledBorders(extender->enabledBordersForItem(q));
|
|
|
|
}
|
2010-03-06 02:43:44 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
background->getMargins(bgLeft, bgTop, bgRight, bgBottom);
|
|
|
|
|
|
|
|
dragger->setImagePath("widgets/extender-dragger");
|
2009-02-07 16:08:17 +01:00
|
|
|
|
|
|
|
//Read the preferred icon size hint, look at the font size, and calculate the desired title bar
|
|
|
|
//icon height.
|
|
|
|
dragger->resize();
|
|
|
|
QSizeF size = dragger->elementSize("hint-preferred-icon-size");
|
2009-02-15 17:35:52 +01:00
|
|
|
size = size.expandedTo(QSizeF(KIconLoader::SizeSmall,KIconLoader::SizeSmall));
|
2009-02-07 16:08:17 +01:00
|
|
|
|
|
|
|
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
|
|
|
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
|
|
|
|
iconSize = qMax(size.height(), (qreal) fm.height());
|
|
|
|
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
dragger->getMargins(dragLeft, dragTop, dragRight, dragBottom);
|
|
|
|
|
|
|
|
QSizeF panelSize(QSizeF(q->size().width() - bgLeft - bgRight,
|
2009-02-07 16:08:17 +01:00
|
|
|
iconSize + dragTop + dragBottom));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//resize the collapse icon.
|
2009-02-07 16:08:17 +01:00
|
|
|
collapseIcon->resize(collapseIcon->sizeFromIconSize(iconSize));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//reposition the collapse icon based on the new margins and size.
|
|
|
|
collapseIcon->setPos(bgLeft + dragLeft,
|
|
|
|
panelSize.height()/2 -
|
|
|
|
collapseIcon->size().height()/2 + bgTop);
|
|
|
|
|
|
|
|
//reposition the widget based on the new margins.
|
|
|
|
if (widget) {
|
|
|
|
widget->setPos(QPointF(bgLeft + dragLeft, panelSize.height() +
|
2009-04-16 00:21:29 +02:00
|
|
|
bgTop));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//reposition the toolbox.
|
|
|
|
repositionToolbox();
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
updateSizeHints();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-01-08 12:28:58 +01:00
|
|
|
if (!q->size().isEmpty())
|
|
|
|
resizeContent(q->size());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::sourceAppletRemoved()
|
|
|
|
{
|
|
|
|
//the original source applet is removed, set the pointer to 0 and no longer show the return to
|
|
|
|
//source icon.
|
|
|
|
sourceApplet = 0;
|
|
|
|
updateToolBox();
|
|
|
|
}
|
|
|
|
|
2008-12-10 01:57:42 +01:00
|
|
|
void ExtenderItemPrivate::resizeContent(const QSizeF &newSize)
|
|
|
|
{
|
|
|
|
qreal width = newSize.width();
|
|
|
|
qreal height = newSize.height();
|
|
|
|
|
|
|
|
//resize the dragger
|
|
|
|
dragger->resizeFrame(QSizeF(width - bgLeft - bgRight,
|
2009-02-07 16:08:17 +01:00
|
|
|
iconSize + dragTop + dragBottom));
|
2008-12-10 01:57:42 +01:00
|
|
|
|
|
|
|
//resize the applet background
|
|
|
|
background->resizeFrame(newSize);
|
|
|
|
|
|
|
|
//resize the widget
|
|
|
|
if (widget && widget->isWidget()) {
|
|
|
|
QSizeF newWidgetSize(width - bgLeft - bgRight - dragLeft - dragRight,
|
|
|
|
height - dragHandleRect().height() - bgTop - bgBottom -
|
2009-04-16 00:21:29 +02:00
|
|
|
dragTop - dragBottom);
|
2008-12-10 01:57:42 +01:00
|
|
|
|
|
|
|
QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget*>(widget);
|
|
|
|
graphicsWidget->resize(newWidgetSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
//reposition the toolbox.
|
|
|
|
repositionToolbox();
|
|
|
|
|
|
|
|
q->update();
|
|
|
|
}
|
|
|
|
|
2009-01-09 03:15:23 +01:00
|
|
|
void ExtenderItemPrivate::actionDestroyed(QObject *o)
|
|
|
|
{
|
|
|
|
QAction *action = static_cast<QAction *>(o);
|
|
|
|
QMutableHashIterator<QString, QAction *> hit(actions);
|
|
|
|
while (hit.hasNext()) {
|
|
|
|
if (hit.next().value() == action) {
|
|
|
|
hit.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QMutableListIterator<QAction *> lit(actionsInOrder);
|
|
|
|
while (lit.hasNext()) {
|
|
|
|
if (lit.next() == action) {
|
|
|
|
lit.remove();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
void ExtenderItemPrivate::updateSizeHints()
|
|
|
|
{
|
|
|
|
if (!widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal marginWidth = bgLeft + bgRight + dragLeft + dragRight;
|
2009-11-28 21:19:03 +01:00
|
|
|
qreal marginHeight = bgTop + bgBottom + dragTop + dragBottom;
|
2009-02-09 19:10:45 +01:00
|
|
|
|
|
|
|
QSizeF min;
|
|
|
|
QSizeF pref;
|
|
|
|
QSizeF max;
|
|
|
|
|
2010-04-01 11:18:00 +02:00
|
|
|
min = widget->boundingRect().size();
|
|
|
|
pref = widget->boundingRect().size();
|
|
|
|
max = widget->boundingRect().size();
|
2009-02-09 19:10:45 +01:00
|
|
|
|
|
|
|
if (collapsed) {
|
2009-11-28 15:24:20 +01:00
|
|
|
preferredSize = QSizeF(pref.width() + marginWidth,
|
|
|
|
dragHandleRect().height() + marginHeight);
|
|
|
|
minimumSize = QSizeF(min.width() + marginWidth,
|
|
|
|
dragHandleRect().height() + marginHeight);
|
|
|
|
maximumSize = QSizeF(max.width() + marginWidth,
|
|
|
|
dragHandleRect().height() + marginHeight);
|
2009-02-09 19:10:45 +01:00
|
|
|
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
if (collapseIcon) {
|
|
|
|
collapseIcon->setToolTip(i18n("Expand this widget"));
|
|
|
|
}
|
|
|
|
} else {
|
2009-11-28 15:24:20 +01:00
|
|
|
preferredSize = QSizeF(pref.width() + marginWidth,
|
|
|
|
pref.height() + dragHandleRect().height() + marginHeight);
|
|
|
|
minimumSize = QSizeF(min.width() + marginWidth,
|
|
|
|
min.height() + dragHandleRect().height() + marginHeight);
|
|
|
|
maximumSize = QSizeF(max.width() + marginWidth,
|
|
|
|
max.height() + dragHandleRect().height() + marginHeight);
|
2009-02-09 19:10:45 +01:00
|
|
|
|
2009-12-10 10:16:30 +01:00
|
|
|
//set sane size policies depending on the appearance.
|
2009-02-09 19:10:45 +01:00
|
|
|
if (extender->d->appearance == Extender::TopDownStacked ||
|
|
|
|
extender->d->appearance == Extender::BottomUpStacked) {
|
|
|
|
//used in popups, so fixed make sense.
|
|
|
|
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
|
|
} else if (extender->d->appearance == Extender::NoBorders) {
|
|
|
|
//on the desktop or panel so take all the space we want.
|
|
|
|
q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collapseIcon) {
|
|
|
|
collapseIcon->setToolTip(i18n("Collapse this widget"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
q->updateGeometry();
|
2009-11-28 15:24:20 +01:00
|
|
|
//FIXME: it should be done from updateGeometry() ??!!??
|
|
|
|
if (extender && extender->layout()) {
|
|
|
|
extender->layout()->activate();
|
|
|
|
}
|
2009-02-09 19:10:45 +01:00
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
uint ExtenderItemPrivate::s_maxExtenderItemId = 0;
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "extenderitem.moc"
|