API review:

isContainment(), setIsContainment() -> actAsContainment(),
setActAsContainment()
 set is protected

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=801425
This commit is contained in:
Marco Martin 2008-04-26 15:52:48 +00:00
parent b21b9380de
commit 6d8a1752a7
4 changed files with 36 additions and 36 deletions

View File

@ -117,7 +117,7 @@ public:
immutability(NotImmutable), immutability(NotImmutable),
hasConfigurationInterface(false), hasConfigurationInterface(false),
failed(false), failed(false),
isContainment(false), actAsContainment(false),
square(false), square(false),
transient(false) transient(false)
{ {
@ -254,7 +254,7 @@ public:
return mainConfig; return mainConfig;
} }
if (isContainment) { if (actAsContainment) {
const Containment *asContainment = qobject_cast<Containment*>(const_cast<Applet*>(q)); const Containment *asContainment = qobject_cast<Containment*>(const_cast<Applet*>(q));
Q_ASSERT(asContainment); Q_ASSERT(asContainment);
@ -338,7 +338,7 @@ public:
ImmutabilityType immutability; ImmutabilityType immutability;
bool hasConfigurationInterface : 1; bool hasConfigurationInterface : 1;
bool failed : 1; bool failed : 1;
bool isContainment : 1; bool actAsContainment : 1;
bool square : 1; bool square : 1;
bool transient : 1; bool transient : 1;
}; };
@ -514,7 +514,7 @@ KConfigGroup Applet::config(const QString &group) const
KConfigGroup Applet::config() const KConfigGroup Applet::config() const
{ {
if (d->isContainment) { if (d->actAsContainment) {
return *(d->mainConfigGroup(this)); return *(d->mainConfigGroup(this));
} }
@ -524,8 +524,8 @@ KConfigGroup Applet::config() const
KConfigGroup Applet::globalConfig() const KConfigGroup Applet::globalConfig() const
{ {
KConfigGroup globalAppletConfig; KConfigGroup globalAppletConfig;
const Containment *c = isContainment() ? dynamic_cast<const Containment*>(this) : containment(); const Containment *c = actAsContainment() ? dynamic_cast<const Containment*>(this) : containment();
QString group = isContainment() ? "ContainmentGlobals" : "AppletGlobals"; QString group = actAsContainment() ? "ContainmentGlobals" : "AppletGlobals";
if (c && c->corona()) { if (c && c->corona()) {
KSharedConfig::Ptr coronaConfig = c->corona()->config(); KSharedConfig::Ptr coronaConfig = c->corona()->config();
@ -935,7 +935,7 @@ void Applet::flushUpdatedConstraints()
setBackgroundHints(d->backgroundHints^ShadowedBackground); setBackgroundHints(d->backgroundHints^ShadowedBackground);
} }
if (!isContainment() && f != Vertical && f != Horizontal) { if (!actAsContainment() && f != Vertical && f != Horizontal) {
setBackgroundHints(d->backgroundHints|StandardBackground); setBackgroundHints(d->backgroundHints|StandardBackground);
} else { } else {
setBackgroundHints(d->backgroundHints^StandardBackground); setBackgroundHints(d->backgroundHints^StandardBackground);
@ -971,7 +971,7 @@ void Applet::flushUpdatedConstraints()
} }
Containment* containment = qobject_cast<Plasma::Containment*>(this); Containment* containment = qobject_cast<Plasma::Containment*>(this);
if (isContainment() && containment) { if (actAsContainment() && containment) {
containment->d->containmentConstraintsUpdated(c); containment->d->containmentConstraintsUpdated(c);
} }
@ -989,7 +989,7 @@ int Applet::type() const
QPainterPath Applet::shape() const QPainterPath Applet::shape() const
{ {
if (isContainment()) { if (actAsContainment()) {
return QGraphicsWidget::shape(); return QGraphicsWidget::shape();
} }
@ -1054,7 +1054,7 @@ void Applet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QW
d->background->paintPanel(painter, option->rect, QPointF(0,0)); d->background->paintPanel(painter, option->rect, QPointF(0,0));
} }
if (!d->failed) { if (!d->failed) {
if (widget && isContainment()) { if (widget && actAsContainment()) {
// note that the widget we get is actually the viewport of the view, not the view itself // note that the widget we get is actually the viewport of the view, not the view itself
View* v = qobject_cast<Plasma::View*>(widget->parent()); View* v = qobject_cast<Plasma::View*>(widget->parent());
if (!v || v->isWallpaperEnabled()) { if (!v || v->isWallpaperEnabled()) {
@ -1095,7 +1095,7 @@ Containment* Applet::containment() const
/* /*
* while this is probably "more correct", much of the code in applet assumes containment * while this is probably "more correct", much of the code in applet assumes containment
* returns zero in the case that this is a containment itself. * returns zero in the case that this is a containment itself.
* if (isContainment()) { * if (actAsContainment()) {
return dynamic_cast<Containment*>(const_cast<Applet*>(this)); return dynamic_cast<Containment*>(const_cast<Applet*>(this));
} }
*/ */
@ -1105,7 +1105,7 @@ Containment* Applet::containment() const
while (parent) { while (parent) {
Containment *possibleC = dynamic_cast<Containment*>(parent); Containment *possibleC = dynamic_cast<Containment*>(parent);
if (possibleC && possibleC->isContainment()) { if (possibleC && possibleC->actAsContainment()) {
c = possibleC; c = possibleC;
break; break;
} }
@ -1254,7 +1254,7 @@ void Applet::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem *parent = parentItem(); QGraphicsItem *parent = parentItem();
Plasma::Applet *applet = qgraphicsitem_cast<Plasma::Applet*>(parent); Plasma::Applet *applet = qgraphicsitem_cast<Plasma::Applet*>(parent);
if (applet && applet->isContainment()) { if (applet && applet->actAsContainment()) {
// our direct parent is a containment. just move ourselves. // our direct parent is a containment. just move ourselves.
QPointF curPos = event->pos(); QPointF curPos = event->pos();
QPointF lastPos = event->lastPos(); QPointF lastPos = event->lastPos();
@ -1427,12 +1427,12 @@ Applet* Applet::load(const QString& appletName, uint appletId, const QVariantLis
QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName); QString constraint = QString("[X-KDE-PluginInfo-Name] == '%1'").arg(appletName);
KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint); KService::List offers = KServiceTypeTrader::self()->query("Plasma/Applet", constraint);
bool isContainment = false; bool actAsContainment = false;
if (offers.isEmpty()) { if (offers.isEmpty()) {
//TODO: what would be -really- cool is offer to try and download the applet //TODO: what would be -really- cool is offer to try and download the applet
// from the network at this point // from the network at this point
offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint); offers = KServiceTypeTrader::self()->query("Plasma/Containment", constraint);
isContainment = true; actAsContainment = true;
if (offers.isEmpty()) { if (offers.isEmpty()) {
kDebug() << "offers is empty for " << appletName; kDebug() << "offers is empty for " << appletName;
return 0; return 0;
@ -1449,7 +1449,7 @@ Applet* Applet::load(const QString& appletName, uint appletId, const QVariantLis
if (!offer->property("X-Plasma-Language").toString().isEmpty()) { if (!offer->property("X-Plasma-Language").toString().isEmpty()) {
kDebug() << "we have a script in the language of" << offer->property("X-Plasma-Language").toString(); kDebug() << "we have a script in the language of" << offer->property("X-Plasma-Language").toString();
if (isContainment) { if (actAsContainment) {
return new Containment(0, offer->storageId(), appletId); return new Containment(0, offer->storageId(), appletId);
} }
return new Applet(0, offer->storageId(), appletId); return new Applet(0, offer->storageId(), appletId);
@ -1549,13 +1549,13 @@ void Applet::lower()
setZValue(--Private::s_minZValue); setZValue(--Private::s_minZValue);
} }
void Applet::setIsContainment(bool isContainment) void Applet::setActAsContainment(bool actAsContainment)
{ {
if (d->isContainment == isContainment) { if (d->actAsContainment == actAsContainment) {
return; return;
} }
d->isContainment = isContainment; d->actAsContainment = actAsContainment;
Containment *c = qobject_cast<Containment*>(this); Containment *c = qobject_cast<Containment*>(this);
if (c) { if (c) {
@ -1564,9 +1564,9 @@ void Applet::setIsContainment(bool isContainment)
} }
} }
bool Applet::isContainment() const bool Applet::actAsContainment() const
{ {
return d->isContainment; return d->actAsContainment;
} }
void Applet::themeChanged() void Applet::themeChanged()

View File

@ -452,15 +452,10 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
*/ */
BackgroundHints backgroundHints() const; BackgroundHints backgroundHints() const;
/**
* Sets whether or not this Applet is acting as a Containment
*/
void setIsContainment(bool isContainment);
/** /**
* @return true if this Applet is currently being used as a Containment, false otherwise * @return true if this Applet is currently being used as a Containment, false otherwise
*/ */
bool isContainment() const; bool actAsContainment() const;
/** /**
* Sets the geometry of this Plasma::Applet. Should not be used directly by * Sets the geometry of this Plasma::Applet. Should not be used directly by
@ -661,6 +656,11 @@ class PLASMA_EXPORT Applet : public QGraphicsWidget
**/ **/
QString instanceName() const; QString instanceName() const;
/**
* Sets whether or not this Applet is acting as a Containment
*/
void setActAsContainment(bool actAsContainment);
/** /**
* Sets the BackgroundHints for this applet @see BackgroundHint * Sets the BackgroundHints for this applet @see BackgroundHint
* *

View File

@ -196,7 +196,7 @@ void Containment::setContainmentType(Containment::Type type)
{ {
d->type = type; d->type = type;
if (isContainment() && type == DesktopContainment) { if (actAsContainment() && type == DesktopContainment) {
if (!d->toolBox) { if (!d->toolBox) {
QGraphicsWidget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets")); QGraphicsWidget *addWidgetTool = addToolBoxTool("addwidgets", "list-add", i18n("Add Widgets"));
connect(addWidgetTool, SIGNAL(clicked()), this, SLOT(triggerShowAddWidgets())); connect(addWidgetTool, SIGNAL(clicked()), this, SLOT(triggerShowAddWidgets()));
@ -218,7 +218,7 @@ void Containment::setContainmentType(Containment::Type type)
connect(activityTool, SIGNAL(clicked()), this, SLOT(addSiblingContainment())); connect(activityTool, SIGNAL(clicked()), this, SLOT(addSiblingContainment()));
} }
} else if (isContainment() && type == PanelContainment) { } else if (actAsContainment() && type == PanelContainment) {
if (!d->toolBox) { if (!d->toolBox) {
d->createToolBox(); d->createToolBox();
d->toolBox->setSize(22); d->toolBox->setSize(22);
@ -238,7 +238,7 @@ Corona* Containment::corona() const
void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event) void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
{ {
//kDebug() << "let's see if we manage to get a context menu here, huh"; //kDebug() << "let's see if we manage to get a context menu here, huh";
if (!isContainment() || !scene() || !KAuthorized::authorizeKAction("desktop_contextmenu")) { if (!actAsContainment() || !scene() || !KAuthorized::authorizeKAction("desktop_contextmenu")) {
Applet::contextMenuEvent(event); Applet::contextMenuEvent(event);
return; return;
} }
@ -253,7 +253,7 @@ void Containment::contextMenuEvent(QGraphicsSceneContextMenuEvent* event)
while (item) { while (item) {
applet = qgraphicsitem_cast<Applet*>(item); applet = qgraphicsitem_cast<Applet*>(item);
if (applet && !applet->isContainment()) { if (applet && !applet->actAsContainment()) {
break; break;
} }
@ -360,7 +360,7 @@ void Containment::setFormFactor(FormFactor formFactor)
d->formFactor = formFactor; d->formFactor = formFactor;
if (isContainment() && containmentType() == PanelContainment && was != formFactor) { if (actAsContainment() && containmentType() == PanelContainment && was != formFactor) {
// we are a panel and we have chaged our orientation // we are a panel and we have chaged our orientation
d->positionPanel(true); d->positionPanel(true);
} }
@ -434,7 +434,7 @@ void Containment::createLayout(FormFactor formFactor)
FormFactor Containment::formFactor() const FormFactor Containment::formFactor() const
{ {
if (isContainment()) { if (actAsContainment()) {
return d->formFactor; return d->formFactor;
} }
@ -800,7 +800,7 @@ QVariant Containment::itemChange(GraphicsItemChange change, const QVariant &valu
{ {
Q_UNUSED(value) Q_UNUSED(value)
if (isContainment() && if (actAsContainment() &&
(change == QGraphicsItem::ItemSceneHasChanged || change == QGraphicsItem::ItemPositionHasChanged) && (change == QGraphicsItem::ItemSceneHasChanged || change == QGraphicsItem::ItemPositionHasChanged) &&
!d->positioning) { !d->positioning) {
switch (containmentType()) { switch (containmentType()) {
@ -970,7 +970,7 @@ void Containment::Private::setLockToolText()
void Containment::Private::containmentConstraintsUpdated(Plasma::Constraints constraints) void Containment::Private::containmentConstraintsUpdated(Plasma::Constraints constraints)
{ {
if (!q->isContainment()) { if (!q->actAsContainment()) {
return; return;
} }

View File

@ -154,7 +154,7 @@ public:
containment->setFormFactor(Plasma::Planar); containment->setFormFactor(Plasma::Planar);
} }
containment->setIsContainment(true); containment->setActAsContainment(true);
if (!delayedInit) { if (!delayedInit) {
q->addItem(containment); q->addItem(containment);