* use EaseIn for the icon button show

* show the button(s) in .2s rather than the very slow feeling .5s
* don't leak the timeline
* don't connect to the timeline signal more than once
* comment in code that is ifdef'd out anyways
* don't set the svg element for fg and bg unless it exists
* remove some dead code

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=676786
This commit is contained in:
Aaron J. Seigo 2007-06-17 17:49:49 +00:00
parent a452da7dd2
commit 1fa0feaa48

View File

@ -78,7 +78,6 @@ class Icon::Private
svgElements |= SvgForegroundPressed; svgElements |= SvgForegroundPressed;
} }
stepMenu = 0; stepMenu = 0;
timeline = new QTimeLine;
button1Pressed = false; button1Pressed = false;
button1Hovered = false; button1Hovered = false;
} }
@ -104,7 +103,7 @@ class Icon::Private
QSizeF size; QSizeF size;
QSizeF iconSize; QSizeF iconSize;
QIcon icon; QIcon icon;
QTimeLine *timeline; QTimeLine timeline;
ButtonState state; ButtonState state;
Svg svg; Svg svg;
int svgElements; int svgElements;
@ -123,7 +122,10 @@ Icon::Icon(QGraphicsItem *parent)
setEnabled(true); setEnabled(true);
setFlags(ItemIsMovable); setFlags(ItemIsMovable);
setPos(QPointF(0.0,0.0)); setPos(QPointF(0.0,0.0));
d->timeline->setDuration(500); connect(&d->timeline, SIGNAL(frameChanged(int)), this, SLOT(animateBubbles(int)));
d->timeline.setCurveShape(QTimeLine::EaseInCurve);
d->timeline.setDuration(200);
d->timeline.setFrameRange(0, 5);
} }
Icon::~Icon() Icon::~Icon()
@ -142,24 +144,23 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
Q_UNUSED(widget) Q_UNUSED(widget)
#ifdef PROVE_IT_CAN_BE_DONE #ifdef PROVE_IT_CAN_BE_DONE
// if (d->state == Private::HoverState && scene()) { if (d->state == Private::HoverState && scene()) {
// QList<QGraphicsView*> views = scene()->views(); QList<QGraphicsView*> views = scene()->views();
// if (views.count() > 0) { if (views.count() > 0) {
// QPixmap* pix = static_cast<QPixmap*>(views[0]->windowSurface()->paintDevice()); QPixmap* pix = static_cast<QPixmap*>(views[0]->windowSurface()->paintDevice());
// QImage image(boundingRect().size().toSize(), QImage::Format_ARGB32_Premultiplied); QImage image(boundingRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
// { {
// QPainter p(&image); QPainter p(&image);
// p.drawPixmap(image.rect(), *pix, sceneBoundingRect()); p.drawPixmap(image.rect(), *pix, sceneBoundingRect());
// } }
// expblur<16,7>(image, 8); expblur<16,7>(image, 8);
// painter->save(); painter->save();
// painter->drawImage(0, 0, image); painter->drawImage(0, 0, image);
// painter->restore(); painter->restore();
// } }
// } }
#endif #endif
QString element; QString element;
if (d->svgElements & Private::SvgBackground) { if (d->svgElements & Private::SvgBackground) {
element = "background"; element = "background";
@ -167,7 +168,6 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
switch (d->state) { switch (d->state) {
case Private::NoState: case Private::NoState:
element = "background";
break; break;
case Private::HoverState: case Private::HoverState:
if (d->svgElements & Private::SvgBackgroundHover) { if (d->svgElements & Private::SvgBackgroundHover) {
@ -219,7 +219,6 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
switch (d->state) { switch (d->state) {
case Private::NoState: case Private::NoState:
element = "foreground";
break; break;
case Private::HoverState: case Private::HoverState:
if (d->svgElements & Private::SvgForegroundHover) { if (d->svgElements & Private::SvgForegroundHover) {
@ -244,19 +243,16 @@ void Icon::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWid
// Draw top-left button // Draw top-left button
QColor colorButton1; QColor colorButton1;
if (d->button1Hovered) { if (d->button1Hovered) {
// colorButton1 = QColor(0, 49, 110); //Oxygen color
element = "button1-hover"; element = "button1-hover";
} else if (d->button1Pressed) { } else if (d->button1Pressed) {
// colorButton1 = QColor(29, 10, 85); //Oxygen color
element = "button1-pressed"; element = "button1-pressed";
} else { } else {
// colorButton1 = QColor(0, 67, 138); //Oxygen color
element = "button1"; element = "button1";
} }
KIcon exec("exec"); KIcon exec("exec");
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
painter->setOpacity(d->stepMenu*0.04); painter->setOpacity(d->stepMenu*0.2);
// painter->setBrush(colorButton1); // painter->setBrush(colorButton1);
painter->setPen(Qt::NoPen); painter->setPen(Qt::NoPen);
@ -388,33 +384,20 @@ void Icon::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
d->button1Hovered = false; d->button1Hovered = false;
} }
if (d->timeline->state() == QTimeLine::Running) { d->timeline.setDirection(QTimeLine::Forward);
d->timeline->setPaused(true);
}
d->timeline->setFrameRange(0, 25);
d->timeline->setDirection(QTimeLine::Forward);
connect(d->timeline, SIGNAL(frameChanged(int)), this, SLOT(animateBubbles(int)));
d->state = Private::HoverState; d->state = Private::HoverState;
QGraphicsItem::hoverEnterEvent(event); QGraphicsItem::hoverEnterEvent(event);
d->timeline->start(); d->timeline.start();
} }
void Icon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void Icon::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
if (d->timeline->state() == QTimeLine::Running) { d->timeline.setDirection(QTimeLine::Backward);
d->timeline->setPaused(true);
}
d->timeline->setFrameRange(0, 25);
d->timeline->setDirection(QTimeLine::Backward);
connect(d->timeline, SIGNAL(frameChanged(int)), this, SLOT(animateBubbles(int)));
d->state = Private::HoverState; d->state = Private::HoverState;
QGraphicsItem::hoverEnterEvent(event); QGraphicsItem::hoverEnterEvent(event);
d->timeline->start(); d->timeline.start();
d->state = Private::NoState; d->state = Private::NoState;
QGraphicsItem::hoverLeaveEvent(event); QGraphicsItem::hoverLeaveEvent(event);
} }