On Tuesday 09 September 2008, Aaron J. Seigo wrote:
> have popupapplet support a null icon being passed into setIcon, which will
> cause it to kill it's own icon. at that point, you are quite free to
> reimplement paintInterface or instantiate your widget.

something like the completely untested patch that is attached =)

-- 
Aaron J. Seigo
humru othro a kohnu se
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA  EE75 D6B7 2EB1 A7F1 DB43

KDE core developer sponsored by Trolltech

Index: popupapplet.cpp
===================================================================
--- popupapplet.cpp	(revision 859133)
+++ popupapplet.cpp	(working copy)
@@ -81,6 +81,7 @@
 {
     int iconSize = IconSize(KIconLoader::Desktop);
     resize(iconSize, iconSize);
+    setIcon(KIcon("icons"));
 }
 
 PopupApplet::~PopupApplet()
@@ -90,8 +91,27 @@
 
 void PopupApplet::setIcon(const QIcon &icon)
 {
+    if (icon.isNull()) {
+        if (d->icon) {
+            delete d->icon;
+            d->icon = 0;
+            delete d->layout;
+            d->layout = 0;
+        }
+
+        return;
+    }
+
     if (!d->icon) {
         d->icon = new Plasma::Icon(icon, QString(), this);
+        connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup()));
+
+        d->layout = new QGraphicsLinearLayout(this);
+        d->layout->setContentsMargins(0, 0, 0, 0);
+        d->layout->setSpacing(0);
+        d->layout->setOrientation(Qt::Horizontal);
+        setAspectRatioMode(Plasma::ConstrainedSquare);
+        setLayout(d->layout);
     } else {
         d->icon->setIcon(icon);
     }
@@ -99,16 +119,12 @@
 
 void PopupApplet::setIcon(const QString &iconName)
 {
-    if (!d->icon) {
-        d->icon = new Plasma::Icon(KIcon(iconName), QString(), this);
-    } else {
-        d->icon->setIcon(iconName);
-    }
+    setIcon(KIcon(iconName));
 }
 
 QIcon PopupApplet::icon() const
 {
-    return d->icon->icon();
+    return d->icon ? d->icon->icon() : QIcon();
 }
 
 QWidget *PopupApplet::widget()
@@ -123,37 +139,18 @@
 
 void PopupApplet::constraintsEvent(Plasma::Constraints constraints)
 {
-    if (constraints & Plasma::StartupCompletedConstraint) {
-        if (!d->icon) {
-            d->icon = new Plasma::Icon(KIcon("icons"), QString(), this);
+    if (constraints & Plasma::FormFactorConstraint) {
+        if (d->layout) {
+            d->layout->removeAt(0);
         }
 
-        d->layout = new QGraphicsLinearLayout(this);
-        d->layout->setContentsMargins(0, 0, 0, 0);
-        d->layout->setSpacing(0);
-        d->layout->setOrientation(Qt::Horizontal);
-        setAspectRatioMode(Plasma::ConstrainedSquare);
-        setLayout(d->layout);
+        if ((formFactor() != Plasma::Vertical && formFactor() != Plasma::Horizontal) &&
+             d->icon) {
+            // we only switch to expanded if we aren't horiz/vert constrained and
+            // this applet has an icon.
+            // otherwise, we leave it up to the applet itself to figure it out
+            d->icon->hide();
 
-        connect(d->icon, SIGNAL(clicked()), this, SLOT(togglePopup()));
-    }
-
-    //since we call this function when an extender's geometry gets updated, we want to avoid doing
-    //anything if the StartupCompletedConstraint hasn't been called yet.
-    if (!d->layout) {
-        return;
-    }
-
-    if (constraints & Plasma::FormFactorConstraint) {
-        d->layout->removeAt(0);
-
-        switch (formFactor()) {
-        case Plasma::Planar:
-        case Plasma::MediaCenter: {
-            if (d->icon) {
-                d->icon->hide();
-            }
-
             if (d->savedAspectRatio != Plasma::InvalidAspectRatioMode) {
                 setAspectRatioMode(d->savedAspectRatio);
             }
@@ -186,11 +183,7 @@
                 d->layout->addItem(d->proxy);
                 setMinimumSize(widget() ? widget()->minimumSize() + marginSize : QSizeF(300, 200));
             }
-
-            break;
-        }
-        case Plasma::Horizontal:
-        case Plasma::Vertical:
+        } else {
             //save the aspect ratio mode in case we drag'n drop in the Desktop later
             d->savedAspectRatio = aspectRatioMode();
             setAspectRatioMode(Plasma::ConstrainedSquare);
@@ -206,7 +199,8 @@
             }
 
             if (!d->dialog) {
-                d->dialog = new Plasma::Dialog();
+                kDebug() << "making dialog with view" << view();
+                d->dialog = new Plasma::Dialog(view());
 
                 //no longer use Qt::Popup since that seems to cause a lot of problem when you drag
                 //stuff out of your Dialog (extenders). Monitor WindowDeactivate events so we can
@@ -239,8 +233,6 @@
 
             d->dialog->adjustSize();
             d->layout->addItem(d->icon);
-
-            break;
         }
     }
 }

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Plasma-devel mailing list
Plasma-devel@kde.org
https://mail.kde.org/mailman/listinfo/plasma-devel

Reply via email to