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

QFont DSRichText::parseStyle ( const QString &  s,
QColor *  color 
) [private]

parse the css style attribute of a tag and return a matching QFont for these style. The font color is saved in the QColor* color.

Definition at line 267 of file dsrichtext.cpp.

Referenced by DSRichText(), and parseParagraph().

{
    QString style = QString( s );

    style = style.left( style.length() - 1 );
    if( style.startsWith("style=\"" ) )
        style = style.mid( 7, style.length() - 7 );

    QFont f = m_base;
    *color = m_color;
    
    for ( int i = 0; i < style.contains(';')+1; i++ ) {
        QString s = style.section( ';', i, i );
        if( s.isEmpty() )
            continue;
                    
        if ( s.startsWith("font-size:" ) ) {
            f.setPointSize( s.mid(10, s.length() - 12).toInt() );
        } else if ( s.startsWith("font-family:" )  ) {
            f.setFamily( s.right( s.length() - 12 ) );
        } else if( s.startsWith( "color:" ) ) {
            color->setNamedColor( s.right( s.length() - 6 ) );
        } else if( s.startsWith("text-decoration:") ) {
            if( s.endsWith( "underline" ) )
                f.setUnderline( true );
/*#if QT_VERSION >= 0x030200
       else if( s.endsWith( "overline" ) )
                f.setOverline( true );
#endif */
            else if( s.endsWith( "line-through" ) )
                f.setStrikeOut( true );
        } else if( s.startsWith( "font-style:") ) {
            if( s.endsWith( "italic" ) || s.endsWith( "oblique" ) )
                f.setItalic( true );
        } else if( s.startsWith( "font-weight:" ) ) {
            bool ok = false;
            int n = s.right( s.length() - 12 ).toInt( &ok );
            if( s.endsWith( "bold" ) )
                f.setBold( true );
            else if( ok )
                f.setWeight( n / 8 ); // convert CSS values to Qt values
        }
    }

    return f;
}


Generated by  Doxygen 1.6.0   Back to index