applet doesn't inherit from QGraphicsWidget

This commit is contained in:
Marco Martin 2012-09-24 14:30:42 +02:00
parent 09cf013164
commit cc21f6fcfe
10 changed files with 56 additions and 320 deletions

View File

@ -116,8 +116,8 @@
namespace Plasma namespace Plasma
{ {
Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId) Applet::Applet(const KPluginInfo &info, QObject *parent, uint appletId)
: QGraphicsWidget(parent), : QObject(parent),
d(new AppletPrivate(KService::Ptr(), &info, appletId, this)) d(new AppletPrivate(KService::Ptr(), &info, appletId, this))
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
@ -125,8 +125,8 @@ Applet::Applet(const KPluginInfo &info, QGraphicsItem *parent, uint appletId)
d->init(); d->init();
} }
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId) Applet::Applet(QObject *parent, const QString &serviceID, uint appletId)
: QGraphicsWidget(parent), : QObject(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this)) d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
@ -134,8 +134,8 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId)
d->init(); d->init();
} }
Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, const QVariantList &args) Applet::Applet(QObject *parent, const QString &serviceID, uint appletId, const QVariantList &args)
: QGraphicsWidget(parent), : QObject(parent),
d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this)) d(new AppletPrivate(KService::serviceByStorageId(serviceID), 0, appletId, this))
{ {
// WARNING: do not access config() OR globalConfig() in this method! // WARNING: do not access config() OR globalConfig() in this method!
@ -156,7 +156,7 @@ Applet::Applet(QGraphicsItem *parent, const QString &serviceID, uint appletId, c
} }
Applet::Applet(QObject *parentObject, const QVariantList &args) Applet::Applet(QObject *parentObject, const QVariantList &args)
: QGraphicsWidget(0), : QObject(0),
d(new AppletPrivate( d(new AppletPrivate(
KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0, KService::serviceByStorageId(args.count() > 0 ? args[0].toString() : QString()), 0,
args.count() > 1 ? args[1].toInt() : 0, this)) args.count() > 1 ? args[1].toInt() : 0, this))
@ -186,7 +186,7 @@ Applet::Applet(QObject *parentObject, const QVariantList &args)
} }
Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args) Applet::Applet(const QString &packagePath, uint appletId, const QVariantList &args)
: QGraphicsWidget(0), : QObject(0),
d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this)) d(new AppletPrivate(KService::Ptr(new KService(packagePath + "/metadata.desktop")), 0, appletId, this))
{ {
Q_UNUSED(args) // FIXME? Q_UNUSED(args) // FIXME?
@ -625,7 +625,6 @@ void Applet::setBackgroundHints(const Plasma::BackgroundHints hints)
if ((hints & StandardBackground) || (hints & TranslucentBackground)) { if ((hints & StandardBackground) || (hints & TranslucentBackground)) {
if (!d->background) { if (!d->background) {
d->background = new Plasma::FrameSvg(this); d->background = new Plasma::FrameSvg(this);
QObject::connect(d->background, SIGNAL(repaintNeeded()), this, SLOT(themeChanged()));
} }
if ((hints & TranslucentBackground) && if ((hints & TranslucentBackground) &&
@ -976,16 +975,16 @@ void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *o
FormFactor Applet::formFactor() const FormFactor Applet::formFactor() const
{ {
Containment *c = containment(); Containment *c = containment();
QGraphicsWidget *pw = qobject_cast<QGraphicsWidget *>(parent()); QObject *pw = qobject_cast<QObject *>(parent());
if (!pw) { if (!pw) {
pw = dynamic_cast<QGraphicsWidget *>(parentItem()); pw = dynamic_cast<QObject *>(parentItem());
} }
Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw); Plasma::Applet *parentApplet = qobject_cast<Plasma::Applet *>(pw);
//assumption: this loop is usually is -really- short or doesn't run at all //assumption: this loop is usually is -really- short or doesn't run at all
while (!parentApplet && pw && pw->parentWidget()) { while (!parentApplet && pw && pw->parentWidget()) {
QGraphicsWidget *parentWidget = qobject_cast<QGraphicsWidget *>(pw->parent()); QObject *parentWidget = qobject_cast<QObject *>(pw->parent());
if (!parentWidget) { if (!parentWidget) {
parentWidget = dynamic_cast<QGraphicsWidget *>(pw->parentItem()); parentWidget = dynamic_cast<QObject *>(pw->parentItem());
} }
pw = parentWidget; pw = parentWidget;
parentApplet = qobject_cast<Plasma::Applet *>(pw); parentApplet = qobject_cast<Plasma::Applet *>(pw);
@ -1021,7 +1020,7 @@ Containment *Applet::containment() const
} }
} }
QGraphicsItem *parent = parentItem(); QObject *parent = parentItem();
Containment *c = 0; Containment *c = 0;
while (parent) { while (parent) {
@ -1122,7 +1121,7 @@ void Applet::setAspectRatioMode(Plasma::AspectRatioMode mode)
d->aspectRatioMode = mode; d->aspectRatioMode = mode;
} }
void Applet::registerAsDragHandle(QGraphicsItem *item) void Applet::registerAsDragHandle(QObject *item)
{ {
if (!item || d->registeredAsDragHandle.contains(item)) { if (!item || d->registeredAsDragHandle.contains(item)) {
return; return;
@ -1132,7 +1131,7 @@ void Applet::registerAsDragHandle(QGraphicsItem *item)
item->installSceneEventFilter(this); item->installSceneEventFilter(this);
} }
void Applet::unregisterAsDragHandle(QGraphicsItem *item) void Applet::unregisterAsDragHandle(QObject *item)
{ {
if (!item) { if (!item) {
return; return;
@ -1145,7 +1144,7 @@ void Applet::unregisterAsDragHandle(QGraphicsItem *item)
} }
} }
bool Applet::isRegisteredAsDragHandle(QGraphicsItem *item) bool Applet::isRegisteredAsDragHandle(QObject *item)
{ {
return d->registeredAsDragHandle.contains(item); return d->registeredAsDragHandle.contains(item);
} }
@ -1211,14 +1210,14 @@ void Applet::setHasConfigurationInterface(bool hasInterface)
d->hasConfigurationInterface = hasInterface; d->hasConfigurationInterface = hasInterface;
} }
bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event) bool Applet::sceneEventFilter(QObject *watched, QEvent *event)
{ {
if (watched == this) { if (watched == this) {
switch (event->type()) { switch (event->type()) {
case QEvent::GraphicsSceneHoverEnter: case QEvent::GraphicsSceneHoverEnter:
//kDebug() << "got hoverenterEvent" << immutability() << " " << immutability(); //kDebug() << "got hoverenterEvent" << immutability() << " " << immutability();
if (immutability() == Mutable) { if (immutability() == Mutable) {
QGraphicsWidget *pw = this; QObject *pw = this;
//This is for the rare case of applet in applet (systray) //This is for the rare case of applet in applet (systray)
//if the applet is in an applet that is not a containment, don't create the handle BUG:301648 //if the applet is in an applet that is not a containment, don't create the handle BUG:301648
while (pw = pw->parentWidget()) { while (pw = pw->parentWidget()) {
@ -1235,8 +1234,7 @@ bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
} else { } else {
//kDebug() << "generated applet handle"; //kDebug() << "generated applet handle";
AppletHandle *handle = new AppletHandle(containment(), this, he->pos()); AppletHandle *handle = new AppletHandle(containment(), this, he->pos());
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
this, SLOT(handleDisappeared(AppletHandle*)));
connect(this, SIGNAL(geometryChanged()), connect(this, SIGNAL(geometryChanged()),
handle, SLOT(appletResized())); handle, SLOT(appletResized()));
d->handle = handle; d->handle = handle;
@ -1278,13 +1276,13 @@ bool Applet::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
break; break;
} }
return QGraphicsItem::sceneEventFilter(watched, event); return QObject::sceneEventFilter(watched, event);
} }
void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (immutability() == Mutable && formFactor() == Plasma::Planar && (flags() & ItemIsMovable)) { if (immutability() == Mutable && formFactor() == Plasma::Planar && (flags() & ItemIsMovable)) {
QGraphicsWidget::mouseMoveEvent(event); QObject::mouseMoveEvent(event);
} }
} }
@ -1295,12 +1293,12 @@ void Applet::focusInEvent(QFocusEvent *event)
containment()->d->focusApplet(this); containment()->d->focusApplet(this);
} }
QGraphicsWidget::focusInEvent(event); QObject::focusInEvent(event);
} }
void Applet::resizeEvent(QGraphicsSceneResizeEvent *event) void Applet::resizeEvent(QGraphicsSceneResizeEvent *event)
{ {
QGraphicsWidget::resizeEvent(event); QObject::resizeEvent(event);
if (d->background) { if (d->background) {
d->background->resizeFrame(boundingRect().size()); d->background->resizeFrame(boundingRect().size());
@ -1623,82 +1621,18 @@ Applet *Applet::loadPlasmoid(const QString &path, uint appletId, const QVariantL
return 0; return 0;
} }
QVariant Applet::itemChange(GraphicsItemChange change, const QVariant &value)
{
QVariant ret = QGraphicsWidget::itemChange(change, value);
//kDebug() << change;
switch (change) {
case ItemSceneHasChanged: {
Corona *newCorona = qobject_cast<Corona *>(qvariant_cast<QGraphicsScene*>(value));
if (newCorona && newCorona->immutability() != Mutable) {
updateConstraints(ImmutableConstraint);
}
}
break;
case ItemParentChange:
if (!d->isContainment) {
Containment *c = containment();
if (d->mainConfig && !c) {
kWarning() << "Configuration object was requested prior to init(), which is too early. "
"Please fix this item:" << parentItem() << value.value<QGraphicsItem *>()
<< name();
Applet *newC = dynamic_cast<Applet*>(value.value<QGraphicsItem *>());
if (newC) {
// if this is an applet, and we've just been assigned to our first containment,
// but the applet did something stupid like ask for the config() object prior to
// this happening (e.g. inits ctor) then let's repair that situation for them.
KConfigGroup *old = d->mainConfig;
KConfigGroup appletConfig = newC->config();
appletConfig = KConfigGroup(&appletConfig, "Applets");
d->mainConfig = new KConfigGroup(&appletConfig, QString::number(d->appletId));
old->copyTo(d->mainConfig);
old->deleteGroup();
delete old;
}
}
}
break;
case ItemParentHasChanged:
{
if (isContainment()) {
removeSceneEventFilter(this);
} else {
Containment *c = containment();
if (c && c->containmentType() == Containment::DesktopContainment) {
installSceneEventFilter(this);
} else {
removeSceneEventFilter(this);
}
}
}
break;
case ItemPositionHasChanged:
emit geometryChanged();
// fall through!
case ItemTransformHasChanged:
d->scheduleModificationNotification();
break;
default:
break;
};
return ret;
}
QPainterPath Applet::shape() const QPainterPath Applet::shape() const
{ {
if (d->script) { if (d->script) {
return d->script->shape(); return d->script->shape();
} }
return QGraphicsWidget::shape(); return QObject::shape();
} }
QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const QSizeF Applet::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{ {
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint); QSizeF hint = QObject::sizeHint(which, constraint);
const FormFactor ff = formFactor(); const FormFactor ff = formFactor();
// in panels make sure that the contents won't exit from the panel // in panels make sure that the contents won't exit from the panel

View File

@ -70,7 +70,7 @@ class Package;
* *
* See techbase.kde.org for tutorials on writing Applets using this class. * See techbase.kde.org for tutorials on writing Applets using this class.
*/ */
class PLASMA_EXPORT Applet : public QGraphicsWidget class PLASMA_EXPORT Applet : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface) Q_PROPERTY(bool hasConfigurationInterface READ hasConfigurationInterface)
@ -809,6 +809,14 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
void runAssociatedApplication(); void runAssociatedApplication();
bool hasFocus() const;
void setFocus(Qt::FocusReason);
void resize(const QSizeF &size);
QSizeF size() const;
QRectF geometry() const;
void setGeometry(const QRect &geom);
protected: protected:
/** /**
* This constructor is to be used with the plugin loading systems * This constructor is to be used with the plugin loading systems
@ -951,11 +959,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
void resizeEvent(QGraphicsSceneResizeEvent *event); void resizeEvent(QGraphicsSceneResizeEvent *event);
/**
* Reimplemented from QGraphicsItem
*/
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/** /**
* Reimplemented from QGraphicsItem * Reimplemented from QGraphicsItem
*/ */
@ -993,8 +996,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
Applet(const QString &packagePath, uint appletId, const QVariantList &args); Applet(const QString &packagePath, uint appletId, const QVariantList &args);
Q_PRIVATE_SLOT(d, void setFocus())
Q_PRIVATE_SLOT(d, void themeChanged())
Q_PRIVATE_SLOT(d, void cleanUpAndDelete()) Q_PRIVATE_SLOT(d, void cleanUpAndDelete())
Q_PRIVATE_SLOT(d, void selectItemToDestroy()) Q_PRIVATE_SLOT(d, void selectItemToDestroy())
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect)) Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
@ -1003,7 +1004,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state)) Q_PRIVATE_SLOT(d, void publishCheckboxStateChanged(int state))
Q_PRIVATE_SLOT(d, void globalShortcutChanged()) Q_PRIVATE_SLOT(d, void globalShortcutChanged())
Q_PRIVATE_SLOT(d, void propagateConfigChanged()) Q_PRIVATE_SLOT(d, void propagateConfigChanged())
Q_PRIVATE_SLOT(d, void handleDisappeared(AppletHandle *handle))
/** /**
* Reimplemented from QGraphicsItem * Reimplemented from QGraphicsItem

View File

@ -611,12 +611,6 @@ void Containment::setFormFactor(FormFactor formFactor)
//kDebug() << "switching FF to " << formFactor; //kDebug() << "switching FF to " << formFactor;
d->formFactor = formFactor; d->formFactor = formFactor;
if (isContainment() &&
(d->type == PanelContainment || d->type == CustomPanelContainment)) {
// we are a panel and we have chaged our orientation
d->positionPanel(true);
}
if (d->toolBox) { if (d->toolBox) {
d->toolBox.data()->reposition(); d->toolBox.data()->reposition();
} }
@ -971,9 +965,7 @@ void Containment::resizeEvent(QGraphicsSceneResizeEvent *event)
Applet::resizeEvent(event); Applet::resizeEvent(event);
if (isContainment()) { if (isContainment()) {
if (d->isPanelContainment()) { if (corona()) {
d->positionPanel();
} else if (corona()) {
corona()->layoutContainments(); corona()->layoutContainments();
} }
@ -1027,29 +1019,6 @@ void Containment::wheelEvent(QGraphicsSceneWheelEvent *event)
} }
} }
QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &value)
{
//FIXME if the applet is moved to another containment we need to unfocus it
if (isContainment() &&
(change == QGraphicsItem::ItemSceneHasChanged ||
change == QGraphicsItem::ItemPositionHasChanged)) {
switch (d->type) {
case PanelContainment:
case CustomPanelContainment:
d->positionPanel();
break;
default:
if (corona()) {
corona()->layoutContainments();
}
break;
}
}
return Applet::itemChange(change, value);
}
void Containment::enableAction(const QString &name, bool enable) void Containment::enableAction(const QString &name, bool enable)
{ {
QAction *action = this->action(name); QAction *action = this->action(name);

View File

@ -409,6 +409,9 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
KConfigGroup containmentActionsConfig(); KConfigGroup containmentActionsConfig();
void setAcceptDrops(bool accept);
bool acceptDrops() const;
Q_SIGNALS: Q_SIGNALS:
/** /**
* This signal is emitted when a new applet is created by the containment * This signal is emitted when a new applet is created by the containment
@ -548,7 +551,6 @@ Q_SIGNALS:
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void wheelEvent(QGraphicsSceneWheelEvent *event); void wheelEvent(QGraphicsSceneWheelEvent *event);
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
/** /**
* @reimp * @reimp

View File

@ -131,7 +131,6 @@ void AppletPrivate::init(const QString &packagePath)
<< "You probably want to be passing in a Service::Ptr " << "You probably want to be passing in a Service::Ptr "
<< "or a QVariantList with a valid storageid as arg[0]."; << "or a QVariantList with a valid storageid as arg[0].";
#endif #endif
q->resize(size);
return; return;
} }
@ -140,7 +139,6 @@ void AppletPrivate::init(const QString &packagePath)
size = s.toSize(); size = s.toSize();
} }
//kDebug() << "size" << size; //kDebug() << "size" << size;
q->resize(size);
QString api = appletDescription.property("X-Plasma-API").toString(); QString api = appletDescription.property("X-Plasma-API").toString();
@ -205,15 +203,11 @@ void AppletPrivate::init(const QString &packagePath)
} }
} }
void AppletPrivate::setFocus()
{
//kDebug() << "setting focus";
q->setFocus(Qt::ShortcutFocusReason);
}
void AppletPrivate::selectItemToDestroy() void AppletPrivate::selectItemToDestroy()
{ {
//FIXME: this will not work nicely with multiple screens and being zoomed out! //FIXME: this will not work nicely with multiple screens and being zoomed out!
//TODO: port away from QGV
/*
if (isContainment) { if (isContainment) {
QGraphicsView *view = q->view(); QGraphicsView *view = q->view();
if (view && view->transform().isScaling() && if (view && view->transform().isScaling() &&
@ -229,16 +223,11 @@ void AppletPrivate::selectItemToDestroy()
} }
} }
} }
} }*/
q->destroy(); q->destroy();
} }
void AppletPrivate::updateRect(const QRectF &rect)
{
q->update(rect);
}
void AppletPrivate::cleanUpAndDelete() void AppletPrivate::cleanUpAndDelete()
{ {
// reimplemented in the UI specific library // reimplemented in the UI specific library
@ -684,7 +673,7 @@ KConfigGroup *AppletPrivate::mainConfigGroup()
} }
if (isContainment) { if (isContainment) {
Corona *corona = qobject_cast<Corona*>(q->scene()); Corona *corona = static_cast<Containment*>(q)->corona();
KConfigGroup containmentConfig; KConfigGroup containmentConfig;
//kDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q; //kDebug() << "got a corona, baby?" << (QObject*)corona << (QObject*)q;
@ -733,22 +722,6 @@ QString AppletPrivate::visibleFailureText(const QString &reason)
return text; return text;
} }
void AppletPrivate::themeChanged()
{
if (background) {
//do again the translucent background fallback
q->setBackgroundHints(backgroundHints);
qreal left;
qreal right;
qreal top;
qreal bottom;
background->getMargins(left, top, right, bottom);
q->setContentsMargins(left, right, top, bottom);
}
q->update();
}
void AppletPrivate::resetConfigurationObject() void AppletPrivate::resetConfigurationObject()
{ {
// make sure mainConfigGroup exists in all cases // make sure mainConfigGroup exists in all cases
@ -758,24 +731,15 @@ void AppletPrivate::resetConfigurationObject()
delete mainConfig; delete mainConfig;
mainConfig = 0; mainConfig = 0;
Corona * corona = qobject_cast<Corona*>(q->scene()); if (!q->containment()) {
return;
}
Corona * corona = q->containment()->corona();
if (corona) { if (corona) {
corona->requireConfigSync(); corona->requireConfigSync();
} }
} }
void AppletPrivate::handleDisappeared(AppletHandle *h)
{
if (h == handle.data()) {
h->detachApplet();
QGraphicsScene *scene = q->scene();
if (scene && h->scene() == scene) {
scene->removeItem(h);
}
h->deleteLater();
}
}
uint AppletPrivate::s_maxAppletId = 0; uint AppletPrivate::s_maxAppletId = 0;
int AppletPrivate::s_maxZValue = 0; int AppletPrivate::s_maxZValue = 0;
int AppletPrivate::s_minZValue = 0; int AppletPrivate::s_minZValue = 0;

