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"
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
#include <QAction>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsSceneHoverEvent>
|
|
|
|
#include <QPainter>
|
2010-01-04 07:41:43 +01:00
|
|
|
#include <QGraphicsLinearLayout>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QGraphicsView>
|
|
|
|
|
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
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
#include <plasma/animations/animation.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>
|
2010-01-04 07:41:43 +01:00
|
|
|
#include <plasma/framesvg.h>
|
|
|
|
#include <plasma/paintutils.h>
|
|
|
|
#include <plasma/theme.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
|
|
|
|
{
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
class EmptyGraphicsItem : public QGraphicsWidget
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EmptyGraphicsItem(QGraphicsItem *parent)
|
2010-01-04 07:41:43 +01:00
|
|
|
: QGraphicsWidget(parent),
|
|
|
|
m_toolbar(true)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
setAcceptsHoverEvents(true);
|
2010-01-04 07:41:43 +01:00
|
|
|
m_layout = new QGraphicsLinearLayout(this);
|
|
|
|
m_layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_layout->setSpacing(0);
|
|
|
|
m_background = new Plasma::FrameSvg(this);
|
|
|
|
setIsToolbar(false);
|
2008-11-28 18:32:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
~EmptyGraphicsItem()
|
|
|
|
{
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
void setIsToolbar(bool toolbar)
|
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
if (m_toolbar == toolbar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
m_toolbar = toolbar;
|
2010-01-04 07:41:43 +01:00
|
|
|
if (m_toolbar) {
|
|
|
|
m_background->setImagePath("widgets/toolbox");
|
|
|
|
m_background->setEnabledBorders(FrameSvg::LeftBorder|FrameSvg::RightBorder|FrameSvg::BottomBorder);
|
|
|
|
m_layout->setOrientation(Qt::Horizontal);
|
|
|
|
} else {
|
|
|
|
m_background->setImagePath("widgets/background");
|
|
|
|
m_background->setEnabledBorders(FrameSvg::AllBorders);
|
|
|
|
m_layout->setOrientation(Qt::Vertical);
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
m_background->getMargins(left, top, right, bottom);
|
|
|
|
setContentsMargins(left, top, right, bottom);
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool isToolbar() const
|
|
|
|
{
|
|
|
|
return m_toolbar;
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
void paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
|
2008-12-01 13:40:08 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
m_background->paintFrame(p);
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
void clearLayout()
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
while (m_layout->count()) {
|
|
|
|
m_layout->removeAt(0);
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
void addToLayout(QGraphicsWidget *widget)
|
2008-12-01 13:40:08 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
m_layout->addItem(widget);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
protected:
|
|
|
|
void resizeEvent(QGraphicsSceneResizeEvent *)
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
2010-01-04 07:41:43 +01:00
|
|
|
m_background->resizeFrame(size());
|
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;
|
2010-01-04 07:41:43 +01:00
|
|
|
QGraphicsLinearLayout *m_layout;
|
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),
|
|
|
|
animHighlightId(0),
|
|
|
|
animCircleFrame(0),
|
|
|
|
animHighlightFrame(0),
|
|
|
|
hovering(0)
|
|
|
|
{}
|
|
|
|
|
2009-03-05 23:15:06 +01:00
|
|
|
void adjustBackgroundBorders()
|
|
|
|
{
|
|
|
|
switch (q->corner()) {
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::TopRight:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Top:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::TopLeft:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Left:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Right:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::BottomBorder|FrameSvg::TopBorder|FrameSvg::LeftBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::BottomLeft:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::Bottom:
|
2009-03-05 23:15:06 +01:00
|
|
|
background->setEnabledBorders(FrameSvg::TopBorder|FrameSvg::LeftBorder|FrameSvg::RightBorder);
|
|
|
|
break;
|
2009-10-20 16:14:53 +02:00
|
|
|
case InternalToolBox::BottomRight:
|
2009-03-05 23:15:06 +01:00
|
|
|
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 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)
|
2009-10-20 16:14:53 +02:00
|
|
|
: InternalToolBox(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(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()) {
|
2009-10-13 14:40:13 +02:00
|
|
|
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 + 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()) {
|
2009-10-13 14:40:13 +02:00
|
|
|
extraSpace = Plasma::Theme::defaultTheme()->fontMetrics().width(d->containment->activity()+'x');
|
2009-07-28 05:19:33 +02:00
|
|
|
}
|
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()
|
|
|
|
{
|
2009-10-20 16:14:53 +02:00
|
|
|
if (isToolbar() || isShowing()) {
|
2009-10-07 20:32:15 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolTipContent c(i18n("Tool Box"),
|
2009-10-09 22:07:44 +02:00
|
|
|
i18n("Click to access configuration options and controls, or to add more widgets to the %1.",
|
2009-10-07 20:32:15 +02:00
|
|
|
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-10-13 14:40:13 +02: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-10-20 16:14:53 +02:00
|
|
|
if (isShowing() && (!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();
|
2009-10-13 14:40:13 +02:00
|
|
|
textSize = Plasma::Theme::defaultTheme()->fontMetrics().size(Qt::TextSingleLine, activityName+'x');
|
2009-03-24 21:37:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-10-20 16:14:53 +02:00
|
|
|
if (isShowing() || d->hovering) {
|
2008-11-04 00:08:39 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
QGraphicsWidget *DesktopToolBox::toolParent()
|
|
|
|
{
|
|
|
|
if (!d->toolBacker) {
|
|
|
|
d->toolBacker = new EmptyGraphicsItem(this);
|
|
|
|
d->toolBacker->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
return d->toolBacker;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
void DesktopToolBox::showToolBox()
|
|
|
|
{
|
2009-03-02 14:14:58 +01:00
|
|
|
setFlag(ItemIgnoresTransformations, isToolbar());
|
|
|
|
|
2009-10-20 16:14:53 +02:00
|
|
|
if (isShowing() && !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
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
if (!d->toolBacker) {
|
|
|
|
d->toolBacker = new EmptyGraphicsItem(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
d->toolBacker->setZValue(zValue() + 1);
|
|
|
|
d->toolBacker->clearLayout();
|
|
|
|
d->toolBacker->setIsToolbar(isToolbar());
|
|
|
|
|
|
|
|
QMap<ToolType, IconWidget *> t = tools();
|
|
|
|
QMapIterator<ToolType, IconWidget *> it(t);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
|
|
|
IconWidget *icon = it.value();
|
|
|
|
//kDebug() << "showing off" << it.key() << icon->text();
|
|
|
|
if (icon->isEnabled()) {
|
|
|
|
icon->show();
|
|
|
|
d->toolBacker->addToLayout(icon);
|
|
|
|
} else {
|
|
|
|
icon->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
d->toolBacker->getContentsMargins(&left, &top, &right, &bottom);
|
|
|
|
d->toolBacker->adjustSize();
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2009-02-15 17:35:52 +01:00
|
|
|
const int iconWidth = KIconLoader::SizeMedium;
|
2008-11-04 00:08:39 +01:00
|
|
|
switch (corner()) {
|
|
|
|
case TopRight:
|
2010-01-04 07:41:43 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5 - d->toolBacker->size().width();
|
2008-11-14 08:54:49 +01:00
|
|
|
y = (int)boundingRect().top() + 10;
|
2008-11-04 00:08:39 +01:00
|
|
|
break;
|
|
|
|
case Top:
|
2010-01-04 07:41:43 +01:00
|
|
|
x = (int)boundingRect().center().x() - iconWidth - (d->toolBacker->size().width() / 2);
|
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:
|
2010-01-04 07:41:43 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5 - d->toolBacker->size().width();
|
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:
|
2010-01-04 07:41:43 +01:00
|
|
|
x = (int)boundingRect().center().x() - iconWidth - (d->toolBacker->size().width() / 2);
|
2008-11-04 00:08:39 +01:00
|
|
|
y = (int)boundingRect().bottom() - iconWidth - 5;
|
|
|
|
break;
|
|
|
|
case BottomRight:
|
|
|
|
default:
|
2010-01-04 07:41:43 +01:00
|
|
|
x = (int)boundingRect().right() - iconWidth - 5 - d->toolBacker->size().width();
|
2008-11-04 00:08:39 +01:00
|
|
|
y = (int)boundingRect().bottom() - iconWidth - 5;
|
|
|
|
break;
|
|
|
|
}
|
2008-11-14 08:54:49 +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
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(topRight.x() - d->toolBacker->size().width(), topRight.y());
|
2008-12-01 13:40:08 +01:00
|
|
|
} else {
|
|
|
|
//kDebug() << "starting at" << x << startY;
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(x, y);
|
|
|
|
// now check that it actually fits within the parent's boundaries
|
|
|
|
QRectF backerRect = mapToParent(d->toolBacker->geometry()).boundingRect();
|
2008-12-01 13:40:08 +01:00
|
|
|
QSizeF parentSize = parentWidget()->size();
|
|
|
|
if (backerRect.x() < 5) {
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(5, y);
|
2008-12-01 13:40:08 +01:00
|
|
|
} else if (backerRect.right() > parentSize.width() - 5) {
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(parentSize.width() - 5 - backerRect.width(), y);
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
2008-11-19 06:35:34 +01:00
|
|
|
|
2008-12-01 13:40:08 +01:00
|
|
|
if (backerRect.y() < 5) {
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(x, 5);
|
2008-12-01 13:40:08 +01:00
|
|
|
} else if (backerRect.bottom() > parentSize.height() - 5) {
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setPos(x, parentSize.height() - 5 - backerRect.height());
|
2008-12-01 13:40:08 +01:00
|
|
|
}
|
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
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
d->toolBacker->setOpacity(0);
|
2008-11-04 00:08:39 +01:00
|
|
|
d->toolBacker->show();
|
2010-01-04 07:41:43 +01:00
|
|
|
Plasma::Animation *fadeAnim = Animator::create(Animator::FadeAnimation, d->toolBacker);
|
2010-01-04 10:19:08 +01:00
|
|
|
fadeAnim->setTargetWidget(d->toolBacker);
|
2010-01-04 07:41:43 +01:00
|
|
|
fadeAnim->setProperty("startOpacity", 0);
|
|
|
|
fadeAnim->setProperty("targetOpacity", 1);
|
|
|
|
fadeAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void DesktopToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
|
|
|
//kDebug() << event->pos() << event->scenePos()
|
|
|
|
// << d->toolBacker->rect().contains(event->scenePos().toPoint());
|
2009-10-20 16:14:53 +02:00
|
|
|
if (!d->hovering || isShowing() || 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()
|
|
|
|
{
|
|
|
|
Plasma::Animator *animdriver = Plasma::Animator::self();
|
2010-01-04 07:41:43 +01:00
|
|
|
foreach (QGraphicsItem *tool, tools()) {
|
2008-11-04 00:08:39 +01:00
|
|
|
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();
|
|
|
|
}
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->toolBacker) {
|
2010-01-04 07:41:43 +01:00
|
|
|
Plasma::Animation *fadeAnim = Animator::create(Animator::FadeAnimation, d->toolBacker);
|
|
|
|
connect(fadeAnim, SIGNAL(finished()), this, SLOT(hideToolBacker()));
|
2010-01-04 10:19:08 +01:00
|
|
|
fadeAnim->setTargetWidget(d->toolBacker);
|
2010-01-04 07:41:43 +01:00
|
|
|
fadeAnim->setProperty("startOpacity", 1);
|
|
|
|
fadeAnim->setProperty("targetOpacity", 0);
|
|
|
|
fadeAnim->start(QAbstractAnimation::DeleteWhenStopped);
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
void DesktopToolBox::hideToolBacker()
|
|
|
|
{
|
|
|
|
d->toolBacker->hide();
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:08:39 +01:00
|
|
|
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::toggle()
|
|
|
|
{
|
2008-11-28 18:32:21 +01:00
|
|
|
if (isToolbar()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-04 07:41:43 +01:00
|
|
|
setShowing(!isShowing());
|
2008-11-04 00:08:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // plasma namespace
|
|
|
|
|
|
|
|
#include "desktoptoolbox_p.moc"
|