2008-04-14 15:05:49 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
|
|
|
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "toolbox_p.h"
|
|
|
|
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
|
|
|
|
#include <plasma/theme.h>
|
|
|
|
#include <KColorScheme>
|
|
|
|
|
|
|
|
#include <KDebug>
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
// used with QGrahphicsItem::setData
|
|
|
|
static const int ToolName = 7001;
|
|
|
|
|
|
|
|
class Toolbox::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
|
|
|
: size(50),
|
|
|
|
iconSize(32, 32),
|
|
|
|
hidden(false),
|
2008-04-16 15:55:23 +02:00
|
|
|
showing(false),
|
|
|
|
orientation(Qt::Horizontal)
|
2008-04-14 15:05:49 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
int size;
|
|
|
|
QSize iconSize;
|
|
|
|
bool hidden;
|
|
|
|
bool showing;
|
2008-04-16 15:55:23 +02:00
|
|
|
Qt::Orientation orientation;
|
2008-04-14 15:05:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Toolbox::Toolbox(QGraphicsItem *parent)
|
|
|
|
: QGraphicsItem(parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::addTool(QGraphicsItem *tool, const QString &name)
|
|
|
|
{
|
|
|
|
if (!tool) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tool->hide();
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
|
|
|
tool->setPos(QPoint( d->size*2,-height));
|
|
|
|
tool->setZValue(zValue() + 1);
|
|
|
|
tool->setParentItem(this);
|
|
|
|
tool->setData(ToolName, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::enableTool(const QString &toolName, bool visible)
|
|
|
|
{
|
|
|
|
//kDebug() << (visible? "enabling" : "disabling") << "tool" << toolName;
|
|
|
|
QGraphicsItem *t = tool(toolName);
|
|
|
|
|
|
|
|
if (t && t->isEnabled() != visible) {
|
|
|
|
t->setEnabled(visible);
|
|
|
|
// adjust the visible items
|
|
|
|
if ( d->showing) {
|
|
|
|
d->showing = false;
|
|
|
|
showToolbox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Toolbox::isToolEnabled(const QString &toolName) const
|
|
|
|
{
|
|
|
|
QGraphicsItem *t = tool(toolName);
|
|
|
|
|
|
|
|
if (t) {
|
|
|
|
return t->isEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsItem* Toolbox::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!";
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Toolbox::size() const
|
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::setSize(const int newSize)
|
|
|
|
{
|
|
|
|
d->size = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Toolbox::iconSize() const
|
|
|
|
{
|
|
|
|
return d->iconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::setIconSize(const QSize newSize)
|
|
|
|
{
|
|
|
|
d->iconSize = newSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Toolbox::showing() const
|
|
|
|
{
|
|
|
|
return d->showing;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::setShowing(const bool show)
|
|
|
|
{
|
2008-04-16 15:55:23 +02:00
|
|
|
d->showing = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Orientation Toolbox::orientation() const
|
|
|
|
{
|
|
|
|
return d->orientation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::setOrientation( Qt::Orientation orient )
|
|
|
|
{
|
|
|
|
d->orientation = orient;
|
2008-04-14 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
2008-04-26 19:31:49 +02:00
|
|
|
void Toolbox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (boundingRect().contains(event->pos())) {
|
|
|
|
emit toggled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
} // plasma namespace
|
|
|
|
|
|
|
|
#include "toolbox_p.moc"
|
|
|
|
|