QWindowsVistaAnimation: inherit QBlendStyleAnimation

Change-Id: I15b348eb842730513480ecbb90bca87174d7c771
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
bb10
J-P Nurmi 2012-10-23 16:39:57 +02:00 committed by The Qt Project
parent d53ac9d8ca
commit 324a41db45
2 changed files with 10 additions and 131 deletions

View File

@ -235,119 +235,16 @@ static int buttonStateId(int flags, int partId)
return stateId;
}
void QWindowsVistaAnimation::paint(QPainter *painter, const QStyleOption *option)
{
Q_UNUSED(option);
Q_UNUSED(painter);
}
bool QWindowsVistaAnimation::isUpdateNeeded() const
{
return QWindowsVistaStylePrivate::useVista();
}
/*! \internal
Helperfunction to paint the current transition state between two
animation frames.
The result is a blended image consisting of ((alpha)*_primaryImage)
+ ((1-alpha)*_secondaryImage)
*/
void QWindowsVistaAnimation::drawBlendedImage(QPainter *painter, QRect rect, float alpha) {
if (_secondaryImage.isNull() || _primaryImage.isNull())
return;
if (_tempImage.isNull())
_tempImage = _secondaryImage;
const int a = qRound(alpha*256);
const int ia = 256 - a;
const int sw = _primaryImage.width();
const int sh = _primaryImage.height();
const int bpl = _primaryImage.bytesPerLine();
switch(_primaryImage.depth()) {
case 32:
{
uchar *mixed_data = _tempImage.bits();
const uchar *back_data = _primaryImage.bits();
const uchar *front_data = _secondaryImage.bits();
for (int sy = 0; sy < sh; sy++) {
quint32* mixed = (quint32*)mixed_data;
const quint32* back = (const quint32*)back_data;
const quint32* front = (const quint32*)front_data;
for (int sx = 0; sx < sw; sx++) {
quint32 bp = back[sx];
quint32 fp = front[sx];
mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8,
(qGreen(bp)*ia + qGreen(fp)*a)>>8,
(qBlue(bp)*ia + qBlue(fp)*a)>>8,
(qAlpha(bp)*ia + qAlpha(fp)*a)>>8);
}
mixed_data += bpl;
back_data += bpl;
front_data += bpl;
}
}
default:
break;
}
painter->drawImage(rect, _tempImage);
}
/*! \internal
Paints a transition state. The result will be a mix between the
initial and final state of the transition, depending on the time
difference between startTime and current time.
*/
void QWindowsVistaTransition::paint(QPainter *painter, const QStyleOption *option)
void QWindowsVistaAnimation::paint(QPainter *painter, const QStyleOption *option)
{
float alpha = 1.0;
if (_duration > 0) {
QTime current = QTime::currentTime();
if (startTime() > current)
setStartTime(current);
int timeDiff = startTime().msecsTo(current);
alpha = timeDiff/(float)_duration;
if (timeDiff > _duration) {
stop();
alpha = 1.0;
}
}
else {
stop();
}
drawBlendedImage(painter, option->rect, alpha);
painter->drawImage(option->rect, currentImage());
}
/*! \internal
Paints a pulse. The result will be a mix between the primary and
secondary pulse images depending on the time difference between
startTime and current time.
*/
void QWindowsVistaPulse::paint(QPainter *painter, const QStyleOption *option)
{
float alpha = 1.0;
if (_duration > 0) {
QTime current = QTime::currentTime();
if (startTime() > current)
setStartTime(current);
int timeDiff = startTime().msecsTo(current) % _duration*2;
if (timeDiff > _duration)
timeDiff = _duration*2 - timeDiff;
alpha = timeDiff/(float)_duration;
} else {
stop();
}
drawBlendedImage(painter, option->rect, alpha);
}
/*!
\internal
@ -1088,8 +985,8 @@ void QWindowsVistaStyle::drawControl(ControlElement element, const QStyleOption
theme.stateId = PBS_DEFAULTED_ANIMATING;
theme.painter = &alternatePainter;
d->drawBackground(theme);
pulse->setPrimaryImage(startImage);
pulse->setAlternateImage(alternateImage);
pulse->setStartImage(startImage);
pulse->setEndImage(alternateImage);
pulse->setStartTime(QTime::currentTime());
pulse->setDuration(2000);
d->startAnimation(pulse);

View File

@ -135,24 +135,14 @@ QT_BEGIN_NAMESPACE
#define TDLG_SECONDARYPANEL 8
#endif
class QWindowsVistaAnimation : public QStyleAnimation
class QWindowsVistaAnimation : public QBlendStyleAnimation
{
Q_OBJECT
public:
QWindowsVistaAnimation(QObject *target) : QStyleAnimation(target), _duration(-1) { }
virtual ~QWindowsVistaAnimation() { }
virtual void paint(QPainter *painter, const QStyleOption *option);
virtual bool isUpdateNeeded() const;
virtual int duration() const { return _duration; }
//set time in ms to complete a state transition / pulse cycle
void setDuration(int duration) { _duration = duration; }
QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { }
protected:
void drawBlendedImage(QPainter *painter, QRect rect, float value);
QImage _primaryImage;
QImage _secondaryImage;
QImage _tempImage;
int _duration;
virtual bool isUpdateNeeded() const;
void paint(QPainter *painter, const QStyleOption *option);
};
@ -161,11 +151,7 @@ class QWindowsVistaTransition : public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaTransition(QObject *target) : QWindowsVistaAnimation(target) {}
virtual ~QWindowsVistaTransition() { }
void setStartImage(const QImage &image) { _primaryImage = image; }
void setEndImage(const QImage &image) { _secondaryImage = image; }
virtual void paint(QPainter *painter, const QStyleOption *option);
QWindowsVistaTransition(QObject *target) : QWindowsVistaAnimation(Transition, target) {}
};
@ -174,11 +160,7 @@ class QWindowsVistaPulse: public QWindowsVistaAnimation
{
Q_OBJECT
public:
QWindowsVistaPulse(QObject *target) : QWindowsVistaAnimation(target) {}
virtual ~QWindowsVistaPulse() { }
void setPrimaryImage(const QImage &image) { _primaryImage = image; }
void setAlternateImage(const QImage &image) { _secondaryImage = image; }
virtual void paint(QPainter *painter, const QStyleOption *option);
QWindowsVistaPulse(QObject *target) : QWindowsVistaAnimation(Pulse, target) {}
};