diff --git a/applet.cpp b/applet.cpp index 178483e20..951d4f7f1 100644 --- a/applet.cpp +++ b/applet.cpp @@ -28,9 +28,10 @@ #include #include -#include "corona.h" -#include "dataenginemanager.h" -#include "plasma.h" +#include "plasma/corona.h" +#include "plasma/dataenginemanager.h" +#include "plasma/plasma.h" +#include "plasma/svg.h" namespace Plasma { @@ -43,7 +44,8 @@ class Applet::Private globalConfig( 0 ), appletConfig( 0 ), appletDescription(new KPluginInfo(appletDescription)), - immutable(false) + immutable(false), + background(0) { if (appletId > s_maxAppletId) { s_maxAppletId = appletId; @@ -56,6 +58,7 @@ class Applet::Private DataEngineManager::self()->unloadDataEngine( engine ); } delete appletDescription; + delete background; } static uint nextId() @@ -72,6 +75,7 @@ class Applet::Private QStringList loadedEngines; static uint s_maxAppletId; bool immutable; + Plasma::Svg *background; }; uint Applet::Private::s_maxAppletId = 0; @@ -166,7 +170,37 @@ void Applet::setImmutable(bool immutable) d->immutable = immutable; } +bool Applet::drawStandardBackground() +{ + return d->background != 0; +} + +void Applet::setDrawStandardBackground(bool drawBackground) +{ + if (drawBackground) { + if (!d->background) { + d->background = new Plasma::Svg("widgets/background"); + } + } else { + delete d->background; + d->background = 0; + } +} + + void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + if (d->background) { + d->background->resize(boundingRect().size()); + d->background->paint(painter, boundingRect()); + } + + paintInterface(painter, option, widget); + + //TODO: interface overlays on hover? +} + +void Applet::paintInterface(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(painter) Q_UNUSED(option) diff --git a/applet.h b/applet.h index 3097e3d64..f06e19c51 100644 --- a/applet.h +++ b/applet.h @@ -169,6 +169,14 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0, const QStringList& args = QStringList()); + /** + * This method is called when the interface should be painted. + * @see QGraphicsItem::paint + **/ + virtual void paintInterface(QPainter *painter, + const QStyleOptionGraphicsItem *option, + QWidget *widget = 0); + /** * Returns the user-visible name for the applet, as specified in the * .desktop file. @@ -189,9 +197,16 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem void setImmutable(bool immutable); /** - * Reimplemented from QGraphicsItem + * @return returns whether or not the applet is using the standard + * background **/ - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + bool drawStandardBackground(); + + /** + * Sets whether or not the applet should automatically draw the standard + * background or not. Defaults to false + **/ + void setDrawStandardBackground(bool drawBackground); /** * Reimplented from QGraphicsItem @@ -250,6 +265,11 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem bool eventFilter( QObject *o, QEvent *e ); private: + /** + * Reimplemented from QGraphicsItem + **/ + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + void init(); class Private;