qwt_painter.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. class QPainter;
  17. class QBrush;
  18. class QColor;
  19. class QWidget;
  20. class QPolygonF;
  21. class QRectF;
  22. class QImage;
  23. class QPixmap;
  24. class QwtScaleMap;
  25. class QwtColorMap;
  26. class QwtInterval;
  27. class QPalette;
  28. class QTextDocument;
  29. /*!
  30. \brief A collection of QPainter workarounds
  31. */
  32. class QWT_EXPORT QwtPainter
  33. {
  34. public:
  35. static void setPolylineSplitting( bool );
  36. static bool polylineSplitting();
  37. static void setRoundingAlignment( bool );
  38. static bool roundingAlignment();
  39. static bool roundingAlignment(QPainter *);
  40. static void drawText( QPainter *, double x, double y, const QString & );
  41. static void drawText( QPainter *, const QPointF &, const QString & );
  42. static void drawText( QPainter *, double x, double y, double w, double h,
  43. int flags, const QString & );
  44. static void drawText( QPainter *, const QRectF &,
  45. int flags, const QString & );
  46. #ifndef QT_NO_RICHTEXT
  47. static void drawSimpleRichText( QPainter *, const QRectF &,
  48. int flags, const QTextDocument & );
  49. #endif
  50. static void drawRect( QPainter *, double x, double y, double w, double h );
  51. static void drawRect( QPainter *, const QRectF &rect );
  52. static void fillRect( QPainter *, const QRectF &, const QBrush & );
  53. static void drawEllipse( QPainter *, const QRectF & );
  54. static void drawPie( QPainter *, const QRectF & r, int a, int alen );
  55. static void drawLine( QPainter *, double x1, double y1, double x2, double y2 );
  56. static void drawLine( QPainter *, const QPointF &p1, const QPointF &p2 );
  57. static void drawLine( QPainter *, const QLineF & );
  58. static void drawPolygon( QPainter *, const QPolygonF &pa );
  59. static void drawPolyline( QPainter *, const QPolygonF &pa );
  60. static void drawPolyline( QPainter *, const QPointF *, int pointCount );
  61. static void drawPoint( QPainter *, double x, double y );
  62. static void drawPoint( QPainter *, const QPointF & );
  63. static void drawImage( QPainter *, const QRectF &, const QImage & );
  64. static void drawPixmap( QPainter *, const QRectF &, const QPixmap & );
  65. static void drawRoundFrame( QPainter *, const QRect &,
  66. int width, const QPalette &, bool sunken );
  67. static void drawFocusRect( QPainter *, QWidget * );
  68. static void drawFocusRect( QPainter *, QWidget *, const QRect & );
  69. static void drawColorBar( QPainter *painter,
  70. const QwtColorMap &, const QwtInterval &,
  71. const QwtScaleMap &, Qt::Orientation, const QRectF & );
  72. static bool isAligning( QPainter *painter );
  73. private:
  74. static void drawColoredArc( QPainter *, const QRect &,
  75. int peak, int arc, int intervall, const QColor &c1, const QColor &c2 );
  76. static bool d_polylineSplitting;
  77. static bool d_roundingAlignment;
  78. };
  79. //! Wrapper for QPainter::drawPoint()
  80. inline void QwtPainter::drawPoint( QPainter *painter, double x, double y )
  81. {
  82. QwtPainter::drawPoint( painter, QPointF( x, y ) );
  83. }
  84. //! Wrapper for QPainter::drawLine()
  85. inline void QwtPainter::drawLine( QPainter *painter,
  86. double x1, double y1, double x2, double y2 )
  87. {
  88. QwtPainter::drawLine( painter, QPointF( x1, y1 ), QPointF( x2, y2 ) );
  89. }
  90. //! Wrapper for QPainter::drawLine()
  91. inline void QwtPainter::drawLine( QPainter *painter, const QLineF &line )
  92. {
  93. QwtPainter::drawLine( painter, line.p1(), line.p2() );
  94. }
  95. /*!
  96. Returns whether line splitting for the raster paint engine is enabled.
  97. \sa setPolylineSplitting()
  98. */
  99. inline bool QwtPainter::polylineSplitting()
  100. {
  101. return d_polylineSplitting;
  102. }
  103. /*!
  104. Returns whether coordinates should be rounded, before they are painted
  105. to a paint engine that floors to integer values. For other paint engines
  106. this ( Pdf, SVG ), this flag has no effect.
  107. \sa setRoundingAlignment(), isAligning()
  108. */
  109. inline bool QwtPainter::roundingAlignment()
  110. {
  111. return d_roundingAlignment;
  112. }
  113. /*!
  114. \return roundingAlignment() && isAligning(painter);
  115. \param painter Painter
  116. */
  117. inline bool QwtPainter::roundingAlignment(QPainter *painter)
  118. {
  119. return d_roundingAlignment && isAligning(painter);
  120. }
  121. #endif