[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdebase/workspace/libs/plasma/widgets
From: Marco Martin <notmart () gmail ! com>
Date: 2008-10-02 19:39:01
Message-ID: 1222976341.252272.15999.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 867098 by mart:
combobox uses PaintUtils::transition
some cleanups in PushButton
M +37 -46 combobox.cpp
M +1 -1 combobox.h
M +1 -11 pushbutton.cpp
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/combobox.cpp #867097:867098
@@ -30,6 +30,7 @@
#include "theme.h"
#include "panelsvg.h"
#include "animator.h"
+#include "paintutils.h"
namespace Plasma
{
@@ -39,8 +40,7 @@
public:
ComboBoxPrivate(ComboBox *comboBox)
: q(comboBox),
- background(0),
- activeBackgroundPixmap(0)
+ background(0)
{
}
@@ -48,30 +48,20 @@
{
}
- void renderActiveBackgroundPixmap();
void syncActiveRect();
void syncBorders();
- void elementAnimationFinished(int id);
+ void animationUpdate(qreal progress);
ComboBox *q;
PanelSvg *background;
- QPixmap *activeBackgroundPixmap;
int animId;
+ bool fadeIn;
+ qreal opacity;
QRectF activeRect;
};
-void ComboBoxPrivate::renderActiveBackgroundPixmap()
-{
- background->setElementPrefix("active");
- activeBackgroundPixmap = new QPixmap(activeRect.size().toSize());
- activeBackgroundPixmap->fill(Qt::transparent);
-
- QPainter painter(activeBackgroundPixmap);
- background->paintPanel(&painter);
-}
-
void ComboBoxPrivate::syncActiveRect()
{
background->setElementPrefix("normal");
@@ -102,14 +92,21 @@
syncActiveRect();
}
-void ComboBoxPrivate::elementAnimationFinished(int id)
+void ComboBoxPrivate::animationUpdate(qreal progress)
{
- if (id == animId) {
+ if (progress == 1) {
animId = -1;
+ fadeIn = true;
}
+
+ opacity = fadeIn ? progress : 1 - progress;
+
+ // explicit update
+ q->update();
}
+
ComboBox::ComboBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent),
d(new ComboBoxPrivate(this))
@@ -126,7 +123,6 @@
d->syncBorders();
setAcceptHoverEvents(true);
- connect(Plasma::Animator::self(), SIGNAL(elementAnimationFinished(int)), this, \
SLOT(elementAnimationFinished(int)));
connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), \
SLOT(syncBorders())); }
@@ -179,11 +175,6 @@
d->background->setElementPrefix("normal");
d->background->resizePanel(size());
-
- if (d->activeBackgroundPixmap) {
- delete d->activeBackgroundPixmap;
- d->activeBackgroundPixmap = 0;
- }
}
QGraphicsProxyWidget::resizeEvent(event);
@@ -200,12 +191,15 @@
QPixmap bufferPixmap;
- //Normal button, pressed or not
+ //normal button
if (isEnabled()) {
d->background->setElementPrefix("normal");
- d->background->paintPanel(painter);
- //flat or disabled
- } else if (!isEnabled()) {
+
+ if (d->animId == -1) {
+ d->background->paintPanel(painter);
+ }
+ //disabled widget
+ } else {
bufferPixmap = QPixmap(rect().size().toSize());
bufferPixmap.fill(Qt::transparent);
@@ -220,12 +214,13 @@
//if is under mouse draw the animated glow overlay
if (isEnabled() && acceptHoverEvents()) {
if (d->animId != -1) {
- painter->drawPixmap(d->activeRect.topLeft(), \
Plasma::Animator::self()->currentPixmap(d->animId) ); + \
d->background->setElementPrefix("normal"); + QPixmap normalPix = \
d->background->panelPixmap(); + d->background->setElementPrefix("active");
+ painter->drawPixmap(d->activeRect.topLeft(), \
PaintUtils::transition(d->background->panelPixmap(), normalPix, 1 - d->opacity)); } \
else if (isUnderMouse()) {
- if (d->activeBackgroundPixmap == 0) {
- d->renderActiveBackgroundPixmap();
- }
- painter->drawPixmap( d->activeRect.topLeft(), *d->activeBackgroundPixmap \
); + d->background->setElementPrefix("active");
+ d->background->paintPanel(painter, d->activeRect.topLeft());
}
}
@@ -253,35 +248,31 @@
void ComboBox::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
+ const int FadeInDuration = 75;
+
if (d->animId != -1) {
- Plasma::Animator::self()->stopElementAnimation(d->animId);
+ Plasma::Animator::self()->stopCustomAnimation(d->animId);
}
- d->animId = Plasma::Animator::self()->animateElement(this, \
Plasma::Animator::AppearAnimation); + d->animId = \
Plasma::Animator::self()->customAnimation(40 / (1000 / FadeInDuration), \
FadeInDuration,Plasma::Animator::LinearCurve, this, "animationUpdate");
d->background->setElementPrefix("active");
- if (!d->activeBackgroundPixmap) {
- d->renderActiveBackgroundPixmap();
- }
- Plasma::Animator::self()->setInitialPixmap( d->animId, \
*d->activeBackgroundPixmap );
-
QGraphicsProxyWidget::hoverEnterEvent(event);
}
void ComboBox::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
+ const int FadeOutDuration = 150;
+
if (d->animId != -1) {
- Plasma::Animator::self()->stopElementAnimation(d->animId);
+ Plasma::Animator::self()->stopCustomAnimation(d->animId != -1);
}
- d->animId = Plasma::Animator::self()->animateElement(this, \
Plasma::Animator::DisappearAnimation);
+ d->fadeIn = false;
+ d->animId = Plasma::Animator::self()->customAnimation(40 / (1000 / \
FadeOutDuration), FadeOutDuration,Plasma::Animator::LinearCurve, this, \
"animationUpdate"); +
d->background->setElementPrefix("active");
- if (!d->activeBackgroundPixmap) {
- d->renderActiveBackgroundPixmap();
- }
- Plasma::Animator::self()->setInitialPixmap( d->animId, \
*d->activeBackgroundPixmap );
-
QGraphicsProxyWidget::hoverLeaveEvent(event);
}
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/combobox.h #867097:867098
@@ -97,7 +97,7 @@
friend class ComboBoxPrivate;
Q_PRIVATE_SLOT(d, void syncBorders())
- Q_PRIVATE_SLOT(d, void elementAnimationFinished(int id))
+ Q_PRIVATE_SLOT(d, void animationUpdate(qreal progress))
};
} // namespace Plasma
--- trunk/KDE/kdebase/workspace/libs/plasma/widgets/pushbutton.cpp #867097:867098
@@ -45,7 +45,6 @@
PushButtonPrivate(PushButton *pushButton)
: q(pushButton),
background(0),
- activeBackgroundPixmap(0),
animId(-1),
fadeIn(false),
svg(0)
@@ -84,8 +83,6 @@
PushButton *q;
PanelSvg *background;
- QPixmap *activeBackgroundPixmap;
- QPixmap *backgroundPixmap;
int animId;
bool fadeIn;
qreal opacity;
@@ -229,8 +226,6 @@
if (d->background) {
//resize all four panels
- d->background->setElementPrefix("normal");
- d->background->resizePanel(size());
d->background->setElementPrefix("pressed");
d->background->resizePanel(size());
d->background->setElementPrefix("focus");
@@ -242,11 +237,7 @@
d->background->resizePanel(d->activeRect.size());
d->background->setElementPrefix("normal");
-
- if (d->activeBackgroundPixmap) {
- delete d->activeBackgroundPixmap;
- d->activeBackgroundPixmap = 0;
- }
+ d->background->resizePanel(size());
}
QGraphicsProxyWidget::resizeEvent(event);
@@ -289,7 +280,6 @@
//if is under mouse draw the animated glow overlay
if (!nativeWidget()->isDown() && isEnabled() && acceptHoverEvents()) {
if (d->animId != -1) {
- //QPixmap normalPix = QPixmap(d->activeRect.size());
QPixmap normalPix = d->background->panelPixmap();
d->background->setElementPrefix("active");
painter->drawPixmap(d->activeRect.topLeft(), \
PaintUtils::transition(d->background->panelPixmap(), normalPix, 1 - d->opacity));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic