api changes:

init() and setFailedToLaunch are now protected
containment and corona are friends of applet

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=798585
This commit is contained in:
Marco Martin 2008-04-18 16:05:20 +00:00
parent 463a6beff7
commit 1e77632048
3 changed files with 87 additions and 81 deletions

View File

@ -298,6 +298,19 @@ public:
} }
} }
QString visibleFailureText(const QString& reason)
{
QString text;
if (reason.isEmpty()) {
text = i18n("This object could not be created.");
} else {
text = i18n("This object could not be created for the following reason:<p><b>%1</b></p>", reason);
}
return text;
}
//TODO: examine the usage of memory here; there's a pretty large //TODO: examine the usage of memory here; there's a pretty large
// number of members at this point. // number of members at this point.
static uint s_maxAppletId; static uint s_maxAppletId;
@ -439,6 +452,49 @@ void Applet::restore(KConfigGroup *c)
} }
} }
void Applet::setFailedToLaunch(bool failed, const QString& reason)
{
if (d->failed == failed) {
return;
}
d->failed = failed;
prepareGeometryChange();
qDeleteAll(QGraphicsItem::children());
setLayout(0);
if (failed) {
setDrawStandardBackground(true);
#ifdef TOPORT
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
d->failureText = new LineEdit(this);
d->failureText->setTextInteractionFlags( Qt::TextSelectableByMouse );
d->failureText->setStyled(false);
d->failureText->document()->setTextWidth(200);
d->failureText->setHtml(visibleFailureText(reason));
//FIXME: this needs to get the colour from the theme's colour scheme
d->failureText->setDefaultTextColor(KStatefulBrush(KColorScheme::Window,
KColorScheme::NormalText,
Theme::self()->colors())
.brush(QPalette::Normal).color());
failureLayout->addItem(d->failureText);
#endif
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout();
failureLayout->setContentsMargins(0, 0, 0, 0);
QGraphicsProxyWidget * failureWidget = new QGraphicsProxyWidget(this);
QLabel * label = new QLabel(d->visibleFailureText(reason));
label->setWordWrap(true);
failureWidget->setWidget(label);
failureLayout->addItem(failureWidget);
setLayout(failureLayout);
}
update();
}
void Applet::saveState(KConfigGroup* group) const void Applet::saveState(KConfigGroup* group) const
{ {
if (group->config()->name() != config().config()->name()) { if (group->config()->name() != config().config()->name()) {
@ -757,19 +813,6 @@ bool Applet::hasFailedToLaunch() const
return d->failed; return d->failed;
} }
QString visibleFailureText(const QString& reason)
{
QString text;
if (reason.isEmpty()) {
text = i18n("This object could not be created.");
} else {
text = i18n("This object could not be created for the following reason:<p><b>%1</b></p>", reason);
}
return text;
}
void Applet::paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) void Applet::paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{ {
//Here come the code for the window frame //Here come the code for the window frame
@ -777,49 +820,6 @@ void Applet::paintWindowFrame ( QPainter * painter, const QStyleOptionGraphicsIt
//painter->drawRoundedRect(windowFrameGeometry(),5,5); //painter->drawRoundedRect(windowFrameGeometry(),5,5);
} }
void Applet::setFailedToLaunch(bool failed, const QString& reason)
{
if (d->failed == failed) {
return;
}
d->failed = failed;
prepareGeometryChange();
qDeleteAll(QGraphicsItem::children());
setLayout(0);
if (failed) {
setDrawStandardBackground(true);
#ifdef TOPORT
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
d->failureText = new LineEdit(this);
d->failureText->setTextInteractionFlags( Qt::TextSelectableByMouse );
d->failureText->setStyled(false);
d->failureText->document()->setTextWidth(200);
d->failureText->setHtml(visibleFailureText(reason));
//FIXME: this needs to get the colour from the theme's colour scheme
d->failureText->setDefaultTextColor(KStatefulBrush(KColorScheme::Window,
KColorScheme::NormalText,
Theme::self()->colors())
.brush(QPalette::Normal).color());
failureLayout->addItem(d->failureText);
#endif
QGraphicsLinearLayout *failureLayout = new QGraphicsLinearLayout();
failureLayout->setContentsMargins(0, 0, 0, 0);
QGraphicsProxyWidget * failureWidget = new QGraphicsProxyWidget(this);
QLabel * label = new QLabel(visibleFailureText(reason));
label->setWordWrap(true);
failureWidget->setWidget(label);
failureLayout->addItem(failureWidget);
setLayout(failureLayout);
}
update();
}
bool Applet::needsConfiguring() const bool Applet::needsConfiguring() const
{ {
return d->needsConfigOverlay != 0; return d->needsConfigOverlay != 0;

View File

@ -107,14 +107,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
static PackageStructure::Ptr packageStructure(); static PackageStructure::Ptr packageStructure();
/**
* This method is called once the applet is loaded and added to a Corona.
* If the applet requires a QGraphicsScene or has an particularly intensive
* set of initialization routines to go through, consider implementing it
* in this method instead of the constructor.
**/
virtual void init();
/** /**
* @return the id of this applet * @return the id of this applet
*/ */
@ -451,20 +443,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
**/ **/
bool hasFailedToLaunch() const; bool hasFailedToLaunch() const;
/**
* Call this method when the applet fails to launch properly. An
* optional reason can be provided.
*
* 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 failed true when the applet failed, false when it succeeded
* @param reason an optional reason to show the user why the applet
* failed to launch
**/
void setFailedToLaunch(bool failed, const QString& reason = QString());
/** /**
* @return true if the applet currently needs to be configured, * @return true if the applet currently needs to be configured,
* otherwise, false * otherwise, false
@ -637,6 +615,28 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
void themeChanged(); void themeChanged();
protected: protected:
/**
* This method is called once the applet is loaded and added to a Corona.
* If the applet requires a QGraphicsScene or has an particularly intensive
* set of initialization routines to go through, consider implementing it
* in this method instead of the constructor.
**/
virtual void init();
/**
* Call this method when the applet fails to launch properly. An
* optional reason can be provided.
*
* 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 failed true when the applet failed, false when it succeeded
* @param reason an optional reason to show the user why the applet
* failed to launch
**/
void setFailedToLaunch(bool failed, const QString& reason = QString());
/** /**
* Called when a request to save the state of the applet is made * Called when a request to save the state of the applet is made
* during runtime * during runtime
@ -753,6 +753,10 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
class Private; class Private;
Private* const d; Private* const d;
//Corona needs to access setFailedToLaunch and init
friend class Corona;
friend class Containment;
}; };
} // Plasma namespace } // Plasma namespace

View File

@ -316,9 +316,11 @@ void Containment::setContainmentType(Containment::Type type)
} }
} else if (isContainment() && type == PanelContainment) { } else if (isContainment() && type == PanelContainment) {
if (!d->toolbox) {
d->createToolbox(); d->createToolbox();
d->toolbox->setSize(24); d->toolbox->setSize(22);
d->toolbox->setIconSize(QSize(16, 16)); d->toolbox->setIconSize(QSize(16, 16));
}
} else { } else {
delete d->toolbox; delete d->toolbox;
d->toolbox = 0; d->toolbox = 0;