Logo Search packages:      
Sourcecode: kbarcode version File versions  Download package

void DSRichText::draw ( QPainter *  p  ) 

draw the formated text on the QPainter* p

Definition at line 130 of file dsrichtext.cpp.

References formated_word::alignment, formated_word::color, drawJustified(), fillLines(), formated_word::font, formated_line::formats, formated_line::lineSpacing, formated_word::text, formated_line::width, and yDeviation().

{
    /* don't try to draw if there is no space to draw */
    if( !w || !h )
        return;
        
    fillLines();

    painter = p;
    painter->save();
    painter->setClipRect( 0, 0, int(w*sx), int(h*sy), QPainter::CoordPainter );

    for( unsigned int z = 0; z < line_p.count(); z++ ) {
        LineList lines = line_p[z];
        if( lines.count() && z )
            y += int( lines[0].lineSpacing * 0.5);

        for( unsigned int i = 0; i < lines.count(); i++ ) {
            formated_line l = lines[i];
            
            if( l.formats.count() && l.formats[0].alignment == Qt::AlignJustify && i != lines.count() - 1 ) {
                // last line in a paragraph is not justified (in blocksatz mode)!
                drawJustified( &l );
            } else {
                for( unsigned int z = 0; z < l.formats.count(); z++ ) {
                    formated_word f = l.formats[z];
            
                    painter->setFont( f.font );
                    painter->setPen( QPen( f.color ) );

                    int a = f.alignment;
                    if( a == Qt::AlignRight ) {
                        a = Qt::AlignLeft;
                        if( !x )
                            x = w - l.width;
                    } else if( a == Qt::AlignHCenter ) {
                        a = Qt::AlignLeft;
                        if( !x )
                            x = ( w - l.width ) / 2;
                    } 

                    int ya = yDeviation( &l );
                    painter->drawText( int(x*sx), int((y+ya)*sy), int(l.width*sx), int(l.lineSpacing * sy), a, f.text );
                    x +=  painter->fontMetrics().width( f.text );
                }
            }

            x = 0;
            y += l.lineSpacing;
        }
    }

    painter->restore();
}


Generated by  Doxygen 1.6.0   Back to index