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>
|
2009-10-07 20:32:15 +02:00
|
|
|
#include <plasma/tooltipcontent.h>
|
|
|
|
#include <plasma/tooltipmanager.h>
|
2008-11-28 18:32:21 +01:00
|
|
|
#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");
|
2009-09-25 15:30:30 +02:00
|
|
|
m_background->setImagePath("widgets/toolbox");
|
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)
|
|
|
|
{
|
2009-07-25 07:47:12 +02:00
|
|
|
if (m_rect == rect) {
|
2009-07-16 15:09:19 +02:00
|
|
|
return;
|
2009-07-25 07:47:12 +02:00
|
|
|
}
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
//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),
|
2009-03-05 23:15:06 +01:00
|
|
|
background(0),
|
2008-11-28 18:32:21 +01:00
|
|
|
containment(0),
|
|
|
|
icon("plasma"),
|
2008-11-04 00:08:39 +01:00
|
|
|
toolBacker(0),
|
|
|
|
animCircleId(0),
|
|
|
|
animHighlightId(0),
|
|
|
|
animCircleFrame(0),
|
|
|
|
animHighlightFrame(0),
|
|
|
|
hovering(0)
|
|
|
|
{}
|
|
|
|
|
2009-03-05 23:15:06 +01:00
|
|
|
void adjustBackgroundBorders()
|
|
|
|
{
|
|
|
|
switch (q->corner()) {
|
|
|
|
case ToolBox::TopRight:
|
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::Top:
|
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::TopLeft:
|
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::Left:
|
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::Right:
|
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::BottomLeft:
|
|
|
|
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::Bottom:
|
|
|
|
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
|
|
|
case ToolBox::BottomRight:
|
|
|
|
default:
|
|
|
|
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
2009-03-24 12:45:53 +01:00
|
|
|
d->background = new Plasma::FrameSvg(this);
|
2009-03-05 23:15:06 +01:00
|
|
|
d->background->setImagePath("widgets/toolbox");
|
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
d->containment = parent;
|
2008-11-04 00:08:39 +01:00
|
|
|
setZValue(10000000);
|
2009-03-02 14:14:58 +01:00
|
|
|
|
2008-11-10 04:53:35 +01:00
|
|
|
setIsMovable(true);
|
2009-07-28 05:19:33 +02:00
|
|
|
updateTheming();
|
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()),
|
2009-07-28 05:19:33 +02:00
|
|
|
this, SLOT(updateTheming()));
|
2009-10-07 20:32:15 +02:00
|
|
|
ToolTipManager::self()->registerWidget(this);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DesktopToolBox::~DesktopToolBox()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
QSize DesktopToolBox::cornerSize() const
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2009-07-28 05:19:33 +02:00
|
|
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
d->adjustBackgroundBorders();
|
2009-03-05 23:15:06 +01:00
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
return QSize(size() + left, size() + bottom);
|
|
|
|
}
|
2009-03-24 21:37:28 +01:00
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
QSize DesktopToolBox::fullWidth() const
|
|
|
|
{
|
|
|
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
d->adjustBackgroundBorders();
|
|
|
|
|
|
|
|
int extraSpace = 0;
|
2009-03-24 21:37:28 +01:00
|
|
|
if (!d->containment->activity().isNull()) {
|
|
|
|
extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
|
|
|
|
}
|
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
return QSize(size() + left + right + extraSpace, size() + bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize DesktopToolBox::fullHeight() const
|
|
|
|
{
|
2009-03-24 21:37:28 +01:00
|
|
|
d->background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
d->adjustBackgroundBorders();
|
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
int extraSpace = 0;
|
|
|
|
if (!d->containment->activity().isNull()) {
|
|
|
|
extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
|
|
|
|
}
|
2009-03-24 21:37:28 +01:00
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
return QSize(size() + left, size() + top + bottom + extraSpace);
|
2009-03-24 21:37:28 +01:00
|
|
|
}
|
|
|
|
|
2009-10-07 20:32:15 +02:00
|
|
|
void DesktopToolBox::toolTipAboutToShow()
|
|
|
|
{
|
|
|
|
if (isToolbar() || showing()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTipContent c(i18n("Tool Box"),
|
|
|
|
i18n("Click to access configuration options and controls or to add more widget to the %1.",
|
|
|
|
containment()->name()),
|
|
|
|
KIcon("plasma"));
|
|
|
|
c.setAutohide(false);
|
|
|
|
ToolTipManager::self()->setContent(this, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::toolTipHidden()
|
|
|
|
{
|
|
|
|
ToolTipManager::self()->clearContent(this);
|
|
|
|
}
|
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
QRectF DesktopToolBox::boundingRect() const
|
2009-03-24 21:37:28 +01:00
|
|
|
{
|
|
|
|
int extraSpace = size();
|
|
|
|
|
2009-03-05 23:15:06 +01:00
|
|
|
d->adjustBackgroundBorders();
|
|
|
|
|
2009-03-06 13:52:21 +01:00
|
|
|
//keep space for the label and a character more
|
2009-03-05 23:15:06 +01:00
|
|
|
if (!d->containment->activity().isNull()) {
|
2009-03-06 13:52:21 +01:00
|
|
|
extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+"x");
|
2009-03-05 23:15:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->background->getMargins(left, top, right, bottom);
|
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
QRectF rect;
|
|
|
|
|
|
|
|
//disable text at corners
|
|
|
|
if (corner() == TopLeft || corner() == TopRight || corner() == BottomLeft || corner() == BottomRight) {
|
|
|
|
rect = QRectF(0, 0, size()+left+right, size()+top+bottom);
|
|
|
|
} else if (corner() == Left || corner() == Right) {
|
|
|
|
rect = QRectF(0, 0, size()+left+right, size()+extraSpace+top+bottom);
|
|
|
|
//top or bottom
|
2009-03-05 23:15:06 +01:00
|
|
|
} else {
|
2009-03-24 21:37:28 +01:00
|
|
|
rect = QRectF(0, 0, size()+extraSpace+left+right, size()+top+bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
2008-11-11 09:12:20 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-07-28 05:19:33 +02:00
|
|
|
void DesktopToolBox::updateTheming()
|
2008-11-11 09:12:20 +01:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2009-06-29 03:22:58 +02:00
|
|
|
QAction *action = qobject_cast<QAction *>(sender());
|
|
|
|
|
2009-09-10 22:31:45 +02:00
|
|
|
if (showing() && (!action || !action->autoRepeat())) {
|
2009-09-10 22:23:07 +02:00
|
|
|
emit toggled();
|
2009-06-29 03:22:58 +02:00
|
|
|
}
|
2009-01-28 14:38:57 +01:00
|
|
|
}
|
|
|
|
|
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;
|
2009-07-28 05:19:33 +02:00
|
|
|
const QRectF rect = boundingRect();
|
2008-11-11 09:12:20 +01:00
|
|
|
const QSize icons = iconSize();
|
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
QString cornerElement;
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
switch (corner()) {
|
|
|
|
case TopLeft:
|
|
|
|
cornerElement = "desktop-northwest";
|
|
|
|
break;
|
|
|
|
case TopRight:
|
|
|
|
cornerElement = "desktop-northeast";
|
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
cornerElement = "desktop-southeast";
|
|
|
|
break;
|
|
|
|
case BottomLeft:
|
|
|
|
cornerElement = "desktop-southwest";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-03-05 23:15:06 +01:00
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
QString activityName;
|
2009-03-05 23:15:06 +01:00
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
QSize textSize;
|
|
|
|
if (cornerElement.isNull()) {
|
|
|
|
activityName = d->containment->activity();
|
|
|
|
textSize = Plasma::Theme::defaultTheme()->fontMetrics().size(Qt::TextSingleLine, activityName+"x");
|
|
|
|
}
|
|
|
|
|
|
|
|
d->adjustBackgroundBorders();
|
2009-03-05 23:15:06 +01:00
|
|
|
|
|
|
|
d->background->resizeFrame(rect.size());
|
2009-03-24 21:37:28 +01:00
|
|
|
|
|
|
|
if (!cornerElement.isNull()) {
|
|
|
|
d->background->paint(painter, rect, cornerElement);
|
|
|
|
} else {
|
|
|
|
d->background->paintFrame(painter, rect.topLeft());
|
|
|
|
}
|
2009-03-05 23:15:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
QRect iconRect;
|
|
|
|
QRect textRect;
|
|
|
|
|
|
|
|
if (corner() == Left || corner() == Right) {
|
|
|
|
Qt::Alignment alignment;
|
|
|
|
|
|
|
|
if (activityName.isNull()) {
|
|
|
|
alignment = Qt::Alignment(Qt::AlignCenter);
|
|
|
|
} else {
|
|
|
|
alignment = Qt::Alignment(Qt::AlignHCenter|Qt::AlignTop);
|
|
|
|
}
|
|
|
|
|
|
|
|
iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
|
|
|
|
|
|
|
|
QRect boundRect(QPoint(d->background->contentsRect().top(),
|
|
|
|
d->background->contentsRect().left()),
|
|
|
|
QSize(d->background->contentsRect().height(),
|
|
|
|
d->background->contentsRect().width()));
|
|
|
|
|
|
|
|
textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, boundRect);
|
2009-03-24 21:37:28 +01:00
|
|
|
textRect.moveTopLeft(textRect.topLeft() + QPoint(rect.top(), rect.left()));
|
2008-12-04 21:36:35 +01:00
|
|
|
} else {
|
2009-03-05 23:15:06 +01:00
|
|
|
Qt::Alignment alignment;
|
|
|
|
|
|
|
|
if (activityName.isNull()) {
|
|
|
|
alignment = Qt::Alignment(Qt::AlignCenter);
|
|
|
|
} else {
|
|
|
|
alignment = Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter);
|
|
|
|
}
|
|
|
|
|
|
|
|
iconRect = QStyle::alignedRect(QApplication::layoutDirection(), alignment, iconSize(), d->background->contentsRect().toRect());
|
|
|
|
|
|
|
|
textRect = QStyle::alignedRect(QApplication::layoutDirection(), Qt::AlignRight|Qt::AlignVCenter, textSize, d->background->contentsRect().toRect());
|
2009-03-24 21:37:28 +01:00
|
|
|
textRect.moveTopLeft(textRect.topLeft() + rect.topLeft().toPoint());
|
2008-12-04 21:36:35 +01:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
iconRect.moveTopLeft(iconRect.topLeft() + rect.topLeft().toPoint());
|
|
|
|
|
2009-03-05 23:15:06 +01:00
|
|
|
|
|
|
|
iconPos = iconRect.topLeft();
|
|
|
|
|
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);
|
|
|
|
}
|
2009-03-05 23:15:06 +01:00
|
|
|
|
2009-03-24 21:37:28 +01:00
|
|
|
if (!cornerElement.isNull() || activityName.isNull()) {
|
2009-03-05 23:15:06 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor textColor = Plasma::Theme::defaultTheme()->color(Theme::TextColor);
|
|
|
|
QColor shadowColor;
|
|
|
|
QPoint shadowOffset;
|
|
|
|
|
|
|
|
if (qGray(textColor.rgb()) > 192) {
|
|
|
|
shadowColor = Qt::black;
|
|
|
|
shadowOffset = QPoint(1,1);
|
|
|
|
} else {
|
|
|
|
shadowColor = Qt::white;
|
|
|
|
shadowOffset = QPoint(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap shadowText = Plasma::PaintUtils::shadowText(activityName, textColor, shadowColor, shadowOffset);
|
|
|
|
|
|
|
|
painter->save();
|
|
|
|
if (corner() == Left || corner() == Right) {
|
|
|
|
painter->rotate(90);
|
|
|
|
painter->translate(textRect.left(), -textRect.top()-textRect.height());
|
|
|
|
painter->drawPixmap(QPoint(0,0), shadowText);
|
|
|
|
} else {
|
|
|
|
painter->drawPixmap(textRect.topLeft(), shadowText);
|
|
|
|
}
|
|
|
|
|
|
|
|
painter->restore();
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QPainterPath DesktopToolBox::shape() const
|
|
|
|
{
|
2009-07-28 05:19:33 +02:00
|
|
|
const QRectF rect = boundingRect();
|
2008-11-11 09:12:20 +01:00
|
|
|
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()
|
|
|
|
{
|
2009-03-02 14:14:58 +01:00
|
|
|
setFlag(ItemIgnoresTransformations, isToolbar());
|
|
|
|
|
2009-07-25 07:47:12 +02:00
|
|
|
if (showing() && !isToolbar()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
return;
|
2009-07-25 07:47:12 +02:00
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2009-02-26 22:21:05 +01:00
|
|
|
//y += 5;
|
|
|
|
|
2008-11-28 18:32:21 +01:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-02-26 22:21:05 +01:00
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->toolBacker->getContentsMargins(left, top, right, bottom);
|
|
|
|
|
|
|
|
// the rect the tools back should have
|
|
|
|
QRectF backerRect = QRectF(QPointF(x, startY), QSizeF(maxWidth + left+right, y - startY + top + bottom));
|
|
|
|
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
d->toolBacker->setIsToolbar(isToolbar());
|
|
|
|
|
2009-02-26 22:21:05 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2009-02-26 22:21:05 +01:00
|
|
|
x = backerRect.x() + left;
|
|
|
|
y = backerRect.y() + top;
|
2008-11-19 06:35:34 +01:00
|
|
|
|
|
|
|
// 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-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"
|