From 32ac2f11fbd5b8d9400d63ddabd77be236e7791e Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Sat, 8 Aug 2009 11:34:49 +0000 Subject: [PATCH] when an applet is in another applet return a constrained formfactor if the parent applet is too little popupapplet uses the parent size insted of the containment to decide the switch between full and popup, in all normal cases parent is the containment, except for the ugly applet in applet cases svn path=/trunk/KDE/kdelibs/; revision=1008775 --- applet.cpp | 14 ++++++++++++++ popupapplet.cpp | 11 ++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/applet.cpp b/applet.cpp index aee513060..06699e1c2 100644 --- a/applet.cpp +++ b/applet.cpp @@ -1289,6 +1289,20 @@ void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *o FormFactor Applet::formFactor() const { Containment *c = containment(); + QGraphicsWidget *p = dynamic_cast(parentItem()); + + + //if the applet is in a widget that isn't a containment + //try to retrieve the formFactor from the parent size + //we can't use our own sizeHint here because it needs formFactor, so endless recursion + if (p && p != c && c != this && layout()) { + if (p->size().width() < layout()->effectiveSizeHint(Qt::MinimumSize).width()) { + return Plasma::Vertical; + } else if (p->size().height() < layout()->effectiveSizeHint(Qt::MinimumSize).height()) { + return Plasma::Horizontal; + } + } + return c ? c->d->formFactor : Plasma::Planar; } diff --git a/popupapplet.cpp b/popupapplet.cpp index b935aa020..c8835a3c3 100644 --- a/popupapplet.cpp +++ b/popupapplet.cpp @@ -171,7 +171,7 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) } QSizeF minimum; - QSizeF containmentSize; + QSizeF parentSize; QGraphicsWidget *gWidget = q->graphicsWidget(); //kDebug() << "graphics widget is" << (QObject*)gWidget; @@ -189,14 +189,15 @@ void PopupAppletPrivate::popupConstraintsEvent(Plasma::Constraints constraints) minimum = qWidget->minimumSizeHint(); } - if (q->containment()) { - containmentSize = q->containment()->size(); + //99% of the times q->parentWidget() is the containment, but using it we can also manage the applet-in-applet case (i.e. systray) + if (q->parentWidget()) { + parentSize = q->parentWidget()->size(); } //Applet on desktop if (icon && !icon->icon().isNull() && ((f != Plasma::Vertical && f != Plasma::Horizontal) || - ((f == Plasma::Vertical && containmentSize.width() >= minimum.width()) || - (f == Plasma::Horizontal && containmentSize.height() >= minimum.height())))) { + ((f == Plasma::Vertical && parentSize.width() >= minimum.width()) || + (f == Plasma::Horizontal && parentSize.height() >= minimum.height())))) { //kDebug() << "we are expanding the popupapplet"; // we only switch to expanded if we aren't horiz/vert constrained and