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
{
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

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.
* 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

View File

@ -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

View File

@ -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);