diff --git a/containment.cpp b/containment.cpp index 9d8d4472e..0918b37ce 100644 --- a/containment.cpp +++ b/containment.cpp @@ -412,7 +412,7 @@ Applet* Containment::addApplet(const QString& name, const QVariantList& args, ui int index = -1; QPointF position = appletGeometry.topLeft(); BoxLayout *l = dynamic_cast(layout()); - if (l && position != QPointF(-1, -1)) { + if (!delayInit && l && position != QPointF(-1, -1)) { foreach (Applet *existingApplet, d->applets) { if (formFactor() == Horizontal) { qreal middle = (existingApplet->geometry().left() + diff --git a/corona.cpp b/corona.cpp index c471735d7..901b50e52 100644 --- a/corona.cpp +++ b/corona.cpp @@ -174,6 +174,16 @@ void Corona::scheduleConfigSync() const } } +bool appletConfigLessThan(const KConfigGroup &c1, const KConfigGroup &c2) +{ + QPointF p1 = c1.readEntry("geometry", QRectF()).topLeft(); + QPointF p2 = c2.readEntry("geometry", QRectF()).topLeft(); + if (p1.x() != p2.x()) { + return p1.x() < p2.x(); + } + return p1.y() < p2.y(); +} + void Corona::loadApplets(const QString& configName) { clearApplets(); @@ -205,10 +215,18 @@ void Corona::loadApplets(const QString& configName) //kDebug() << "Containment" << c->id() << "geometry is" << c->geometry().toRect() << "config'd with" << appletConfig.name(); KConfigGroup applets(&containmentConfig, "Applets"); + // Sort the applet configs in order of geometry to ensure that applets + // are added from left to right or top to bottom for a panel containment + QList appletConfigs; foreach (const QString &appletGroup, applets.groupList()) { //kDebug() << "reading from applet group" << appletGroup; - int appId = appletGroup.toUInt(); KConfigGroup appletConfig(&applets, appletGroup); + appletConfigs.append(appletConfig); + } + qSort(appletConfigs.begin(), appletConfigs.end(), appletConfigLessThan); + + foreach (KConfigGroup appletConfig, appletConfigs) { + int appId = appletConfig.name().toUInt(); //kDebug() << "the name is" << appletConfig.name(); QString plugin = appletConfig.readEntry("plugin", QString());