23 #include <QtGui/QWidget>
24 #include <QtCore/QPoint>
25 #include <QtCore/QRect>
26 #include <QtGui/QPainter>
27 #include <QtCore/QTimer>
28 #include <QtCore/QEvent>
29 #include <QtCore/QPointer>
30 #include <QtCore/QCoreApplication>
35 class KPixmapSequenceOverlayPainter::Private
46 QPointer<QWidget> m_widget;
47 Qt::Alignment m_alignment;
60 void KPixmapSequenceOverlayPainter::Private::_k_timeout()
62 if (sequence().isEmpty()) {
66 m_counter %= sequence().frameCount();
68 m_widget->update(pixmapRect());
72 void KPixmapSequenceOverlayPainter::Private::paintFrame()
74 if (m_counter >= sequence().frameCount()) {
78 p.drawPixmap(pixmapRect(), sequence().frameAt(m_counter),
QRect(
QPoint(0, 0), sequence().frameSize()));
85 if(m_sequence.isEmpty())
92 QRect KPixmapSequenceOverlayPainter::Private::pixmapRect()
96 rect = m_widget->rect();
98 QPoint pos(rect.topLeft());
99 if (m_alignment & Qt::AlignHCenter)
100 pos.setX(rect.center().x() - (sequence().frameSize().width() / 2));
101 else if (m_alignment & Qt::AlignRight)
102 pos.setX(rect.right() - sequence().frameSize().width());
104 if (m_alignment & Qt::AlignVCenter)
105 pos.setY(rect.center().y() - (sequence().frameSize().height() / 2));
106 else if (m_alignment & Qt::AlignBottom)
107 pos.setY(rect.bottom() - sequence().frameSize().height());
111 return QRect( pos, sequence().frameSize());
121 d->m_alignment = Qt::AlignCenter;
122 d->m_started =
false;
124 connect(&d->m_timer, SIGNAL(
timeout()),
this, SLOT(_k_timeout()));
137 return d->sequence();
143 return d->m_timer.interval();
149 if(d->m_rect.isValid()) {
152 else if(d->m_widget) {
153 return d->m_widget->rect();
163 return d->m_alignment;
175 bool restart = d->m_started;
184 d->m_timer.setInterval(msecs);
197 bool restart = d->m_started;
206 bool restart = d->m_started;
208 d->m_alignment = align;
215 bool restart = d->m_started;
229 d->m_widget->installEventFilter(
this);
230 if(d->m_widget->isVisible()) {
232 d->m_widget->update(d->pixmapRect());
242 d->m_started =
false;
243 d->m_widget->removeEventFilter(
this);
244 d->m_widget->update(d->pixmapRect());
249 bool KPixmapSequenceOverlayPainter::eventFilter(
QObject *obj, QEvent *event)
251 if (obj == d->m_widget ) {
252 switch (event->type()) {
255 obj->removeEventFilter(
this);
256 QCoreApplication::sendEvent(obj, event);
258 obj->installEventFilter(
this);
267 d->m_widget->update(d->pixmapRect());
278 #include "kpixmapsequenceoverlaypainter.moc"