qwt_painter.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 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_PAINTER_H
  10. #define QWT_PAINTER_H
  11. #include "qwt_global.h"
  12. #include <qpoint.h>
  13. #include <qrect.h>
  14. #include <qpen.h>
  15. #include <qline.h>
  16. #include <qpalette.h>
  17. class QPainter;
  18. class QBrush;
  19. class QColor;
  20. class QWidget;
  21. class QPolygonF;
  22. class QRectF;
  23. class QImage;
  24. class QPixmap;
  25. class QwtScaleMap;
  26. class QwtColorMap;
  27. class QwtInterval;
  28. class QTextDocument;
  29. class QPainterPath;
  30. /*!
  31. \brief A collection of QPainter workarounds
  32. */
  33. class QWT_EXPORT QwtPainter
  34. {
  35. public:
  36. static void setPolylineSplitting( bool );
  37. static bool polylineSplitting();
  38. static void setRoundingAlignment( bool );
  39. static bool roundingAlignment();
  40. static bool roundingAlignment(QPainter *);
  41. static void drawText( QPainter *, double x, double y, const QString & );
  42. static void drawText( QPainter *, const QPointF &, const QString & );
  43. static void drawText( QPainter *, double x, double y, double w, double h,
  44. int flags, const QString & );
  45. static void drawText( QPainter *, const QRectF &,
  46. int flags, const QString & );
  47. #ifndef QT_NO_RICHTEXT
  48. static void drawSimpleRichText( QPainter *, const QRectF &,
  49. int flags, const QTextDocument & );
  50. #endif
  51. static void drawRect( QPainter *, double x, double y, double w, double h );
  52. static void drawRect( QPainter *, const QRectF &rect );
  53. static void fillRect( QPainter *, const QRectF &, const QBrush & );
  54. static void drawEllipse( QPainter *, const QRectF & );
  55. static void drawPie( QPainter *, const QRectF &, int a, int alen );
  56. static void drawLine( QPainter *, double x1, double y1, double x2, double y2 );
  57. static void drawLine( QPainter *, const QPointF &p1, const QPointF &p2 );
  58. static void drawLine( QPainter *, const QLineF & );
  59. static void drawPolygon( QPainter *, const QPolygonF & );
  60. static void drawPolyline( QPainter *, const QPolygonF & );
  61. static void drawPolyline( QPainter *, const QPointF *, int pointCount );
  62. static void drawPolygon( QPainter *, const QPolygon & );
  63. static void drawPolyline( QPainter *, const QPolygon & );
  64. static void drawPolyline( QPainter *, const QPoint *, int pointCount );
  65. static void drawPoint( QPainter *, const QPoint & );
  66. static void drawPoints( QPainter *, const QPolygon & );
  67. static void drawPoints( QPainter *, const QPoint *, int pointCount );
  68. static void drawPoint( QPainter *, double x, double y );
  69. static void drawPoint( QPainter *, const QPointF & );
  70. static void drawPoints( QPainter *, const QPolygonF & );
  71. static void drawPoints( QPainter *, const QPointF *, int pointCount );
  72. static void drawPath( QPainter *, const QPainterPath & );
  73. static void drawImage( QPainter *, const QRectF &, const QImage & );
  74. static void drawPixmap( QPainter *, const QRectF &, const QPixmap & );
  75. static void drawRoundFrame( QPainter *,
  76. const QRectF &, const QPalette &, int lineWidth, int frameStyle );
  77. static void drawRoundedFrame( QPainter *,
  78. const QRectF &, double xRadius, double yRadius,
  79. const QPalette &, int lineWidth, int frameStyle );
  80. static void drawFrame( QPainter *, const QRectF &rect,
  81. const QPalette &palette, QPalette::ColorRole foregroundRole,
  82. int frameWidth, int midLineWidth, int frameStyle );
  83. static void drawFocusRect( QPainter *, const QWidget * );
  84. static void drawFocusRect( QPainter *, const QWidget *, const QRect & );
  85. static void drawColorBar( QPainter *painter,
  86. const QwtColorMap &, const QwtInterval &,
  87. const QwtScaleMap &, Qt::Orientation, const QRectF & );
  88. static bool isAligning( QPainter *painter );
  89. static bool isX11GraphicsSystem();
  90. static void fillPixmap( const QWidget *,
  91. QPixmap &, const QPoint &offset = QPoint() );
  92. static void drawBackgound( QPainter *painter,
  93. const QRectF &rect, const QWidget *widget );
  94. static QPixmap backingStore( QWidget *, const QSize & );
  95. private:
  96. static bool d_polylineSplitting;
  97. static bool d_roundingAlignment;
  98. };
  99. //! Wrapper for QPainter::drawPoint()
  100. inline void QwtPainter::drawPoint( QPainter *painter, double x, double y )
  101. {
  102. QwtPainter::drawPoint( painter, QPointF( x, y ) );
  103. }
  104. //! Wrapper for QPainter::drawPoints()
  105. inline void QwtPainter::drawPoints( QPainter *painter, const QPolygon &polygon )
  106. {
  107. drawPoints( painter, polygon.data(), polygon.size() );
  108. }
  109. //! Wrapper for QPainter::drawPoints()
  110. inline void QwtPainter::drawPoints( QPainter *painter, const QPolygonF &polygon )
  111. {
  112. drawPoints( painter, polygon.data(), polygon.size() );
  113. }
  114. //! Wrapper for QPainter::drawLine()
  115. inline void QwtPainter::drawLine( QPainter *painter,
  116. double x1, double y1, double x2, double y2 )
  117. {
  118. QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) );
  119. }
  120. //! Wrapper for QPainter::drawLine()
  121. inline void QwtPainter::drawLine( QPainter *painter, const QLineF &line )
  122. {
  123. QwtPainter::drawLine( painter, line.p1(), line.p2() );
  124. }
  125. /*!
  126. \return True, when line splitting for the raster paint engine is enabled.
  127. \sa setPolylineSplitting()
  128. */
  129. inline bool QwtPainter::polylineSplitting()
  130. {
  131. return d_polylineSplitting;
  132. }
  133. /*!
  134. Check whether coordinates should be rounded, before they are painted
  135. to a paint engine that rounds to integer values. For other paint engines
  136. ( PDF, SVG ), this flag has no effect.
  137. \return True, when rounding is enabled
  138. \sa setRoundingAlignment(), isAligning()
  139. */
  140. inline bool QwtPainter::roundingAlignment()
  141. {
  142. return d_roundingAlignment;
  143. }
  144. /*!
  145. \return roundingAlignment() && isAligning(painter);
  146. \param painter Painter
  147. */
  148. inline bool QwtPainter::roundingAlignment(QPainter *painter)
  149. {
  150. return d_roundingAlignment && isAligning(painter);
  151. }
  152. #endif