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"
|
|
|
|
|
2008-05-24 03:48:36 +02:00
|
|
|
#include <QAction>
|
2008-04-14 15:05:49 +02:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
|
|
|
|
#include <KColorScheme>
|
|
|
|
#include <KDebug>
|
|
|
|
|
2008-05-24 03:48:36 +02:00
|
|
|
#include <plasma/theme.h>
|
|
|
|
#include "widgets/icon.h"
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class ToolBoxPrivate
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
ToolBoxPrivate()
|
2008-04-14 15:05:49 +02:00
|
|
|
: 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
|
|
|
};
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
ToolBox::ToolBox(QGraphicsItem *parent)
|
2008-04-14 15:05:49 +02:00
|
|
|
: QGraphicsItem(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new ToolBoxPrivate)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
ToolBox::~ToolBox()
|
2008-05-09 09:04:36 +02:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::addTool(QAction *action)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
2008-05-24 03:48:36 +02:00
|
|
|
if (!action) {
|
2008-04-14 15:05:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-24 03:48:36 +02:00
|
|
|
Plasma::Icon *tool = new Plasma::Icon(this);
|
|
|
|
|
|
|
|
tool->setAction(action);
|
|
|
|
tool->setDrawBackground(true);
|
|
|
|
tool->setOrientation(Qt::Horizontal);
|
|
|
|
QSizeF iconSize = tool->sizeFromIconSize(22);
|
|
|
|
tool->setMinimumSize(iconSize);
|
|
|
|
tool->setMaximumSize(iconSize);
|
|
|
|
tool->resize(tool->size());
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
tool->hide();
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
|
|
|
tool->setPos(QPoint( d->size*2,-height));
|
|
|
|
tool->setZValue(zValue() + 1);
|
|
|
|
|
2008-05-24 03:48:36 +02:00
|
|
|
//make enabled/disabled tools appear/disappear instantly
|
2008-05-24 14:25:56 +02:00
|
|
|
connect(tool, SIGNAL(changed()), this, SLOT(updateToolBox()));
|
2008-04-14 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::updateToolBox()
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
2008-05-24 03:48:36 +02:00
|
|
|
if ( d->showing) {
|
|
|
|
d->showing = false;
|
2008-05-24 14:25:56 +02:00
|
|
|
showToolBox();
|
2008-04-14 15:05:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::removeTool(QAction *action)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
foreach (QGraphicsItem *child, QGraphicsItem::children()) {
|
|
|
|
//kDebug() << "checking tool" << child << child->data(ToolName);
|
2008-05-24 03:48:36 +02:00
|
|
|
Plasma::Icon *tool = dynamic_cast<Plasma::Icon*>(child);
|
|
|
|
if (tool && tool->action() == action) {
|
2008-04-14 15:05:49 +02:00
|
|
|
//kDebug() << "tool found!";
|
2008-05-24 03:48:36 +02:00
|
|
|
tool->deleteLater();
|
|
|
|
break;
|
2008-04-14 15:05:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
int ToolBox::size() const
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::setSize(const int newSize)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
d->size = newSize;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
QSize ToolBox::iconSize() const
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
return d->iconSize;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::setIconSize(const QSize newSize)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
d->iconSize = newSize;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
bool ToolBox::showing() const
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
|
|
|
return d->showing;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::setShowing(const bool show)
|
2008-04-14 15:05:49 +02:00
|
|
|
{
|
2008-04-16 15:55:23 +02:00
|
|
|
d->showing = show;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
Qt::Orientation ToolBox::orientation() const
|
2008-04-16 15:55:23 +02:00
|
|
|
{
|
|
|
|
return d->orientation;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::setOrientation( Qt::Orientation orient )
|
2008-04-16 15:55:23 +02:00
|
|
|
{
|
|
|
|
d->orientation = orient;
|
2008-04-14 15:05:49 +02:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
2008-04-26 19:31:49 +02:00
|
|
|
{
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void ToolBox::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
2008-04-26 19:31:49 +02:00
|
|
|
{
|
|
|
|
if (boundingRect().contains(event->pos())) {
|
|
|
|
emit toggled();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
} // plasma namespace
|
|
|
|
|
|
|
|
#include "toolbox_p.moc"
|
|
|
|
|