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
This commit is contained in:
Jason Stubbs 2008-01-03 08:44:14 +00:00
parent b1714c2248
commit 092b7ff835
2 changed files with 20 additions and 2 deletions

View File

@ -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<BoxLayout *>(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() +

View File

@ -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<KConfigGroup> 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());