support for fade in/fade out to transparent

svn path=/trunk/KDE/kdelibs/; revision=1081537
This commit is contained in:
Marco Martin 2010-01-28 17:08:07 +00:00
parent 3618f03425
commit 54eeaa5f91

View File

@ -20,6 +20,7 @@
#include "pixmaptransition_p.h"
#include <QPainter>
#include <QPixmap>
#include <kdebug.h>
@ -76,12 +77,46 @@ void PixmapTransition::updateState(QAbstractAnimation::State newState, QAbstract
return;
}
if (!m_startPixmap.isNull() && !m_targetPixmap.isNull()) {
if (oldState == Stopped && newState == Running) {
Plasma::PaintUtils::centerPixmaps(m_startPixmap, m_targetPixmap);
m_currentPixmap = (direction() == Forward ? m_startPixmap : m_targetPixmap);
} else if (newState == Stopped) {
m_currentPixmap = (direction() == Forward ? m_targetPixmap : m_startPixmap);
}
} else if (m_startPixmap.isNull()) {
if (oldState == Stopped && newState == Running) {
if (direction() == Forward) {
m_currentPixmap = QPixmap(m_targetPixmap.size());
m_currentPixmap.fill(Qt::transparent);
} else {
m_currentPixmap = m_targetPixmap;
}
} else if (newState == Stopped) {
if (direction() == Forward) {
m_currentPixmap = m_targetPixmap;
} else {
m_currentPixmap = QPixmap(m_targetPixmap.size());
m_currentPixmap.fill(Qt::transparent);
}
}
} else if (m_targetPixmap.isNull()) {
if (oldState == Stopped && newState == Running) {
if (direction() == Forward) {
m_currentPixmap = m_targetPixmap;
} else {
m_currentPixmap = QPixmap(m_targetPixmap.size());
m_currentPixmap.fill(Qt::transparent);
}
} else if (newState == Stopped) {
if (direction() == Forward) {
m_currentPixmap = QPixmap(m_targetPixmap.size());
m_currentPixmap.fill(Qt::transparent);
} else {
m_currentPixmap = m_targetPixmap;
}
}
}
w->update();
}
@ -92,7 +127,21 @@ void PixmapTransition::updateCurrentTime(int currentTime)
if (w) {
qreal delta = currentTime / qreal(duration());
delta *= Animation::easingCurve().valueForProgress(delta);
if (!m_startPixmap.isNull() && !m_targetPixmap.isNull()) {
m_currentPixmap = Plasma::PaintUtils::transition(m_startPixmap, m_targetPixmap, delta);
} else if (m_startPixmap.isNull()) {
m_currentPixmap.fill(QColor(0, 0, 0, (int)(((qreal)255)*delta)));
QPainter p(&m_currentPixmap);
p.setCompositionMode(QPainter::CompositionMode_SourceIn);
p.drawPixmap(m_currentPixmap.rect(), m_targetPixmap, m_targetPixmap.rect());
p.end();
} else if (m_targetPixmap.isNull()) {
m_currentPixmap = m_targetPixmap;
QPainter p(&m_currentPixmap);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(m_currentPixmap.rect(), QColor(0, 0, 0, (int)(((qreal)255)*delta)));
p.end();
}
}
Animation::updateCurrentTime(currentTime);