21 #include "pixmaptransition_p.h"
33 PixmapTransition::PixmapTransition(
QObject *parent)
34 : EasingAnimation(parent),
40 PixmapTransition::~PixmapTransition()
44 void PixmapTransition::setStartPixmap(
const QPixmap &pixmap)
46 if (state() == Running) {
50 m_startPixmap = pixmap;
53 updateEffectiveTime(0);
56 QPixmap PixmapTransition::startPixmap()
const
61 void PixmapTransition::setTargetPixmap(
const QPixmap &pixmap)
63 if (state() == Running) {
67 m_targetPixmap = pixmap;
69 updateEffectiveTime(0);
72 void PixmapTransition::setUsesCache(
bool cache)
77 bool PixmapTransition::usesCache()
const
82 QPixmap PixmapTransition::targetPixmap()
const
84 return m_targetPixmap;
87 QPixmap PixmapTransition::currentPixmap()
const
89 if (m_cache && !m_dirty) {
90 return m_currentPixmap;
93 QPixmap currentPixmap;
94 qreal delta = currentTime() / qreal(duration());
95 if (!m_startPixmap.isNull() && !m_targetPixmap.isNull()) {
98 }
else if (m_startPixmap.isNull()) {
99 if (qFuzzyCompare(delta, qreal(1.0))) {
100 currentPixmap = alignedTargetPixmap();
101 return currentPixmap;
104 if (currentPixmap.isNull()) {
105 currentPixmap = QPixmap(m_pixmapSize);
108 currentPixmap.fill(QColor(0, 0, 0, (
int)(((qreal)255)*delta)));
109 QPainter p(¤tPixmap);
110 p.setCompositionMode(QPainter::CompositionMode_SourceIn);
112 p.drawPixmap(m_targetRect, m_targetPixmap);
114 }
else if (m_targetPixmap.isNull()) {
115 currentPixmap = alignedStartPixmap();
116 if (qFuzzyCompare(delta, qreal(1.0))) {
117 return m_currentPixmap;
120 QPainter p(¤tPixmap);
121 p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
122 p.fillRect(currentPixmap.rect(), QColor(0, 0, 0, (
int)(254 - ((qreal)254)*delta)));
127 const_cast<PixmapTransition *
>(
this)->m_currentPixmap = currentPixmap;
130 return currentPixmap;
133 QPixmap PixmapTransition::alignedTargetPixmap()
const
135 QPixmap pm(m_pixmapSize);
136 pm.fill(Qt::transparent);
138 p.drawPixmap(m_targetRect, m_targetPixmap);
142 QPixmap PixmapTransition::alignedStartPixmap()
const
144 QPixmap pm(m_pixmapSize);
145 pm.fill(Qt::transparent);
147 p.drawPixmap(m_startRect, m_startPixmap);
151 void PixmapTransition::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState)
153 if (oldState == Stopped && newState == Running) {
154 m_targetRect = m_targetPixmap.rect();
155 m_startRect = m_startPixmap.rect();
156 m_pixmapSize = m_startRect.size().expandedTo(m_targetRect.size());
157 QRect actualRect = QRect(QPoint(0,0), m_pixmapSize);
158 m_targetRect.moveCenter(actualRect.center());
159 m_startRect.moveCenter(actualRect.center());
167 void PixmapTransition::updateEffectiveTime(
int currentTime)
169 Q_UNUSED(currentTime)
180 #include "pixmaptransition_p.moc"
QPixmap transition(const QPixmap &from, const QPixmap &to, qreal amount)
Blends a pixmap into another.