DocumentShape Class Reference

#include <displayshape.h>

Inheritance diagram for DocumentShape:

Inheritance graph
[legend]
Collaboration diagram for DocumentShape:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 126 of file displayshape.h.

Public Member Functions

 DocumentShape (const QString &text, const QFont &font, const QPointF &position, const QSizeF &maxSize, int alpha=0)
 ~DocumentShape ()
bool animate ()
void paint (QPainter *painter) const
QRectF rect () const

Private Member Functions

void redraw ()

Private Attributes

QImage source
int alpha
QTextDocument textDocument


Constructor & Destructor Documentation

DocumentShape::DocumentShape ( const QString text,
const QFont font,
const QPointF position,
const QSizeF maxSize,
int  alpha = 0 
)

Definition at line 363 of file displayshape.cpp.

References QPainter::Antialiasing, QPainter::begin(), ceil, QTextDocument::documentLayout(), QAbstractTextDocumentLayout::documentSize(), QAbstractTextDocumentLayout::draw(), QPainter::end(), QImage::fill(), QImage::Format_ARGB32_Premultiplied, QSizeF::height(), DisplayShape::image, int, Qt::KeepAspectRatio, DisplayShape::maxSize, qMin(), qRgba(), redraw(), QTextDocument::setDefaultFont(), QTextDocument::setHtml(), QTextDocument::setPageSize(), QAbstractTextDocumentLayout::setPaintDevice(), QPainter::setRenderHint(), DisplayShape::setSize(), Qt::SmoothTransformation, source, QPainter::TextAntialiasing, textDocument, and QSizeF::width().

00366     : DisplayShape(position, maxSize), alpha(alpha)
00367 {
00368     textDocument.setHtml(text);
00369     textDocument.setDefaultFont(font);
00370     textDocument.setPageSize(maxSize);
00371     QSizeF documentSize = textDocument.documentLayout()->documentSize();
00372     setSize(QSizeF(maxSize.width(),
00373                       qMin(maxSize.height(), documentSize.height())));
00374 
00375     source = QImage(int(ceil(documentSize.width())),
00376                     int(ceil(documentSize.height())),
00377                     QImage::Format_ARGB32_Premultiplied);
00378     source.fill(qRgba(255, 255, 255, 255));
00379 
00380     QAbstractTextDocumentLayout::PaintContext context;
00381     textDocument.documentLayout()->setPaintDevice(&source);
00382 
00383     QPainter painter;
00384     painter.begin(&source);
00385     painter.setRenderHint(QPainter::TextAntialiasing);
00386     painter.setRenderHint(QPainter::Antialiasing);
00387     textDocument.documentLayout()->draw(&painter, context);
00388     painter.end();
00389 
00390     source = source.scaled(int(ceil(maxSize.width())),
00391                            int(ceil(maxSize.height())),
00392                            Qt::KeepAspectRatio,
00393                            Qt::SmoothTransformation);
00394 
00395     image = QImage(source.size(), source.format());
00396     redraw();
00397 }

Here is the call graph for this function:

DocumentShape::~DocumentShape (  ) 

Definition at line 399 of file displayshape.cpp.

00400 {
00401 }


Member Function Documentation

bool DocumentShape::animate (  )  [virtual]

Reimplemented from DisplayShape.

Definition at line 403 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().

00404 {
00405     bool updated = false;
00406 
00407     if (!meta.contains("destroy")) {
00408         if (meta.contains("fade")) {
00409             alpha = qBound(meta.value("fade minimum").toInt(),
00410                            alpha + meta.value("fade").toInt(), 255);
00411             redraw();
00412 
00413             if (alpha == 0) {
00414                 meta["destroy"] = true;
00415                 meta.remove("fade");
00416             } else if (alpha == 255)
00417                 meta.remove("fade");
00418 
00419             updated = true;
00420         }
00421     }
00422 
00423     return DisplayShape::animate() || updated;
00424 }

Here is the call graph for this function:

void DocumentShape::paint ( QPainter painter  )  const [virtual]

Reimplemented from DisplayShape.

Definition at line 437 of file displayshape.cpp.

References QPainter::drawImage(), DisplayShape::image, and DisplayShape::pos.

00438 {
00439     painter->drawImage(pos, image);
00440 }

Here is the call graph for this function:

QRectF DocumentShape::rect (  )  const [virtual]

Reimplemented from DisplayShape.

Definition at line 442 of file displayshape.cpp.

References DisplayShape::maxSize, and DisplayShape::pos.

Referenced by Launcher::showExampleSummary().

00443 {
00444     return QRectF(pos, maxSize);
00445 }

void DocumentShape::redraw (  )  [private]

Definition at line 426 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 DocumentShape().

00427 {
00428     image.fill(qRgba(alpha, alpha, alpha, alpha));
00429 
00430     QPainter painter;
00431     painter.begin(&image);
00432     painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
00433     painter.drawImage(0, 0, source);
00434     painter.end();
00435 }

Here is the call graph for this function:


Member Data Documentation

QImage DocumentShape::source [private]

Definition at line 141 of file displayshape.h.

Referenced by DocumentShape(), and redraw().

int DocumentShape::alpha [private]

Definition at line 142 of file displayshape.h.

Referenced by animate(), and redraw().

QTextDocument DocumentShape::textDocument [private]

Definition at line 143 of file displayshape.h.

Referenced by DocumentShape().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 14:52:44 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1