2008-09-07 23:33:02 +02:00
|
|
|
/*
|
2008-09-08 19:32:25 +02:00
|
|
|
* Copyright 2008 by Rob Scheepmaker <r.scheepmaker@student.utwente.nl>
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02: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.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* 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.
|
2008-09-07 23:33:02 +02:00
|
|
|
*
|
2008-09-08 19:32:25 +02:00
|
|
|
* 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
|
2008-09-07 23:33:02 +02:00
|
|
|
*/
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
#include "extenderitem.h"
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QAction>
|
2008-08-02 19:46:32 +02:00
|
|
|
#include <QGraphicsSceneResizeEvent>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
#include <QGraphicsLinearLayout>
|
2008-08-29 21:00:10 +02:00
|
|
|
#include <QLayout>
|
2008-08-02 19:46:32 +02:00
|
|
|
#include <QPainter>
|
2008-08-02 13:48:56 +02:00
|
|
|
#include <QTimer>
|
|
|
|
|
2008-08-02 19:46:32 +02:00
|
|
|
#include <KDebug>
|
|
|
|
#include <KIcon>
|
|
|
|
#include <KWindowSystem>
|
2008-08-02 13:48:56 +02:00
|
|
|
|
2008-08-02 19:46:32 +02:00
|
|
|
#include "applet.h"
|
|
|
|
#include "containment.h"
|
|
|
|
#include "corona.h"
|
2008-08-29 21:00:10 +02:00
|
|
|
#include "dialog.h"
|
2008-08-02 19:46:32 +02:00
|
|
|
#include "extender.h"
|
|
|
|
#include "panelsvg.h"
|
2008-09-05 15:44:45 +02:00
|
|
|
#include "popupapplet.h"
|
2008-08-02 19:46:32 +02:00
|
|
|
#include "theme.h"
|
|
|
|
#include "view.h"
|
|
|
|
|
|
|
|
#include "private/applet_p.h"
|
|
|
|
#include "private/extender_p.h"
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class ExtenderItemPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ExtenderItemPrivate(ExtenderItem *extenderItem, Extender *hostExtender)
|
|
|
|
: q(extenderItem),
|
|
|
|
widget(0),
|
|
|
|
toplevel(0),
|
|
|
|
previousTargetExtender(0),
|
|
|
|
extender(hostExtender),
|
|
|
|
title(QString()),
|
|
|
|
sourceAppletId(hostExtender->d->applet->id()),
|
|
|
|
mousePressed(false),
|
|
|
|
expirationTimer(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~ExtenderItemPrivate()
|
|
|
|
{
|
|
|
|
delete toplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return a Rect containing the area of the detachable where the draghandle can be drawn.
|
|
|
|
*/
|
|
|
|
QRectF dragHandleRect()
|
|
|
|
{
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
dragger->getMargins(left, top, right, bottom);
|
2008-08-03 14:16:41 +02:00
|
|
|
QRectF rect(0, 0, q->size().width(),
|
|
|
|
dragger->elementSize("hint-preferred-icon-size").height() + top + bottom);
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF titleRect()
|
|
|
|
{
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
dragger->getMargins(left, top, right, bottom);
|
2008-08-03 14:16:41 +02:00
|
|
|
return dragHandleRect().adjusted(left + collapseIcon->size().width() + 1, top,
|
2008-08-02 13:48:56 +02:00
|
|
|
-toolbox->size().width(), -bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
//XXX kinda duplicated from applethandle.
|
|
|
|
//returns true if the applet overlaps with a different view then the current one.
|
|
|
|
bool leaveCurrentView(const QRect &rect)
|
|
|
|
{
|
2008-08-26 01:16:18 +02:00
|
|
|
if ((q->sceneBoundingRect().left() < 0)) {
|
|
|
|
//always leaveCurrentView when the item is in a Plasma::Dialog which can easy be
|
|
|
|
//seen by checking if it is in topleft quadrant and it's not just there because it's
|
|
|
|
//being viewed by the toplevel view.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
foreach (QWidget *widget, QApplication::topLevelWidgets()) {
|
2008-08-26 01:16:18 +02:00
|
|
|
if (widget->geometry().intersects(rect) && widget->isVisible() && widget != toplevel) {
|
2008-08-02 13:48:56 +02:00
|
|
|
//is this widget a plasma view, a different view then our current one,
|
|
|
|
//AND not a dashboardview?
|
2008-08-25 15:55:26 +02:00
|
|
|
QGraphicsView *v = qobject_cast<QGraphicsView*>(widget);
|
|
|
|
QGraphicsView *currentV = 0;
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
if (hostApplet()) {
|
2008-08-25 15:55:26 +02:00
|
|
|
currentV = qobject_cast<QGraphicsView*>(hostApplet()->containment()->view());
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
2008-08-25 15:55:26 +02:00
|
|
|
|
|
|
|
if (v && v != currentV) {
|
2008-08-02 13:48:56 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRect screenRect() {
|
|
|
|
return hostApplet()->containment()->view()
|
|
|
|
->mapFromScene(q->sceneBoundingRect()).boundingRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void toggleCollapse() {
|
|
|
|
q->setCollapsed(!q->isCollapsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateToolBox() {
|
|
|
|
if (toolbox && dragger && toolboxLayout) {
|
|
|
|
//clean the layout.
|
|
|
|
uint iconHeight = dragger->elementSize("hint-preferred-icon-size").height();
|
|
|
|
|
|
|
|
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.
|
|
|
|
foreach (QAction *action, actions) {
|
|
|
|
if (action->isVisible()) {
|
|
|
|
Icon *icon = new Icon(q);
|
|
|
|
icon->setAction(action);
|
|
|
|
QSizeF iconSize = icon->sizeFromIconSize(iconHeight);
|
|
|
|
icon->setMinimumSize(iconSize);
|
|
|
|
icon->setMaximumSize(iconSize);
|
|
|
|
toolboxLayout->addItem(icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toolboxLayout->updateGeometry();
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
dragger->getMargins(left, top, right, bottom);
|
|
|
|
|
|
|
|
//position the toolbox correctly.
|
|
|
|
QSizeF minimum = toolboxLayout->minimumSize();
|
2008-08-25 17:17:54 +02:00
|
|
|
toolbox->resize(minimum);
|
2008-08-02 13:48:56 +02:00
|
|
|
toolbox->setPos(q->size().width() - minimum.width(),
|
|
|
|
((dragger->size().height() + top + bottom)/2) -
|
|
|
|
(minimum.height()/2));
|
2008-08-25 17:17:54 +02:00
|
|
|
toolbox->update();
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: something like this as static function in corona might be a good idea.
|
|
|
|
QPointF scenePosFromScreenPos(const QPoint &pos) const
|
|
|
|
{
|
|
|
|
//get the stacking order of the toplevel windows and remove the toplevel view that's
|
|
|
|
//only here while dragging, since we're not interested in finding that.
|
|
|
|
QList<WId> order = KWindowSystem::stackingOrder();
|
|
|
|
if (toplevel) {
|
|
|
|
order.removeOne(toplevel->winId());
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsView *found = 0;
|
|
|
|
foreach (QWidget *w, QApplication::topLevelWidgets()) {
|
2008-08-29 21:00:10 +02:00
|
|
|
QGraphicsView *v = 0;
|
|
|
|
|
|
|
|
//first check if we're over a Dialog.
|
|
|
|
Dialog *dialog = qobject_cast<Dialog*>(w);
|
|
|
|
if (dialog) {
|
|
|
|
if (dialog->isVisible() && dialog->geometry().contains(pos)) {
|
|
|
|
v = qobject_cast<QGraphicsView*>(dialog->layout()->itemAt(0)->widget());
|
|
|
|
if (v) {
|
|
|
|
return v->mapToScene(v->mapFromGlobal(pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
v = qobject_cast<QGraphicsView *>(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
//else check if it is a QGV:
|
|
|
|
if (v && w->isVisible() && w->geometry().contains(pos)) {
|
|
|
|
if (found && order.contains(found->winId())) {
|
2008-08-02 13:48:56 +02:00
|
|
|
if (order.indexOf(found->winId()) < order.indexOf(v->winId())) {
|
|
|
|
found = v;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
found = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-18 05:56:41 +02:00
|
|
|
if (!found) {
|
|
|
|
return QPointF();
|
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
return found->mapToScene(found->mapFromGlobal(pos));
|
|
|
|
}
|
|
|
|
|
|
|
|
Applet *hostApplet() const
|
|
|
|
{
|
|
|
|
if (extender) {
|
|
|
|
return extender->d->applet;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderItem *q;
|
|
|
|
|
2008-09-19 18:23:08 +02:00
|
|
|
QGraphicsItem *widget;
|
2008-08-02 13:48:56 +02:00
|
|
|
QGraphicsWidget *toolbox;
|
|
|
|
QGraphicsLinearLayout *toolboxLayout;
|
|
|
|
QGraphicsView *toplevel;
|
|
|
|
|
|
|
|
Extender *previousTargetExtender;
|
|
|
|
Extender *extender;
|
|
|
|
Applet *sourceApplet;
|
|
|
|
|
|
|
|
KConfigGroup config;
|
|
|
|
|
|
|
|
PanelSvg *dragger;
|
|
|
|
PanelSvg *appletBackground;
|
|
|
|
|
|
|
|
Icon *collapseIcon;
|
|
|
|
QAction *returnAction;
|
|
|
|
QMap<QString, QAction*> actions;
|
|
|
|
|
|
|
|
QString title;
|
|
|
|
QString name;
|
|
|
|
|
|
|
|
uint sourceAppletId;
|
|
|
|
uint extenderItemId;
|
|
|
|
|
|
|
|
QPointF deltaScene;
|
|
|
|
QPoint mousePos;
|
|
|
|
|
|
|
|
bool mousePressed;
|
|
|
|
bool mouseOver;
|
|
|
|
|
|
|
|
QTimer *expirationTimer;
|
|
|
|
|
|
|
|
static uint s_maxExtenderItemId;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint ExtenderItemPrivate::s_maxExtenderItemId = 0;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->sourceApplet = hostExtender->d->applet;
|
|
|
|
|
|
|
|
//create items's configgroup
|
|
|
|
if (hostExtender->d->applet) {
|
|
|
|
KConfigGroup cg = hostExtender->d->applet->config("ExtenderItems");
|
|
|
|
KConfigGroup dg = KConfigGroup(&cg, QString::number(d->extenderItemId));
|
|
|
|
|
|
|
|
if (!dg.readEntry("sourceAppletId", 0)) {
|
|
|
|
//The item is new
|
|
|
|
dg.writeEntry("sourceAppletPluginName", hostExtender->d->applet->pluginName());
|
|
|
|
dg.writeEntry("sourceAppletId", hostExtender->d->applet->id());
|
|
|
|
d->sourceAppletId = hostExtender->d->applet->id();
|
|
|
|
d->sourceApplet = hostExtender->d->applet;
|
|
|
|
} else {
|
|
|
|
//The item allready exists.
|
|
|
|
d->name = dg.readEntry("extenderItemName", "");
|
|
|
|
d->sourceAppletId = dg.readEntry("sourceAppletId", 0);
|
|
|
|
//Set the sourceapplet.
|
|
|
|
Corona *corona = hostExtender->d->applet->containment()->corona();
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
foreach (Applet *applet, containment->applets()) {
|
|
|
|
if (applet->id() == d->sourceAppletId &&
|
|
|
|
applet->pluginName() == dg.readEntry("sourceAppletPluginName", "")) {
|
|
|
|
d->sourceApplet = applet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//create the dragger and standard applet background.
|
2008-08-23 19:47:50 +02:00
|
|
|
d->dragger = new PanelSvg(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
d->dragger->setImagePath("widgets/dragger");
|
|
|
|
|
2008-08-23 19:47:50 +02:00
|
|
|
d->appletBackground = new PanelSvg(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
d->appletBackground->setImagePath("widgets/background");
|
|
|
|
d->appletBackground->setEnabledBorders(0);
|
|
|
|
|
|
|
|
//create the toolbox.
|
|
|
|
d->toolbox = new QGraphicsWidget(this);
|
2008-08-25 17:17:54 +02:00
|
|
|
d->toolboxLayout = new QGraphicsLinearLayout(d->toolbox);
|
2008-08-02 13:48:56 +02:00
|
|
|
d->toolbox->setLayout(d->toolboxLayout);
|
|
|
|
|
|
|
|
//allow the theme to set the size of the icon.
|
|
|
|
//TODO: discuss with others to determine details of the theming implementation. I don't really
|
|
|
|
//like this approach, but it works...
|
|
|
|
QSizeF iconSize = d->dragger->elementSize("hint-preferred-icon-size");
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->dragger->getMargins(left, top, right, bottom);
|
|
|
|
|
|
|
|
//create the collapse/applet icon.
|
|
|
|
d->collapseIcon = new Icon(KIcon(hostExtender->d->applet->icon()), "", this);
|
|
|
|
d->collapseIcon->resize(d->collapseIcon->sizeFromIconSize(iconSize.height()));
|
|
|
|
d->collapseIcon->setPos(left, (d->dragger->size().height() + top + bottom)/2 -
|
|
|
|
d->collapseIcon->size().height()/2);
|
|
|
|
connect(d->collapseIcon, SIGNAL(clicked()), this, SLOT(toggleCollapse()));
|
|
|
|
|
|
|
|
//Add the return to source action.
|
|
|
|
d->returnAction = new QAction(this);
|
|
|
|
d->returnAction->setIcon(KIcon("returntosource"));
|
|
|
|
d->returnAction->setEnabled(true);
|
|
|
|
d->returnAction->setVisible(true);
|
|
|
|
connect(d->returnAction, SIGNAL(triggered()), this, SLOT(moveBackToSource()));
|
|
|
|
addAction("returntosource", d->returnAction);
|
|
|
|
|
|
|
|
//set the extender we want to move to.
|
|
|
|
setExtender(hostExtender);
|
|
|
|
|
|
|
|
setCollapsed(false); //sets the size hints.
|
|
|
|
setAcceptHoverEvents(true);
|
|
|
|
|
|
|
|
d->updateToolBox();
|
|
|
|
updateGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtenderItem::~ExtenderItem()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
KConfigGroup ExtenderItem::config() const
|
|
|
|
{
|
2008-09-18 04:44:08 +02:00
|
|
|
KConfigGroup cg = d->extender->d->applet->config("ExtenderItems");
|
2008-08-02 13:48:56 +02:00
|
|
|
return KConfigGroup(&cg, QString::number(d->extenderItemId));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setTitle(const QString &title)
|
|
|
|
{
|
|
|
|
d->title = title;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-09-19 18:23:08 +02:00
|
|
|
void ExtenderItem::setWidget(QGraphicsItem *widget)
|
2008-08-02 13:48:56 +02:00
|
|
|
{
|
2008-09-15 00:10:55 +02:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->dragger->getMargins(left, top, right, bottom);
|
2008-08-02 13:48:56 +02:00
|
|
|
widget->setParentItem(this);
|
2008-09-15 00:10:55 +02:00
|
|
|
widget->setPos(QPointF(left, d->dragHandleRect().height() + bottom));
|
2008-08-02 13:48:56 +02:00
|
|
|
d->widget = widget;
|
|
|
|
setCollapsed(isCollapsed()); //updates the size hints.
|
|
|
|
}
|
|
|
|
|
2008-09-19 18:23:08 +02:00
|
|
|
QGraphicsItem *ExtenderItem::widget() const
|
2008-08-02 13:48:56 +02:00
|
|
|
{
|
|
|
|
return d->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setIcon(const QIcon &icon)
|
|
|
|
{
|
|
|
|
d->collapseIcon->setIcon(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setIcon(const QString &icon)
|
|
|
|
{
|
|
|
|
d->collapseIcon->setIcon(icon);
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon ExtenderItem::icon() const
|
|
|
|
{
|
|
|
|
return d->collapseIcon->icon();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setExtender(Extender *extender, const QPointF &pos)
|
|
|
|
{
|
2008-09-24 23:46:37 +02:00
|
|
|
Q_ASSERT(extender);
|
|
|
|
|
2008-09-17 15:30:18 +02: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;
|
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
//We are switching extender...
|
|
|
|
//first remove this item from the old extender.
|
2008-09-24 23:46:37 +02:00
|
|
|
d->extender->d->removeExtenderItem(this);
|
|
|
|
emit d->extender->itemDetached(this);
|
|
|
|
|
|
|
|
//collapse the popupapplet if the last item is removed.
|
|
|
|
if (!d->extender->attachedItems().count()) {
|
|
|
|
PopupApplet *applet = qobject_cast<PopupApplet*>(d->extender->d->applet);
|
|
|
|
if (applet) {
|
|
|
|
applet->hidePopup();
|
2008-09-15 00:43:53 +02:00
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//move the configuration.
|
|
|
|
if (d->hostApplet() && (extender != d->extender)) {
|
|
|
|
KConfigGroup c = extender->d->applet->config("ExtenderItems");
|
|
|
|
config().reparent(&c);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->extender = extender;
|
|
|
|
|
|
|
|
//change parent.
|
|
|
|
setParentItem(extender);
|
|
|
|
extender->d->addExtenderItem(this, pos);
|
|
|
|
|
|
|
|
//cancel the timer.
|
|
|
|
if (d->expirationTimer && isDetached()) {
|
|
|
|
d->expirationTimer->stop();
|
|
|
|
delete d->expirationTimer;
|
|
|
|
d->expirationTimer = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Extender *ExtenderItem::extender() const
|
|
|
|
{
|
|
|
|
return d->extender;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::isCollapsed() const
|
|
|
|
{
|
|
|
|
if (!d->widget) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return !d->widget->isVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setAutoExpireDelay(uint time)
|
|
|
|
{
|
2008-08-03 23:47:21 +02:00
|
|
|
if (!time) {
|
|
|
|
if (d->expirationTimer) {
|
|
|
|
d->expirationTimer->stop();
|
|
|
|
delete d->expirationTimer;
|
|
|
|
d->expirationTimer = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
if (!isDetached()) {
|
2008-08-03 19:34:47 +02:00
|
|
|
if (!d->expirationTimer) {
|
|
|
|
d->expirationTimer = new QTimer(this);
|
|
|
|
connect(d->expirationTimer, SIGNAL(timeout()), this, SLOT(destroy()));
|
|
|
|
}
|
|
|
|
|
|
|
|
d->expirationTimer->stop();
|
2008-08-02 13:48:56 +02:00
|
|
|
d->expirationTimer->setSingleShot(true);
|
|
|
|
d->expirationTimer->setInterval(time);
|
|
|
|
d->expirationTimer->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::autoExpireDelay() const
|
|
|
|
{
|
|
|
|
if (d->expirationTimer) {
|
|
|
|
return d->expirationTimer->interval();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExtenderItem::isDetached() const
|
|
|
|
{
|
|
|
|
if (d->hostApplet()) {
|
|
|
|
return (sourceAppletId() != d->hostApplet()->id());
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::addAction(const QString &name, QAction *action)
|
|
|
|
{
|
|
|
|
Q_ASSERT(action);
|
|
|
|
|
|
|
|
d->actions[name] = action;
|
|
|
|
connect(action, SIGNAL(changed()), this, SLOT(updateToolBox()));
|
|
|
|
d->updateToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
QAction *ExtenderItem::action(const QString &name) const
|
|
|
|
{
|
|
|
|
if (d->actions.contains(name)) {
|
|
|
|
return d->actions[name];
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint ExtenderItem::sourceAppletId() const
|
|
|
|
{
|
|
|
|
return d->sourceAppletId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::destroy()
|
|
|
|
{
|
2008-09-05 16:16:55 +02:00
|
|
|
if (d->mousePressed) {
|
|
|
|
//avoid being destroyed while we're being dragged.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-08-03 14:16:41 +02:00
|
|
|
d->hostApplet()->config("ExtenderItems").deleteGroup(QString::number(d->extenderItemId));
|
2008-09-24 23:46:37 +02:00
|
|
|
d->extender->d->removeExtenderItem(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
deleteLater();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::setCollapsed(bool collapsed)
|
|
|
|
{
|
|
|
|
if (!d->widget) {
|
|
|
|
setPreferredSize(QSizeF(200, d->dragHandleRect().height()));
|
|
|
|
setMinimumSize(QSizeF(0, d->dragHandleRect().height()));
|
|
|
|
//FIXME: wasn't there some sort of QWIDGETMAXSIZE thingy?
|
|
|
|
setMaximumSize(QSizeF(1000, d->dragHandleRect().height()));
|
2008-08-03 14:27:19 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2008-08-02 13:48:56 +02:00
|
|
|
updateGeometry();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->dragger->getMargins(left, top, right, bottom);
|
|
|
|
|
|
|
|
d->widget->setVisible(!collapsed);
|
|
|
|
|
2008-09-19 18:23:08 +02:00
|
|
|
QSizeF minimumSize;
|
|
|
|
QSizeF preferredSize;
|
|
|
|
QSizeF maximumSize;
|
|
|
|
|
|
|
|
if (d->widget->isWidget()) {
|
|
|
|
QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget*>(d->widget);
|
|
|
|
minimumSize = graphicsWidget->minimumSize();
|
|
|
|
preferredSize = graphicsWidget->preferredSize();
|
|
|
|
maximumSize = graphicsWidget->maximumSize();
|
|
|
|
} else {
|
|
|
|
minimumSize = d->widget->boundingRect().size();
|
|
|
|
preferredSize = d->widget->boundingRect().size();
|
|
|
|
maximumSize = d->widget->boundingRect().size();
|
|
|
|
}
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
if (collapsed) {
|
2008-09-19 18:23:08 +02:00
|
|
|
setPreferredSize(QSizeF(preferredSize.width() + left + right,
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height()));
|
2008-09-19 18:23:08 +02:00
|
|
|
setMinimumSize(QSizeF(minimumSize.width() + left + right,
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height()));
|
2008-09-19 18:23:08 +02:00
|
|
|
setMaximumSize(QSizeF(maximumSize.width() + left + right,
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height()));
|
2008-08-03 14:27:19 +02:00
|
|
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
2008-08-02 13:48:56 +02:00
|
|
|
//FIXME: why don't tooltips work?
|
2008-09-15 00:10:55 +02:00
|
|
|
if (d->collapseIcon) {
|
|
|
|
d->collapseIcon->setToolTip(i18n("Expand this widget"));
|
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
} else {
|
2008-09-19 18:23:08 +02:00
|
|
|
setPreferredSize(QSizeF(preferredSize.width() + left + right,
|
|
|
|
preferredSize.height() +
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height() + top + bottom));
|
2008-09-19 18:23:08 +02:00
|
|
|
setMinimumSize( QSizeF(minimumSize.width() + left + right,
|
|
|
|
minimumSize.height() +
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height() + top + bottom));
|
2008-09-19 18:23:08 +02:00
|
|
|
setMaximumSize( QSizeF(maximumSize.width() + left + right,
|
|
|
|
maximumSize.height() +
|
2008-09-15 00:10:55 +02:00
|
|
|
d->dragHandleRect().height() + top + bottom));
|
2008-08-03 14:27:19 +02:00
|
|
|
|
2008-09-19 18:23:08 +02:00
|
|
|
if (d->widget->isWidget()) {
|
|
|
|
QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget*>(d->widget);
|
|
|
|
setSizePolicy(graphicsWidget->sizePolicy());
|
|
|
|
} else {
|
|
|
|
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
}
|
|
|
|
|
2008-09-15 00:10:55 +02:00
|
|
|
if (d->collapseIcon) {
|
|
|
|
d->collapseIcon->setToolTip(i18n("Collapse this widget"));
|
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
|
2008-09-15 00:10:55 +02:00
|
|
|
updateGeometry();
|
|
|
|
|
2008-09-24 23:46:37 +02:00
|
|
|
d->extender->d->adjustSizeHints();
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::moveBackToSource()
|
|
|
|
{
|
|
|
|
if (!d->sourceApplet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setExtender(d->sourceApplet->d->extender);
|
|
|
|
}
|
|
|
|
|
|
|
|
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->mousePressed) {
|
|
|
|
//only paint the standard applet background when dragging the thing around.
|
|
|
|
d->appletBackground->paintPanel(painter); //, QRectF(QPointF(0,0), size()));
|
|
|
|
}
|
|
|
|
d->dragger->paintPanel(painter); //, d->dragHandleRect());
|
|
|
|
|
|
|
|
//draw the title.
|
|
|
|
Plasma::Theme *theme = Plasma::Theme::defaultTheme();
|
|
|
|
QFont font = theme->font(Plasma::Theme::DefaultFont);
|
|
|
|
font.setPointSize(font.pointSize() - 2);
|
2008-09-16 18:26:57 +02:00
|
|
|
font.setWeight(QFont::Bold);
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
//XXX: duplicated from windowtaskitem.
|
|
|
|
//TODO: hmm, create something generic for this... there's probably more stuff that wants to have
|
|
|
|
//this functionality
|
|
|
|
QRectF rect = QRectF(d->titleRect().width() - 30, 0, 30, d->titleRect().height());
|
|
|
|
|
|
|
|
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.
|
|
|
|
alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
|
|
|
|
alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
|
|
|
|
|
|
|
|
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
|
|
|
|
p.fillRect(rect, alphaGradient);
|
|
|
|
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
painter->drawPixmap(d->titleRect().topLeft(), pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
|
|
{
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->dragger->getMargins(left, top, right, bottom);
|
|
|
|
|
|
|
|
//resize the dragger
|
|
|
|
QSizeF newDraggerSize = event->newSize();
|
|
|
|
newDraggerSize.setHeight(d->dragger->elementSize("hint-preferred-icon-size").height() + top + bottom);
|
|
|
|
d->dragger->resizePanel(newDraggerSize);
|
|
|
|
|
|
|
|
//resize the applet background
|
|
|
|
d->appletBackground->resizePanel(event->newSize());
|
|
|
|
|
|
|
|
//resize the widget
|
2008-09-19 18:23:08 +02:00
|
|
|
if (d->widget && d->widget->isWidget()) {
|
2008-08-02 13:48:56 +02:00
|
|
|
QSizeF newWidgetSize = event->newSize();
|
|
|
|
newWidgetSize.setHeight(newWidgetSize.height() - d->dragger->size().height() - top - bottom);
|
2008-09-15 00:10:55 +02:00
|
|
|
newWidgetSize.setWidth(newWidgetSize.width() - left - right);
|
2008-09-19 18:23:08 +02:00
|
|
|
|
|
|
|
QGraphicsWidget *graphicsWidget = static_cast<QGraphicsWidget*>(d->widget);
|
|
|
|
graphicsWidget->resize(newWidgetSize);
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
d->updateToolBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!(d->dragHandleRect().contains(event->pos()))) {
|
2008-09-15 00:10:55 +02:00
|
|
|
event->ignore();
|
2008-08-02 13:48:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->mousePressed = true;
|
|
|
|
d->deltaScene = pos();
|
|
|
|
|
|
|
|
Applet *parentApplet = d->hostApplet();
|
|
|
|
|
2008-08-26 01:16:18 +02:00
|
|
|
d->mousePos = event->pos().toPoint();
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
parentApplet->raise();
|
|
|
|
setZValue(parentApplet->zValue());
|
|
|
|
|
2008-09-24 23:46:37 +02:00
|
|
|
QPointF mousePos = d->scenePosFromScreenPos(event->screenPos());
|
2008-09-18 05:56:41 +02:00
|
|
|
|
2008-09-24 23:46:37 +02:00
|
|
|
if (!mousePos.isNull()) {
|
|
|
|
d->extender->itemHoverMoveEvent(this, d->extender->mapFromScene(mousePos));
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
|
2008-08-29 21:00:10 +02:00
|
|
|
d->extender->d->removeExtenderItem(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
QApplication::setOverrideCursor(Qt::ClosedHandCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (!d->mousePressed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//keep track of the movement in scene coordinates. we use this to set the position of the
|
|
|
|
//applet when remaining in the current view.
|
|
|
|
d->deltaScene += event->scenePos() - event->lastScenePos();
|
|
|
|
|
|
|
|
//set a rect in screencoordinates so we can check when we need to move to a toplevel
|
|
|
|
//view.
|
|
|
|
QRect screenRect = QRect();
|
|
|
|
screenRect.setTopLeft(event->screenPos() - d->mousePos);
|
|
|
|
screenRect.setSize(d->screenRect().size());
|
|
|
|
|
2008-08-28 16:32:48 +02:00
|
|
|
Corona *corona = d->hostApplet()->containment()->corona();
|
|
|
|
|
2008-08-02 13:48:56 +02:00
|
|
|
if (d->leaveCurrentView(screenRect)) {
|
|
|
|
//we're moving the applet to a toplevel view, so place it somewhere out of sight
|
|
|
|
//first: in the topleft quadrant.
|
|
|
|
|
|
|
|
if (!d->toplevel) {
|
2008-09-18 06:57:50 +02:00
|
|
|
//FIXME: duplication from applethandle
|
2008-08-02 13:48:56 +02:00
|
|
|
//create a toplevel view and aim it at the applet.
|
|
|
|
d->toplevel = new QGraphicsView(corona, 0);
|
2008-08-28 16:32:48 +02:00
|
|
|
|
|
|
|
corona->addOffscreenWidget(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
|
|
|
|
d->toplevel->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint
|
|
|
|
| Qt::WindowStaysOnTopHint);
|
2008-09-04 19:09:34 +02:00
|
|
|
d->toplevel->setFrameShape(QFrame::NoFrame);
|
2008-08-02 13:48:56 +02:00
|
|
|
d->toplevel->resize(screenRect.size());
|
|
|
|
d->toplevel->setSceneRect(sceneBoundingRect());
|
|
|
|
d->toplevel->centerOn(this);
|
|
|
|
|
|
|
|
//We might have to scale the view, because we might be zoomed out.
|
|
|
|
qreal scale = screenRect.width() / boundingRect().width();
|
|
|
|
d->toplevel->scale(scale, scale);
|
|
|
|
|
|
|
|
d->toplevel->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
d->toplevel->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
|
|
|
|
|
|
d->toplevel->update();
|
|
|
|
d->toplevel->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//move the toplevel view.
|
2008-08-26 01:16:18 +02:00
|
|
|
d->toplevel->setSceneRect(sceneBoundingRect());
|
2008-08-02 13:48:56 +02:00
|
|
|
d->toplevel->setGeometry(screenRect);
|
2008-09-05 15:44:45 +02:00
|
|
|
update();
|
2008-08-02 13:48:56 +02:00
|
|
|
} else {
|
2008-08-28 16:32:48 +02:00
|
|
|
corona->removeOffscreenWidget(this);
|
2008-08-02 13:48:56 +02:00
|
|
|
setParentItem(d->hostApplet());
|
|
|
|
setPos(d->deltaScene);
|
|
|
|
|
|
|
|
//remove the toplevel view.
|
|
|
|
if (d->toplevel) {
|
|
|
|
delete d->toplevel;
|
|
|
|
d->toplevel = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//let's insert spacers in applets we're hovering over for some usefull visual feedback.
|
|
|
|
//check which view we're hovering over and use that information to get the mouse
|
|
|
|
//position in scene coordinates (event->scenePos won't work, since it doesn't take in
|
|
|
|
//consideration that you're leaving the current view).
|
|
|
|
QPointF mousePos = d->scenePosFromScreenPos(event->screenPos());
|
|
|
|
|
|
|
|
//find the extender we're hovering over.
|
|
|
|
Extender *targetExtender = 0;
|
2008-09-18 05:56:41 +02:00
|
|
|
|
|
|
|
if (!mousePos.isNull()) {
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
foreach (Applet *applet, containment->applets()) {
|
|
|
|
if (applet->d->extender &&
|
|
|
|
(applet->sceneBoundingRect().contains(mousePos) ||
|
|
|
|
applet->d->extender->sceneBoundingRect().contains(mousePos))) {
|
|
|
|
targetExtender = applet->d->extender;
|
|
|
|
|
|
|
|
//check if we're hovering over an popupapplet, and open it up in case it does.
|
|
|
|
PopupApplet *popupApplet = qobject_cast<PopupApplet*>(applet);
|
|
|
|
if (popupApplet && (applet->formFactor() == Plasma::Horizontal ||
|
|
|
|
applet->formFactor() == Plasma::Vertical)) {
|
|
|
|
popupApplet->showPopup();
|
|
|
|
}
|
2008-09-05 15:44:45 +02:00
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//remove any previous spacers.
|
|
|
|
if (targetExtender != d->previousTargetExtender) {
|
|
|
|
if (d->previousTargetExtender) {
|
|
|
|
d->previousTargetExtender->itemHoverLeaveEvent(this);
|
|
|
|
}
|
|
|
|
d->previousTargetExtender = targetExtender;
|
|
|
|
if (targetExtender) {
|
|
|
|
targetExtender->itemHoverEnterEvent(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//insert a spacer if the applet accepts detachables.
|
|
|
|
if (targetExtender) {
|
|
|
|
if (targetExtender->sceneBoundingRect().contains(mousePos)) {
|
|
|
|
targetExtender->itemHoverMoveEvent(this, targetExtender->mapFromScene(mousePos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (d->titleRect().contains(event->pos())) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExtenderItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->mousePressed) {
|
|
|
|
d->mousePressed = false;
|
|
|
|
|
|
|
|
//remove the toplevel view
|
|
|
|
if (d->toplevel) {
|
|
|
|
delete d->toplevel;
|
|
|
|
d->toplevel = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//let's insert spacers in applets we're hovering over for some usefull visual feedback.
|
|
|
|
//check which view we're hovering over and use that information to get the mouse
|
|
|
|
//position in scene coordinates (event->scenePos won't work, since it doesn't take in
|
|
|
|
//consideration that you're leaving the current view).
|
|
|
|
QPointF mousePos = d->scenePosFromScreenPos(event->screenPos());
|
|
|
|
|
|
|
|
//find the extender we're hovering over.
|
|
|
|
Extender *targetExtender = 0;
|
|
|
|
Corona *corona = qobject_cast<Corona*>(scene());
|
2008-08-28 16:32:48 +02:00
|
|
|
|
|
|
|
corona->removeOffscreenWidget(this);
|
|
|
|
|
2008-09-18 05:56:41 +02:00
|
|
|
if (!mousePos.isNull()) {
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
foreach (Applet *applet, containment->applets()) {
|
|
|
|
if (applet->d->extender &&
|
|
|
|
(applet->sceneBoundingRect().contains(mousePos) ||
|
|
|
|
applet->d->extender->sceneBoundingRect().contains(mousePos))) {
|
|
|
|
targetExtender = applet->d->extender;
|
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//are we hovering over an applet that accepts extender items?
|
|
|
|
if (targetExtender) {
|
|
|
|
if (targetExtender->sceneBoundingRect().contains(mousePos)) {
|
|
|
|
setExtender(targetExtender, targetExtender->mapFromScene(mousePos));
|
|
|
|
} else {
|
|
|
|
setExtender(targetExtender);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//apparently, it is not, so instantiate a new ExtenderApplet.
|
|
|
|
//TODO: maybe we alow the user to choose a default extenderapplet.
|
|
|
|
kDebug() << "Instantiate a new ExtenderApplet";
|
|
|
|
mousePos = d->scenePosFromScreenPos(event->screenPos() - d->mousePos);
|
2008-09-18 05:56:41 +02:00
|
|
|
if (!mousePos.isNull()) {
|
|
|
|
foreach (Containment *containment, corona->containments()) {
|
|
|
|
if (containment->sceneBoundingRect().contains(mousePos)) {
|
|
|
|
Applet *applet = containment->addApplet("internal:extender",
|
|
|
|
QVariantList(),
|
|
|
|
QRectF(mousePos, size()));
|
|
|
|
setExtender(applet->d->extender);
|
|
|
|
}
|
2008-08-02 13:48:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "extenderitem.moc"
|