QTextImage
 All Classes Functions Pages
Public Member Functions | Static Public Member Functions | List of all members
QTextImage Class Reference

An ASCII-encoded image. More...

#include <qtextimage.h>

Public Member Functions

 QTextImage ()
 Constructs a null image.
 
 QTextImage (const QTextImage &)
 
QTextImageoperator= (const QTextImage &)
 
bool isValid () const
 Whether this image was parsed from a correct ASCIImage string.
 
QImage render (int scale, const QPen &strokePen, const QBrush &fillBrush=QBrush()) const
 Render the image on a QImage. More...
 
QImage render (int scale, std::function< void(char, QPainter &)> lineConfig) const
 Render the image on a QImage. More...
 

Static Public Member Functions

static QTextImage parse (const QByteArray &text)
 Parse a QTextImage from a byte array. More...
 
static QTextImage parse (const QString &text)
 Parse a QTextImage from a string. More...
 
static QTextImage parse (const QStringList &text)
 Parse a QTextImage from a list of strings. More...
 

Detailed Description

An ASCII-encoded image.

To create a QTextImage use the parse factory methods.

See http://asciimage.org/ for the language reference and other information.

QTextImage is implicitely shared (copy-on-write), so you can pass it by value with negligible overhead.

Member Function Documentation

QTextImage QTextImage::parse ( const QByteArray &  text)
static

Parse a QTextImage from a byte array.

Rows will be separated by newline charachters.

QTextImage QTextImage::parse ( const QString &  text)
inlinestatic

Parse a QTextImage from a string.

Rows will be separated by newline charachters.

QTextImage QTextImage::parse ( const QStringList &  text)
inlinestatic

Parse a QTextImage from a list of strings.

Each string will be parsed as a different row.

QImage QTextImage::render ( int  scale,
const QPen &  strokePen,
const QBrush &  fillBrush = QBrush() 
) const

Render the image on a QImage.

Parameters
scaleThe scale of the rendering (1 = 1px per character)
strokePenThe pen for stroking lines and points
fillBrushThe brush for filling ellipses and polygons
QImage QTextImage::render ( int  scale,
std::function< void(char, QPainter &)>  lineConfig 
) const

Render the image on a QImage.

Parameters
scaleThe scale of the rendering (1 = 1px per character)
lineConfigA function that will configure the painter for each character

For multi-character lines (polygons and ellypses), the first character will be passed to lineConfig If the painter is not configured for a character, QPainter default configuration will be used.

Sample usage (A black circle with a transparent X in the middle):

QTextImage textImage = QTextImage::parse(QStringLiteral(
". . . . 1 1 1 . . . .\n"
". . 1 . . . . . 1 . .\n"
". 1 . . . . . . . 1 .\n"
"1 . . 2 . . . 3 . . 1\n"
"1 . . . # . # . . . 1\n"
"1 . . . . # . . . . 1\n"
"1 . . . # . # . . . 1\n"
"1 . . 3 . . . 2 . . 1\n"
". 1 . . . . . . . 1 .\n"
". . 1 . . . . . 1 . .\n"
". . . 1 1 1 1 1 . . .\n"));
QImage img = textImage.render(2, [](char glyph, QPainter &painter){
switch (glyph) {
case '1':
painter.setBrush(Qt::black);
break;
case '2':
case '3':
// This will cut a transparent hole in the image
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.setPen(Qt::transparent);
break;
}
});

The documentation for this class was generated from the following files: