From 092b7ff835292e6036babc7b1d24077c873d0e68 Mon Sep 17 00:00:00 2001 From: Jason Stubbs Date: Thu, 3 Jan 2008 08:44:14 +0000 Subject: [PATCH] Ensure that applets are added to the panel in left to right (or top to bottom) order as BoxLayout is not really capable of anything else. On the containment side, ignore the specified geometry when delaying init as the placement calculations can lead to slight mispositioning of applets even when received in the correct order. svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=756435 --- containment.cpp | 2 +- corona.cpp | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) 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());