qwt_plot_canvas.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_PLOT_CANVAS_H
  10. #define QWT_PLOT_CANVAS_H
  11. #include "qwt_global.h"
  12. #include <qframe.h>
  13. #include <qpainterpath.h>
  14. class QwtPlot;
  15. class QPixmap;
  16. /*!
  17. \brief Canvas of a QwtPlot.
  18. Canvas is the widget where all plot items are displayed
  19. \sa QwtPlot::setCanvas(), QwtPlotGLCanvas
  20. */
  21. class QWT_EXPORT QwtPlotCanvas : public QFrame
  22. {
  23. Q_OBJECT
  24. Q_PROPERTY( double borderRadius READ borderRadius WRITE setBorderRadius )
  25. public:
  26. /*!
  27. \brief Paint attributes
  28. The default setting enables BackingStore and Opaque.
  29. \sa setPaintAttribute(), testPaintAttribute()
  30. */
  31. enum PaintAttribute
  32. {
  33. /*!
  34. \brief Paint double buffered reusing the content
  35. of the pixmap buffer when possible.
  36. Using a backing store might improve the performance
  37. significantly, when working with widget overlays ( like rubber bands ).
  38. Disabling the cache might improve the performance for
  39. incremental paints (using QwtPlotDirectPainter ).
  40. \sa backingStore(), invalidateBackingStore()
  41. */
  42. BackingStore = 1,
  43. /*!
  44. \brief Try to fill the complete contents rectangle
  45. of the plot canvas
  46. When using styled backgrounds Qt assumes, that the
  47. canvas doesn't fill its area completely
  48. ( f.e because of rounded borders ) and fills the area
  49. below the canvas. When this is done with gradients it might
  50. result in a serious performance bottleneck - depending on the size.
  51. When the Opaque attribute is enabled the canvas tries to
  52. identify the gaps with some heuristics and to fill those only.
  53. \warning Will not work for semitransparent backgrounds
  54. */
  55. Opaque = 2,
  56. /*!
  57. \brief Try to improve painting of styled backgrounds
  58. QwtPlotCanvas supports the box model attributes for
  59. customizing the layout with style sheets. Unfortunately
  60. the design of Qt style sheets has no concept how to
  61. handle backgrounds with rounded corners - beside of padding.
  62. When HackStyledBackground is enabled the plot canvas tries
  63. to separate the background from the background border
  64. by reverse engineering to paint the background before and
  65. the border after the plot items. In this order the border
  66. gets perfectly antialiased and you can avoid some pixel
  67. artifacts in the corners.
  68. */
  69. HackStyledBackground = 4,
  70. /*!
  71. When ImmediatePaint is set replot() calls repaint()
  72. instead of update().
  73. \sa replot(), QWidget::repaint(), QWidget::update()
  74. */
  75. ImmediatePaint = 8
  76. };
  77. //! Paint attributes
  78. typedef QFlags<PaintAttribute> PaintAttributes;
  79. /*!
  80. \brief Focus indicator
  81. The default setting is NoFocusIndicator
  82. \sa setFocusIndicator(), focusIndicator(), drawFocusIndicator()
  83. */
  84. enum FocusIndicator
  85. {
  86. //! Don't paint a focus indicator
  87. NoFocusIndicator,
  88. /*!
  89. The focus is related to the complete canvas.
  90. Paint the focus indicator using drawFocusIndicator()
  91. */
  92. CanvasFocusIndicator,
  93. /*!
  94. The focus is related to an item (curve, point, ...) on
  95. the canvas. It is up to the application to display a
  96. focus indication using f.e. highlighting.
  97. */
  98. ItemFocusIndicator
  99. };
  100. explicit QwtPlotCanvas( QwtPlot * = NULL );
  101. virtual ~QwtPlotCanvas();
  102. QwtPlot *plot();
  103. const QwtPlot *plot() const;
  104. void setFocusIndicator( FocusIndicator );
  105. FocusIndicator focusIndicator() const;
  106. void setBorderRadius( double );
  107. double borderRadius() const;
  108. void setPaintAttribute( PaintAttribute, bool on = true );
  109. bool testPaintAttribute( PaintAttribute ) const;
  110. const QPixmap *backingStore() const;
  111. void invalidateBackingStore();
  112. virtual bool event( QEvent * );
  113. Q_INVOKABLE QPainterPath borderPath( const QRect & ) const;
  114. public Q_SLOTS:
  115. void replot();
  116. protected:
  117. virtual void paintEvent( QPaintEvent * );
  118. virtual void resizeEvent( QResizeEvent * );
  119. virtual void drawFocusIndicator( QPainter * );
  120. virtual void drawBorder( QPainter * );
  121. void updateStyleSheetInfo();
  122. private:
  123. void drawCanvas( QPainter *, bool withBackground );
  124. class PrivateData;
  125. PrivateData *d_data;
  126. };
  127. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtPlotCanvas::PaintAttributes )
  128. #endif