qwt_widget_overlay.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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_WIDGET_OVERLAY_H
  10. #define QWT_WIDGET_OVERLAY_H
  11. #include "qwt_global.h"
  12. #include <qwidget.h>
  13. #include <qregion.h>
  14. class QPainter;
  15. /*!
  16. \brief An overlay for a widget
  17. The main use case of an widget overlay is to avoid
  18. heavy repaint operation of the widget below.
  19. F.e. in combination with the plot canvas an overlay
  20. avoid replots as the content of the canvas can be restored from
  21. its backing store.
  22. QwtWidgetOverlay is an abstract base class. Deriving classes are
  23. supposed to reimplement the following methods:
  24. - drawOverlay()
  25. - maskHint()
  26. Internally QwtPlotPicker uses overlays for displaying
  27. the rubber band and the tracker text.
  28. \sa QwtPlotCanvas::BackingStore
  29. */
  30. class QWT_EXPORT QwtWidgetOverlay: public QWidget
  31. {
  32. public:
  33. /*!
  34. \brief Mask mode
  35. When using masks the widget below gets paint events for
  36. the masked regions of the overlay only. Otherwise
  37. Qt triggers full repaints. On less powerful hardware
  38. ( f.e embedded systems ) - or when using the raster paint
  39. engine on a remote desktop - bit blitting is a noticeable
  40. operation, that needs to be avoided.
  41. If and how to mask depends on how expensive the calculation
  42. of the mask is and how many pixels can be excluded by the mask.
  43. The default setting is MaskHint.
  44. \sa setMaskMode(), maskMode()
  45. */
  46. enum MaskMode
  47. {
  48. //! Don't use a mask.
  49. NoMask,
  50. /*!
  51. \brief Use maskHint() as mask
  52. For many situations a fast approximation is good enough
  53. and it is not necessary to build a more detailed mask
  54. ( f.e the bounding rectangle of a text ).
  55. */
  56. MaskHint,
  57. /*!
  58. \brief Calculate a mask by checking the alpha values
  59. Sometimes it is not possible to give a fast approximation
  60. and the mask needs to be calculated by drawing the overlay
  61. and testing the result.
  62. When a valid maskHint() is available
  63. only pixels inside this approximation are checked.
  64. */
  65. AlphaMask
  66. };
  67. /*!
  68. \brief Render mode
  69. For calculating the alpha mask the overlay has already
  70. been painted to a temporary QImage. Instead of rendering
  71. the overlay twice this buffer can be copied for drawing
  72. the overlay.
  73. On graphic systems using the raster paint engine ( QWS, Windows )
  74. it means usually copying some memory only. On X11 it results in an
  75. expensive operation building a pixmap and for simple overlays
  76. it might not be recommended.
  77. \note The render mode has no effect, when maskMode() != AlphaMask.
  78. */
  79. enum RenderMode
  80. {
  81. //! Copy the buffer, when using the raster paint engine.
  82. AutoRenderMode,
  83. //! Always copy the buffer
  84. CopyAlphaMask,
  85. //! Never copy the buffer
  86. DrawOverlay
  87. };
  88. QwtWidgetOverlay( QWidget* );
  89. virtual ~QwtWidgetOverlay();
  90. void setMaskMode( MaskMode );
  91. MaskMode maskMode() const;
  92. void setRenderMode( RenderMode );
  93. RenderMode renderMode() const;
  94. void updateOverlay();
  95. virtual bool eventFilter( QObject *, QEvent *);
  96. protected:
  97. virtual void paintEvent( QPaintEvent* event );
  98. virtual void resizeEvent( QResizeEvent* event );
  99. virtual QRegion maskHint() const;
  100. /*!
  101. Draw the widget overlay
  102. \param painter Painter
  103. */
  104. virtual void drawOverlay( QPainter *painter ) const = 0;
  105. private:
  106. void updateMask();
  107. void draw( QPainter * ) const;
  108. private:
  109. class PrivateData;
  110. PrivateData *d_data;
  111. };
  112. #endif