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