allow querying if a tool is enabled or not

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=750286
This commit is contained in:
Aaron J. Seigo 2007-12-19 02:41:45 +00:00
parent 65af194560
commit e8e3b503e2
4 changed files with 45 additions and 16 deletions

View File

@ -54,8 +54,9 @@ static const int INTER_CONTAINMENT_MARGIN = 6;
class Containment::Private class Containment::Private
{ {
public: public:
Private() Private(Containment* c)
: formFactor(Planar), : q(c),
formFactor(Planar),
location(Floating), location(Floating),
screen(-1), screen(-1),
immutable(false), immutable(false),
@ -70,16 +71,17 @@ public:
applets.clear(); applets.clear();
} }
DesktopToolbox* createToolbox(Containment* c) DesktopToolbox* createToolbox()
{ {
if (!toolbox) { if (!toolbox) {
toolbox = new DesktopToolbox(c); toolbox = new DesktopToolbox(q);
toolbox->setPos(c->geometry().width() - toolbox->boundingRect().width(), 0); toolbox->setPos(q->geometry().width() - toolbox->boundingRect().width(), 0);
} }
return toolbox; return toolbox;
} }
Containment *q;
FormFactor formFactor; FormFactor formFactor;
Location location; Location location;
Applet::List applets; Applet::List applets;
@ -94,7 +96,7 @@ Containment::Containment(QGraphicsItem* parent,
const QString& serviceId, const QString& serviceId,
uint containmentId) uint containmentId)
: Applet(parent, serviceId, containmentId), : Applet(parent, serviceId, containmentId),
d(new Private) d(new Private(this))
{ {
// 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
@ -104,7 +106,7 @@ Containment::Containment(QGraphicsItem* parent,
Containment::Containment(QObject* parent, const QVariantList& args) Containment::Containment(QObject* parent, const QVariantList& args)
: Applet(parent, args), : Applet(parent, args),
d(new Private) d(new Private(this))
{ {
// 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
@ -708,12 +710,17 @@ void Containment::emitLaunchActivated()
void Containment::addToolBoxTool(QGraphicsItem *tool, const QString& toolName) 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) 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 } // Plasma namespace

View File

@ -215,7 +215,6 @@ class PLASMA_EXPORT Containment : public Applet
/** /**
* Adds an item to the toolbox. The toolbox takes over ownership of the item. * 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()); 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); void enableToolBoxTool(const QString &toolname, bool enable);
/**
* Returns whether or not a given toolbox tool is enabled
*/
bool isToolboxToolEnabled(const QString &toolname) const;
/** /**
* @internal * @internal
* Called when constraints have been updated on this containment to provide * Called when constraints have been updated on this containment to provide

View File

@ -180,19 +180,35 @@ void DesktopToolbox::addTool(QGraphicsItem *tool, const QString &name)
void DesktopToolbox::enableTool(const QString &toolName, bool visible) void DesktopToolbox::enableTool(const QString &toolName, bool visible)
{ {
//kDebug() << (visible? "enabling" : "disabling") << "tool" << toolName; //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()) { foreach (QGraphicsItem *child, QGraphicsItem::children()) {
//kDebug() << "checking tool" << child << child->data(ToolName); //kDebug() << "checking tool" << child << child->data(ToolName);
if (child->data(ToolName).toString() == toolName) { if (child->data(ToolName).toString() == toolName) {
//kDebug() << "tool found!"; //kDebug() << "tool found!";
tool = child; return child;
break;
} }
} }
if (tool) { return 0;
tool->setEnabled(visible);
}
} }
} // plasma namespace } // plasma namespace

View File

@ -43,6 +43,8 @@ public:
void addTool(QGraphicsItem *tool, const QString &name); void addTool(QGraphicsItem *tool, const QString &name);
void enableTool(const QString &tool, bool enabled); void enableTool(const QString &tool, bool enabled);
bool isToolEnabled(const QString &tool) const;
QGraphicsItem* tool(const QString &tool) const;
protected: protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);