Qwt User's Guide: qwt_mathml_text_engine.cpp Source File

- Main Page
- Classes
- Files
- Related Pages

- File List
- File Members

# qwt_mathml_text_engine.cpp

    00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
    00002  * Qwt Widget Library
    00003  * Copyright (C) 1997   Josef Wilgen
    00004  * Copyright (C) 2003   Uwe Rathmann
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the Qwt License, Version 1.0
    00008  *****************************************************************************/
    00009
    00010 // vim: expandtab
    00011
    00012 #include <qglobal.h>
    00013 #if QT_VERSION >= 0x040000
    00014
    00015 #include <qstring.h>
    00016 #include <qpainter.h>
    00017 #include "qwt_mathml_text_engine.h"
    00018
    00019 #include <qtmmlwidget.h>
    00020
    00022 QwtMathMLTextEngine::QwtMathMLTextEngine()
    00023 {
    00024 }
    00025
    00027 QwtMathMLTextEngine::~QwtMathMLTextEngine()
    00028 {
    00029 }
    00030
    00041 int QwtMathMLTextEngine::heightForWidth(const QFont& font, int flags,
    00042         const QString& text, int) const
    00043 {
    00044     return textSize(font, flags, text).height();
    00045 }
    00046
    00056 QSize QwtMathMLTextEngine::textSize(const QFont &font,
    00057     int, const QString& text) const
    00058 {
    00059     static QString t;
    00060     static QSize sz;
    00061
    00062     if ( text != t )
    00063     {
    00064         QtMmlDocument doc;
    00065         doc.setContent(text);
    00066         doc.setBaseFontPointSize(font.pointSize());
    00067
    00068         sz = doc.size();
    00069         t = text;
    00070     }
    00071
    00072     return sz;
    00073 }
    00074
    00083 void QwtMathMLTextEngine::textMargins(const QFont &, const QString &,
    00084     int &left, int &right, int &top, int &bottom) const
    00085 {
    00086     left = right = top = bottom = 0;
    00087 }
    00088
    00097 void QwtMathMLTextEngine::draw(QPainter *painter, const QRect &rect,
    00098     int flags, const QString& text) const
    00099 {
    00100     QtMmlDocument doc;
    00101     doc.setContent(text);
    00102     doc.setBaseFontPointSize(painter->font().pointSize());
    00103
    00104     const QSize docSize = doc.size();
    00105
    00106     QPoint pos = rect.topLeft();
    00107     if ( rect.width() > docSize.width() )
    00108     {
    00109         if ( flags & Qt::AlignRight )
    00110             pos.setX(rect.right() - docSize.width());
    00111         if ( flags & Qt::AlignHCenter )
    00112             pos.setX(rect.center().x() - docSize.width() / 2);
    00113     }
    00114     if ( rect.height() > docSize.height() )
    00115     {
    00116         if ( flags & Qt::AlignBottom )
    00117             pos.setY(rect.bottom() - docSize.height());
    00118         if ( flags & Qt::AlignVCenter )
    00119             pos.setY(rect.center().y() - docSize.height() / 2);
    00120     }
    00121
    00122     doc.paint(painter, pos);
    00123 }
    00124
    00131 bool QwtMathMLTextEngine::mightRender(const QString &text) const
    00132 {
    00133     return text.trimmed().startsWith("<math");
    00134 }
    00135
    00136 #endif // QT_VERSION < 0x040000