2007-05-29 09:59:50 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 by Aaron Seigo aseigo@kde.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2007-05-30 18:47:36 +02:00
|
|
|
#include "icon.h"
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
2007-06-07 21:07:45 +02:00
|
|
|
#include <QGraphicsView>
|
2007-06-08 07:39:34 +02:00
|
|
|
|
2007-06-17 19:49:49 +02:00
|
|
|
//#define PROVE_IT_CAN_BE_DONE
|
2007-06-08 07:39:34 +02:00
|
|
|
|
|
|
|
#ifdef PROVE_IT_CAN_BE_DONE
|
2007-06-07 21:07:45 +02:00
|
|
|
#include <private/qwindowsurface_p.h>
|
2007-06-08 07:39:34 +02:00
|
|
|
#endif
|
2007-05-29 09:59:50 +02:00
|
|
|
|
|
|
|
#include <KIcon>
|
2007-06-07 21:07:45 +02:00
|
|
|
#include <KImageEffect>
|
2007-06-17 00:35:31 +02:00
|
|
|
#include <KUrl>
|
|
|
|
#include <KRun>
|
|
|
|
#include <KMimeType>
|
2007-05-29 09:59:50 +02:00
|
|
|
#include <KDebug>
|
|
|
|
|
2007-06-19 23:56:40 +02:00
|
|
|
#include "phase.h"
|
2007-05-29 09:59:50 +02:00
|
|
|
#include "svg.h"
|
2007-06-07 21:10:48 +02:00
|
|
|
#include "effects/blur.cpp"
|
2007-05-29 09:59:50 +02:00
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
|
|
|
|
class Icon::Private
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Private()
|
2007-05-29 22:37:21 +02:00
|
|
|
: size(128*1.1, 128*1.1),
|
2007-06-05 21:48:14 +02:00
|
|
|
iconSize(128, 128),
|
2007-05-29 22:37:21 +02:00
|
|
|
state(Private::NoState),
|
2007-06-19 23:56:40 +02:00
|
|
|
svg("widgets/iconbutton"),
|
|
|
|
svgElements(0),
|
|
|
|
button1AnimId(0)
|
2007-05-29 09:59:50 +02:00
|
|
|
{
|
2007-05-29 22:37:21 +02:00
|
|
|
svg.setContentType(Plasma::Svg::ImageSet);
|
|
|
|
svg.resize(size);
|
|
|
|
|
2007-06-19 23:56:40 +02:00
|
|
|
//TODO: recheck when svg changes
|
|
|
|
checkSvgElements();
|
|
|
|
}
|
|
|
|
|
|
|
|
void checkSvgElements()
|
|
|
|
{
|
2007-05-29 22:37:21 +02:00
|
|
|
if (svg.elementExists("background")) {
|
|
|
|
svgElements |= SvgBackground;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("background-hover")) {
|
|
|
|
svgElements |= SvgBackgroundHover;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("background-pressed")) {
|
|
|
|
svgElements |= SvgBackgroundPressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("foreground")) {
|
|
|
|
svgElements |= SvgForeground;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("foreground-hover")) {
|
|
|
|
svgElements |= SvgForegroundHover;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("foreground-pressed")) {
|
|
|
|
svgElements |= SvgForegroundPressed;
|
|
|
|
}
|
2007-06-19 23:56:40 +02:00
|
|
|
|
|
|
|
if (svg.elementExists("minibutton")) {
|
|
|
|
svgElements |= SvgMinibutton;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("minibutton-hover")) {
|
|
|
|
svgElements |= SvgMinibuttonHover;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (svg.elementExists("minibutton-pressed")) {
|
|
|
|
svgElements |= SvgMinibuttonPressed;
|
|
|
|
}
|
|
|
|
|
2007-06-17 00:35:31 +02:00
|
|
|
button1Pressed = false;
|
|
|
|
button1Hovered = false;
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
2007-06-20 01:32:04 +02:00
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
~Private() {}
|
2007-05-29 22:37:21 +02:00
|
|
|
enum ButtonState
|
|
|
|
{
|
|
|
|
NoState,
|
|
|
|
HoverState,
|
|
|
|
PressedState
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum { NoSvg = 0,
|
|
|
|
SvgBackground = 1,
|
|
|
|
SvgBackgroundHover = 2,
|
|
|
|
SvgBackgroundPressed = 4,
|
|
|
|
SvgForeground = 8,
|
|
|
|
SvgForegroundHover = 16,
|
2007-06-19 23:56:40 +02:00
|
|
|
SvgForegroundPressed = 32,
|
|
|
|
SvgMinibutton = 64,
|
|
|
|
SvgMinibuttonHover = 256,
|
|
|
|
SvgMinibuttonPressed = 128};
|
2007-05-29 09:59:50 +02:00
|
|
|
|
2007-06-17 00:35:31 +02:00
|
|
|
KUrl url;
|
2007-05-29 09:59:50 +02:00
|
|
|
QString text;
|
|
|
|
QSizeF size;
|
2007-06-05 21:48:14 +02:00
|
|
|
QSizeF iconSize;
|
|
|
|
QIcon icon;
|
2007-05-29 22:37:21 +02:00
|
|
|
ButtonState state;
|
|
|
|
Svg svg;
|
|
|
|
int svgElements;
|
2007-06-19 23:56:40 +02:00
|
|
|
//TODO: create a proper state int for this, as we do with ButtonState
|
|
|
|
// for each possible button
|
2007-06-17 00:35:31 +02:00
|
|
|
bool button1Hovered;
|
|
|
|
bool button1Pressed;
|
2007-06-19 23:56:40 +02:00
|
|
|
Phase::AnimId button1AnimId;
|
2007-05-29 09:59:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Icon::Icon(QGraphicsItem *parent)
|
|
|
|
: QObject(),
|
|
|
|
QGraphicsItem(parent),
|
|
|
|
d(new Private)
|
|
|
|
{
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
setAcceptsHoverEvents(true);
|
|
|
|
setEnabled(true);
|
|
|
|
setPos(QPointF(0.0,0.0));
|
|
|
|
}
|
|
|
|
|
|
|
|
Icon::~Icon()
|
|
|
|
{
|
|
|
|
delete d;
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Icon::boundingRect() const
|
|
|
|
{
|
2007-05-29 22:37:21 +02:00
|
|
|
return QRectF(QPointF(0, 0), d->size);
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
|
|
{
|
|
|
|
Q_UNUSED(option)
|
|
|
|
Q_UNUSED(widget)
|
2007-06-25 21:20:54 +02:00
|
|
|
painter->save();
|
|
|
|
painter->setCompositionMode(QPainter::CompositionMode_Source);
|
2007-06-19 23:56:40 +02:00
|
|
|
painter->fillRect(boundingRect(), Qt::transparent);
|
2007-06-25 21:20:54 +02:00
|
|
|
painter->restore();
|
2007-05-29 09:59:50 +02:00
|
|
|
|
2007-06-08 07:39:34 +02:00
|
|
|
#ifdef PROVE_IT_CAN_BE_DONE
|
2007-06-17 19:49:49 +02:00
|
|
|
if (d->state == Private::HoverState && scene()) {
|
|
|
|
QList<QGraphicsView*> views = scene()->views();
|
|
|
|
if (views.count() > 0) {
|
|
|
|
QPixmap* pix = static_cast<QPixmap*>(views[0]->windowSurface()->paintDevice());
|
|
|
|
QImage image(boundingRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
|
|
|
|
{
|
|
|
|
QPainter p(&image);
|
|
|
|
p.drawPixmap(image.rect(), *pix, sceneBoundingRect());
|
|
|
|
}
|
|
|
|
expblur<16,7>(image, 8);
|
|
|
|
painter->drawImage(0, 0, image);
|
|
|
|
}
|
|
|
|
}
|
2007-06-08 07:39:34 +02:00
|
|
|
#endif
|
2007-06-07 21:07:45 +02:00
|
|
|
|
2007-05-29 22:37:21 +02:00
|
|
|
QString element;
|
|
|
|
if (d->svgElements & Private::SvgBackground) {
|
|
|
|
element = "background";
|
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
|
|
|
|
switch (d->state) {
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::NoState:
|
2007-05-29 09:59:50 +02:00
|
|
|
break;
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::HoverState:
|
|
|
|
if (d->svgElements & Private::SvgBackgroundHover) {
|
|
|
|
element = "background-hover";
|
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
break;
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::PressedState:
|
|
|
|
if (d->svgElements & Private::SvgBackgroundPressed) {
|
|
|
|
element = "background-pressed";
|
2007-06-06 22:48:06 +02:00
|
|
|
} else if (d->svgElements & Private::SvgBackgroundHover) {
|
|
|
|
element = "background-hover";
|
2007-05-29 22:37:21 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!element.isEmpty()) {
|
2007-06-06 22:48:06 +02:00
|
|
|
d->svg.paint(painter, 0, 0, element);
|
2007-05-29 22:37:21 +02:00
|
|
|
element = QString();
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!d->icon.isNull()) {
|
2007-06-06 07:19:44 +02:00
|
|
|
qreal iw = d->iconSize.width();
|
|
|
|
qreal ih = d->iconSize.height();
|
|
|
|
qreal deltaX = (d->size.width() - iw) / 2;
|
|
|
|
qreal deltaY = (d->size.height() - ih) / 2 ;
|
2007-06-20 01:32:04 +02:00
|
|
|
if (d->state == Private::PressedState) {
|
2007-06-06 21:45:00 +02:00
|
|
|
painter->save();
|
|
|
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
painter->scale(0.95, 0.95);
|
|
|
|
deltaY *= 0.95;
|
|
|
|
deltaX *= 0.95;
|
2007-06-17 00:35:31 +02:00
|
|
|
painter->drawPixmap((int)(deltaX + (iw * .025)), (int)(deltaY + (ih * .025)),
|
2007-06-06 21:45:00 +02:00
|
|
|
d->icon.pixmap(d->iconSize.toSize()));
|
|
|
|
painter->restore();
|
2007-06-20 01:32:04 +02:00
|
|
|
} else {
|
2007-06-17 00:35:31 +02:00
|
|
|
painter->drawPixmap((int)deltaX, (int)deltaY, d->icon.pixmap(d->iconSize.toSize()));
|
2007-06-06 07:19:44 +02:00
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//TODO: draw text
|
|
|
|
|
2007-06-17 00:35:31 +02:00
|
|
|
// Make it default
|
2007-05-29 22:37:21 +02:00
|
|
|
if (d->svgElements & Private::SvgForeground) {
|
|
|
|
element = "foreground";
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
switch (d->state) {
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::NoState:
|
2007-05-29 09:59:50 +02:00
|
|
|
break;
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::HoverState:
|
|
|
|
if (d->svgElements & Private::SvgForegroundHover) {
|
|
|
|
element = "foreground-hover";
|
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
break;
|
2007-05-29 22:37:21 +02:00
|
|
|
case Private::PressedState:
|
|
|
|
if (d->svgElements & Private::SvgForegroundPressed) {
|
|
|
|
element = "foreground-pressed";
|
2007-06-06 22:48:06 +02:00
|
|
|
} else if (d->svgElements & Private::SvgForegroundHover) {
|
|
|
|
element = "foreground-hover";
|
2007-05-29 22:37:21 +02:00
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
break;
|
|
|
|
}
|
2007-05-29 22:37:21 +02:00
|
|
|
|
|
|
|
if (!element.isEmpty()) {
|
|
|
|
//kDebug() << "painting " << element << endl;
|
|
|
|
d->svg.paint(painter, 0, 0, element);
|
2007-06-17 22:56:03 +02:00
|
|
|
element.clear();
|
2007-05-29 22:37:21 +02:00
|
|
|
}
|
2007-06-17 00:35:31 +02:00
|
|
|
|
|
|
|
// Draw top-left button
|
2007-06-19 23:56:40 +02:00
|
|
|
if (d->button1AnimId) {
|
|
|
|
painter->drawPixmap(6, 6, Phase::self()->animationResult(d->button1AnimId));
|
2007-06-17 00:35:31 +02:00
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::setText(const QString& text)
|
|
|
|
{
|
|
|
|
d->text = text;
|
2007-06-17 00:35:31 +02:00
|
|
|
//TODO: implement this puppy calculateSize();
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString Icon::text() const
|
|
|
|
{
|
|
|
|
return d->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::setIcon(const QString& icon)
|
|
|
|
{
|
2007-06-17 00:35:31 +02:00
|
|
|
kDebug() << "Icon set: " << icon << endl;
|
2007-05-29 09:59:50 +02:00
|
|
|
if (icon.isEmpty()) {
|
|
|
|
setIcon(QIcon());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setIcon(KIcon(icon));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::setIcon(const QIcon& icon)
|
|
|
|
{
|
|
|
|
d->icon = icon;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-06-17 00:35:31 +02:00
|
|
|
void Icon::setUrl(const KUrl& url)
|
|
|
|
{
|
|
|
|
d->url = url;
|
|
|
|
}
|
|
|
|
|
2007-06-20 23:08:30 +02:00
|
|
|
KUrl Icon::url() const
|
2007-06-20 10:10:38 +02:00
|
|
|
{
|
|
|
|
return d->url;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
QSizeF Icon::size() const
|
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
2007-06-05 04:54:48 +02:00
|
|
|
QSizeF Icon::iconSize() const
|
|
|
|
{
|
2007-06-05 21:48:14 +02:00
|
|
|
return d->iconSize;
|
2007-06-05 04:54:48 +02:00
|
|
|
}
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
void Icon::setSize(const QSizeF& s)
|
|
|
|
{
|
|
|
|
prepareGeometryChange();
|
2007-06-05 21:48:14 +02:00
|
|
|
d->iconSize = s;
|
|
|
|
d->size = s * 1.1;
|
2007-05-29 22:37:21 +02:00
|
|
|
d->svg.resize(d->size);
|
2007-05-29 09:59:50 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::setSize(int w, int h)
|
|
|
|
{
|
|
|
|
setSize(QSizeF(w, h));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Icon::isDown()
|
|
|
|
{
|
2007-05-29 22:37:21 +02:00
|
|
|
return d->state == Private::PressedState;
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2007-06-17 00:35:31 +02:00
|
|
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
2007-06-17 22:56:03 +02:00
|
|
|
d->button1Pressed = button1.contains(event->pos());
|
|
|
|
if (!d->button1Pressed) {
|
2007-06-17 00:35:31 +02:00
|
|
|
d->state = Private::PressedState;
|
|
|
|
QGraphicsItem::mousePressEvent(event);
|
|
|
|
update();
|
|
|
|
d->button1Pressed = false;
|
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
2007-06-25 08:02:33 +02:00
|
|
|
kDebug() << "Icon::mouseReleaseEvent" <<endl;
|
2007-05-29 22:37:21 +02:00
|
|
|
bool inside = boundingRect().contains(event->pos());
|
|
|
|
bool wasClicked = d->state == Private::PressedState && inside;
|
|
|
|
|
|
|
|
if (inside) {
|
|
|
|
d->state = Private::HoverState;
|
2007-06-17 22:56:03 +02:00
|
|
|
|
|
|
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
|
|
|
d->button1Hovered = button1.contains(event->pos());
|
|
|
|
if (d->button1Hovered &&
|
|
|
|
d->button1Pressed && d->url.isValid()) {
|
|
|
|
KRun::runUrl(d->url, KMimeType::findByUrl(d->url)->name(), 0);
|
2007-06-17 23:24:50 +02:00
|
|
|
wasClicked = false;
|
2007-06-17 22:56:03 +02:00
|
|
|
}
|
2007-05-29 22:37:21 +02:00
|
|
|
} else {
|
|
|
|
d->state = Private::NoState;
|
|
|
|
}
|
2007-05-29 09:59:50 +02:00
|
|
|
|
|
|
|
if (wasClicked) {
|
|
|
|
emit pressed(false);
|
|
|
|
emit clicked();
|
|
|
|
}
|
2007-06-17 22:56:03 +02:00
|
|
|
|
2007-06-17 00:35:31 +02:00
|
|
|
d->button1Pressed = false;
|
2007-05-29 22:37:21 +02:00
|
|
|
QGraphicsItem::mouseReleaseEvent(event);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2007-06-19 23:56:40 +02:00
|
|
|
QPixmap Icon::buttonPixmap()
|
|
|
|
{
|
|
|
|
//TODO this is just full of assumptions such as sizes and icon names. ugh!
|
|
|
|
QPixmap pix(26, 26);
|
2007-06-21 23:54:42 +02:00
|
|
|
pix.fill(Qt::transparent);
|
|
|
|
|
2007-06-19 23:56:40 +02:00
|
|
|
QPainter painter(&pix);
|
|
|
|
QString element;
|
|
|
|
|
|
|
|
if (d->svgElements & Private::SvgMinibutton) {
|
|
|
|
element = "minibutton";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->button1Pressed) {
|
|
|
|
if (d->svgElements & Private::SvgMinibuttonPressed) {
|
|
|
|
element = "minibutton-pressed";
|
|
|
|
} else if (d->svgElements & Private::SvgMinibuttonHover) {
|
|
|
|
element = "minibutton-hover";
|
|
|
|
}
|
|
|
|
} else if (d->button1Hovered) {
|
|
|
|
if (d->svgElements & Private::SvgMinibuttonHover) {
|
|
|
|
element = "minibutton-hover";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//paint foreground element
|
|
|
|
if (!element.isEmpty()) {
|
2007-06-20 09:39:04 +02:00
|
|
|
//kDebug() << "painting " << element << endl;
|
2007-06-19 23:56:40 +02:00
|
|
|
d->svg.resize(pix.size());
|
|
|
|
d->svg.paint(&painter, 0, 0, element);
|
|
|
|
d->svg.resize(boundingRect().size());
|
|
|
|
}
|
|
|
|
|
|
|
|
KIcon exec("exec");
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setPen(Qt::NoPen);
|
|
|
|
painter.drawPixmap(2, 2, exec.pixmap(22,22));
|
|
|
|
|
|
|
|
return pix;
|
|
|
|
}
|
|
|
|
|
2007-05-29 22:37:21 +02:00
|
|
|
void Icon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2007-06-19 23:56:40 +02:00
|
|
|
d->state = Private::HoverState;
|
2007-06-17 00:35:31 +02:00
|
|
|
d->button1Pressed = false;
|
|
|
|
QRectF button1(6, 6, 32, 32); // The top-left circle
|
2007-06-17 22:56:03 +02:00
|
|
|
d->button1Hovered = button1.contains(event->pos());
|
2007-06-17 00:35:31 +02:00
|
|
|
|
2007-06-20 00:48:42 +02:00
|
|
|
if (d->button1AnimId) {
|
|
|
|
Phase::self()->stopElementAnimation(d->button1AnimId);
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:02:33 +02:00
|
|
|
d->button1AnimId = Phase::self()->animateElement(this, Phase::ElementAppear);
|
2007-06-19 23:56:40 +02:00
|
|
|
Phase::self()->setAnimationPixmap(d->button1AnimId, buttonPixmap());
|
2007-05-29 22:37:21 +02:00
|
|
|
QGraphicsItem::hoverEnterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|
|
|
{
|
2007-06-17 22:56:03 +02:00
|
|
|
d->button1Pressed = false;
|
|
|
|
d->button1Hovered = false;
|
2007-06-20 00:48:42 +02:00
|
|
|
|
|
|
|
if (d->button1AnimId) {
|
|
|
|
Phase::self()->stopElementAnimation(d->button1AnimId);
|
|
|
|
}
|
|
|
|
|
2007-06-25 08:02:33 +02:00
|
|
|
d->button1AnimId = Phase::self()->animateElement(this, Phase::ElementDisappear);
|
2007-06-19 23:56:40 +02:00
|
|
|
Phase::self()->setAnimationPixmap(d->button1AnimId, buttonPixmap());
|
|
|
|
|
|
|
|
d->state = Private::NoState;
|
2007-05-29 22:37:21 +02:00
|
|
|
QGraphicsItem::hoverLeaveEvent(event);
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
2007-06-17 22:56:03 +02:00
|
|
|
void Icon::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (d->button1Pressed) {
|
|
|
|
d->button1Pressed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->state == Private::PressedState) {
|
2007-06-17 23:24:50 +02:00
|
|
|
d->state = Private::HoverState;
|
2007-06-17 22:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsItem::mouseMoveEvent(event);
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
QSizeF Icon::sizeHint() const
|
|
|
|
{
|
|
|
|
return d->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Icon::minimumSize() const
|
|
|
|
{
|
2007-06-05 21:48:14 +02:00
|
|
|
return d->size; // probably should be more flexible on this =)
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF Icon::maximumSize() const
|
|
|
|
{
|
2007-06-05 21:48:14 +02:00
|
|
|
return d->size;
|
2007-05-29 09:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Qt::Orientations Icon::expandingDirections() const
|
|
|
|
{
|
|
|
|
return Qt::Horizontal;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Icon::hasHeightForWidth() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Icon::heightForWidth(qreal w) const
|
|
|
|
{
|
|
|
|
return w; //FIXME: we shouldn't assume squareness but actually calculate based on text and what not
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Icon::hasWidthForHeight() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
qreal Icon::widthForHeight(qreal h) const
|
|
|
|
{
|
|
|
|
return h; //FIXME: we shouldn't assume squareness but actually calculate based on text and what not
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF Icon::geometry() const
|
|
|
|
{
|
|
|
|
return boundingRect().toRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Icon::setGeometry(const QRectF &r)
|
|
|
|
{
|
|
|
|
setSize(r.size());
|
|
|
|
setPos(r.x(),r.y());
|
|
|
|
}
|
|
|
|
|
2007-06-05 04:54:48 +02:00
|
|
|
int Icon::boundsForIconSize(int iconSize)
|
|
|
|
{
|
|
|
|
return iconSize * 1.1;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:59:50 +02:00
|
|
|
} // namespace Plasma
|
|
|
|
|
|
|
|
#include "icon.moc"
|