diff --git a/extender.cpp b/extender.cpp index ecbde94b9..75ed055bd 100644 --- a/extender.cpp +++ b/extender.cpp @@ -22,14 +22,17 @@ #include #include #include +#include #include "applet.h" #include "containment.h" #include "corona.h" #include "extenderitem.h" #include "framesvg.h" +#include "paintutils.h" #include "popupapplet.h" #include "svg.h" +#include "theme.h" #include "widgets/label.h" #include "private/applet_p.h" @@ -39,6 +42,34 @@ namespace Plasma { +//TODO: copied from panel containment. We'll probably want a spacer widget in libplasma for 4.3. +class Spacer : public QGraphicsWidget +{ + public: + Spacer(QGraphicsWidget *parent) + : QGraphicsWidget(parent) + { + } + + ~Spacer() + { + } + + protected: + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0) + { + Q_UNUSED(option) + Q_UNUSED(widget) + + painter->setRenderHint(QPainter::Antialiasing); + QPainterPath p = Plasma::PaintUtils::roundedRectangle(contentsRect().adjusted(4, 4, -4, -4), 4); + + QColor c = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor); + c.setAlphaF(0.3); + painter->fillPath(p, c); + } +}; + Extender::Extender(Applet *applet) : QGraphicsWidget(applet), d(new ExtenderPrivate(applet, this)) @@ -61,7 +92,6 @@ Extender::Extender(Applet *applet) setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); - d->loadExtenderItems(); } @@ -172,6 +202,14 @@ void Extender::resizeEvent(QGraphicsSceneResizeEvent *event) emit geometryChanged(); } +void Extender::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + PopupApplet *popupApplet = qobject_cast(d->applet); + if (attachedItems().isEmpty() && popupApplet) { + popupApplet->hidePopup(); + } +} + void Extender::itemAddedEvent(ExtenderItem *item, const QPointF &pos) { //this is a sane size policy imo. @@ -229,7 +267,7 @@ void Extender::itemHoverMoveEvent(ExtenderItem *item, const QPointF &pos) //Create a widget that functions as spacer, and add that to the layout. if (!d->spacerWidget) { - QGraphicsWidget *widget = new QGraphicsWidget(this); + Spacer *widget = new Spacer(this); widget->setMinimumSize(item->minimumSize()); widget->setPreferredSize(item->preferredSize()); widget->setMaximumSize(item->maximumSize()); diff --git a/extender.h b/extender.h index e2d12cd34..ad084957e 100644 --- a/extender.h +++ b/extender.h @@ -216,6 +216,11 @@ class PLASMA_EXPORT Extender : public QGraphicsWidget */ void resizeEvent(QGraphicsSceneResizeEvent *event); + /** + * Reimplemented from QGraphicsWidget + */ + void mousePressEvent(QGraphicsSceneMouseEvent *event); + Q_SIGNALS: /** * Fires when an extender item is added to this extender. diff --git a/private/extender_p.h b/private/extender_p.h index 7010f5d2e..af81b14a8 100644 --- a/private/extender_p.h +++ b/private/extender_p.h @@ -36,6 +36,7 @@ class Applet; class Extender; class ExtenderItem; class Label; +class Spacer; class Svg; class ExtenderPrivate @@ -59,7 +60,7 @@ class ExtenderPrivate FrameSvg *background; int currentSpacerIndex; - QGraphicsWidget *spacerWidget; + Spacer *spacerWidget; QString emptyExtenderMessage; Label *emptyExtenderLabel; diff --git a/widgets/meter.cpp b/widgets/meter.cpp index cb7c3acf1..ffcc5573a 100644 --- a/widgets/meter.cpp +++ b/widgets/meter.cpp @@ -191,10 +191,10 @@ public: { switch (meterType) { case Meter::BarMeterHorizontal: - meter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); + meter->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); break; case Meter::BarMeterVertical: - meter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + meter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); break; case Meter::AnalogMeter: default: