2
* Copyright 2007 by Aaron Seigo <aseigo@kde.org>
3
* Copyright 2008 by Marco Martin <notmart@gmail.com>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Library General Public License as
7
* published by the Free Software Foundation; either version 2, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details
15
* You should have received a copy of the GNU Library General Public
16
* License along with this program; if not, write to the
17
* Free Software Foundation, Inc.,
18
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
#include "paneltoolbox_p.h"
23
#include <QGraphicsSceneHoverEvent>
25
#include <QRadialGradient>
26
#include <QApplication>
27
#include <QPropertyAnimation>
28
#include <QWeakPointer>
30
#include <kcolorscheme.h>
32
#include <kiconloader.h>
34
#include <plasma/applet.h>
35
#include <plasma/paintutils.h>
36
#include <plasma/svg.h>
37
#include <plasma/theme.h>
38
#include <plasma/tooltipcontent.h>
39
#include <plasma/tooltipmanager.h>
42
class PanelToolBoxPrivate
53
QWeakPointer<QPropertyAnimation> anim;
57
Plasma::Svg *background;
61
PanelToolBox::PanelToolBox(Plasma::Containment *parent)
62
: InternalToolBox(parent),
63
d(new PanelToolBoxPrivate)
68
PanelToolBox::PanelToolBox(QObject *parent, const QVariantList &args)
69
: InternalToolBox(parent, args),
70
d(new PanelToolBoxPrivate)
75
PanelToolBox::~PanelToolBox()
81
void PanelToolBox::init()
83
setIconSize(QSize(KIconLoader::SizeSmall, KIconLoader::SizeSmall));
84
setSize(KIconLoader::SizeSmallMedium);
85
connect(this, SIGNAL(toggled()), this, SLOT(toggle()));
88
setFlag(ItemClipsChildrenToShape, false);
89
//panel toolbox is allowed to zoom, otherwise a part of it will be displayed behind the desktop
90
//toolbox when the desktop is zoomed out
91
setFlag(ItemIgnoresTransformations, false);
93
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()),
94
this, SLOT(assignColors()));
96
d->background = new Plasma::Svg(this);
97
d->background->setImagePath("widgets/toolbox");
98
d->background->setContainsMultipleImages(true);
100
Plasma::ToolTipManager::self()->registerWidget(this);
103
QObject::connect(containment(), SIGNAL(immutabilityChanged(Plasma::ImmutabilityType)),
104
this, SLOT(immutabilityChanged(Plasma::ImmutabilityType)));
108
void PanelToolBox::assignColors()
110
d->bgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::BackgroundColor);
111
d->fgColor = Plasma::Theme::defaultTheme()->color(Plasma::Theme::TextColor);
115
QRectF PanelToolBox::boundingRect() const
119
//Only Left,Right and Bottom supported, default to Right
120
if (corner() == InternalToolBox::Bottom) {
121
r = QRectF(0, 0, size() * 2, size());
122
} else if (corner() == InternalToolBox::Left) {
123
r = QRectF(0, 0, size(), size() * 2);
125
r = QRectF(0, 0, size(), size() * 2);
129
QSizeF s = parentItem()->boundingRect().size();
131
if (r.height() > s.height()) {
132
r.setHeight(s.height());
135
if (r.width() > s.width()) {
136
r.setWidth(s.width());
143
void PanelToolBox::immutabilityChanged(Plasma::ImmutabilityType immutability)
145
setVisible(immutability == Plasma::Mutable);
148
void PanelToolBox::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
153
const qreal progress = d->animFrame / size();
155
QRect backgroundRect;
156
QPoint gradientCenter;
157
QRectF rect = boundingRect();
158
QString cornerElement;
160
if (corner() == InternalToolBox::Bottom) {
161
gradientCenter = QPoint(rect.center().x(), rect.bottom());
162
cornerElement = "panel-south";
164
backgroundRect = d->background->elementRect(cornerElement).toRect();
165
backgroundRect.moveBottomLeft(shape().boundingRect().bottomLeft().toPoint());
166
} else if (corner() == InternalToolBox::Right) {
167
gradientCenter = QPoint(rect.right(), rect.center().y());
168
cornerElement = "panel-east";
170
backgroundRect = d->background->elementRect(cornerElement).toRect();
171
backgroundRect.moveTopRight(shape().boundingRect().topRight().toPoint());
173
gradientCenter = QPoint(rect.right(), rect.center().y());
174
cornerElement = "panel-west";
176
backgroundRect = d->background->elementRect(cornerElement).toRect();
177
backgroundRect.moveTopLeft(shape().boundingRect().topLeft().toPoint());
181
d->background->paint(painter, backgroundRect, cornerElement);
186
//Only Left,Right and Bottom supported, default to Right
187
if (corner() == InternalToolBox::Bottom) {
188
iconRect = QRect(QPoint(gradientCenter.x() - iconSize().width() / 2,
189
(int)rect.bottom() - iconSize().height() - 2), iconSize());
190
} else if (corner() == InternalToolBox::Left) {
191
iconRect = QRect(QPoint(2, gradientCenter.y() - iconSize().height() / 2), iconSize());
193
iconRect = QRect(QPoint((int)rect.right() - iconSize().width() + 1,
194
gradientCenter.y() - iconSize().height() / 2), iconSize());
197
if (qFuzzyCompare(qreal(1.0), progress)) {
198
d->icon.paint(painter, iconRect);
199
} else if (qFuzzyCompare(qreal(1.0), 1 + progress)) {
200
d->icon.paint(painter, iconRect, Qt::AlignCenter, QIcon::Disabled, QIcon::Off);
202
QPixmap disabled = d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off);
203
QPixmap enabled = d->icon.pixmap(iconSize());
204
QPixmap result = Plasma::PaintUtils::transition(
205
d->icon.pixmap(iconSize(), QIcon::Disabled, QIcon::Off),
206
d->icon.pixmap(iconSize()), progress);
207
painter->drawPixmap(iconRect, result);
211
QPainterPath PanelToolBox::shape() const
214
int toolSize = size();// + (int)d->animFrame;
215
QRectF rect = boundingRect();
217
//Only Left,Right and Bottom supported, default to Right
218
if (corner() == InternalToolBox::Bottom) {
219
path.moveTo(rect.bottomLeft());
220
path.arcTo(QRectF(rect.center().x() - toolSize,
221
rect.bottom() - toolSize,
223
toolSize * 2), 0, 180);
224
} else if (corner() == InternalToolBox::Left) {
225
path.arcTo(QRectF(rect.left(),
226
rect.center().y() - toolSize,
228
toolSize * 2), 90, -180);
230
path.moveTo(rect.topRight());
231
path.arcTo(QRectF(rect.left(),
232
rect.center().y() - toolSize,
234
toolSize * 2), 90, 180);
240
void PanelToolBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
243
QGraphicsItem::hoverEnterEvent(event);
246
void PanelToolBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
248
//kDebug() << event->pos() << event->scenePos()
253
QGraphicsItem::hoverLeaveEvent(event);
256
void PanelToolBox::showToolBox()
260
void PanelToolBox::hideToolBox()
264
void PanelToolBox::setShowing(bool show)
266
InternalToolBox::setShowing(show);
270
void PanelToolBox::toolTipAboutToShow()
276
Plasma::ToolTipContent c(i18n("Panel Tool Box"),
277
i18n("Click to access size, location and hiding controls as well as to add "
278
"new widgets to the panel."),
280
c.setAutohide(false);
281
Plasma::ToolTipManager::self()->setContent(this, c);
284
void PanelToolBox::toolTipHidden()
286
Plasma::ToolTipManager::self()->clearContent(this);
289
void PanelToolBox::highlight(bool highlighting)
291
if (d->highlighting == highlighting) {
295
d->highlighting = highlighting;
297
QPropertyAnimation *anim = d->anim.data();
298
if (d->highlighting) {
303
anim = new QPropertyAnimation(this, "highlight", this);
307
if (anim->state() != QAbstractAnimation::Stopped) {
311
anim->setDuration(240);
312
anim->setStartValue(0);
313
anim->setEndValue(size());
315
if(d->highlighting) {
318
anim->setDirection(QAbstractAnimation::Backward);
319
anim->start(QAbstractAnimation::DeleteWhenStopped);
324
void PanelToolBox::setHighlightValue(qreal progress)
326
d->animFrame = progress;
330
qreal PanelToolBox::highlightValue() const
335
void PanelToolBox::toggle()
337
setShowing(!isShowing());
341
#include "paneltoolbox_p.moc"