#include <displayshape.h>
Inheritance diagram for ImageShape:
Definition at line 106 of file displayshape.h.
Public Member Functions | |
ImageShape (const QImage &original, const QPointF &position, const QSizeF &maxSize, int alpha=0, Qt::Alignment alignment=Qt::AlignCenter) | |
bool | animate () |
void | paint (QPainter *painter) const |
QRectF | rect () const |
Private Member Functions | |
void | redraw () |
Private Attributes | |
int | alpha |
QImage | source |
QPointF | offset |
Qt::Alignment | alignment |
ImageShape::ImageShape | ( | const QImage & | original, | |
const QPointF & | position, | |||
const QSizeF & | maxSize, | |||
int | alpha = 0 , |
|||
Qt::Alignment | alignment = Qt::AlignCenter | |||
) |
Definition at line 288 of file displayshape.cpp.
References Qt::AlignBottom, Qt::AlignHCenter, Qt::AlignRight, Qt::AlignVCenter, ceil, QImage::convertToFormat(), QImage::Format_ARGB32_Premultiplied, QImage::height(), QSizeF::height(), DisplayShape::image, int, Qt::KeepAspectRatio, DisplayShape::maxSize, offset, qMin(), redraw(), scale(), QImage::scaled(), QPointF::setX(), QPointF::setY(), Qt::SmoothTransformation, source, QImage::width(), and QSizeF::width().
00291 : DisplayShape(position, maxSize), alpha(alpha), alignment(alignment) 00292 { 00293 source = original.convertToFormat(QImage::Format_ARGB32_Premultiplied); 00294 qreal scale = qMin(qMin(maxSize.width()/source.width(), 00295 maxSize.height()/source.height()), qreal(1.0)); 00296 00297 source = source.scaled(int(ceil(source.width() * scale)), 00298 int(ceil(source.height() * scale)), 00299 Qt::KeepAspectRatio, 00300 Qt::SmoothTransformation); 00301 00302 image = QImage(source.size(), QImage::Format_ARGB32_Premultiplied); 00303 00304 offset = QPointF(0.0, 0.0); 00305 00306 if (alignment & Qt::AlignHCenter) 00307 offset.setX((maxSize.width() - image.width())/2); 00308 else if (alignment & Qt::AlignRight) 00309 offset.setX(maxSize.width() - image.width()); 00310 00311 if (alignment & Qt::AlignVCenter) 00312 offset.setY((maxSize.height() - image.height())/2); 00313 else if (alignment & Qt::AlignBottom) 00314 offset.setY(maxSize.height() - image.height()); 00315 00316 redraw(); 00317 }
Here is the call graph for this function:
bool ImageShape::animate | ( | ) | [virtual] |
Reimplemented from DisplayShape.
Definition at line 340 of file displayshape.cpp.
References alpha, DisplayShape::animate(), QHash< Key, T >::contains(), DisplayShape::meta, redraw(), QHash< Key, T >::remove(), QVariant::toInt(), and QHash< Key, T >::value().
00341 { 00342 bool updated = false; 00343 00344 if (!meta.contains("destroy")) { 00345 if (meta.contains("fade")) { 00346 alpha = qBound(meta.value("fade minimum").toInt(), 00347 alpha + meta.value("fade").toInt(), 255); 00348 redraw(); 00349 00350 if (alpha == 0) { 00351 meta["destroy"] = true; 00352 meta.remove("fade"); 00353 } else if (alpha == 255) 00354 meta.remove("fade"); 00355 00356 updated = true; 00357 } 00358 } 00359 00360 return DisplayShape::animate() || updated; 00361 }
Here is the call graph for this function:
void ImageShape::paint | ( | QPainter * | painter | ) | const [virtual] |
Reimplemented from DisplayShape.
Definition at line 330 of file displayshape.cpp.
References QPainter::drawImage(), DisplayShape::image, offset, and DisplayShape::pos.
Here is the call graph for this function:
QRectF ImageShape::rect | ( | ) | const [virtual] |
Reimplemented from DisplayShape.
Definition at line 335 of file displayshape.cpp.
References DisplayShape::maxSize, and DisplayShape::pos.
void ImageShape::redraw | ( | ) | [private] |
Definition at line 319 of file displayshape.cpp.
References alpha, QPainter::begin(), QPainter::CompositionMode_SourceIn, QPainter::drawImage(), QPainter::end(), QImage::fill(), DisplayShape::image, qRgba(), QPainter::setCompositionMode(), and source.
Referenced by animate(), and ImageShape().
00320 { 00321 image.fill(qRgba(alpha, alpha, alpha, alpha)); 00322 00323 QPainter painter; 00324 painter.begin(&image); 00325 painter.setCompositionMode(QPainter::CompositionMode_SourceIn); 00326 painter.drawImage(0, 0, source); 00327 painter.end(); 00328 }
Here is the call graph for this function:
int ImageShape::alpha [private] |
QImage ImageShape::source [private] |
QPointF ImageShape::offset [private] |
Qt::Alignment ImageShape::alignment [private] |
Definition at line 123 of file displayshape.h.