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:
|
||||
Private(KService::Ptr service, int uniqueID)
|
||||
: appletId(uniqueID),
|
||||
backgroundHints(StandardBackground),
|
||||
appletDescription(service),
|
||||
package(0),
|
||||
needsConfigOverlay(0),
|
||||
@ -196,7 +197,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
applet->setDrawStandardBackground(true);
|
||||
applet->setBackgroundHints(DefaultBackground);
|
||||
|
||||
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), applet, SLOT(themeChanged()));
|
||||
}
|
||||
@ -310,6 +311,68 @@ public:
|
||||
|
||||
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
|
||||
// number of members at this point.
|
||||
@ -318,6 +381,7 @@ public:
|
||||
static uint s_minZValue;
|
||||
static PackageStructure::Ptr packageStructure;
|
||||
uint appletId;
|
||||
BackgroundHints backgroundHints;
|
||||
KPluginInfo appletDescription;
|
||||
Package* package;
|
||||
OverlayWidget *needsConfigOverlay;
|
||||
@ -464,7 +528,7 @@ void Applet::setFailedToLaunch(bool failed, const QString& reason)
|
||||
setLayout(0);
|
||||
|
||||
if (failed) {
|
||||
setDrawStandardBackground(true);
|
||||
setBackgroundHints(d->backgroundHints|StandardBackground);
|
||||
|
||||
#ifdef TOPORT
|
||||
Layout* failureLayout = new BoxLayout(BoxLayout::TopToBottom, this);
|
||||
@ -776,14 +840,17 @@ void Applet::setImmutability(const ImmutabilityType immutable)
|
||||
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) {
|
||||
d->background = new Plasma::PanelSvg();
|
||||
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
|
||||
//on the first virtual desktop
|
||||
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;
|
||||
d->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 (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
|
||||
@ -900,8 +991,17 @@ void Applet::flushUpdatedConstraints()
|
||||
|
||||
if (c & Plasma::FormFactorConstraint) {
|
||||
FormFactor f = formFactor();
|
||||
setShadowShown(f == Planar);
|
||||
setDrawStandardBackground(!isContainment() && f != Vertical && f != Horizontal);
|
||||
if (f == Planar) {
|
||||
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,
|
||||
@ -1438,39 +1538,6 @@ Applet* Applet::load(const KPluginInfo& info, uint appletId, const QVariantList&
|
||||
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
|
||||
{
|
||||
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 category READ category)
|
||||
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 needsConfiguring READ needsConfiguring WRITE setNeedsConfiguring)
|
||||
Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
|
||||
@ -77,6 +76,16 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
typedef QList<Applet*> List;
|
||||
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 serviceId the name of the .desktop file containing the
|
||||
@ -415,20 +424,6 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
@ -475,14 +470,10 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
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);
|
||||
|
||||
/**
|
||||
* Returns true if the given item has a shadow shown.
|
||||
*/
|
||||
bool isShadowShown() const;
|
||||
BackgroundHints backgroundHints() const;
|
||||
|
||||
/**
|
||||
* Sets whether or not this Applet is acting as a Containment
|
||||
@ -670,6 +661,13 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
**/
|
||||
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.
|
||||
*
|
||||
@ -762,6 +760,8 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
|
||||
|
||||
} // Plasma namespace
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Plasma::Applet::BackgroundHints)
|
||||
|
||||
/**
|
||||
* 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!
|
||||
// that requires a scene, which is not available at this point
|
||||
setPos(0, 0);
|
||||
setDrawStandardBackground(false);
|
||||
setBackgroundHints(DefaultBackground);
|
||||
setContainmentType(CustomContainment);
|
||||
}
|
||||
|
||||
@ -91,7 +91,7 @@ Containment::Containment(QObject* parent, const QVariantList& args)
|
||||
// WARNING: do not access config() OR globalConfig() in this method!
|
||||
// that requires a scene, which is not available at this point
|
||||
setPos(0, 0);
|
||||
setDrawStandardBackground(false);
|
||||
setBackgroundHints(NoBackground);
|
||||
}
|
||||
|
||||
Containment::~Containment()
|
||||
@ -514,7 +514,7 @@ void Containment::addApplet(Applet *applet, const QPointF &pos, bool delayInit)
|
||||
|
||||
if (containmentType() == PanelContainment) {
|
||||
//panels don't want backgrounds, which is important when setting geometry
|
||||
applet->setDrawStandardBackground(false);
|
||||
setBackgroundHints(NoBackground);
|
||||
}
|
||||
|
||||
if (currentContainment && currentContainment != this) {
|
||||
|
Loading…
Reference in New Issue
Block a user