From 7890d0c816f7b22488ae9c80ad483871bdc7e79d Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Mon, 24 Aug 2009 17:27:24 +0000 Subject: [PATCH] * unify the code that positions the message overlay * always use contentsRect(), never geometry or boundingRect; this prevents how it sometimes overlaps the borders of applets * always make sure that the zOrder is set, not just in the non-popup case svn path=/trunk/KDE/kdelibs/; revision=1015154 --- applet.cpp | 78 ++++++++++++++++++++++++---------------------- popupapplet.h | 1 + private/applet_p.h | 1 + 3 files changed, 43 insertions(+), 37 deletions(-) diff --git a/applet.cpp b/applet.cpp index bdb37c7f4..951b2a0db 100644 --- a/applet.cpp +++ b/applet.cpp @@ -507,38 +507,57 @@ void AppletPrivate::createMessageOverlay(bool usePopup) PopupApplet *popup = qobject_cast(q); if (!messageOverlay) { - if (usePopup && popup && popup->widget()) { - messageOverlayProxy = new QGraphicsProxyWidget(q); - messageOverlayProxy->setWidget(popup->widget()); - messageOverlay = new AppletOverlayWidget(messageOverlayProxy); - } else if (usePopup && popup && popup->graphicsWidget() && - popup->graphicsWidget() != extender) { - messageOverlay = new AppletOverlayWidget(popup->graphicsWidget()); - } else { + if (usePopup && popup) { + if (popup->widget()) { + messageOverlayProxy = new QGraphicsProxyWidget(q); + messageOverlayProxy->setWidget(popup->widget()); + messageOverlay = new AppletOverlayWidget(messageOverlayProxy); + } else if (popup->graphicsWidget() && + popup->graphicsWidget() != extender) { + messageOverlay = new AppletOverlayWidget(popup->graphicsWidget()); + } + } + + if (!messageOverlay) { messageOverlay = new AppletOverlayWidget(q); } } - if (usePopup && popup && popup->widget()) { + positionMessageOverlay(); +} + +void AppletPrivate::positionMessageOverlay() +{ + if (!messageOverlay) { + return; + } + + PopupApplet *popup = qobject_cast(q); + const bool usePopup = popup && messageOverlay->parentItem() == q; + QGraphicsItem *topItem = q; + + if (usePopup && popup->widget()) { // popupapplet with widget() + topItem = popup->d->proxy; messageOverlay->setGeometry(popup->widget()->contentsRect()); - } else if (usePopup && popup && popup->graphicsWidget() && - popup->graphicsWidget() != extender) { + } else if (usePopup && popup->graphicsWidget() && popup->graphicsWidget() != extender) { // popupapplet with graphicsWidget() - messageOverlay->setGeometry(popup->graphicsWidget()->boundingRect()); + topItem = popup->graphicsWidget(); + QGraphicsWidget *w = dynamic_cast(topItem); + messageOverlay->setGeometry(w ? w->contentsRect() : topItem->boundingRect()); } else { // normal applet messageOverlay->setGeometry(q->contentsRect()); - - // raise the overlay above all the other children! - int zValue = 100; - foreach (QGraphicsItem *child, q->QGraphicsItem::children()) { - if (child->zValue() > zValue) { - zValue = child->zValue() + 1; - } - } - messageOverlay->setZValue(zValue); } + + // raise the overlay above all the other children! + int zValue = 100; + foreach (QGraphicsItem *child, topItem->children()) { + if (child->zValue() > zValue) { + zValue = child->zValue() + 1; + } + } + messageOverlay->setZValue(zValue); } void AppletPrivate::destroyMessageOverlay() @@ -1101,22 +1120,7 @@ void Applet::flushPendingConstraintsEvents() } if (c & Plasma::SizeConstraint) { - if (d->messageOverlay) { - d->messageOverlay->setGeometry(QRectF(QPointF(0, 0), geometry().size())); -/* - QGraphicsItem *button = 0; - QList children = d->messageOverlay->QGraphicsItem::children(); - - if (!children.isEmpty()) { - button = children.first(); - } - - if (button) { - QSizeF s = button->boundingRect().size(); - button->setPos(d->messageOverlay->boundingRect().width() / 2 - s.width() / 2, - d->messageOverlay->boundingRect().height() / 2 - s.height() / 2); - }*/ - } + d->positionMessageOverlay(); if (d->started && layout()) { layout()->updateGeometry(); diff --git a/popupapplet.h b/popupapplet.h index 3d6afdbbc..656b87325 100644 --- a/popupapplet.h +++ b/popupapplet.h @@ -160,6 +160,7 @@ private: Q_PRIVATE_SLOT(d, void updateDialogPosition()) friend class Applet; + friend class AppletPrivate; friend class PopupAppletPrivate; PopupAppletPrivate * const d; }; diff --git a/private/applet_p.h b/private/applet_p.h index 3b23190d0..cd96925fb 100644 --- a/private/applet_p.h +++ b/private/applet_p.h @@ -88,6 +88,7 @@ public: void setFocus(); void cleanUpAndDelete(); void createMessageOverlay(bool usePopup = true); + void positionMessageOverlay(); void destroyMessageOverlay(); void addGlobalShortcutsPage(KConfigDialog *dialog); void clearShortcutEditorPtr();