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>
|
2010-07-24 02:52:46 +02:00
|
|
|
#include <ksharedconfig.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"
|
2010-09-19 23:28:39 +02:00
|
|
|
#include "widgets/pushbutton.h"
|
2009-02-09 19:10:45 +01:00
|
|
|
|
|
|
|
#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"
|
2010-04-07 04:04:52 +02:00
|
|
|
#include "widgets/label.h"
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
class ExtenderItemToolbox : public QGraphicsWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ExtenderItemToolbox(QGraphicsWidget *parent)
|
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
m_background(new FrameSvg(this))
|
|
|
|
{
|
|
|
|
m_background->setImagePath("widgets/extender-dragger");
|
2010-04-08 00:02:52 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2010-04-07 04:04:52 +02:00
|
|
|
updateTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal iconSize()
|
|
|
|
{
|
|
|
|
return m_iconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
|
|
|
{
|
|
|
|
m_background->paintFrame(painter, option->exposedRect, option->exposedRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateTheme()
|
|
|
|
{
|
|
|
|
//Read the preferred icon size hint, look at the font size, and calculate the desired title bar
|
|
|
|
//icon height.
|
|
|
|
m_background->resize();
|
|
|
|
QSizeF size = m_background->elementSize("hint-preferred-icon-size");
|
|
|
|
size = size.expandedTo(QSizeF(KIconLoader::SizeSmall,KIconLoader::SizeSmall));
|
|
|
|
|
|
|
|
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
|
|
|
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
m_iconSize = qMax(size.height(), (qreal) fm.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent *)
|
|
|
|
{
|
|
|
|
m_background->resizeFrame(size());
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
m_background->getMargins(left, top, right, bottom);
|
|
|
|
setContentsMargins(0, top, 0, bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
FrameSvg *m_background;
|
|
|
|
qreal m_iconSize;
|
|
|
|
};
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
ExtenderItem::ExtenderItem(Extender *hostExtender, uint extenderItemId)
|
|
|
|
: QGraphicsWidget(hostExtender),
|
|
|
|
d(new ExtenderItemPrivate(this, hostExtender))
|
|
|
|
{
|
|
|
|
Q_ASSERT(hostExtender);
|
2010-04-09 15:05:48 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//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.
|
2010-04-07 04:04:52 +02:00
|
|
|
d->toolbox = new ExtenderItemToolbox(this);
|
2010-04-06 23:56:32 +02:00
|
|
|
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
|
2009-01-19 17:03:20 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//create items's configgroup
|
2010-05-27 21:59:15 +02:00
|
|
|
KConfigGroup cg = hostExtender->d->applet.data()->config("ExtenderItems");
|
2008-11-04 00:08:39 +01:00
|
|
|
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.
|
2010-04-07 04:04:52 +02:00
|
|
|
d->collapseIcon = new IconWidget(d->toolbox);
|
2010-06-10 19:46:08 +02:00
|
|
|
d->collapseIcon->setCursor(Qt::ArrowCursor);
|
2010-04-07 04:04:52 +02:00
|
|
|
d->titleLabel = new Label(d->toolbox);
|
|
|
|
|
|
|
|
d->toolboxLayout->addItem(d->collapseIcon);
|
|
|
|
d->toolboxLayout->addItem(d->titleLabel);
|
|
|
|
d->toolboxLayout->setStretchFactor(d->titleLabel, 10);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (!sourceAppletId) {
|
|
|
|
//The item is new
|
2010-05-27 21:59:15 +02:00
|
|
|
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet.data()->pluginName());
|
|
|
|
dg.writeEntry("sourceAppletId", hostExtender->d->applet.data()->id());
|
|
|
|
dg.writeEntry("extenderIconName", hostExtender->d->applet.data()->icon());
|
|
|
|
d->sourceApplet = hostExtender->d->applet.data();
|
|
|
|
d->collapseIcon->setIcon(KIcon(hostExtender->d->applet.data()->icon()));
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
//The item already exists.
|
|
|
|
d->name = dg.readEntry("extenderItemName", "");
|
2010-04-07 04:04:52 +02:00
|
|
|
d->titleLabel->setText(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";
|
|
|
|
}
|
2010-04-07 04:04:52 +02:00
|
|
|
d->collapseIcon->setIcon(iconName);
|
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.
|
2010-05-27 21:59:15 +02:00
|
|
|
Corona *corona = hostExtender->d->applet.data()->containment()->corona();
|
2010-09-20 21:25:30 +02:00
|
|
|
if (sourceAppletId == hostExtender->applet()->id()) {
|
|
|
|
d->sourceApplet = hostExtender->applet();
|
|
|
|
} else {
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
foreach (Applet *applet, containment->applets()) {
|
|
|
|
if (applet->id() == sourceAppletId &&
|
|
|
|
applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) {
|
|
|
|
d->sourceApplet = applet;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//make sure we keep monitoring if the source applet still exists, so the return to source icon
|
|
|
|
//can be hidden if it is removed.
|
2010-06-24 20:32:49 +02:00
|
|
|
if (d->sourceApplet) {
|
|
|
|
connect(d->sourceApplet, SIGNAL(destroyed()), this, SLOT(sourceAppletRemoved()));
|
|
|
|
}
|
2010-06-12 00:02:54 +02:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
connect(d->collapseIcon, SIGNAL(clicked()), this, SLOT(toggleCollapse()));
|
|
|
|
|
|
|
|
//set the extender we want to move to.
|
|
|
|
setExtender(hostExtender);
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
//set the image paths, image sizes
|
2008-11-04 00:08:39 +01:00
|
|
|
d->themeChanged();
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
//show or hide the toolbox interface itmems
|
|
|
|
d->updateToolBox();
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
|
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), this, SLOT(themeChanged()));
|
2010-05-27 21:59:15 +02:00
|
|
|
d->setMovable(d->extender->d->applet.data()->immutability() == Plasma::Mutable);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderItem::~ExtenderItem()
|
|
|
|
{
|
2010-02-10 09:43:08 +01:00
|
|
|
emit destroyed(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup ExtenderItem::config() const
|
|
|
|
{
|
2010-05-21 20:12:20 +02:00
|
|
|
if (!d->extender->d->applet) {
|
2010-05-21 20:09:15 +02:00
|
|
|
return KConfigGroup();
|
|
|
|
}
|
2010-07-23 21:29:50 +02:00
|
|
|
|
2010-05-27 21:59:15 +02:00
|
|
|
KConfigGroup cg = d->extender->d->applet.data()->config("ExtenderItems");
|
2010-07-23 21:29:50 +02:00
|
|
|
KConfigGroup itemCg = KConfigGroup(&cg, QString::number(d->extenderItemId));
|
|
|
|
|
|
|
|
//we try to figure out if we are a transient ExtenderItem
|
|
|
|
//if we are, return an in memory config group (nothing will be saved on disk)
|
|
|
|
//if we aren't, return the ExtenderItems subgroup of our applet, as usual
|
|
|
|
if (d->transient) {
|
|
|
|
//create the dummy config group pointer if doesn't exists
|
|
|
|
if (!d->transientConfig) {
|
|
|
|
d->transientConfig = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
KConfigGroup dummyGroup = KConfigGroup(d->transientConfig, "ExtenderItems");
|
|
|
|
itemCg.reparent(&dummyGroup);
|
|
|
|
return itemCg;
|
|
|
|
}
|
|
|
|
KConfigGroup dummyGroup = KConfigGroup(d->transientConfig, "ExtenderItems");
|
|
|
|
dummyGroup = KConfigGroup(&dummyGroup, QString::number(d->extenderItemId));
|
|
|
|
return dummyGroup;
|
|
|
|
} else {
|
|
|
|
//if the dummy config pointer still exists, get rid of it
|
|
|
|
if (d->transientConfig) {
|
|
|
|
KConfigGroup dummyGroup = KConfigGroup(d->transientConfig, "ExtenderItems");
|
|
|
|
dummyGroup = KConfigGroup(&dummyGroup, QString::number(d->extenderItemId));
|
|
|
|
dummyGroup.reparent(&cg);
|
|
|
|
delete d->transientConfig.data();
|
|
|
|
d->transientConfig.clear();
|
|
|
|
return dummyGroup;
|
|
|
|
}
|
|
|
|
return itemCg;
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setTitle(const QString &title)
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
if (d->titleLabel->text() != title) {
|
|
|
|
d->titleLabel->setText(title);
|
2009-09-01 13:00:10 +02:00
|
|
|
config().writeEntry("extenderTitle", title);
|
|
|
|
update();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ExtenderItem::title() const
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
return d->titleLabel->text();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2010-04-07 04:04:52 +02:00
|
|
|
d->layout->removeItem(d->widget);
|
2009-07-25 06:53:35 +02:00
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
if (!widget || !widget->isWidget()) {
|
2009-07-25 06:53:35 +02:00
|
|
|
d->widget = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
widget->setParentItem(this);
|
2010-04-07 04:04:52 +02:00
|
|
|
d->widget = static_cast<QGraphicsWidget *>(widget);
|
|
|
|
d->layout->insertItem(1, d->widget);
|
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.
|
2010-07-23 21:29:50 +02:00
|
|
|
if (!d->transient && d->hostApplet() && (extender != d->extender)) {
|
2010-05-27 21:59:15 +02:00
|
|
|
KConfigGroup c = extender->d->applet.data()->config("ExtenderItems");
|
2008-11-04 00:08:39 +01:00
|
|
|
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);
|
2010-06-12 00:02:54 +02:00
|
|
|
if (d->extender) {
|
|
|
|
disconnect(d->extender->applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SLOT(updateToolBox()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
d->extender = extender;
|
2010-06-12 00:02:54 +02:00
|
|
|
connect(d->extender->applet(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)), this, SLOT(updateToolBox()));
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
//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;
|
|
|
|
}
|
|
|
|
|
2010-04-10 18:43:56 +02:00
|
|
|
//TODO KDE5: only one setGroup()
|
2009-03-23 17:30:32 +01:00
|
|
|
void ExtenderItem::setGroup(ExtenderGroup *group)
|
2010-04-10 18:43:56 +02:00
|
|
|
{
|
|
|
|
setGroup(group, QPointF(-1, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setGroup(ExtenderGroup *group, const QPointF &pos)
|
2009-03-23 17:30:32 +01:00
|
|
|
{
|
2009-04-26 19:03:15 +02:00
|
|
|
if (isGroup()) {
|
2010-05-18 20:55:00 +02:00
|
|
|
//nesting extender groups is just insane. I don't think we'd even want to support that.
|
|
|
|
kWarning() << "Nesting ExtenderGroups is not supported";
|
2009-04-26 19:03:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-09 19:59:56 +02:00
|
|
|
ExtenderGroup *oldGroup = d->group;
|
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());
|
|
|
|
}
|
2010-04-10 18:43:56 +02:00
|
|
|
group->d->addItemToGroup(this, pos);
|
2009-04-26 19:03:15 +02:00
|
|
|
} else {
|
2010-04-09 19:59:56 +02:00
|
|
|
if (oldGroup) {
|
|
|
|
oldGroup->d->removeItemFromGroup(this);
|
|
|
|
}
|
2009-04-26 19:03:15 +02:00
|
|
|
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
|
|
|
|
{
|
2010-05-18 11:28:06 +02:00
|
|
|
return (config().readEntry("isGroup", false) && qobject_cast<const Plasma::ExtenderGroup *>(this));
|
2009-03-23 17:30:32 +01:00
|
|
|
}
|
|
|
|
|
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());
|
2010-09-19 22:05:09 +02:00
|
|
|
if (corona) {
|
|
|
|
KConfigGroup extenderItemGroup(corona->config(), "DetachedExtenderItems");
|
|
|
|
if (extenderItemGroup.hasGroup(QString::number(d->extenderItemId))) {
|
|
|
|
extenderItemGroup.deleteGroup(QString::number(d->extenderItemId));
|
|
|
|
}
|
2009-03-12 18:19:45 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2010-04-07 04:04:52 +02:00
|
|
|
d->collapseIcon->setToolTip(collapsed ? i18n("Expand this widget") : i18n("Collapse this widget"));
|
2009-02-09 19:10:45 +01:00
|
|
|
if (d->widget) {
|
|
|
|
d->widget->setVisible(!collapsed);
|
2010-04-07 15:48:43 +02:00
|
|
|
if (collapsed) {
|
|
|
|
d->layout->removeItem(d->widget);
|
|
|
|
} else {
|
|
|
|
d->layout->insertItem(1, d->widget);
|
|
|
|
}
|
2010-05-20 22:41:11 +02:00
|
|
|
updateGeometry();
|
|
|
|
if (extender()) {
|
|
|
|
extender()->resize(extender()->effectiveSizeHint(Qt::PreferredSize));
|
2010-04-07 15:53:49 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
void ExtenderItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
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.
|
2010-04-07 04:04:52 +02:00
|
|
|
d->background->paintFrame(painter, option->exposedRect, option->exposedRect);
|
2010-04-06 22:42:25 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
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)
|
2010-04-07 04:04:52 +02:00
|
|
|
//resize the applet background
|
|
|
|
d->background->resizeFrame(size());
|
|
|
|
//d->resizeContent(size());
|
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())) ||
|
2010-05-27 21:59:15 +02:00
|
|
|
d->extender->d->applet.data()->immutability() != Plasma::Mutable) {
|
2008-11-04 00:08:39 +01:00
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2010-06-12 11:51:42 +02:00
|
|
|
QPoint mousePressPos = event->buttonDownPos(Qt::LeftButton).toPoint();
|
|
|
|
if (!(event->buttons() & Qt::LeftButton) ||
|
|
|
|
(event->pos().toPoint() - mousePressPos).manhattanLength()
|
2009-02-09 19:10:45 +01:00
|
|
|
< QApplication::startDragDistance()) {
|
2008-11-28 18:06:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-05-27 21:59:15 +02:00
|
|
|
if (!d->extender->d->applet) {
|
|
|
|
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-04-07 04:04:52 +02:00
|
|
|
mimeData->setPointerOffset(mousePressPos);
|
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.
|
2010-05-27 21:59:15 +02:00
|
|
|
ExtenderApplet *extenderApplet = qobject_cast<ExtenderApplet*>(d->extender->d->applet.data());
|
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();
|
|
|
|
}
|
|
|
|
|
2010-04-09 19:59:56 +02:00
|
|
|
if (!isGroup() && this->group()) {
|
|
|
|
setGroup(0);
|
|
|
|
}
|
|
|
|
|
2009-02-09 19:10:45 +01:00
|
|
|
//and execute the drag.
|
2010-05-27 21:59:15 +02:00
|
|
|
QWidget *dragParent = extender()->d->applet.data()->view();
|
2009-02-09 19:10:45 +01:00
|
|
|
QDrag *drag = new QDrag(dragParent);
|
|
|
|
drag->setPixmap(pixmap);
|
|
|
|
drag->setMimeData(mimeData);
|
2010-04-07 04:04:52 +02:00
|
|
|
drag->setHotSpot(mousePressPos);
|
2010-06-12 11:51:42 +02:00
|
|
|
|
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)
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
if (d->dragHandleRect().contains(event->pos())) {
|
2008-11-04 00:08:39 +01:00
|
|
|
d->toggleCollapse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
bool ExtenderItem::sceneEventFilter(QGraphicsItem *, QEvent *)
|
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
|
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
void ExtenderItem::hoverMoveEvent(QGraphicsSceneHoverEvent *)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
void ExtenderItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-11-28 15:24:20 +01:00
|
|
|
QSizeF ExtenderItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
return QGraphicsWidget::sizeHint(which, constraint);
|
2009-11-28 15:24:20 +01:00
|
|
|
}
|
|
|
|
|
2010-07-23 21:29:50 +02:00
|
|
|
void ExtenderItem::setTransient(const bool transient)
|
|
|
|
{
|
|
|
|
d->transient = transient;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::isTransient() const
|
|
|
|
{
|
|
|
|
return d->transient;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
background(new FrameSvg(extenderItem)),
|
|
|
|
collapseIcon(0),
|
2010-07-24 02:52:46 +02:00
|
|
|
expirationTimer(0),
|
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),
|
2010-07-23 21:29:50 +02:00
|
|
|
transient(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
return toolbox->boundingRect();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::toggleCollapse()
|
|
|
|
{
|
|
|
|
q->setCollapsed(!q->isCollapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::updateToolBox()
|
|
|
|
{
|
|
|
|
Q_ASSERT(toolbox);
|
|
|
|
Q_ASSERT(toolboxLayout);
|
|
|
|
|
2010-04-06 23:56:32 +02:00
|
|
|
QAction *closeAction = actions.value("close");
|
|
|
|
QAction *returnToSourceAction = actions.value("extenderItemReturnToSource");
|
2010-06-12 00:02:54 +02:00
|
|
|
bool returnToSourceVisibility = q->isDetached() && sourceApplet && (hostApplet()->immutability() == Plasma::Mutable);
|
2010-04-06 23:56:32 +02:00
|
|
|
int closeIndex = -1;
|
|
|
|
int returnToSourceIndex = -1;
|
2010-04-07 04:04:52 +02:00
|
|
|
const int startingIndex = 2; // collapse item is index 0, title label is 1
|
|
|
|
const QSizeF widgetSize = collapseIcon->sizeFromIconSize(toolbox->iconSize());
|
2010-04-06 23:56:32 +02:00
|
|
|
|
|
|
|
QSet<QAction*> shownActions = actionsInOrder.toSet();
|
2010-09-19 23:28:39 +02:00
|
|
|
|
|
|
|
QHash<QAction *, QGraphicsWidget *> actionWidgets;
|
2010-04-06 23:56:32 +02:00
|
|
|
for (int index = startingIndex; index < toolboxLayout->count(); ++index) {
|
2010-09-19 23:28:39 +02:00
|
|
|
QGraphicsWidget *widget = dynamic_cast<QGraphicsWidget*>(toolboxLayout->itemAt(index));
|
|
|
|
QAction *widgetAction = 0;
|
2010-04-06 23:56:32 +02:00
|
|
|
|
|
|
|
if (!widget) {
|
|
|
|
continue;
|
2010-09-19 23:28:39 +02:00
|
|
|
} else if (qobject_cast<IconWidget*>(widget)) {
|
|
|
|
widgetAction = static_cast<IconWidget*>(widget)->action();
|
|
|
|
} else if (qobject_cast<PushButton*>(widget)) {
|
|
|
|
widgetAction = static_cast<PushButton*>(widget)->action();
|
|
|
|
} else {
|
|
|
|
continue;
|
2010-04-06 23:56:32 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 23:28:39 +02:00
|
|
|
|
2010-04-06 23:56:32 +02:00
|
|
|
if (closeIndex == -1 && destroyActionVisibility &&
|
2010-09-19 23:28:39 +02:00
|
|
|
closeAction && widgetAction == closeAction) {
|
2010-04-06 23:56:32 +02:00
|
|
|
closeIndex = index;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnToSourceIndex == -1 && returnToSourceVisibility &&
|
2010-09-19 23:28:39 +02:00
|
|
|
returnToSourceAction && widgetAction == returnToSourceAction) {
|
2010-04-06 23:56:32 +02:00
|
|
|
returnToSourceIndex = index;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-19 23:28:39 +02:00
|
|
|
if (shownActions.contains(widgetAction)) {
|
|
|
|
actionWidgets.insert(widgetAction, widget);
|
2010-04-06 23:56:32 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
toolboxLayout->removeAt(index);
|
2008-11-04 00:08:39 +01:00
|
|
|
widget->deleteLater();
|
|
|
|
}
|
|
|
|
|
2010-09-19 23:28:39 +02:00
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
// ensure the collapseIcon is the correct size.
|
|
|
|
collapseIcon->setMinimumSize(widgetSize);
|
|
|
|
collapseIcon->setMaximumSize(widgetSize);
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
//add the actions that are actually set to visible.
|
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) {
|
2010-09-19 23:28:39 +02:00
|
|
|
IconWidget *icon = qobject_cast<IconWidget*>(actionWidgets.value(action));
|
|
|
|
PushButton *button = qobject_cast<PushButton*>(actionWidgets.value(action));
|
2010-04-06 23:56:32 +02:00
|
|
|
|
2010-09-19 23:28:39 +02:00
|
|
|
if (action->icon().isNull() && !action->text().isNull()) {
|
|
|
|
if (!button) {
|
|
|
|
button = new PushButton(q);
|
|
|
|
button->setAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
button->setMinimumHeight(widgetSize.height());
|
|
|
|
button->setMaximumHeight(widgetSize.height());
|
|
|
|
button->setCursor(Qt::ArrowCursor);
|
|
|
|
toolboxLayout->insertItem(startingIndex, button);
|
|
|
|
} else {
|
|
|
|
if (!icon) {
|
|
|
|
icon = new IconWidget(q);
|
|
|
|
icon->setAction(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action->icon().isNull()) {
|
|
|
|
icon->setText(action->text());
|
|
|
|
}
|
|
|
|
icon->setMinimumSize(widgetSize);
|
|
|
|
icon->setMaximumSize(widgetSize);
|
|
|
|
icon->setCursor(Qt::ArrowCursor);
|
|
|
|
toolboxLayout->insertItem(startingIndex, icon);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//add the returntosource icon if we are detached, and have a source applet.
|
2010-04-06 23:56:32 +02:00
|
|
|
if (returnToSourceVisibility && returnToSourceIndex == -1) {
|
|
|
|
IconWidget *returnToSourceIcon = new IconWidget(q);
|
|
|
|
if (!returnToSourceAction) {
|
|
|
|
returnToSourceAction = new QAction(q);
|
|
|
|
returnToSourceAction->setToolTip(i18n("Reattach"));
|
|
|
|
actions.insert("extenderItemReturnToSource", returnToSourceAction);
|
|
|
|
QObject::connect(returnToSourceAction, SIGNAL(triggered()), q, SLOT(returnToSource()));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-04-06 23:56:32 +02:00
|
|
|
returnToSourceIcon->setAction(returnToSourceAction);
|
|
|
|
returnToSourceIcon->setSvg("widgets/configuration-icons", "return-to-source");
|
2010-04-07 04:04:52 +02:00
|
|
|
returnToSourceIcon->setMinimumSize(widgetSize);
|
|
|
|
returnToSourceIcon->setMaximumSize(widgetSize);
|
2010-06-10 19:46:08 +02:00
|
|
|
returnToSourceIcon->setCursor(Qt::ArrowCursor);
|
2010-04-06 23:56:32 +02:00
|
|
|
|
|
|
|
if (closeIndex == -1) {
|
|
|
|
toolboxLayout->addItem(returnToSourceIcon);
|
|
|
|
} else {
|
|
|
|
toolboxLayout->insertItem(closeIndex - 1, returnToSourceIcon);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//add the close icon if desired.
|
2010-04-06 23:56:32 +02:00
|
|
|
if (destroyActionVisibility && closeIndex == -1) {
|
2010-04-07 04:04:52 +02:00
|
|
|
IconWidget *destroyButton = new IconWidget(q);
|
2010-03-16 19:35:07 +01:00
|
|
|
if (!closeAction) {
|
|
|
|
closeAction = new QAction(q);
|
|
|
|
actions.insert("close", closeAction);
|
2010-04-07 15:17:55 +02:00
|
|
|
if (returnToSourceAction) {
|
|
|
|
returnToSourceAction->setToolTip(i18n("Close"));
|
|
|
|
}
|
2010-03-16 19:35:07 +01:00
|
|
|
QObject::connect(closeAction, SIGNAL(triggered()), q, SLOT(destroy()));
|
2009-11-10 23:13:00 +01:00
|
|
|
}
|
2010-04-06 23:56:32 +02: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");
|
2010-04-07 04:04:52 +02:00
|
|
|
destroyButton->setMinimumSize(widgetSize);
|
|
|
|
destroyButton->setMaximumSize(widgetSize);
|
2010-06-10 19:46:08 +02:00
|
|
|
destroyButton->setCursor(Qt::ArrowCursor);
|
2009-11-10 23:13:00 +01:00
|
|
|
toolboxLayout->addItem(destroyButton);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *ExtenderItemPrivate::hostApplet() const
|
|
|
|
{
|
|
|
|
if (extender) {
|
2010-05-27 21:59:15 +02:00
|
|
|
return extender->d->applet.data();
|
2008-11-04 00:08:39 +01:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItemPrivate::themeChanged()
|
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
kDebug();
|
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
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
background->getMargins(left, top, right, bottom);
|
|
|
|
layout->setContentsMargins(left, top, right, bottom);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
toolbox->updateTheme();
|
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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-07 04:04:52 +02:00
|
|
|
void ExtenderItemPrivate::setMovable(bool movable)
|
2009-02-09 19:10:45 +01:00
|
|
|
{
|
2010-04-07 04:04:52 +02:00
|
|
|
if (movable) {
|
|
|
|
titleLabel->setCursor(Qt::OpenHandCursor);
|
|
|
|
toolbox->setCursor(Qt::OpenHandCursor);
|
2009-02-09 19:10:45 +01:00
|
|
|
} else {
|
2010-04-07 04:04:52 +02:00
|
|
|
titleLabel->unsetCursor();
|
|
|
|
toolbox->unsetCursor();
|
2009-11-28 15:24:20 +01:00
|
|
|
}
|
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"
|