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)
-{
- 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);
-}
-
-/*! \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)
+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) % _duration*2;
- if (timeDiff > _duration)
- timeDiff = _duration*2 - timeDiff;
- alpha = timeDiff/(float)_duration;
- } else {
- stop();
- }
- drawBlendedImage(painter, option->rect, alpha);
+ painter->drawImage(option->rect, currentImage());
}
-
/*!
\internal
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);
#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);
+ QWindowsVistaAnimation(Type type, QObject *target) : QBlendStyleAnimation(type, target) { }
+
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; }
-
-protected:
- void drawBlendedImage(QPainter *painter, QRect rect, float value);
- QImage _primaryImage;
- QImage _secondaryImage;
- QImage _tempImage;
- int _duration;
+ void paint(QPainter *painter, const QStyleOption *option);
};
{
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) {}
};
{
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) {}
};