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     static QwtText *makeText(const QString &, Qt::TextFormat,
00041         int align, const QFont &, const QColor &color = QColor(),
00042         const QPen &pen = QPen(Qt::NoPen),
00043         const QBrush &brush = QBrush(Qt::NoBrush));
00044 
00045     static QwtText *makeText(const QString &, 
00046         int align, const QFont &, const QColor &color = QColor(),
00047         const QPen &pen = QPen(Qt::NoPen),
00048         const QBrush &brush = QBrush(Qt::NoBrush));
00049 
00050     static void setDefaultFormat(Qt::TextFormat);
00051     static Qt::TextFormat defaultFormat();
00052 
00053     virtual void setText(const QString &);
00054     QString text() const;
00055 
00056     inline bool isNull() const { return text().isNull(); }
00057     inline bool isEmpty() const { return text().isEmpty(); }
00058 
00059     virtual void setFont(const QFont &);
00060     QFont font() const;
00061     QFontMetrics fontMetrics() const;
00062 
00063     virtual void setAlignment(int align);
00064     int alignment() const;
00065 
00066     virtual void setColor(const QColor &);
00067     QColor color() const;
00068 
00069     virtual void setRectPen(const QPen &);
00070     QPen rectPen() const;
00071 
00072     virtual void setRectBrush(const QBrush &);
00073     QBrush rectBrush() const;
00074 
00080     virtual int heightForWidth(int width) const = 0;
00081 
00095     virtual QRect boundingRect(QPainter *painter = 0) const = 0;
00096 
00102     virtual void draw(QPainter *painter, const QRect &rect) const = 0;
00103 
00107     virtual QwtText *clone() const = 0;
00108 
00109 protected:
00110     QwtText(const QString &text, const QFont &, int align, const QColor &,
00111         const QPen &pen = QPen(Qt::NoPen),
00112         const QBrush &brush = QBrush(Qt::NoBrush));
00113 
00114 private:
00115     int d_align;
00116     QString d_text;
00117     QFont d_font;
00118     QColor d_color;
00119     QFontMetrics d_fm;
00120     QPen d_rectPen;
00121     QBrush d_rectBrush;
00122 
00123     static Qt::TextFormat d_defaultFormat;
00124 };
00125 
00126 
00130 class QWT_EXPORT QwtPlainText: public QwtText
00131 {
00132 public:
00133     QwtPlainText(const QString &text, const QFont &,
00134         int align = Qt::AlignCenter | Qt::WordBreak | Qt::ExpandTabs,
00135         const QColor &color = QColor(), const QPen &pen = QPen(Qt::NoPen),
00136         const QBrush &brush = QBrush(Qt::NoBrush));
00137 
00138     QwtPlainText(const QString &text, const QFont &font,
00139                  const QColor &color);
00140 
00141     virtual QwtText *clone() const;
00142 
00143     virtual int heightForWidth(int width) const;
00144     virtual QRect boundingRect(QPainter *painter = 0) const;
00145 
00146     virtual void draw(QPainter *painter, const QRect &rect) const;
00147 };
00148 
00149 
00150 #ifndef QT_NO_RICHTEXT
00151 
00155 class QWT_EXPORT QwtRichText: public QwtText
00156 {
00157 public:
00158     QwtRichText(const QString &text, const QFont &font,
00159         int align = Qt::AlignCenter | Qt::WordBreak | Qt::ExpandTabs,
00160         const QColor &color = QColor(),
00161         const QPen &pen = QPen(Qt::NoPen),
00162         const QBrush &brush = QBrush(Qt::NoBrush));
00163 
00164     QwtRichText(const QString &, const QFont &, const QColor &);
00165 
00166     virtual ~QwtRichText();
00167 
00168     virtual QwtText *clone() const;
00169 
00170     virtual void setText(const QString &text);
00171     virtual void setFont(const QFont &font);
00172     virtual void setAlignment(int align);
00173 
00174     virtual int heightForWidth(int width) const;
00175     virtual QRect boundingRect(QPainter *painter = 0) const;
00176 
00177     virtual void draw(QPainter *painter, const QRect &rect) const;
00178 
00179 private:
00180     QString taggedText(const QString &text, int alignment) const;
00181 
00182     QSimpleRichText *d_doc;
00183 };
00184 
00185 #endif
00186 
00187 #endif
00188 
00189 // Local Variables:
00190 // mode: C++
00191 // c-file-style: "stroustrup"
00192 // End:

Generated on Sun Sep 26 23:24:38 2004 for Qwt User's Guide by doxygen 1.3.6