2007-11-19 02:19:12 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
|
2008-04-14 23:09:15 +02:00
|
|
|
* Copyright 2008 by Marco Martin <notmart@gmail.com>
|
2007-11-19 02:19:12 +01:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-12-21 02:14:32 +01:00
|
|
|
#include "desktoptoolbox_p.h"
|
2007-11-19 02:19:12 +01:00
|
|
|
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRadialGradient>
|
2008-04-28 21:41:43 +02:00
|
|
|
#include <QGraphicsView>
|
2007-11-19 02:19:12 +01:00
|
|
|
|
2008-01-07 05:33:44 +01:00
|
|
|
#include <plasma/theme.h>
|
2008-09-30 21:54:04 +02:00
|
|
|
#include <plasma/paintutils.h>
|
2008-01-07 05:33:44 +01:00
|
|
|
#include <KColorScheme>
|
|
|
|
|
2007-12-05 21:22:25 +01:00
|
|
|
#include <KDebug>
|
|
|
|
|
2008-04-13 23:47:47 +02:00
|
|
|
#include <plasma/applet.h>
|
|
|
|
|
2007-11-19 02:19:12 +01:00
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
2008-01-10 22:05:56 +01:00
|
|
|
class EmptyGraphicsItem : public QGraphicsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EmptyGraphicsItem(QGraphicsItem *parent)
|
|
|
|
: QGraphicsItem(parent)
|
|
|
|
{
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF boundingRect() const
|
|
|
|
{
|
|
|
|
return QRectF(QPointF(0, 0), m_rect.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF rect() const
|
|
|
|
{
|
|
|
|
return m_rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRect(const QRectF &rect)
|
|
|
|
{
|
|
|
|
//kDebug() << "setting rect to" << rect;
|
|
|
|
prepareGeometryChange();
|
|
|
|
m_rect = rect;
|
|
|
|
setPos(rect.topLeft());
|
|
|
|
}
|
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
2008-01-10 22:05:56 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(p)
|
|
|
|
//p->setPen(Qt::red);
|
|
|
|
//p->drawRect(boundingRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QRectF m_rect;
|
|
|
|
};
|
|
|
|
|
2007-12-05 21:22:25 +01:00
|
|
|
// used with QGrahphicsItem::setData
|
|
|
|
static const int ToolName = 7001;
|
|
|
|
|
2008-07-01 20:56:43 +02:00
|
|
|
class DesktopToolBoxPrivate
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-04-14 15:05:49 +02:00
|
|
|
public:
|
2008-07-01 20:56:43 +02:00
|
|
|
DesktopToolBoxPrivate()
|
2008-04-14 15:05:49 +02:00
|
|
|
: icon("plasma"),
|
|
|
|
toolBacker(0),
|
2008-05-19 02:41:41 +02:00
|
|
|
animCircleId(0),
|
|
|
|
animHighlightId(0),
|
|
|
|
animCircleFrame(0),
|
|
|
|
animHighlightFrame(0),
|
|
|
|
hovering(0)
|
2008-04-14 15:05:49 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
KIcon icon;
|
|
|
|
EmptyGraphicsItem *toolBacker;
|
2008-05-19 02:41:41 +02:00
|
|
|
int animCircleId;
|
|
|
|
int animHighlightId;
|
|
|
|
qreal animCircleFrame;
|
|
|
|
qreal animHighlightFrame;
|
2008-08-28 17:59:03 +02:00
|
|
|
QRect shapeRect;
|
2008-05-19 02:41:41 +02:00
|
|
|
bool hovering : 1;
|
2008-04-14 15:05:49 +02:00
|
|
|
};
|
2007-11-19 02:19:12 +01:00
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
DesktopToolBox::DesktopToolBox(QGraphicsItem *parent)
|
|
|
|
: ToolBox(parent),
|
2008-07-01 20:56:43 +02:00
|
|
|
d(new DesktopToolBoxPrivate)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-10-12 01:28:20 +02:00
|
|
|
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
|
|
|
this, SLOT(toolMoved(QGraphicsItem*)));
|
2008-07-04 18:46:30 +02:00
|
|
|
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
|
2008-04-20 16:23:37 +02:00
|
|
|
|
|
|
|
setZValue(10000000);
|
|
|
|
setFlag(ItemClipsToShape, true);
|
|
|
|
setFlag(ItemClipsChildrenToShape, false);
|
|
|
|
setFlag(ItemIgnoresTransformations, true);
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
DesktopToolBox::~DesktopToolBox()
|
2008-05-11 23:30:28 +02:00
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
QRectF DesktopToolBox::boundingRect() const
|
2008-04-20 16:23:37 +02:00
|
|
|
{
|
2008-08-28 17:59:03 +02:00
|
|
|
Corner c = corner();
|
|
|
|
qreal width;
|
|
|
|
qreal height;
|
|
|
|
|
|
|
|
if (c == Left || c == Right) {
|
2008-10-12 01:28:20 +02:00
|
|
|
height = size() * 4;
|
2008-08-28 17:59:03 +02:00
|
|
|
} else {
|
2008-10-12 01:28:20 +02:00
|
|
|
height = size() * 2;
|
2008-08-28 17:59:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == Bottom || c == BottomRight || c == BottomLeft) {
|
|
|
|
height = -height;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == Top || c == Bottom) {
|
2008-10-12 01:28:20 +02:00
|
|
|
width = size() * 4;
|
2008-08-28 17:59:03 +02:00
|
|
|
} else {
|
2008-10-12 01:28:20 +02:00
|
|
|
width = size() * 2;
|
2008-08-28 17:59:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c == Right || c == TopRight || c == BottomRight) {
|
|
|
|
width = -width;
|
2008-10-12 01:28:20 +02:00
|
|
|
}
|
2008-08-28 17:59:03 +02:00
|
|
|
|
|
|
|
return QRectF(0, 0, width, height);
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
void DesktopToolBox::paint(QPainter *painter,
|
|
|
|
const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
painter->save();
|
|
|
|
painter->translate(boundingRect().topLeft());
|
|
|
|
|
2008-01-07 05:33:44 +01:00
|
|
|
QColor color1 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Theme::defaultTheme()->colorScheme()).background().color();
|
2008-01-07 05:33:44 +01:00
|
|
|
color1.setAlpha(64);
|
|
|
|
|
|
|
|
QColor color2 = KColorScheme(QPalette::Active, KColorScheme::Window,
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Theme::defaultTheme()->colorScheme()).foreground().color();
|
2008-01-07 05:33:44 +01:00
|
|
|
color2.setAlpha(64);
|
|
|
|
|
2007-11-19 02:19:12 +01:00
|
|
|
QPainterPath p = shape();
|
2008-08-28 17:59:03 +02:00
|
|
|
|
|
|
|
QPoint iconPos;
|
|
|
|
QPointF gradientCenter;
|
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
|
|
|
iconPos = QPoint((int)boundingRect().left() - iconSize().width() + 2, 2);
|
|
|
|
gradientCenter = boundingRect().topLeft();
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
iconPos = QPoint(boundingRect().center().x() - iconSize().width() / 2, 2);
|
|
|
|
gradientCenter = QPoint(boundingRect().center().x(), boundingRect().y());
|
|
|
|
break;
|
|
|
|
case TopLeft:
|
|
|
|
iconPos = QPoint(2, 2);
|
|
|
|
gradientCenter = boundingRect().topLeft();
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
iconPos = QPoint(2, boundingRect().center().y() - iconSize().height() / 2);
|
|
|
|
gradientCenter = QPointF(boundingRect().left(), boundingRect().center().y());
|
|
|
|
break;
|
|
|
|
case Right:
|
2008-10-12 01:28:20 +02:00
|
|
|
iconPos = QPoint((int)boundingRect().left() - iconSize().width() + 2,
|
|
|
|
boundingRect().center().y() - iconSize().height() / 2);
|
2008-08-28 17:59:03 +02:00
|
|
|
gradientCenter = QPointF(boundingRect().left(), boundingRect().center().y());
|
|
|
|
break;
|
|
|
|
case BottomLeft:
|
|
|
|
iconPos = QPoint(2, boundingRect().top() - iconSize().height() - 2);
|
|
|
|
gradientCenter = boundingRect().topLeft();
|
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-10-12 01:28:20 +02:00
|
|
|
iconPos = QPoint(boundingRect().center().x() - iconSize().width() / 2,
|
|
|
|
boundingRect().top() - iconSize().height() - 2);
|
2008-08-28 17:59:03 +02:00
|
|
|
gradientCenter = QPointF(boundingRect().center().x(), boundingRect().top());
|
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
2008-10-12 01:28:20 +02:00
|
|
|
iconPos = QPoint((int)boundingRect().left() - iconSize().width() - 2,
|
|
|
|
(int)boundingRect().top() - iconSize().height() - 2);
|
2008-08-28 17:59:03 +02:00
|
|
|
gradientCenter = boundingRect().topLeft();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRadialGradient gradient(gradientCenter, size() + d->animCircleFrame);
|
|
|
|
gradient.setFocalPoint(gradientCenter);
|
2008-01-07 05:33:44 +01:00
|
|
|
gradient.setColorAt(0, color1);
|
2008-01-07 06:46:53 +01:00
|
|
|
gradient.setColorAt(.87, color1);
|
|
|
|
gradient.setColorAt(.97, color2);
|
2008-01-08 00:01:38 +01:00
|
|
|
color2.setAlpha(0);
|
|
|
|
gradient.setColorAt(1, color2);
|
2007-11-19 02:19:12 +01:00
|
|
|
painter->save();
|
|
|
|
painter->setPen(Qt::NoPen);
|
|
|
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
painter->setBrush(gradient);
|
|
|
|
painter->drawPath(p);
|
|
|
|
painter->restore();
|
2008-01-07 23:52:21 +01:00
|
|
|
|
2008-05-19 02:41:41 +02:00
|
|
|
const qreal progress = d->animHighlightFrame;
|
2008-01-07 23:52:21 +01:00
|
|
|
|
2008-09-30 21:54:04 +02:00
|
|
|
if (qFuzzyCompare(qreal(1.0), progress)) {
|
2008-08-28 17:59:03 +02:00
|
|
|
d->icon.paint(painter, QRect(iconPos, iconSize()));
|
2008-09-30 21:54:04 +02:00
|
|
|
} else if (qFuzzyCompare(qreal(1.0), 1 + progress)) {
|
2008-10-12 01:28:20 +02:00
|
|
|
d->icon.paint(painter, QRect(iconPos, iconSize()),
|
|
|
|
Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
2008-09-30 21:54:04 +02:00
|
|
|
} else {
|
|
|
|
QPixmap disabled = d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off);
|
|
|
|
QPixmap enabled = d->icon.pixmap(iconSize());
|
2008-10-12 01:28:20 +02:00
|
|
|
QPixmap result = PaintUtils::transition(
|
|
|
|
d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off),
|
|
|
|
d->icon.pixmap(iconSize()), progress);
|
2008-09-30 21:54:04 +02:00
|
|
|
painter->drawPixmap(QRect(iconPos, iconSize()), result);
|
2008-01-07 23:52:21 +01:00
|
|
|
}
|
2008-04-14 15:05:49 +02:00
|
|
|
|
|
|
|
painter->restore();
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
QPainterPath DesktopToolBox::shape() const
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
|
|
|
QPainterPath path;
|
2008-05-19 02:41:41 +02:00
|
|
|
int toolSize = size() + (int)d->animCircleFrame;
|
2008-08-28 17:59:03 +02:00
|
|
|
|
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize, boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 180, 90);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case Top:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().center().x() - toolSize,
|
|
|
|
boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 180, 180);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case TopLeft:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
|
|
boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 270, 90);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case Left:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
|
|
boundingRect().center().y() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 270, 180);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case Right:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
|
|
boundingRect().center().y() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 90, 180);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case BottomLeft:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
|
|
boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 0, 90);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().center().x() - toolSize,
|
|
|
|
boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 0, 180);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
2008-10-12 01:28:20 +02:00
|
|
|
path.arcTo(QRectF(boundingRect().left() - toolSize,
|
|
|
|
boundingRect().top() - toolSize,
|
|
|
|
toolSize * 2, toolSize * 2), 90, 90);
|
2008-08-28 17:59:03 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-04-14 15:05:49 +02:00
|
|
|
|
2007-11-19 02:19:12 +01:00
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-05-19 02:41:41 +02:00
|
|
|
if (showing() || d->hovering) {
|
2008-01-08 06:04:11 +01:00
|
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
2008-05-19 02:41:41 +02:00
|
|
|
if (d->animHighlightId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animHighlightId);
|
2008-03-03 20:53:13 +01:00
|
|
|
}
|
2008-05-19 02:41:41 +02:00
|
|
|
d->hovering = true;
|
2008-10-12 01:28:20 +02:00
|
|
|
d->animHighlightId =
|
|
|
|
animdriver->customAnimation(
|
|
|
|
10, 240, Plasma::Animator::EaseInCurve, this, "animateHighlight");
|
2008-03-03 20:53:13 +01:00
|
|
|
|
2008-01-21 16:10:19 +01:00
|
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::showToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-04-14 15:05:49 +02:00
|
|
|
if (showing()) {
|
2008-01-21 16:10:19 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-01-08 06:04:11 +01:00
|
|
|
|
2008-01-05 22:16:35 +01:00
|
|
|
int maxwidth = 0;
|
2008-10-12 01:28:20 +02:00
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
2008-01-05 22:16:35 +01:00
|
|
|
if (!tool->isEnabled()) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-01-08 06:04:11 +01:00
|
|
|
maxwidth = qMax(static_cast<int>(tool->boundingRect().width()), maxwidth);
|
2008-01-05 22:16:35 +01:00
|
|
|
}
|
2008-01-08 06:04:11 +01:00
|
|
|
|
|
|
|
// put tools 5px from icon edge
|
2008-01-07 23:53:52 +01:00
|
|
|
const int iconWidth = 32;
|
2008-08-28 17:59:03 +02:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
|
|
|
x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
|
|
|
|
y = (int)boundingRect().top() + 5;
|
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
x = (int)boundingRect().center().x() - iconWidth;
|
|
|
|
y = (int)boundingRect().top() + iconWidth + 5;
|
|
|
|
break;
|
|
|
|
case TopLeft:
|
|
|
|
x = (int)boundingRect().left() + iconWidth + 5;
|
|
|
|
y = (int)boundingRect().top() + 5;
|
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
x = (int)boundingRect().left() + iconWidth + 5;
|
|
|
|
y = (int)boundingRect().center().y() - iconWidth;
|
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
|
|
|
|
y = (int)boundingRect().center().y() - iconWidth;
|
|
|
|
break;
|
|
|
|
case BottomLeft:
|
|
|
|
x = (int)boundingRect().left() + iconWidth + 5;
|
|
|
|
y = (int)boundingRect().bottom() - 5;
|
|
|
|
break;
|
|
|
|
case Bottom:
|
|
|
|
x = (int)boundingRect().center().x() - iconWidth;
|
|
|
|
y = (int)boundingRect().bottom() - iconWidth - 5;
|
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
|
|
|
x = (int)boundingRect().left() - maxwidth - iconWidth - 5;
|
|
|
|
y = (int)boundingRect().bottom() - iconWidth - 5;
|
|
|
|
break;
|
|
|
|
}
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
2008-04-14 15:05:49 +02:00
|
|
|
if (tool == d->toolBacker) {
|
2008-01-30 04:40:17 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tool->isEnabled()) {
|
|
|
|
if (tool->isVisible()) {
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
2008-10-12 01:28:20 +02:00
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement,
|
|
|
|
toolPosition(height));
|
2008-01-30 04:40:17 +01:00
|
|
|
}
|
2007-12-05 21:22:25 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "let's show and move" << tool << tool->boundingRect();
|
2007-11-19 02:19:12 +01:00
|
|
|
tool->show();
|
2008-04-25 05:11:59 +02:00
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
|
2007-11-19 02:19:12 +01:00
|
|
|
//x += 0;
|
|
|
|
y += static_cast<int>(tool->boundingRect().height()) + 5;
|
|
|
|
}
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
if (!d->toolBacker) {
|
|
|
|
d->toolBacker = new EmptyGraphicsItem(this);
|
2008-01-10 22:05:56 +01:00
|
|
|
}
|
2008-04-14 15:05:49 +02:00
|
|
|
d->toolBacker->setRect(QRectF(QPointF(x, 0), QSizeF(maxwidth, y - 10)));
|
|
|
|
d->toolBacker->show();
|
2008-01-08 06:04:11 +01:00
|
|
|
|
2008-05-19 02:41:41 +02:00
|
|
|
if (d->animCircleId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animCircleId);
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
setShowing(true);
|
2008-01-03 10:43:13 +01:00
|
|
|
// TODO: 10 and 200 shouldn't be hardcoded here. There needs to be a way to
|
|
|
|
// match whatever the time is that moveItem() takes. Same in hoverLeaveEvent().
|
2008-10-12 01:28:20 +02:00
|
|
|
d->animCircleId =
|
|
|
|
animdriver->customAnimation(10, 240, Plasma::Animator::EaseInCurve, this, "animateCircle");
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-10-12 01:28:20 +02:00
|
|
|
//kDebug() << event->pos() << event->scenePos()
|
|
|
|
// << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
2008-05-19 02:41:41 +02:00
|
|
|
if (! d->hovering) {
|
2008-01-08 06:04:11 +01:00
|
|
|
QGraphicsItem::hoverLeaveEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
2008-05-19 02:41:41 +02:00
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
hideToolBox();
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
2008-05-19 02:41:41 +02:00
|
|
|
if (d->animHighlightId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animHighlightId);
|
|
|
|
}
|
|
|
|
d->hovering = false;
|
2008-10-12 01:28:20 +02:00
|
|
|
d->animHighlightId =
|
|
|
|
animdriver->customAnimation(
|
|
|
|
10, 240, Plasma::Animator::EaseOutCurve, this, "animateHighlight");
|
2008-05-19 02:41:41 +02:00
|
|
|
|
2008-01-21 16:10:19 +01:00
|
|
|
QGraphicsItem::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::hideToolBox()
|
2008-01-21 16:10:19 +01:00
|
|
|
{
|
2008-04-14 15:05:49 +02:00
|
|
|
if (!showing()) {
|
2008-01-21 16:10:19 +01:00
|
|
|
return;
|
|
|
|
}
|
2008-01-08 06:04:11 +01:00
|
|
|
|
2008-10-12 01:28:20 +02:00
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
2008-04-14 15:05:49 +02:00
|
|
|
if (tool == d->toolBacker) {
|
2008-01-10 22:05:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
2008-08-28 17:59:03 +02:00
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, toolPosition(height));
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-19 02:41:41 +02:00
|
|
|
if (d->animCircleId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animCircleId);
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
setShowing(false);
|
2008-10-12 01:28:20 +02:00
|
|
|
d->animCircleId =
|
|
|
|
animdriver->customAnimation(10, 240, Plasma::Animator::EaseOutCurve, this, "animateCircle");
|
2008-01-10 22:05:56 +01:00
|
|
|
|
2008-04-14 15:05:49 +02:00
|
|
|
if (d->toolBacker) {
|
|
|
|
d->toolBacker->hide();
|
2008-01-10 22:05:56 +01:00
|
|
|
}
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::animateCircle(qreal progress)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-04-14 15:05:49 +02:00
|
|
|
if (showing()) {
|
2008-05-19 02:41:41 +02:00
|
|
|
d->animCircleFrame = size() * progress;
|
2007-11-19 02:19:12 +01:00
|
|
|
} else {
|
2008-05-19 02:41:41 +02:00
|
|
|
d->animCircleFrame = size() * (1.0 - progress);
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
2008-05-19 02:41:41 +02:00
|
|
|
if (progress >= 1) {
|
|
|
|
d->animCircleId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::animateHighlight(qreal progress)
|
2008-05-19 02:41:41 +02:00
|
|
|
{
|
|
|
|
if (d->hovering) {
|
|
|
|
d->animHighlightFrame = progress;
|
|
|
|
} else {
|
|
|
|
d->animHighlightFrame = 1.0 - progress;
|
|
|
|
}
|
2007-11-19 02:19:12 +01:00
|
|
|
|
|
|
|
if (progress >= 1) {
|
2008-05-19 02:41:41 +02:00
|
|
|
d->animHighlightId = 0;
|
2007-11-19 02:19:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::toolMoved(QGraphicsItem *item)
|
2007-11-19 02:19:12 +01:00
|
|
|
{
|
2008-01-08 02:25:09 +01:00
|
|
|
//kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
|
2008-04-14 15:05:49 +02:00
|
|
|
if (!showing() &&
|
2008-04-13 23:47:47 +02:00
|
|
|
QGraphicsItem::children().indexOf(static_cast<Plasma::Applet*>(item)) != -1) {
|
2007-11-19 02:19:12 +01:00
|
|
|
item->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-24 14:25:56 +02:00
|
|
|
void DesktopToolBox::toggle()
|
2008-05-19 02:41:41 +02:00
|
|
|
{
|
|
|
|
if (showing()) {
|
2008-05-24 14:25:56 +02:00
|
|
|
hideToolBox();
|
2008-05-19 02:41:41 +02:00
|
|
|
} else {
|
2008-05-24 14:25:56 +02:00
|
|
|
showToolBox();
|
2008-05-19 02:41:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-19 02:19:12 +01:00
|
|
|
} // plasma namespace
|
|
|
|
|
2007-12-21 02:14:32 +01:00
|
|
|
#include "desktoptoolbox_p.moc"
|