2008-11-04 00:08:39 +01: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 "desktoptoolbox_p.h"
|
|
|
|
|
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QRadialGradient>
|
|
|
|
#include <QGraphicsView>
|
2008-11-28 18:32:21 +01:00
|
|
|
#include <QAction>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-04 03:39:56 +01:00
|
|
|
#include <kcolorscheme.h>
|
|
|
|
#include <kdebug.h>
|
2009-02-15 17:35:52 +01:00
|
|
|
#include <kiconloader.h>
|
2008-11-04 03:39:56 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <plasma/theme.h>
|
|
|
|
#include <plasma/paintutils.h>
|
2008-11-28 18:32:21 +01:00
|
|
|
#include <plasma/framesvg.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include <plasma/applet.h>
|
2008-11-28 18:32:21 +01:00
|
|
|
#include <plasma/containment.h>
|
|
|
|
#include <plasma/widgets/iconwidget.h>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class EmptyGraphicsItem : public QGraphicsItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EmptyGraphicsItem(QGraphicsItem *parent)
|
2008-12-01 13:40:08 +01:00
|
|
|
: QGraphicsItem(parent),
|
|
|
|
m_toolbar(false)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
setAcceptsHoverEvents(true);
|
2008-11-28 18:32:21 +01:00
|
|
|
m_background = new Plasma::FrameSvg();
|
2008-12-01 13:40:08 +01:00
|
|
|
m_toolbarBackground = new Plasma::FrameSvg();
|
|
|
|
|
|
|
|
m_toolbarBackground->setImagePath("widgets/background");
|
2008-11-28 18:32:21 +01:00
|
|
|
m_background->setImagePath("widgets/translucentbackground");
|
2008-12-01 13:40:08 +01:00
|
|
|
|
|
|
|
m_toolbarBackground->setEnabledBorders(FrameSvg::LeftBorder|FrameSvg::RightBorder|FrameSvg::BottomBorder);
|
|
|
|
m_background->setEnabledBorders(FrameSvg::AllBorders);
|
2008-11-28 18:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~EmptyGraphicsItem()
|
|
|
|
{
|
|
|
|
delete m_background;
|
2008-12-01 13:40:08 +01:00
|
|
|
delete m_toolbarBackground;
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QRectF boundingRect() const
|
|
|
|
{
|
|
|
|
return QRectF(QPointF(0, 0), m_rect.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF rect() const
|
|
|
|
{
|
|
|
|
return m_rect;
|
|
|
|
}
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
void setIsToolbar(bool toolbar)
|
|
|
|
{
|
|
|
|
m_toolbar = toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isToolbar() const
|
|
|
|
{
|
|
|
|
return m_toolbar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void getContentsMargins(qreal &left, qreal &top, qreal &right, qreal &bottom)
|
|
|
|
{
|
|
|
|
if (m_toolbar) {
|
|
|
|
m_toolbarBackground->getMargins(left, top, right, bottom);
|
|
|
|
} else {
|
|
|
|
m_background->getMargins(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF contentsRect() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
if (m_toolbar) {
|
|
|
|
m_toolbarBackground->getMargins(left, top, right, bottom);
|
|
|
|
} else {
|
|
|
|
m_background->getMargins(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
return m_rect.adjusted(left, top, -right, -bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRect(const QRectF &rect)
|
|
|
|
{
|
|
|
|
//kDebug() << "setting rect to" << rect;
|
2008-11-04 00:08:39 +01:00
|
|
|
prepareGeometryChange();
|
2008-12-01 13:40:08 +01:00
|
|
|
m_rect = rect;
|
2008-11-28 18:32:21 +01:00
|
|
|
setPos(m_rect.topLeft());
|
2008-12-01 13:40:08 +01:00
|
|
|
if (m_toolbar) {
|
|
|
|
m_toolbarBackground->resizeFrame(m_rect.size());
|
|
|
|
} else {
|
|
|
|
m_background->resizeFrame(m_rect.size());
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
|
|
|
{
|
2008-12-01 13:40:08 +01:00
|
|
|
if (m_toolbar) {
|
|
|
|
m_toolbarBackground->paintFrame(p);
|
|
|
|
} else {
|
|
|
|
m_background->paintFrame(p);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2008-12-01 13:40:08 +01:00
|
|
|
bool m_toolbar;
|
2008-11-04 00:08:39 +01:00
|
|
|
QRectF m_rect;
|
2008-12-01 13:40:08 +01:00
|
|
|
Plasma::FrameSvg *m_toolbarBackground;
|
2008-11-28 18:32:21 +01:00
|
|
|
Plasma::FrameSvg *m_background;
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// used with QGrahphicsItem::setData
|
|
|
|
static const int ToolName = 7001;
|
|
|
|
|
|
|
|
class DesktopToolBoxPrivate
|
|
|
|
{
|
|
|
|
public:
|
2008-11-28 18:32:21 +01:00
|
|
|
DesktopToolBoxPrivate(DesktopToolBox *toolbox)
|
|
|
|
: q(toolbox),
|
|
|
|
containment(0),
|
|
|
|
icon("plasma"),
|
2008-11-04 00:08:39 +01:00
|
|
|
toolBacker(0),
|
|
|
|
animCircleId(0),
|
|
|
|
animHighlightId(0),
|
|
|
|
animCircleFrame(0),
|
|
|
|
animHighlightFrame(0),
|
|
|
|
hovering(0)
|
|
|
|
{}
|
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
|
|
|
|
DesktopToolBox *q;
|
2008-12-04 21:36:35 +01:00
|
|
|
Plasma::FrameSvg *background;
|
2008-11-28 18:32:21 +01:00
|
|
|
Containment *containment;
|
2008-11-04 00:08:39 +01:00
|
|
|
KIcon icon;
|
|
|
|
EmptyGraphicsItem *toolBacker;
|
|
|
|
int animCircleId;
|
|
|
|
int animHighlightId;
|
|
|
|
qreal animCircleFrame;
|
|
|
|
qreal animHighlightFrame;
|
|
|
|
QRect shapeRect;
|
2008-11-11 09:12:20 +01:00
|
|
|
QColor fgColor;
|
|
|
|
QColor bgColor;
|
2008-11-04 00:08:39 +01:00
|
|
|
bool hovering : 1;
|
|
|
|
};
|
|
|
|
|
2008-11-14 08:28:02 +01:00
|
|
|
DesktopToolBox::DesktopToolBox(Containment *parent)
|
2008-11-04 00:08:39 +01:00
|
|
|
: ToolBox(parent),
|
2008-11-28 18:32:21 +01:00
|
|
|
d(new DesktopToolBoxPrivate(this))
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
d->containment = parent;
|
2008-11-04 00:08:39 +01:00
|
|
|
setZValue(10000000);
|
|
|
|
setFlag(ItemClipsChildrenToShape, false);
|
|
|
|
setFlag(ItemIgnoresTransformations, true);
|
2008-11-10 04:53:35 +01:00
|
|
|
setIsMovable(true);
|
2008-11-11 09:12:20 +01:00
|
|
|
assignColors();
|
2008-11-18 01:12:05 +01:00
|
|
|
|
2008-12-04 21:36:35 +01:00
|
|
|
d->background = new Plasma::FrameSvg();
|
2009-01-28 22:07:38 +01:00
|
|
|
d->background->setImagePath("widgets/toolbox");
|
2008-12-04 21:36:35 +01:00
|
|
|
|
2008-11-18 01:12:05 +01:00
|
|
|
connect(Plasma::Animator::self(), SIGNAL(movementFinished(QGraphicsItem*)),
|
|
|
|
this, SLOT(toolMoved(QGraphicsItem*)));
|
|
|
|
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
|
|
|
|
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
|
|
|
|
this, SLOT(assignColors()));
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopToolBox::~DesktopToolBox()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF DesktopToolBox::boundingRect() const
|
|
|
|
{
|
2008-11-11 09:12:20 +01:00
|
|
|
return QRectF(0, 0, size(), size());
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-11 09:12:20 +01:00
|
|
|
void DesktopToolBox::assignColors()
|
|
|
|
{
|
|
|
|
d->bgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
|
|
|
|
d->fgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2009-01-28 14:38:57 +01:00
|
|
|
void DesktopToolBox::toolTriggered(bool)
|
|
|
|
{
|
|
|
|
hideToolBox();
|
|
|
|
}
|
|
|
|
|
2008-11-11 09:12:20 +01:00
|
|
|
void DesktopToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
|
|
|
|
2008-12-03 23:44:16 +01:00
|
|
|
if (isToolbar()){
|
2008-11-28 18:32:21 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
QPainterPath p = shape();
|
|
|
|
|
|
|
|
QPoint iconPos;
|
2009-01-28 22:07:38 +01:00
|
|
|
QRect backgroundRect;
|
2008-11-11 09:12:20 +01:00
|
|
|
const QRectF rect = boundingRect();
|
|
|
|
const QSize icons = iconSize();
|
2008-12-04 21:36:35 +01:00
|
|
|
bool atCorner;
|
2009-01-28 22:07:38 +01:00
|
|
|
QString cornerElement;
|
2008-11-11 09:12:20 +01:00
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint((int)rect.right() - icons.width() + 2, 2);
|
2009-01-28 22:07:38 +01:00
|
|
|
cornerElement = "desktop-northeast";
|
|
|
|
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
|
|
|
backgroundRect.moveTopRight(rect.topRight().toPoint());
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Top:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint(rect.center().x() - icons.width() / 2, 2);
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = false;
|
|
|
|
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case TopLeft:
|
|
|
|
iconPos = QPoint(2, 2);
|
2009-01-28 22:07:38 +01:00
|
|
|
cornerElement = "desktop-northwest";
|
|
|
|
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
|
|
|
backgroundRect.moveTopLeft(rect.topLeft().toPoint());
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Left:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint(2, rect.center().y() - icons.height() / 2);
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = false;
|
|
|
|
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Right:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
|
|
|
rect.center().y() - icons.height() / 2);
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = false;
|
|
|
|
d->background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case BottomLeft:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint(2, rect.bottom() - icons.height() - 2);
|
2009-01-28 22:07:38 +01:00
|
|
|
cornerElement = "desktop-southwest";
|
|
|
|
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
|
|
|
backgroundRect.moveBottomLeft(rect.bottomLeft().toPoint());
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Bottom:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint(rect.center().x() - icons.width() / 2,
|
|
|
|
rect.bottom() - icons.height() - 2);
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = false;
|
|
|
|
d->background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
2008-11-11 09:12:20 +01:00
|
|
|
iconPos = QPoint((int)rect.right() - icons.width() + 2,
|
|
|
|
(int)rect.bottom() - icons.height() - 2);
|
2009-01-28 22:07:38 +01:00
|
|
|
cornerElement = "desktop-southeast";
|
|
|
|
backgroundRect = d->background->elementRect(cornerElement).toRect();
|
|
|
|
backgroundRect.moveBottomRight(rect.bottomRight().toPoint());
|
2008-12-04 21:36:35 +01:00
|
|
|
atCorner = true;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-12-04 21:36:35 +01:00
|
|
|
if (atCorner) {
|
2009-01-28 22:07:38 +01:00
|
|
|
d->background->paint(painter, backgroundRect, cornerElement);
|
2008-12-04 21:36:35 +01:00
|
|
|
} else {
|
|
|
|
d->background->resizeFrame(rect.size());
|
|
|
|
d->background->paintFrame(painter);
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
const qreal progress = d->animHighlightFrame;
|
|
|
|
|
|
|
|
if (qFuzzyCompare(qreal(1.0), progress)) {
|
|
|
|
d->icon.paint(painter, QRect(iconPos, iconSize()));
|
|
|
|
} else if (qFuzzyCompare(qreal(1.0), 1 + progress)) {
|
|
|
|
d->icon.paint(painter, QRect(iconPos, iconSize()),
|
|
|
|
Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
|
|
|
|
} else {
|
|
|
|
QPixmap disabled = d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off);
|
|
|
|
QPixmap enabled = d->icon.pixmap(iconSize());
|
|
|
|
QPixmap result = PaintUtils::transition(
|
|
|
|
d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off),
|
|
|
|
d->icon.pixmap(iconSize()), progress);
|
|
|
|
painter->drawPixmap(QRect(iconPos, iconSize()), result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath DesktopToolBox::shape() const
|
|
|
|
{
|
2008-11-11 09:12:20 +01:00
|
|
|
const QRectF rect = boundingRect();
|
|
|
|
const int w = rect.width();
|
|
|
|
const int h = rect.height();
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2008-11-11 09:12:20 +01:00
|
|
|
QPainterPath path;
|
2008-11-04 00:08:39 +01:00
|
|
|
switch (corner()) {
|
2008-11-11 09:12:20 +01:00
|
|
|
case BottomLeft:
|
|
|
|
path.moveTo(rect.bottomLeft());
|
|
|
|
path.arcTo(QRectF(rect.left() - w, rect.top(), w * 2, h * 2), 0, 90);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
2008-11-11 09:12:20 +01:00
|
|
|
case BottomRight:
|
|
|
|
path.moveTo(rect.bottomRight());
|
|
|
|
path.arcTo(QRectF(rect.left(), rect.top(), w * 2, h * 2), 90, 90);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
2008-11-11 09:12:20 +01:00
|
|
|
case TopRight:
|
|
|
|
path.moveTo(rect.topRight());
|
|
|
|
path.arcTo(QRectF(rect.left(), rect.top() - h, w * 2, h * 2), 180, 90);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
2008-11-11 09:12:20 +01:00
|
|
|
case TopLeft:
|
|
|
|
path.arcTo(QRectF(rect.left() - w, rect.top() - h, w * 2, h * 2), 270, 90);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
default:
|
2008-11-11 09:12:20 +01:00
|
|
|
path.addRect(rect);
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
if (showing() || d->hovering) {
|
|
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
if (d->animHighlightId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animHighlightId);
|
|
|
|
}
|
|
|
|
d->hovering = true;
|
|
|
|
d->animHighlightId =
|
|
|
|
animdriver->customAnimation(
|
|
|
|
10, 240, Plasma::Animator::EaseInCurve, this, "animateHighlight");
|
|
|
|
|
|
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::showToolBox()
|
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
if (showing() && !isToolbar()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// put tools 5px from icon edge
|
2009-02-15 17:35:52 +01:00
|
|
|
const int iconWidth = KIconLoader::SizeMedium;
|
2008-11-04 00:08:39 +01:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
2008-11-19 22:18:12 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5;
|
2008-11-14 08:54:49 +01:00
|
|
|
y = (int)boundingRect().top() + 10;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Top:
|
|
|
|
x = (int)boundingRect().center().x() - iconWidth;
|
2008-11-14 08:54:49 +01:00
|
|
|
y = (int)boundingRect().top() + iconWidth + 10;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case TopLeft:
|
|
|
|
x = (int)boundingRect().left() + iconWidth + 5;
|
2008-11-14 08:54:49 +01:00
|
|
|
y = (int)boundingRect().top() + 10;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Left:
|
|
|
|
x = (int)boundingRect().left() + iconWidth + 5;
|
|
|
|
y = (int)boundingRect().center().y() - iconWidth;
|
|
|
|
break;
|
|
|
|
case Right:
|
2008-11-19 22:18:12 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5;
|
2008-11-04 00:08:39 +01:00
|
|
|
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:
|
2008-11-19 22:18:12 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5;
|
2008-11-04 00:08:39 +01:00
|
|
|
y = (int)boundingRect().bottom() - iconWidth - 5;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-14 08:54:49 +01:00
|
|
|
|
|
|
|
int startY = y;
|
|
|
|
|
2008-11-19 06:35:34 +01:00
|
|
|
// find our theoretical X and Y end coordinates
|
2008-11-19 22:18:12 +01:00
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
int maxWidth = 0;
|
|
|
|
int maxHeight = 0;
|
|
|
|
int totalWidth = 0;
|
|
|
|
|
2008-11-19 06:35:34 +01:00
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
|
|
|
if (tool == d->toolBacker) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-11-29 14:06:12 +01:00
|
|
|
Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
|
2008-11-19 06:35:34 +01:00
|
|
|
if (tool->isEnabled()) {
|
2008-12-18 13:32:06 +01:00
|
|
|
tool->show();
|
2008-11-19 06:35:34 +01:00
|
|
|
//kDebug() << tool << "is enabled";
|
|
|
|
y += 5;
|
2008-11-28 18:32:21 +01:00
|
|
|
QSize toolSize = tool->boundingRect().size().toSize();
|
|
|
|
totalWidth += toolSize.width() + 5;
|
|
|
|
|
|
|
|
maxWidth = qMax(toolSize.width(), maxWidth);
|
|
|
|
maxHeight = qMax(toolSize.height(), maxHeight);
|
2008-11-19 06:35:34 +01:00
|
|
|
y += static_cast<int>(tool->boundingRect().height());
|
|
|
|
}
|
2009-02-22 21:18:08 +01:00
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
if (viewTransform().m11() != Plasma::scalingFactor(Plasma::OverviewZoom) &&
|
|
|
|
(viewTransform().m11() == Plasma::scalingFactor(Plasma::DesktopZoom) ||
|
|
|
|
icon->action() == d->containment->action("add sibling containment") ||
|
|
|
|
icon->action() == d->containment->action("add widgets"))) {
|
|
|
|
icon->setText(icon->action()->text());
|
|
|
|
} else {
|
|
|
|
icon->setText(QString());
|
|
|
|
}
|
|
|
|
}
|
2008-11-19 06:35:34 +01:00
|
|
|
}
|
|
|
|
|
2008-11-19 22:18:12 +01:00
|
|
|
if (corner() == TopRight || corner() == Right || corner() == BottomRight) {
|
2008-11-28 18:32:21 +01:00
|
|
|
x -= maxWidth;
|
2008-11-19 22:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
y += 5;
|
2008-11-19 06:35:34 +01:00
|
|
|
// the rect the tools back should have
|
2008-11-28 18:32:21 +01:00
|
|
|
QRectF backerRect = QRectF(QPointF(x, startY), QSizeF(maxWidth + 10, y - startY));
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
if (!d->toolBacker) {
|
|
|
|
d->toolBacker = new EmptyGraphicsItem(this);
|
2008-12-17 01:51:30 +01:00
|
|
|
d->toolBacker->setZValue(zValue() + 1);
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
d->toolBacker->setIsToolbar(isToolbar());
|
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
QPointF topRight;
|
|
|
|
|
|
|
|
//could that cast ever fail?
|
|
|
|
if (d->containment) {
|
2008-12-03 23:44:16 +01:00
|
|
|
topRight = viewTransform().map(mapFromParent(d->containment->boundingRect().bottomRight()));
|
2008-11-28 18:32:21 +01:00
|
|
|
} else {
|
|
|
|
topRight = boundingRect().topRight();
|
|
|
|
}
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->toolBacker->getContentsMargins(left, top, right, bottom);
|
|
|
|
x -= left;
|
|
|
|
|
|
|
|
backerRect.setSize(QSize(totalWidth+left+right, maxHeight+top+bottom));
|
2008-11-28 18:32:21 +01:00
|
|
|
backerRect.moveTopRight(topRight);
|
2008-12-01 13:40:08 +01:00
|
|
|
} else {
|
|
|
|
//kDebug() << "starting at" << x << startY;
|
|
|
|
|
|
|
|
// now check that is actually fits within the parent's boundaries
|
|
|
|
backerRect = mapToParent(backerRect).boundingRect();
|
|
|
|
QSizeF parentSize = parentWidget()->size();
|
|
|
|
if (backerRect.x() < 5) {
|
|
|
|
backerRect.moveLeft(5);
|
|
|
|
} else if (backerRect.right() > parentSize.width() - 5) {
|
|
|
|
backerRect.moveRight(parentSize.width() - 5);
|
|
|
|
}
|
2008-11-19 06:35:34 +01:00
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
if (backerRect.y() < 5) {
|
|
|
|
backerRect.moveTop(5);
|
|
|
|
} else if (backerRect.bottom() > parentSize.height() - 5) {
|
|
|
|
backerRect.moveBottom(parentSize.height() - 5);
|
|
|
|
}
|
2008-11-19 06:35:34 +01:00
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
// re-map our starting points back to our coordinate system
|
|
|
|
backerRect = mapFromParent(backerRect).boundingRect();
|
|
|
|
}
|
2008-11-19 06:35:34 +01:00
|
|
|
x = backerRect.x() + 5;
|
|
|
|
y = backerRect.y();
|
|
|
|
|
|
|
|
// now move the items
|
2008-11-04 00:08:39 +01:00
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
|
|
|
if (tool == d->toolBacker) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-02-14 18:32:55 +01:00
|
|
|
Plasma::IconWidget *icon = qgraphicsitem_cast<Plasma::IconWidget *>(tool);
|
2009-02-22 21:18:08 +01:00
|
|
|
const QSize iconSizeHint = icon->sizeFromIconSize(KIconLoader::SizeSmallMedium).toSize();
|
|
|
|
|
|
|
|
//force max size if we aren't zooming
|
|
|
|
if (viewTransform().m11() == 1) {
|
|
|
|
icon->resize(maxWidth, iconSizeHint.height());
|
|
|
|
} else {
|
|
|
|
icon->resize(iconSizeHint);
|
|
|
|
}
|
2009-02-14 18:32:55 +01:00
|
|
|
|
2008-11-18 01:43:11 +01:00
|
|
|
if (tool->isEnabled()) {
|
2008-11-28 18:32:21 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
//kDebug() << tool << "is enabled";
|
|
|
|
x += 5;
|
|
|
|
//kDebug() << "let's show and move" << tool << tool->boundingRect();
|
|
|
|
tool->show();
|
2008-12-18 16:48:01 +01:00
|
|
|
tool->setPos(QPoint(x, y));
|
2008-11-28 18:32:21 +01:00
|
|
|
x += static_cast<int>(tool->boundingRect().width());
|
|
|
|
} else {
|
|
|
|
//kDebug() << tool << "is enabled";
|
|
|
|
y += 5;
|
|
|
|
//kDebug() << "let's show and move" << tool << tool->boundingRect();
|
|
|
|
tool->show();
|
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideInMovement, QPoint(x, y));
|
|
|
|
//x += 0;
|
|
|
|
y += static_cast<int>(tool->boundingRect().height());
|
|
|
|
}
|
2008-11-18 01:43:11 +01:00
|
|
|
} else if (tool->isVisible()) {
|
|
|
|
// disabled, but visible, so hide it!
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
2008-12-18 16:48:01 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
tool->hide();
|
|
|
|
} else {
|
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, toolPosition(height));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-14 08:54:49 +01:00
|
|
|
|
2008-11-19 06:35:34 +01:00
|
|
|
d->toolBacker->setRect(backerRect);
|
2008-11-04 00:08:39 +01:00
|
|
|
d->toolBacker->show();
|
|
|
|
|
|
|
|
if (d->animCircleId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animCircleId);
|
|
|
|
}
|
|
|
|
|
|
|
|
setShowing(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
//kDebug() << event->pos() << event->scenePos()
|
|
|
|
// << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
2009-01-28 14:38:57 +01:00
|
|
|
if (!d->hovering || showing() || isToolbar()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
QGraphicsItem::hoverLeaveEvent(event);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
if (d->animHighlightId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animHighlightId);
|
|
|
|
}
|
|
|
|
d->hovering = false;
|
|
|
|
d->animHighlightId =
|
|
|
|
animdriver->customAnimation(
|
|
|
|
10, 240, Plasma::Animator::EaseOutCurve, this, "animateHighlight");
|
|
|
|
|
|
|
|
QGraphicsItem::hoverLeaveEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::hideToolBox()
|
|
|
|
{
|
|
|
|
if (!showing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
|
|
|
foreach (QGraphicsItem *tool, QGraphicsItem::children()) {
|
|
|
|
if (tool == d->toolBacker) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int height = static_cast<int>(tool->boundingRect().height());
|
2008-12-18 16:48:01 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
tool->setPos(toolPosition(height));
|
|
|
|
tool->hide();
|
|
|
|
} else {
|
|
|
|
animdriver->moveItem(tool, Plasma::Animator::SlideOutMovement, toolPosition(height));
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->animCircleId) {
|
|
|
|
animdriver->stopCustomAnimation(d->animCircleId);
|
|
|
|
}
|
|
|
|
|
|
|
|
setShowing(false);
|
|
|
|
|
|
|
|
if (d->toolBacker) {
|
|
|
|
d->toolBacker->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::animateHighlight(qreal progress)
|
|
|
|
{
|
|
|
|
if (d->hovering) {
|
|
|
|
d->animHighlightFrame = progress;
|
|
|
|
} else {
|
|
|
|
d->animHighlightFrame = 1.0 - progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (progress >= 1) {
|
|
|
|
d->animHighlightId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::toolMoved(QGraphicsItem *item)
|
|
|
|
{
|
|
|
|
//kDebug() << "geometry is now " << static_cast<Plasma::Widget*>(item)->geometry();
|
|
|
|
if (!showing() &&
|
|
|
|
QGraphicsItem::children().indexOf(static_cast<Plasma::Applet*>(item)) != -1) {
|
|
|
|
item->hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::toggle()
|
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
if (showing()) {
|
|
|
|
hideToolBox();
|
|
|
|
} else {
|
|
|
|
showToolBox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // plasma namespace
|
|
|
|
|
|
|
|
#include "desktoptoolbox_p.moc"
|