don't try and position new applets within layouts ourselves, that's too Containment implementation specific. instead send the pos of the applet with the appletAdded signal and let containment subclasses figure it out themselves.

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=800835
This commit is contained in:
Aaron J. Seigo 2008-04-24 23:07:21 +00:00
parent 3bfaf57014
commit 04ad90006a
3 changed files with 8 additions and 101 deletions

View File

@ -172,7 +172,7 @@ void AppletBrowserWidget::initRunningApplets()
d->runningApplets.clear(); d->runningApplets.clear();
QList<Containment*> containments = c->containments(); QList<Containment*> containments = c->containments();
foreach (Containment * containment,containments) { foreach (Containment * containment,containments) {
connect(containment, SIGNAL(appletAdded(Plasma::Applet*)), this, SLOT(appletAdded(Plasma::Applet*))); connect(containment, SIGNAL(appletAdded(Plasma::Applet*,QPointF)), this, SLOT(appletAdded(Plasma::Applet*)));
//TODO track containments too? //TODO track containments too?
QList<Applet*>applets=containment->applets(); QList<Applet*>applets=containment->applets();
foreach (Applet *applet,applets) { foreach (Applet *applet,applets) {

View File

@ -695,23 +695,6 @@ Applet* Containment::Private::addApplet(const QString& name, const QVariantList&
applet = new Applet; applet = new Applet;
} }
q->addApplet(applet, appletGeometry.topLeft(), delayInit);
/*
if (containmentType() != PanelContainment) {
//kDebug() << "adding applet" << applet->name() << "with a default geometry of" << appletGeometry << appletGeometry.isValid();
if (appletGeometry.isValid()) {
//applet->setGeometry(appletGeometry);
} else if (appletGeometry.x() != -1 && appletGeometry.y() != -1) {
// yes, this means we can't have items start -1, -1
//applet->setGeometry(QRectF(appletGeometry.topLeft(),
// applet->sizeHint()));
} else if (q->geometry().isValid()) {
//applet->setGeometry(geometryForApplet(applet));
}
}
*/
//kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry(); //kDebug() << applet->name() << "sizehint:" << applet->sizeHint() << "geometry:" << applet->geometry();
Corona *c = q->corona(); Corona *c = q->corona();
@ -719,7 +702,7 @@ Applet* Containment::Private::addApplet(const QString& name, const QVariantList&
connect(applet, SIGNAL(configNeedsSaving()), q->corona(), SLOT(scheduleConfigSync())); connect(applet, SIGNAL(configNeedsSaving()), q->corona(), SLOT(scheduleConfigSync()));
} }
emit q->appletAdded(applet); q->addApplet(applet, appletGeometry.topLeft(), delayInit);
return applet; return applet;
} }
@ -739,17 +722,10 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
} }
Containment *currentContainment = applet->containment(); Containment *currentContainment = applet->containment();
int index = -1;
if (containmentType() == PanelContainment) { if (containmentType() == PanelContainment) {
//panels don't want backgrounds, which is important when setting geometry //panels don't want backgrounds, which is important when setting geometry
applet->setDrawStandardBackground(false); applet->setDrawStandardBackground(false);
// Calculate where the user wants the applet to go before adding it
//so long as this isn't a new applet with a delayed init
if (! delayInit || (currentContainment && currentContainment != this)) {
index = indexAt(pos);
}
} }
if (currentContainment && currentContainment != this) { if (currentContainment && currentContainment != this) {
@ -768,76 +744,12 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
d->applets << applet; d->applets << applet;
connect(applet, SIGNAL(destroyed(QObject*)), connect(applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed(QObject*)));
this, SLOT(appletDestroyed(QObject*)));
QGraphicsLayout *lay = layout(); if (pos != QPointF(-1, -1)) {
applet->setPos(pos);
// Reposition the applet after adding has been done
//FIXME adding position incorrect
if (index != -1) {
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (l) {
l->insertItem(index, applet);
d->applets.removeAll(applet);
d->applets.insert(index, applet);
} else {
index = -1;
}
} }
if (index == -1) {
if (pos != QPointF(-1, -1)) {
applet->setPos(pos);
}
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(lay);
if (l) {
l->addItem(applet);
}
//l->addStretch();
}
prepareApplet(applet, delayInit); //must at least flush constraints
}
//containment-relative pos... right?
int Containment::indexAt(const QPointF &pos) const
{
/* if (pos == QPointF(-1, -1)) {
return -1;
}
QGraphicsLinearLayout *l = dynamic_cast<QGraphicsLinearLayout *>(layout());
if (l) {
foreach (Applet *existingApplet, d->applets) {
if (formFactor() == Horizontal) {
qreal middle = (existingApplet->geometry().left() +
existingApplet->geometry().right()) / 2.0;
// Applets are checked in order so there is no need to check
// if the position is equal to or greater than the applet's
// leftmost point. This also allows for dropping in the gap
// between applets.
if (pos.x() < middle) {
return l->indexOf(existingApplet);
} else if (pos.x() <= existingApplet->geometry().right()) {
return l->indexOf(existingApplet) + 1;
}
} else {
qreal middle = (existingApplet->geometry().top() +
existingApplet->geometry().bottom()) / 2.0;
if (pos.y() < middle) {
return l->indexOf(existingApplet);
} else if (pos.y() <= existingApplet->geometry().bottom()) {
return l->indexOf(existingApplet) + 1;
}
}
}
}*/
return -1;
}
void Containment::prepareApplet(Applet *applet, bool delayInit)
{
if (delayInit) { if (delayInit) {
if (containmentType() == DesktopContainment) { if (containmentType() == DesktopContainment) {
applet->installSceneEventFilter(this); applet->installSceneEventFilter(this);
@ -852,6 +764,8 @@ void Containment::prepareApplet(Applet *applet, bool delayInit)
applet->flushUpdatedConstraints(); applet->flushUpdatedConstraints();
emit configNeedsSaving(); emit configNeedsSaving();
} }
emit appletAdded(applet, pos);
} }
bool Containment::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const bool Containment::regionIsEmpty(const QRectF &region, Applet *ignoredApplet) const

View File

@ -204,12 +204,6 @@ class PLASMA_EXPORT Containment : public Applet
*/ */
void clearApplets(); void clearApplets();
/**
* @return the index to insert an applet at if you want it near the point pos.
* @param pos the containment-relative position
*/
virtual int indexAt(const QPointF &pos) const;
/** /**
* Sets the physical screen this Containment is associated with. * Sets the physical screen this Containment is associated with.
* *
@ -291,7 +285,7 @@ class PLASMA_EXPORT Containment : public Applet
/** /**
* 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
*/ */
void appletAdded(Plasma::Applet* applet); void appletAdded(Plasma::Applet* applet, const QPointF &pos);
/** /**
* This signal is emitted when an applet is destroyed * This signal is emitted when an applet is destroyed
@ -417,7 +411,6 @@ class PLASMA_EXPORT Containment : public Applet
private: private:
bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const; bool regionIsEmpty(const QRectF &region, Applet *ignoredApplet=0) const;
void prepareApplet(Applet *applet, bool delayInit);
void positionPanel(bool force = false); void positionPanel(bool force = false);
void positionContainment(); void positionContainment();