a bit of a clean up on the overlay stuff; makes it easy to add overlay messages in the future (planned for 4.3)
svn path=/trunk/KDE/kdelibs/; revision=880833
This commit is contained in:
parent
66dde0f898
commit
aca23afb4a
82
applet.cpp
82
applet.cpp
@ -40,6 +40,7 @@
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
#include <QTextDocument>
|
||||
#include <QUiLoader>
|
||||
#include <QWidget>
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kicon.h>
|
||||
@ -433,6 +434,38 @@ void AppletPrivate::cleanUpAndDelete()
|
||||
q->deleteLater();
|
||||
}
|
||||
|
||||
void AppletPrivate::createMessageOverlay()
|
||||
{
|
||||
if (!messageOverlay) {
|
||||
messageOverlay = new AppletOverlayWidget(q);
|
||||
} else {
|
||||
qDeleteAll(messageOverlay->children());
|
||||
messageOverlay->setLayout(0);
|
||||
}
|
||||
|
||||
messageOverlay->resize(q->contentsRect().size());
|
||||
messageOverlay->setPos(q->contentsRect().topLeft());
|
||||
|
||||
// raise the overlay above all the other children!
|
||||
int zValue = 100;
|
||||
foreach (QGraphicsItem *child, q->QGraphicsItem::children()) {
|
||||
if (child->zValue() > zValue) {
|
||||
zValue = child->zValue() + 1;
|
||||
}
|
||||
}
|
||||
messageOverlay->setZValue(zValue);
|
||||
|
||||
}
|
||||
|
||||
void AppletPrivate::destroyMessageOverlay()
|
||||
{
|
||||
//TODO: fade out? =)
|
||||
QGraphicsWidget *w = messageOverlay;
|
||||
messageOverlay = 0;
|
||||
w->hide();
|
||||
w->deleteLater();
|
||||
}
|
||||
|
||||
ConfigLoader *Applet::configScheme() const
|
||||
{
|
||||
return d->configLoader;
|
||||
@ -731,37 +764,25 @@ void Applet::paintWindowFrame(QPainter *painter,
|
||||
|
||||
bool Applet::configurationRequired() const
|
||||
{
|
||||
return d->needsConfigOverlay != 0;
|
||||
return d->needsConfig;
|
||||
}
|
||||
|
||||
void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
||||
{
|
||||
if ((d->needsConfigOverlay != 0) == needsConfig) {
|
||||
if (d->needsConfig == needsConfig) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (d->needsConfigOverlay) {
|
||||
QGraphicsWidget *w = d->needsConfigOverlay;
|
||||
d->needsConfigOverlay = 0;
|
||||
w->hide();
|
||||
w->deleteLater();
|
||||
d->needsConfig = needsConfig;
|
||||
|
||||
if (!needsConfig) {
|
||||
d->destroyMessageOverlay();
|
||||
return;
|
||||
}
|
||||
|
||||
d->needsConfigOverlay = new AppletOverlayWidget(this);
|
||||
d->needsConfigOverlay->resize(contentsRect().size());
|
||||
d->needsConfigOverlay->setPos(contentsRect().topLeft());
|
||||
d->createMessageOverlay();
|
||||
|
||||
int zValue = 100;
|
||||
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
||||
if (child->zValue() > zValue) {
|
||||
zValue = child->zValue() + 1;
|
||||
}
|
||||
}
|
||||
d->needsConfigOverlay->setZValue(zValue);
|
||||
|
||||
qDeleteAll(d->needsConfigOverlay->QGraphicsItem::children());
|
||||
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(d->needsConfigOverlay);
|
||||
QGraphicsGridLayout *configLayout = new QGraphicsGridLayout(d->messageOverlay);
|
||||
configLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// configLayout->addStretch();
|
||||
@ -772,7 +793,7 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
||||
|
||||
int row = 1;
|
||||
if (!reason.isEmpty()) {
|
||||
Label *explanation = new Label(d->needsConfigOverlay);
|
||||
Label *explanation = new Label(d->messageOverlay);
|
||||
explanation->setText(reason);
|
||||
configLayout->addItem(explanation, row, 1);
|
||||
configLayout->setColumnStretchFactor(1, 10);
|
||||
@ -780,14 +801,14 @@ void Applet::setConfigurationRequired(bool needsConfig, const QString &reason)
|
||||
//configLayout->setAlignment(explanation, Qt::AlignBottom | Qt::AlignCenter);
|
||||
}
|
||||
|
||||
PushButton *configWidget = new PushButton(d->needsConfigOverlay);
|
||||
PushButton *configWidget = new PushButton(d->messageOverlay);
|
||||
configWidget->setText(i18n("Configure..."));
|
||||
connect(configWidget, SIGNAL(clicked()), this, SLOT(showConfigurationInterface()));
|
||||
configLayout->addItem(configWidget, row, 1);
|
||||
//configLayout->setAlignment(configWidget, Qt::AlignTop | Qt::AlignCenter);
|
||||
//configLayout->addStretch();
|
||||
|
||||
d->needsConfigOverlay->show();
|
||||
d->messageOverlay->show();
|
||||
}
|
||||
|
||||
void Applet::flushPendingConstraintsEvents()
|
||||
@ -842,11 +863,11 @@ void Applet::flushPendingConstraintsEvents()
|
||||
}
|
||||
}
|
||||
|
||||
if (c & Plasma::SizeConstraint && d->needsConfigOverlay) {
|
||||
d->needsConfigOverlay->setGeometry(QRectF(QPointF(0, 0), geometry().size()));
|
||||
if (c & Plasma::SizeConstraint && d->messageOverlay) {
|
||||
d->messageOverlay->setGeometry(QRectF(QPointF(0, 0), geometry().size()));
|
||||
|
||||
QGraphicsItem *button = 0;
|
||||
QList<QGraphicsItem*> children = d->needsConfigOverlay->QGraphicsItem::children();
|
||||
QList<QGraphicsItem*> children = d->messageOverlay->QGraphicsItem::children();
|
||||
|
||||
if (!children.isEmpty()) {
|
||||
button = children.first();
|
||||
@ -854,8 +875,8 @@ void Applet::flushPendingConstraintsEvents()
|
||||
|
||||
if (button) {
|
||||
QSizeF s = button->boundingRect().size();
|
||||
button->setPos(d->needsConfigOverlay->boundingRect().width() / 2 - s.width() / 2,
|
||||
d->needsConfigOverlay->boundingRect().height() / 2 - s.height() / 2);
|
||||
button->setPos(d->messageOverlay->boundingRect().width() / 2 - s.width() / 2,
|
||||
d->messageOverlay->boundingRect().height() / 2 - s.height() / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1697,7 +1718,7 @@ AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet
|
||||
extender(0),
|
||||
backgroundHints(Applet::StandardBackground),
|
||||
appletDescription(service),
|
||||
needsConfigOverlay(0),
|
||||
messageOverlay(0),
|
||||
busyWidget(0),
|
||||
background(0),
|
||||
script(0),
|
||||
@ -1715,7 +1736,8 @@ AppletPrivate::AppletPrivate(KService::Ptr service, int uniqueID, Applet *applet
|
||||
failed(false),
|
||||
isContainment(false),
|
||||
transient(false),
|
||||
ghost(false)
|
||||
ghost(false),
|
||||
needsConfig(false)
|
||||
{
|
||||
if (appletId == 0) {
|
||||
appletId = ++s_maxAppletId;
|
||||
|
28
applet.h
28
applet.h
@ -23,8 +23,8 @@
|
||||
#define PLASMA_APPLET_H
|
||||
|
||||
#include <QtGui/QGraphicsItem>
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtGui/QGraphicsWidget>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
#include <kconfiggroup.h>
|
||||
#include <kgenericfactory.h>
|
||||
@ -37,6 +37,8 @@
|
||||
#include <plasma/animator.h>
|
||||
#include <plasma/version.h>
|
||||
|
||||
class QWidget;
|
||||
|
||||
class KConfigDialog;
|
||||
class QGraphicsView;
|
||||
class KActionCollection;
|
||||
@ -78,6 +80,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
Q_PROPERTY(QString category READ category)
|
||||
Q_PROPERTY(ImmutabilityType immutability READ immutability WRITE setImmutability)
|
||||
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
|
||||
Q_PROPERTY(bool isBusy READ isBusy WRITE setBusy)
|
||||
Q_PROPERTY(bool configurationRequired READ configurationRequired WRITE setConfigurationRequired)
|
||||
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
|
||||
Q_PROPERTY(bool shouldConserveResources READ shouldConserveResources)
|
||||
@ -415,6 +418,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
**/
|
||||
bool hasFailedToLaunch() const;
|
||||
|
||||
/**
|
||||
* @return true if the applet is busy and is showing an indicator widget for that
|
||||
*/
|
||||
bool isBusy() const;
|
||||
|
||||
/**
|
||||
* @return true if the applet currently needs to be configured,
|
||||
* otherwise, false
|
||||
@ -542,17 +550,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
const QString &serviceId = QString(),
|
||||
uint appletId = 0);
|
||||
|
||||
/**
|
||||
* Shows a busy indicator that overlays the applet
|
||||
* @param busy show or hide the busy indicator
|
||||
*/
|
||||
void setBusy(bool busy);
|
||||
|
||||
/**
|
||||
* @return true if the applet is busy and is showing an indicator widget for that
|
||||
*/
|
||||
bool isBusy() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* This signal indicates that an application launch, window
|
||||
@ -672,6 +669,12 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
**/
|
||||
void setFailedToLaunch(bool failed, const QString &reason = QString());
|
||||
|
||||
/**
|
||||
* Shows a busy indicator that overlays the applet
|
||||
* @param busy show or hide the busy indicator
|
||||
*/
|
||||
void setBusy(bool busy);
|
||||
|
||||
/**
|
||||
* When called, the Applet should write any information needed as part
|
||||
* of the Applet's running state to the configuration object in config()
|
||||
@ -830,6 +833,7 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
Plasma::Animator::Animation anim))
|
||||
Q_PRIVATE_SLOT(d, void selectItemToDestroy())
|
||||
Q_PRIVATE_SLOT(d, void updateRect(const QRectF& rect))
|
||||
Q_PRIVATE_SLOT(d, void destroyMessageOverlay())
|
||||
|
||||
/**
|
||||
* Reimplemented from QGraphicsItem
|
||||
|
@ -71,6 +71,8 @@ public:
|
||||
void updateRect(const QRectF &rect);
|
||||
void setFocus();
|
||||
void cleanUpAndDelete();
|
||||
void createMessageOverlay();
|
||||
void destroyMessageOverlay();
|
||||
|
||||
static uint s_maxAppletId;
|
||||
static uint s_maxZValue;
|
||||
@ -85,7 +87,7 @@ public:
|
||||
Extender *extender;
|
||||
Applet::BackgroundHints backgroundHints;
|
||||
KPluginInfo appletDescription;
|
||||
AppletOverlayWidget *needsConfigOverlay;
|
||||
AppletOverlayWidget *messageOverlay;
|
||||
Plasma::BusyWidget *busyWidget;
|
||||
QList<QGraphicsItem*> registeredAsDragHandle;
|
||||
QStringList loadedEngines;
|
||||
@ -107,6 +109,7 @@ public:
|
||||
bool square : 1;
|
||||
bool transient : 1;
|
||||
bool ghost : 1;
|
||||
bool needsConfig : 1;
|
||||
};
|
||||
|
||||
} // Plasma namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user