qwt_text.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2003 Uwe Rathmann
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the Qwt License, Version 1.0
  8. *****************************************************************************/
  9. #ifndef QWT_TEXT_H
  10. #define QWT_TEXT_H
  11. #include "qwt_global.h"
  12. #include <qstring.h>
  13. #include <qsize.h>
  14. #include <qfont.h>
  15. class QColor;
  16. class QPen;
  17. class QBrush;
  18. class QRectF;
  19. class QPainter;
  20. class QwtTextEngine;
  21. /*!
  22. \brief A class representing a text
  23. A QwtText is a text including a set of attributes how to render it.
  24. - Format\n
  25. A text might include control sequences (f.e tags) describing
  26. how to render it. Each format (f.e MathML, TeX, Qt Rich Text)
  27. has its own set of control sequences, that can be handles by
  28. a QwtTextEngine for this format.
  29. - Background\n
  30. A text might have a background, defined by a QPen and QBrush
  31. to improve its visibility.
  32. - Font\n
  33. A text might have an individual font.
  34. - Color\n
  35. A text might have an individual color.
  36. - Render Flags\n
  37. Flags from Qt::AlignmentFlag and Qt::TextFlag used like in
  38. QPainter::drawText.
  39. \sa QwtTextEngine, QwtTextLabel
  40. */
  41. class QWT_EXPORT QwtText
  42. {
  43. public:
  44. /*!
  45. \brief Text format
  46. The text format defines the QwtTextEngine, that is used to render
  47. the text.
  48. - AutoText\n
  49. The text format is determined using QwtTextEngine::mightRender for
  50. all available text engines in increasing order > PlainText.
  51. If none of the text engines can render the text is rendered
  52. like PlainText.
  53. - PlainText\n
  54. Draw the text as it is, using a QwtPlainTextEngine.
  55. - RichText\n
  56. Use the Scribe framework (Qt Rich Text) to render the text.
  57. - MathMLText\n
  58. Use a MathML (http://en.wikipedia.org/wiki/MathML) render engine
  59. to display the text. The Qwt MathML extension offers such an engine
  60. based on the MathML renderer of the Qt solutions package.
  61. To enable MathML support the following code needs to be added to the
  62. application:
  63. \verbatimQwtText::setTextEngine(QwtText::MathMLText, new QwtMathMLTextEngine());\endverbatim
  64. - TeXText\n
  65. Use a TeX (http://en.wikipedia.org/wiki/TeX) render engine
  66. to display the text ( not implemented yet ).
  67. - OtherFormat\n
  68. The number of text formats can be extended using setTextEngine.
  69. Formats >= OtherFormat are not used by Qwt.
  70. \sa QwtTextEngine, setTextEngine()
  71. */
  72. enum TextFormat
  73. {
  74. AutoText = 0,
  75. PlainText,
  76. RichText,
  77. MathMLText,
  78. TeXText,
  79. OtherFormat = 100
  80. };
  81. /*!
  82. \brief Paint Attributes
  83. Font and color and background are optional attributes of a QwtText.
  84. The paint attributes hold the information, if they are set.
  85. - PaintUsingTextFont\n
  86. The text has an individual font.
  87. - PaintUsingTextColor\n
  88. The text has an individual color.
  89. - PaintBackground\n
  90. The text has an individual background.
  91. */
  92. enum PaintAttribute
  93. {
  94. PaintUsingTextFont = 1,
  95. PaintUsingTextColor = 2,
  96. PaintBackground = 4
  97. };
  98. /*!
  99. \brief Layout Attributes
  100. The layout attributes affects some aspects of the layout of the text.
  101. - MinimumLayout\n
  102. Layout the text without its margins. This mode is useful if a
  103. text needs to be aligned accurately, like the tick labels of a scale.
  104. If QwtTextEngine::textMargins is not implemented for the format
  105. of the text, MinimumLayout has no effect.
  106. */
  107. enum LayoutAttribute
  108. {
  109. MinimumLayout = 1
  110. };
  111. QwtText( const QString & = QString::null,
  112. TextFormat textFormat = AutoText );
  113. QwtText( const QwtText & );
  114. ~QwtText();
  115. QwtText &operator=( const QwtText & );
  116. bool operator==( const QwtText & ) const;
  117. bool operator!=( const QwtText & ) const;
  118. void setText( const QString &,
  119. QwtText::TextFormat textFormat = AutoText );
  120. QString text() const;
  121. bool isNull() const;
  122. bool isEmpty() const;
  123. void setFont( const QFont & );
  124. QFont font() const;
  125. QFont usedFont( const QFont & ) const;
  126. void setRenderFlags( int flags );
  127. int renderFlags() const;
  128. void setColor( const QColor & );
  129. QColor color() const;
  130. QColor usedColor( const QColor & ) const;
  131. void setBackgroundPen( const QPen & );
  132. QPen backgroundPen() const;
  133. void setBackgroundBrush( const QBrush & );
  134. QBrush backgroundBrush() const;
  135. void setPaintAttribute( PaintAttribute, bool on = true );
  136. bool testPaintAttribute( PaintAttribute ) const;
  137. void setLayoutAttribute( LayoutAttribute, bool on = true );
  138. bool testLayoutAttribute( LayoutAttribute ) const;
  139. double heightForWidth( double width, const QFont & = QFont() ) const;
  140. QSizeF textSize( const QFont & = QFont() ) const;
  141. void draw( QPainter *painter, const QRectF &rect ) const;
  142. static const QwtTextEngine *textEngine(
  143. const QString &text, QwtText::TextFormat = AutoText );
  144. static const QwtTextEngine *textEngine( QwtText::TextFormat );
  145. static void setTextEngine( QwtText::TextFormat, QwtTextEngine * );
  146. private:
  147. class PrivateData;
  148. PrivateData *d_data;
  149. class LayoutCache;
  150. LayoutCache *d_layoutCache;
  151. };
  152. //! \return text().isNull()
  153. inline bool QwtText::isNull() const
  154. {
  155. return text().isNull();
  156. }
  157. //! \return text().isEmpty()
  158. inline bool QwtText::isEmpty() const
  159. {
  160. return text().isEmpty();
  161. }
  162. #endif