diff --git a/containment.cpp b/containment.cpp index 39bab59f7..a1f800a21 100644 --- a/containment.cpp +++ b/containment.cpp @@ -54,8 +54,9 @@ static const int INTER_CONTAINMENT_MARGIN = 6; class Containment::Private { public: - Private() - : formFactor(Planar), + Private(Containment* c) + : q(c), + formFactor(Planar), location(Floating), screen(-1), immutable(false), @@ -70,16 +71,17 @@ public: applets.clear(); } - DesktopToolbox* createToolbox(Containment* c) + DesktopToolbox* createToolbox() { if (!toolbox) { - toolbox = new DesktopToolbox(c); - toolbox->setPos(c->geometry().width() - toolbox->boundingRect().width(), 0); + toolbox = new DesktopToolbox(q); + toolbox->setPos(q->geometry().width() - toolbox->boundingRect().width(), 0); } return toolbox; } + Containment *q; FormFactor formFactor; Location location; Applet::List applets; @@ -94,7 +96,7 @@ Containment::Containment(QGraphicsItem* parent, const QString& serviceId, uint containmentId) : Applet(parent, serviceId, containmentId), - d(new Private) + d(new Private(this)) { // WARNING: do not access config() OR globalConfig() in this method! // that requires a scene, which is not available at this point @@ -104,7 +106,7 @@ Containment::Containment(QGraphicsItem* parent, Containment::Containment(QObject* parent, const QVariantList& args) : Applet(parent, args), - d(new Private) + d(new Private(this)) { // WARNING: do not access config() OR globalConfig() in this method! // that requires a scene, which is not available at this point @@ -708,12 +710,17 @@ void Containment::emitLaunchActivated() void Containment::addToolBoxTool(QGraphicsItem *tool, const QString& toolName) { - d->createToolbox(this)->addTool(tool, toolName); + d->createToolbox()->addTool(tool, toolName); } void Containment::enableToolBoxTool(const QString &toolname, bool enable) { - d->createToolbox(this)->enableTool(toolname, enable); + d->createToolbox()->enableTool(toolname, enable); +} + +bool Containment::isToolboxToolEnabled(const QString &toolname) const +{ + return d->createToolbox()->isToolEnabled(toolname); } } // Plasma namespace diff --git a/containment.h b/containment.h index 1bd263982..714ceb13b 100644 --- a/containment.h +++ b/containment.h @@ -215,7 +215,6 @@ class PLASMA_EXPORT Containment : public Applet /** * Adds an item to the toolbox. The toolbox takes over ownership of the item. - * TODO: add remove and accessor methods */ void addToolBoxTool(QGraphicsItem *tool, const QString &toolname = QString()); @@ -227,6 +226,11 @@ class PLASMA_EXPORT Containment : public Applet */ void enableToolBoxTool(const QString &toolname, bool enable); + /** + * Returns whether or not a given toolbox tool is enabled + */ + bool isToolboxToolEnabled(const QString &toolname) const; + /** * @internal * Called when constraints have been updated on this containment to provide diff --git a/toolbox.cpp b/toolbox.cpp index 16e4e0156..7dedfaa94 100644 --- a/toolbox.cpp +++ b/toolbox.cpp @@ -180,19 +180,35 @@ void DesktopToolbox::addTool(QGraphicsItem *tool, const QString &name) void DesktopToolbox::enableTool(const QString &toolName, bool visible) { //kDebug() << (visible? "enabling" : "disabling") << "tool" << toolName; - QGraphicsItem *tool = 0; + QGraphicsItem *t = tool(toolName); + + if (t) { + t->setEnabled(visible); + } +} + +bool DesktopToolbox::isToolEnabled(const QString &toolName) const +{ + QGraphicsItem *t = tool(toolName); + + if (t) { + return t->isEnabled(); + } + + return false; +} + +QGraphicsItem* DesktopToolbox::tool(const QString &toolName) const +{ foreach (QGraphicsItem *child, QGraphicsItem::children()) { //kDebug() << "checking tool" << child << child->data(ToolName); if (child->data(ToolName).toString() == toolName) { //kDebug() << "tool found!"; - tool = child; - break; + return child; } } - if (tool) { - tool->setEnabled(visible); - } + return 0; } } // plasma namespace diff --git a/toolbox_p.h b/toolbox_p.h index f2ec0d0b6..d27ef2155 100644 --- a/toolbox_p.h +++ b/toolbox_p.h @@ -43,6 +43,8 @@ public: void addTool(QGraphicsItem *tool, const QString &name); void enableTool(const QString &tool, bool enabled); + bool isToolEnabled(const QString &tool) const; + QGraphicsItem* tool(const QString &tool) const; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);