API reviews:
killed drawStandardBackground() and shadowShown() now the two properties are merged in backgroundHints() and setBackgroundHints() using the combination of BackgroundHints flags svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=801282
This commit is contained in:
parent
8cdde181c5
commit
0c283924be
151
applet.cpp
151
applet.cpp
@ -102,6 +102,7 @@ class Applet::Private
|
|||||||
public:
|
public:
|
||||||
Private(KService::Ptr service, int uniqueID)
|
Private(KService::Ptr service, int uniqueID)
|
||||||
: appletId(uniqueID),
|
: appletId(uniqueID),
|
||||||
|
backgroundHints(StandardBackground),
|
||||||
appletDescription(service),
|
appletDescription(service),
|
||||||
package(0),
|
package(0),
|
||||||
needsConfigOverlay(0),
|
needsConfigOverlay(0),
|
||||||
@ -196,7 +197,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applet->setDrawStandardBackground(true);
|
applet->setBackgroundHints(DefaultBackground);
|
||||||
|
|
||||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), applet, SLOT(themeChanged()));
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), applet, SLOT(themeChanged()));
|
||||||
}
|
}
|
||||||
@ -311,6 +312,68 @@ public:
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyBackgroundHints(const BackgroundHints hints)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
backgroundHints = hints;
|
||||||
|
|
||||||
|
//Draw the standard background?
|
||||||
|
if (hints & StandardBackground) {
|
||||||
|
if (!background) {
|
||||||
|
background = new Plasma::PanelSvg();
|
||||||
|
background->setImagePath("widgets/background");
|
||||||
|
background->setEnabledBorders(Plasma::PanelSvg::AllBorders);
|
||||||
|
int left, top, right, bottom;
|
||||||
|
getBorderSize(left, top, right, bottom);
|
||||||
|
setContentsMargins(left, right, top, bottom);
|
||||||
|
|
||||||
|
QSizeF fitSize(left + right, top + bottom);
|
||||||
|
if (minimumSize().expandedTo(fitSize) != minimumSize()) {
|
||||||
|
setMinimumSize(minimumSize().expandedTo(fitSize));
|
||||||
|
}
|
||||||
|
background->resizePanel(boundingRect().size());
|
||||||
|
}
|
||||||
|
} else if (background) {
|
||||||
|
int left, top, right, bottom;
|
||||||
|
getBorderSize(left, top, right, bottom);
|
||||||
|
//Setting a minimum size of 0,0 would result in the panel to be only
|
||||||
|
//on the first virtual desktop
|
||||||
|
setMinimumSize(qMax(minimumSize().width() - left - right, 1.0),
|
||||||
|
qMax(minimumSize().height() - top - bottom, 1.0));
|
||||||
|
|
||||||
|
delete d->background;
|
||||||
|
background = 0;
|
||||||
|
setContentsMargins(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Draw the shadow?
|
||||||
|
//There are various problems with shadows right now:
|
||||||
|
//
|
||||||
|
//1) shadows can be seen through translucent areas, which is probably technically correct ubt
|
||||||
|
//looks odd
|
||||||
|
//2) the shape of the item odesn't conform to the shape of the standard background, e.g. with
|
||||||
|
//rounded corners
|
||||||
|
#ifdef DYNAMIC_SHADOWS
|
||||||
|
if (hints & ShadowedBackground) {
|
||||||
|
if (shadow) {
|
||||||
|
shadow->setVisible(true);
|
||||||
|
} else {
|
||||||
|
shadow = new ShadowItem(this);
|
||||||
|
if (scene()) {
|
||||||
|
scene()->addItem(d->shadow);
|
||||||
|
shadow->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete d->shadow;
|
||||||
|
shadow = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Q_UNUSED(shown);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
//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;
|
||||||
@ -318,6 +381,7 @@ public:
|
|||||||
static uint s_minZValue;
|
static uint s_minZValue;
|
||||||
static PackageStructure::Ptr packageStructure;
|
static PackageStructure::Ptr packageStructure;
|
||||||
uint appletId;
|
uint appletId;
|
||||||
|
BackgroundHints backgroundHints;
|
||||||
KPluginInfo appletDescription;
|
KPluginInfo appletDescription;
|
||||||
Package* package;
|
Package* package;
|
||||||
OverlayWidget *needsConfigOverlay;
|
OverlayWidget *needsConfigOverlay;
|
||||||
@ -464,7 +528,7 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
|||||||
setLayout(0);
|
setLayout(0);
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
setDrawStandardBackground(true);
|
setBackgroundHints(d->backgroundHints|StandardBackground);
|
||||||
|
|
||||||
#ifdef TOPORT
|
#ifdef TOPORT
|
||||||
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
|
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
|
||||||
@ -776,14 +840,17 @@ void Applet::setImmutability(const ImmutabilityType immutable)
|
|||||||
updateConstraints(ImmutableConstraint);
|
updateConstraints(ImmutableConstraint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Applet::drawStandardBackground() const
|
Applet::BackgroundHints Applet::backgroundHints() const
|
||||||
{
|
{
|
||||||
return d->background != 0;
|
return d->backgroundHints;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::setDrawStandardBackground(bool drawBackground)
|
void Applet::setBackgroundHints(const BackgroundHints hints)
|
||||||
{
|
{
|
||||||
if (drawBackground) {
|
d->backgroundHints = hints;
|
||||||
|
|
||||||
|
//Draw the standard background?
|
||||||
|
if (hints & StandardBackground) {
|
||||||
if (!d->background) {
|
if (!d->background) {
|
||||||
d->background = new Plasma::PanelSvg();
|
d->background = new Plasma::PanelSvg();
|
||||||
d->background->setImagePath("widgets/background");
|
d->background->setImagePath("widgets/background");
|
||||||
@ -804,12 +871,36 @@ void Applet::setDrawStandardBackground(bool drawBackground)
|
|||||||
//Setting a minimum size of 0,0 would result in the panel to be only
|
//Setting a minimum size of 0,0 would result in the panel to be only
|
||||||
//on the first virtual desktop
|
//on the first virtual desktop
|
||||||
setMinimumSize(qMax(minimumSize().width() - left - right, 1.0),
|
setMinimumSize(qMax(minimumSize().width() - left - right, 1.0),
|
||||||
qMax(minimumSize().height() - top - bottom, 1.0));
|
qMax(minimumSize().height() - top - bottom, 1.0));
|
||||||
|
|
||||||
delete d->background;
|
delete d->background;
|
||||||
d->background = 0;
|
d->background = 0;
|
||||||
setContentsMargins(0, 0, 0, 0);
|
setContentsMargins(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Draw the shadow?
|
||||||
|
//There are various problems with shadows right now:
|
||||||
|
//
|
||||||
|
//1) shadows can be seen through translucent areas, which is probably technically correct ubt
|
||||||
|
//looks odd
|
||||||
|
//2) the shape of the item odesn't conform to the shape of the standard background, e.g. with
|
||||||
|
//rounded corners
|
||||||
|
#ifdef DYNAMIC_SHADOWS
|
||||||
|
if (hints & ShadowedBackground) {
|
||||||
|
if (d->shadow) {
|
||||||
|
d->shadow->setVisible(true);
|
||||||
|
} else {
|
||||||
|
shadow = new ShadowItem(this);
|
||||||
|
if (scene()) {
|
||||||
|
scene()->addItem(d->shadow);
|
||||||
|
d->shadow->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
delete d->shadow;
|
||||||
|
d->shadow = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Applet::hasFailedToLaunch() const
|
bool Applet::hasFailedToLaunch() const
|
||||||
@ -900,8 +991,17 @@ void Applet::flushUpdatedConstraints()
|
|||||||
|
|
||||||
if (c & Plasma::FormFactorConstraint) {
|
if (c & Plasma::FormFactorConstraint) {
|
||||||
FormFactor f = formFactor();
|
FormFactor f = formFactor();
|
||||||
setShadowShown(f == Planar);
|
if (f == Planar) {
|
||||||
setDrawStandardBackground(!isContainment() && f != Vertical && f != Horizontal);
|
setBackgroundHints(d->backgroundHints|ShadowedBackground);
|
||||||
|
} else {
|
||||||
|
setBackgroundHints(d->backgroundHints^ShadowedBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isContainment() && f != Vertical && f != Horizontal) {
|
||||||
|
setBackgroundHints(d->backgroundHints|StandardBackground);
|
||||||
|
} else {
|
||||||
|
setBackgroundHints(d->backgroundHints^StandardBackground);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
FIXME: what follows was an attempt to constrain the size of applets. it is, however,
|
FIXME: what follows was an attempt to constrain the size of applets. it is, however,
|
||||||
@ -1438,39 +1538,6 @@ Applet* Applet::load(const KPluginInfo& info, uint appletId, const QVariantList&
|
|||||||
return load(info.pluginName(), appletId, args);
|
return load(info.pluginName(), appletId, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Applet::setShadowShown(bool shown)
|
|
||||||
{
|
|
||||||
//There are various problems with shadows right now:
|
|
||||||
//
|
|
||||||
//1) shadows can be seen through translucent areas, which is probably technically correct ubt
|
|
||||||
//looks odd
|
|
||||||
//2) the shape of the item odesn't conform to the shape of the standard background, e.g. with
|
|
||||||
//rounded corners
|
|
||||||
#ifdef DYNAMIC_SHADOWS
|
|
||||||
if (shown) {
|
|
||||||
if (d->shadow) {
|
|
||||||
d->shadow->setVisible(true);
|
|
||||||
} else {
|
|
||||||
d->shadow = new ShadowItem(this);
|
|
||||||
if (scene()) {
|
|
||||||
scene()->addItem(d->shadow);
|
|
||||||
d->shadow->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
delete d->shadow;
|
|
||||||
d->shadow = 0;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
Q_UNUSED(shown);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Applet::isShadowShown() const
|
|
||||||
{
|
|
||||||
return d->shadow && d->shadow->isVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
QPointF Applet::topLeft() const
|
QPointF Applet::topLeft() const
|
||||||
{
|
{
|
||||||
return boundingRect().topLeft();
|
return boundingRect().topLeft();
|
||||||
|
44
applet.h
44
applet.h
@ -66,7 +66,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
Q_PROPERTY(QString name READ name)
|
Q_PROPERTY(QString name READ name)
|
||||||
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 drawStandardBackground READ drawStandardBackground WRITE setDrawStandardBackground)
|
|
||||||
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
|
Q_PROPERTY(bool hasFailedToLaunch READ hasFailedToLaunch WRITE setFailedToLaunch)
|
||||||
Q_PROPERTY(bool needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring)
|
Q_PROPERTY(bool needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring)
|
||||||
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
|
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
|
||||||
@ -77,6 +76,16 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
typedef QList<Applet*> List;
|
typedef QList<Applet*> List;
|
||||||
typedef QHash<QString, Applet*> Dict;
|
typedef QHash<QString, Applet*> Dict;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description on how draw a background for the applet
|
||||||
|
*/
|
||||||
|
enum BackgroundHint { NoBackground = 0 /** Not drawing a background under the applet, the applet has its own implementation */,
|
||||||
|
StandardBackground /** The standard background from the theme is drawn */,
|
||||||
|
ShadowedBackground /** The applet has a drop shadow */,
|
||||||
|
DefaultBackground = StandardBackground | ShadowedBackground /** Default settings: both standard background and shadow */
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(BackgroundHints, BackgroundHint)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param parent the QGraphicsItem this applet is parented to
|
* @param parent the QGraphicsItem this applet is parented to
|
||||||
* @param serviceId the name of the .desktop file containing the
|
* @param serviceId the name of the .desktop file containing the
|
||||||
@ -415,20 +424,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
*/
|
*/
|
||||||
ImmutabilityType immutability() const;
|
ImmutabilityType immutability() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return returns whether or not the applet is using the standard
|
|
||||||
* background
|
|
||||||
**/
|
|
||||||
bool drawStandardBackground() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets whether the applet should automatically draw the standard
|
|
||||||
* background.
|
|
||||||
*
|
|
||||||
* Defaults to true
|
|
||||||
**/
|
|
||||||
void setDrawStandardBackground(bool drawBackground);
|
|
||||||
|
|
||||||
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -475,14 +470,10 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
virtual QList<QAction*> contextualActions();
|
virtual QList<QAction*> contextualActions();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets shadow for the given applet.
|
* @return BackgroundHints flags combination telling if the standard background is shown
|
||||||
|
* and if it has a drop shadow
|
||||||
*/
|
*/
|
||||||
void setShadowShown(bool);
|
BackgroundHints backgroundHints() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given item has a shadow shown.
|
|
||||||
*/
|
|
||||||
bool isShadowShown() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether or not this Applet is acting as a Containment
|
* Sets whether or not this Applet is acting as a Containment
|
||||||
@ -670,6 +661,13 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
**/
|
**/
|
||||||
QString instanceName() const;
|
QString instanceName() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the BackgroundHints for this applet @see BackgroundHint
|
||||||
|
*
|
||||||
|
* @param hints the BackgroundHint combination for this applet
|
||||||
|
*/
|
||||||
|
void setBackgroundHints(const BackgroundHints hints);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register widgets that can receive keyboard focus.
|
* Register widgets that can receive keyboard focus.
|
||||||
*
|
*
|
||||||
@ -762,6 +760,8 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
|||||||
|
|
||||||
} // Plasma namespace
|
} // Plasma namespace
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register an applet when it is contained in a loadable module
|
* Register an applet when it is contained in a loadable module
|
||||||
*/
|
*/
|
||||||
|
@ -80,7 +80,7 @@ Containment::Containment(QGraphicsItem* parent,
|
|||||||
// WARNING: do not access config() OR globalConfig() in this method!
|
// WARNING: do not access config() OR globalConfig() in this method!
|
||||||
// that requires a scene, which is not available at this point
|
// that requires a scene, which is not available at this point
|
||||||
setPos(0, 0);
|
setPos(0, 0);
|
||||||
setDrawStandardBackground(false);
|
setBackgroundHints(DefaultBackground);
|
||||||
setContainmentType(CustomContainment);
|
setContainmentType(CustomContainment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +91,7 @@ Containment::Containment(QObject* parent, const QVariantList& args)
|
|||||||
// WARNING: do not access config() OR globalConfig() in this method!
|
// WARNING: do not access config() OR globalConfig() in this method!
|
||||||
// that requires a scene, which is not available at this point
|
// that requires a scene, which is not available at this point
|
||||||
setPos(0, 0);
|
setPos(0, 0);
|
||||||
setDrawStandardBackground(false);
|
setBackgroundHints(NoBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
Containment::~Containment()
|
Containment::~Containment()
|
||||||
@ -514,7 +514,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
|||||||
|
|
||||||
if (containmentType() == PanelContainment) {
|
if (containmentType() == PanelContainment) {
|
||||||
//panels don't want backgrounds, which is important when setting geometry
|
//panels don't want backgrounds, which is important when setting geometry
|
||||||
applet->setDrawStandardBackground(false);
|
setBackgroundHints(NoBackground);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentContainment && currentContainment != this) {
|
if (currentContainment && currentContainment != this) {
|
||||||
|
Loading…
Reference in New Issue
Block a user