View File

@ -100,18 +100,14 @@ public:
*/ */
void setIsContainment(bool isContainment, bool forceUpdate = false); void setIsContainment(bool isContainment, bool forceUpdate = false);
void handleDisappeared(AppletHandle *handle);
QString globalName() const; QString globalName() const;
QString instanceName(); QString instanceName();
void scheduleConstraintsUpdate(Plasma::Constraints c); void scheduleConstraintsUpdate(Plasma::Constraints c);
void scheduleModificationNotification(); void scheduleModificationNotification();
KConfigGroup *mainConfigGroup(); KConfigGroup *mainConfigGroup();
QString visibleFailureText(const QString &reason); QString visibleFailureText(const QString &reason);
void themeChanged();
void resetConfigurationObject(); void resetConfigurationObject();
void selectItemToDestroy(); void selectItemToDestroy();
void updateRect(const QRectF &rect);
void setFocus();
void addGlobalShortcutsPage(KConfigDialog *dialog); void addGlobalShortcutsPage(KConfigDialog *dialog);
void addPublishPage(KConfigDialog *dialog); void addPublishPage(KConfigDialog *dialog);
void configDialogFinished(); void configDialogFinished();

View File

@ -140,7 +140,7 @@ void ContainmentPrivate::checkContainmentFurniture()
void ContainmentPrivate::addContainmentActions(KMenu &desktopMenu, QEvent *event) void ContainmentPrivate::addContainmentActions(KMenu &desktopMenu, QEvent *event)
{ {
if (static_cast<Corona*>(q->scene())->immutability() != Mutable && if (q->corona()->immutability() != Mutable &&
!KAuthorized::authorizeKAction("plasma/containment_actions")) { !KAuthorized::authorizeKAction("plasma/containment_actions")) {
//kDebug() << "immutability"; //kDebug() << "immutability";
return; return;
@ -213,6 +213,8 @@ void ContainmentPrivate::addAppletActions(KMenu &desktopMenu, Applet *applet, QE
Applet* ContainmentPrivate::appletAt(const QPointF &point) Applet* ContainmentPrivate::appletAt(const QPointF &point)
{ {
return 0;
/*TODO: port away qgv
Applet *applet = 0; Applet *applet = 0;
QGraphicsItem *item = q->scene()->itemAt(point); QGraphicsItem *item = q->scene()->itemAt(point);
@ -239,6 +241,7 @@ Applet* ContainmentPrivate::appletAt(const QPointF &point)
item = item->parentItem(); item = item->parentItem();
} }
return applet; return applet;
*/
} }
void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventInvalidDesktops) void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventInvalidDesktops)
@ -257,9 +260,11 @@ void ContainmentPrivate::setScreen(int newScreen, int newDesktop, bool preventIn
Q_ASSERT(corona); Q_ASSERT(corona);
//if it's an offscreen widget, don't allow to claim a screen, after all it's *off*screen //if it's an offscreen widget, don't allow to claim a screen, after all it's *off*screen
//TODO: port away qgv
/* should decide in a different way if this is a dashboard containment
if (corona->offscreenWidgets().contains(q)) { if (corona->offscreenWidgets().contains(q)) {
return; return;
} }*/
int numScreens = corona->numScreens(); int numScreens = corona->numScreens();
if (newScreen < -1) { if (newScreen < -1) {
@ -360,7 +365,6 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
return; return;
} }
QPointF pos = q->mapFromScene(scenePos);
const QMimeData *mimeData = 0; const QMimeData *mimeData = 0;
if (dropEvent) { if (dropEvent) {
@ -388,7 +392,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
const QStringList appletNames = data.split('\n', QString::SkipEmptyParts); const QStringList appletNames = data.split('\n', QString::SkipEmptyParts);
foreach (const QString &appletName, appletNames) { foreach (const QString &appletName, appletNames) {
//kDebug() << "doing" << appletName; //kDebug() << "doing" << appletName;
QRectF geom(pos, QSize(0, 0)); QRectF geom(scenePos, QSize(0, 0));
q->addApplet(appletName, QVariantList(), geom); q->addApplet(appletName, QVariantList(), geom);
} }
if (dropEvent) { if (dropEvent) {
@ -414,7 +418,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
QMimeDatabase db; QMimeDatabase db;
QMimeType mime = db.mimeTypeForUrl(url); QMimeType mime = db.mimeTypeForUrl(url);
QString mimeName = mime.name(); QString mimeName = mime.name();
QRectF geom(pos, QSize()); QRectF geom(scenePos, QSize());
QVariantList args; QVariantList args;
args << url.toString(); args << url.toString();
#ifndef NDEBUG #ifndef NDEBUG
@ -516,7 +520,7 @@ void ContainmentPrivate::dropData(QPointF scenePos, QPoint screenPos, QGraphicsS
stream.writeRawData(data, data.size()); stream.writeRawData(data, data.size());
} }
QRectF geom(pos, QSize()); QRectF geom(scenePos, QSize());
QVariantList args; QVariantList args;
args << tempFile.fileName(); args << tempFile.fileName();
#ifndef NDEBUG #ifndef NDEBUG
@ -946,125 +950,11 @@ void ContainmentPrivate::appletAppeared(Applet *applet)
emit q->configNeedsSaving(); emit q->configNeedsSaving();
} }
void ContainmentPrivate::positionPanel(bool force)
{
if (!q->scene()) {
#ifndef NDEBUG
kDebug() << "no scene yet";
#endif
return;
}
// already positioning the panel - avoid infinite loops
if (ContainmentPrivate::s_positioningPanels) {
return;
}
// we position panels in negative coordinates, and stack all horizontal
// and all vertical panels with each other.
const QPointF p = q->pos();
if (!force &&
p.y() + q->size().height() < -INTER_CONTAINMENT_MARGIN &&
q->scene()->collidingItems(q).isEmpty()) {
// already positioned and not running into any other panels
return;
}
QPointF newPos = preferredPanelPos(q->corona());
if (p != newPos) {
ContainmentPrivate::s_positioningPanels = true;
q->setPos(newPos);
ContainmentPrivate::s_positioningPanels = false;
}
}
bool ContainmentPrivate::isPanelContainment() const bool ContainmentPrivate::isPanelContainment() const
{ {
return type == Containment::PanelContainment || type == Containment::CustomPanelContainment; return type == Containment::PanelContainment || type == Containment::CustomPanelContainment;
} }
QPointF ContainmentPrivate::preferredPos(Corona *corona) const
{
Q_ASSERT(corona);
if (isPanelContainment()) {
//kDebug() << "is a panel, so put it at" << preferredPanelPos(corona);
return preferredPanelPos(corona);
}
QPointF pos(0, 0);
QTransform t;
while (QGraphicsItem *i = corona->itemAt(pos, t)) {
pos.setX(i->scenePos().x() + i->boundingRect().width() + 10);
}
//kDebug() << "not a panel, put it at" << pos;
return pos;
}
QPointF ContainmentPrivate::preferredPanelPos(Corona *corona) const
{
Q_ASSERT(corona);
//TODO: research how non-Horizontal, non-Vertical (e.g. Planar) panels behave here
bool horiz = formFactor == Plasma::Horizontal;
qreal bottom = horiz ? 0 : VERTICAL_STACKING_OFFSET;
qreal lastHeight = 0;
// this should be ok for small numbers of panels, but if we ever end
// up managing hundreds of them, this simplistic alogrithm will
// likely be too slow.
foreach (const Containment *other, corona->containments()) {
if (other == q ||
!other->d->isPanelContainment() ||
horiz != (other->formFactor() == Plasma::Horizontal)) {
// only line up with panels of the same orientation
continue;
}
if (horiz) {
qreal y = other->pos().y();
if (y < bottom) {
lastHeight = other->size().height();
bottom = y;
}
} else {
qreal width = other->size().width();
qreal x = other->pos().x() + width;
if (x > bottom) {
lastHeight = width;
bottom = x + lastHeight;
}
}
}
// give a space equal to the height again of the last item so there is
// room to grow.
QPointF newPos;
if (horiz) {
bottom -= lastHeight + INTER_CONTAINMENT_MARGIN;
//TODO: fix x position for non-flush-left panels
#ifndef NDEBUG
kDebug() << "moved to" << QPointF(0, bottom - q->size().height());
#endif
newPos = QPointF(0, bottom - q->size().height());
} else {
bottom += lastHeight + INTER_CONTAINMENT_MARGIN;
//TODO: fix y position for non-flush-top panels
#ifndef NDEBUG
kDebug() << "moved to" << QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
#endif
newPos = QPointF(bottom + q->size().width(), -INTER_CONTAINMENT_MARGIN - q->size().height());
}
return newPos;
}
bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu) bool ContainmentPrivate::prepareContainmentActions(const QString &trigger, const QPoint &screenPos, KMenu *menu)
{ {
ContainmentActions *plugin = actionPlugins()->value(trigger); ContainmentActions *plugin = actionPlugins()->value(trigger);

View File

@ -97,10 +97,7 @@ public:
void initApplets(); void initApplets();
void checkContainmentFurniture(); void checkContainmentFurniture();
bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const; bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const;
void positionPanel(bool force = false);
bool isPanelContainment() const; bool isPanelContainment() const;
QPointF preferredPos(Corona *corona) const;
QPointF preferredPanelPos(Corona *corona) const;
void setLockToolText(); void setLockToolText();
void appletDeleted(Applet*); void appletDeleted(Applet*);
void appletAppeared(Applet*); void appletAppeared(Applet*);

View File

@ -86,17 +86,6 @@ QList<QAction*> AppletScript::contextualActions()
return QList<QAction*>(); return QList<QAction*>();
} }
QPainterPath AppletScript::shape() const
{
if (applet()) {
QPainterPath path;
path.addRect(applet()->boundingRect());
return path;
}
return QPainterPath();
}
void AppletScript::setHasConfigurationInterface(bool hasInterface) void AppletScript::setHasConfigurationInterface(bool hasInterface)
{ {
if (applet()) { if (applet()) {

View File

@ -110,11 +110,6 @@ public:
*/ */
virtual QList<QAction*> contextualActions(); virtual QList<QAction*> contextualActions();
/**
* Returns the shape of the widget, defaults to the bounding rect
*/
virtual QPainterPath shape() const;
/** /**
* Sets whether or not this script has a configuration interface or not * Sets whether or not this script has a configuration interface or not
* *