allow applets to register that they need to be configured before use

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=696023
This commit is contained in:
Aaron J. Seigo 2007-08-03 15:23:56 +00:00
parent 0e221b59bd
commit 8fce372a7c
2 changed files with 64 additions and 7 deletions

View File

@ -49,6 +49,7 @@
#include "plasma/widgets/widget.h"
#include "plasma/widgets/lineedit.h"
#include "plasma/widgets/pushbutton.h"
#include "plasma/widgets/vboxlayout.h"
//#include "stackblur_shadows.cpp"
@ -68,12 +69,13 @@ public:
background(0),
failureText(0),
scriptEngine(0),
cachedBackground(0),
configXml(0),
kioskImmutable(false),
immutable(false),
hasConfigurationInterface(false),
failed(false),
cachedBackground(0)
needsConfig(false)
{
if (appletId == 0) {
appletId = nextId();
@ -300,12 +302,12 @@ public:
Plasma::LineEdit *failureText;
ScriptEngine* scriptEngine;
ConfigXml* configXml;
QPixmap* cachedBackground;
bool kioskImmutable : 1;
bool immutable : 1;
bool hasConfigurationInterface : 1;
bool failed : 1;
private:
QPixmap* cachedBackground;
bool needsConfig : 1;
};
uint Applet::Private::s_maxAppletId = 0;
@ -501,7 +503,7 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
delete layout();
if (failed) {
setDrawStandardBackground(failed || d->background != 0);
setDrawStandardBackground(true);
Layout* failureLayout = new VBoxLayout(this);
d->failureText = new LineEdit(this, scene());
d->failureText->setFlags(0);
@ -514,6 +516,39 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
update();
}
bool Applet::needsConfiguring() const
{
return d->needsConfig;
}
void Applet::setNeedsConfiguring(bool needsConfig)
{
if (d->needsConfig == needsConfig) {
return;
}
d->needsConfig = needsConfig;
prepareGeometryChange();
qDeleteAll(QGraphicsItem::children());
delete layout();
if (needsConfig) {
setDrawStandardBackground(true);
Layout* layout = new VBoxLayout(this);
PushButton* button = new PushButton(this);
button->setText(i18n("Configure..."));
connect(button, SIGNAL(clicked()), this, SLOT(performSetupConfig()));
layout->addItem(button);
}
}
void Applet::performSetupConfig()
{
qDeleteAll(QGraphicsItem::children());
delete layout();
showConfigurationInterface();
}
int Applet::type() const
{
return Type;
@ -581,11 +616,10 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
d->paintBackground(painter, this);
}
if (d->failed) {
return;
if (!d->failed && !d->needsConfig) {
paintInterface(painter, option, QRect(QPoint(0,0), d->contentSize(this).toSize()));
}
paintInterface(painter, option, QRect(QPoint(0,0), d->contentSize(this).toSize()));
d->paintHover(painter, this);
} else if (zoomLevel == scalingFactor(Plasma::GroupZoom)) { // Show Groups + Applet outline
//TODO: make pretty.

View File

@ -63,6 +63,7 @@ class PLASMA_EXPORT Applet : public QObject, public Widget
Q_PROPERTY( bool immutable READ isImmutable WRITE setImmutable )
Q_PROPERTY( bool drawStandardBackground READ drawStandardBackground WRITE setDrawStandardBackground )
Q_PROPERTY( bool failedToLaunch READ failedToLaunch WRITE setFailedToLaunch )
Q_PROPERTY( bool needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring )
Q_PROPERTY( QRectF boundingRect READ boundingRect )
public:
@ -401,6 +402,25 @@ class PLASMA_EXPORT Applet : public QObject, public Widget
**/
void setFailedToLaunch(bool failed, const QString& reason = QString());
/**
* @return true if the applet currently needs to be configured,
* otherwise, false
*/
bool needsConfiguring() const;
/**
* When the applet needs to be configured before being usable, this
* method can be called to show a standard interface prompting the user
* to configure the applet
*
* Not that all children items will be deleted when this method is
* called. If you have pointers to these items, you will need to
* reset them after calling this method.
*
* @param needsConfiguring true if the applet needs to be configured,
* or false if it doesn't
*/
void setNeedsConfiguring(bool needsConfiguring);
enum { Type = Plasma::AppletType };
/**
@ -493,6 +513,9 @@ class PLASMA_EXPORT Applet : public QObject, public Widget
**/
bool eventFilter( QObject *o, QEvent *e );
protected Q_SLOTS:
void performSetupConfig();
private:
Q_DISABLE_COPY(Applet)