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
This commit is contained in:
Marco Martin 2009-08-08 11:34:49 +00:00
parent 3421342f5e
commit 32ac2f11fb
2 changed files with 20 additions and 5 deletions

View File

@ -1289,6 +1289,20 @@ void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *o
FormFactor Applet::formFactor() const
{
Containment *c = containment();
QGraphicsWidget *p = dynamic_cast<QGraphicsWidget *>(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;
}

View File

@ -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