time to break everyone's plasmoids.

- add setDrawStandardBackground(bool) to get our common background
- make paint private and introduce paintInterface (with the same params) instead

this should make standardizing looks a bit easier and give us a way to paint the on-hover applet interface. we may need to do the same with boundingRect?

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=679036
This commit is contained in:
Aaron J. Seigo 2007-06-22 20:28:42 +00:00
parent 7d369275a7
commit fbbab1b9b6
2 changed files with 60 additions and 6 deletions

View File

@ -28,9 +28,10 @@
#include <KService> #include <KService>
#include <KServiceTypeTrader> #include <KServiceTypeTrader>
#include "corona.h" #include "plasma/corona.h"
#include "dataenginemanager.h" #include "plasma/dataenginemanager.h"
#include "plasma.h" #include "plasma/plasma.h"
#include "plasma/svg.h"
namespace Plasma namespace Plasma
{ {
@ -43,7 +44,8 @@ class Applet::Private
globalConfig( 0 ), globalConfig( 0 ),
appletConfig( 0 ), appletConfig( 0 ),
appletDescription(new KPluginInfo(appletDescription)), appletDescription(new KPluginInfo(appletDescription)),
immutable(false) immutable(false),
background(0)
{ {
if (appletId > s_maxAppletId) { if (appletId > s_maxAppletId) {
s_maxAppletId = appletId; s_maxAppletId = appletId;
@ -56,6 +58,7 @@ class Applet::Private
DataEngineManager::self()->unloadDataEngine( engine ); DataEngineManager::self()->unloadDataEngine( engine );
} }
delete appletDescription; delete appletDescription;
delete background;
} }
static uint nextId() static uint nextId()
@ -72,6 +75,7 @@ class Applet::Private
QStringList loadedEngines; QStringList loadedEngines;
static uint s_maxAppletId; static uint s_maxAppletId;
bool immutable; bool immutable;
Plasma::Svg *background;
}; };
uint Applet::Private::s_maxAppletId = 0; uint Applet::Private::s_maxAppletId = 0;
@ -166,7 +170,37 @@ void Applet::setImmutable(bool immutable)
d->immutable = 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) 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(painter)
Q_UNUSED(option) Q_UNUSED(option)

View File

@ -169,6 +169,14 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0, static Applet* loadApplet(const KPluginInfo* info, uint appletId = 0,
const QStringList& args = QStringList()); 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 * Returns the user-visible name for the applet, as specified in the
* .desktop file. * .desktop file.
@ -189,9 +197,16 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
void setImmutable(bool immutable); 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 * Reimplented from QGraphicsItem
@ -250,6 +265,11 @@ class PLASMA_EXPORT Applet : public QObject, public QGraphicsItem
bool eventFilter( QObject *o, QEvent *e ); bool eventFilter( QObject *o, QEvent *e );
private: private:
/**
* Reimplemented from QGraphicsItem
**/
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void init(); void init();
class Private; class Private;