Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_text.h

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 #ifndef QWT_TEXT_H
00013 #define QWT_TEXT_H
00014 
00015 #include <qfont.h>
00016 #include <qfontmetrics.h>
00017 #include <qnamespace.h>
00018 #include <qpen.h>
00019 #include <qbrush.h>
00020 #include <qsimplerichtext.h>
00021 #include <qstring.h>
00022 
00023 #include "qwt_global.h"
00024 
00035 class QWT_EXPORT QwtText
00036 {
00037 public:
00038     virtual ~QwtText();
00039 
00040 #ifndef PYQWT_DEBUG
00041     static QwtText *makeText(const QString &, Qt::TextFormat,
00042         int align, const QFont &, const QColor &color = QColor(),
00043         const QPen &pen = QPen(Qt::NoPen),
00044         const QBrush &brush = QBrush(Qt::NoBrush));
00045 
00046     static QwtText *makeText(const QString &, 
00047         int align, const QFont &, const QColor &color = QColor(),
00048         const QPen &pen = QPen(Qt::NoPen),
00049         const QBrush &brush = QBrush(Qt::NoBrush));
00050 #else
00051     static QwtText *makeText(const QString &, Qt::TextFormat,
00052         int align, const QFont &, const QColor &color = QColor(),
00053         const QPen &pen = QPen(Qt::red, 2),
00054         const QBrush &brush = QBrush(Qt::yellow));
00055 
00056     static QwtText *makeText(const QString &, 
00057         int align, const QFont &, const QColor &color = QColor(),
00058         const QPen &pen = QPen(Qt::red, 2),
00059         const QBrush &brush = QBrush(Qt::yellow));
00060 #endif
00061 
00062     static void setDefaultFormat(Qt::TextFormat);
00063     static Qt::TextFormat defaultFormat();
00064 
00065     virtual void setText(const QString &);
00066     QString text() const;
00067 
00068     inline bool isNull() const { return text().isNull(); }
00069     inline bool isEmpty() const { return text().isEmpty(); }
00070 
00071     virtual void setFont(const QFont &);
00072     QFont font() const;
00073     QFontMetrics fontMetrics() const;
00074 
00075     virtual void setAlignment(int align);
00076     int alignment() const;
00077 
00078     virtual void setColor(const QColor &);
00079     QColor color() const;
00080 
00081     virtual void setRectPen(const QPen &);
00082     QPen rectPen() const;
00083 
00084     virtual void setRectBrush(const QBrush &);
00085     QBrush rectBrush() const;
00086 
00092     virtual int heightForWidth(int width) const = 0;
00093 
00107     virtual QRect boundingRect(QPainter *painter = 0) const = 0;
00108 
00114     virtual void draw(QPainter *painter, const QRect &rect) const = 0;
00115 
00119     virtual QwtText *clone() const = 0;
00120 
00121 protected:
00122     QwtText(const QString &text, const QFont &, int align, const QColor &,
00123         const QPen &pen = QPen(Qt::NoPen),
00124         const QBrush &brush = QBrush(Qt::NoBrush));
00125 
00126 private:
00127     int d_align;
00128     QString d_text;
00129     QFont d_font;
00130     QColor d_color;
00131     QFontMetrics d_fm;
00132     QPen d_rectPen;
00133     QBrush d_rectBrush;
00134 
00135     static Qt::TextFormat d_defaultFormat;
00136 };
00137 
00138 
00142 class QWT_EXPORT QwtPlainText: public QwtText
00143 {
00144 public:
00145     QwtPlainText(const QString &text, const QFont &,
00146         int align = Qt::AlignCenter | Qt::WordBreak | Qt::ExpandTabs,
00147         const QColor &color = QColor(), const QPen &pen = QPen(Qt::NoPen),
00148         const QBrush &brush = QBrush(Qt::NoBrush));
00149 
00150     QwtPlainText(const QString &text, const QFont &font,
00151                  const QColor &color);
00152 
00153     virtual QwtText *clone() const;
00154 
00155     virtual int heightForWidth(int width) const;
00156     virtual QRect boundingRect(QPainter *painter = 0) const;
00157 
00158     virtual void draw(QPainter *painter, const QRect &rect) const;
00159 };
00160 
00161 
00162 #ifndef QT_NO_RICHTEXT
00163 
00167 class QWT_EXPORT QwtRichText: public QwtText
00168 {
00169 public:
00170     QwtRichText(const QString &text, const QFont &font,
00171         int align = Qt::AlignCenter | Qt::WordBreak | Qt::ExpandTabs,
00172         const QColor &color = QColor(),
00173         const QPen &pen = QPen(Qt::NoPen),
00174         const QBrush &brush = QBrush(Qt::NoBrush));
00175 
00176     QwtRichText(const QString &, const QFont &, const QColor &);
00177 
00178     virtual ~QwtRichText();
00179 
00180     virtual QwtText *clone() const;
00181 
00182     virtual void setText(const QString &text);
00183     virtual void setFont(const QFont &font);
00184     virtual void setAlignment(int align);
00185 
00186     virtual int heightForWidth(int width) const;
00187     virtual QRect boundingRect(QPainter *painter = 0) const;
00188 
00189     virtual void draw(QPainter *painter, const QRect &rect) const;
00190 
00191 private:
00192     QString taggedText(const QString &text, int alignment) const;
00193 
00194     QSimpleRichText *d_doc;
00195 };
00196 
00197 #endif
00198 
00199 #endif
00200 
00201 // Local Variables:
00202 // mode: C++
00203 // c-file-style: "stroustrup"
00204 // End:

Generated on Sun Nov 21 11:12:44 2004 for Qwt User's Guide by doxygen 1.3.5