qgraphicseffect.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWidgets module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QGRAPHICSEFFECT_H
  40. #define QGRAPHICSEFFECT_H
  41. #include <QtCore/qobject.h>
  42. #include <QtCore/qpoint.h>
  43. #include <QtCore/qrect.h>
  44. #include <QtGui/qcolor.h>
  45. #include <QtGui/qbrush.h>
  46. #ifndef QT_NO_GRAPHICSEFFECT
  47. QT_BEGIN_NAMESPACE
  48. class QGraphicsItem;
  49. class QStyleOption;
  50. class QPainter;
  51. class QPixmap;
  52. class QGraphicsEffectSource;
  53. class QGraphicsEffectPrivate;
  54. class Q_WIDGETS_EXPORT QGraphicsEffect : public QObject
  55. {
  56. Q_OBJECT
  57. Q_FLAGS(ChangeFlags)
  58. Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
  59. public:
  60. enum ChangeFlag {
  61. SourceAttached = 0x1,
  62. SourceDetached = 0x2,
  63. SourceBoundingRectChanged = 0x4,
  64. SourceInvalidated = 0x8
  65. };
  66. Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag)
  67. enum PixmapPadMode {
  68. NoPad,
  69. PadToTransparentBorder,
  70. PadToEffectiveBoundingRect
  71. };
  72. QGraphicsEffect(QObject *parent = Q_NULLPTR);
  73. virtual ~QGraphicsEffect();
  74. virtual QRectF boundingRectFor(const QRectF &sourceRect) const;
  75. QRectF boundingRect() const;
  76. bool isEnabled() const;
  77. public Q_SLOTS:
  78. void setEnabled(bool enable);
  79. void update();
  80. Q_SIGNALS:
  81. void enabledChanged(bool enabled);
  82. protected:
  83. QGraphicsEffect(QGraphicsEffectPrivate &d, QObject *parent = Q_NULLPTR);
  84. virtual void draw(QPainter *painter) = 0;
  85. virtual void sourceChanged(ChangeFlags flags);
  86. void updateBoundingRect();
  87. bool sourceIsPixmap() const;
  88. QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const;
  89. void drawSource(QPainter *painter);
  90. QPixmap sourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates,
  91. QPoint *offset = Q_NULLPTR,
  92. PixmapPadMode mode = PadToEffectiveBoundingRect) const;
  93. private:
  94. Q_DECLARE_PRIVATE(QGraphicsEffect)
  95. Q_DISABLE_COPY(QGraphicsEffect)
  96. friend class QGraphicsItem;
  97. friend class QGraphicsItemPrivate;
  98. friend class QGraphicsScenePrivate;
  99. friend class QWidget;
  100. friend class QWidgetPrivate;
  101. public:
  102. QGraphicsEffectSource *source() const; // internal
  103. };
  104. Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags)
  105. class QGraphicsColorizeEffectPrivate;
  106. class Q_WIDGETS_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect
  107. {
  108. Q_OBJECT
  109. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
  110. Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged)
  111. public:
  112. QGraphicsColorizeEffect(QObject *parent = Q_NULLPTR);
  113. ~QGraphicsColorizeEffect();
  114. QColor color() const;
  115. qreal strength() const;
  116. public Q_SLOTS:
  117. void setColor(const QColor &c);
  118. void setStrength(qreal strength);
  119. Q_SIGNALS:
  120. void colorChanged(const QColor &color);
  121. void strengthChanged(qreal strength);
  122. protected:
  123. void draw(QPainter *painter) Q_DECL_OVERRIDE;
  124. private:
  125. Q_DECLARE_PRIVATE(QGraphicsColorizeEffect)
  126. Q_DISABLE_COPY(QGraphicsColorizeEffect)
  127. };
  128. class QGraphicsBlurEffectPrivate;
  129. class Q_WIDGETS_EXPORT QGraphicsBlurEffect: public QGraphicsEffect
  130. {
  131. Q_OBJECT
  132. Q_FLAGS(BlurHint BlurHints)
  133. Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
  134. Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged)
  135. public:
  136. enum BlurHint {
  137. PerformanceHint = 0x00,
  138. QualityHint = 0x01,
  139. AnimationHint = 0x02
  140. };
  141. Q_DECLARE_FLAGS(BlurHints, BlurHint)
  142. QGraphicsBlurEffect(QObject *parent = Q_NULLPTR);
  143. ~QGraphicsBlurEffect();
  144. QRectF boundingRectFor(const QRectF &rect) const Q_DECL_OVERRIDE;
  145. qreal blurRadius() const;
  146. BlurHints blurHints() const;
  147. public Q_SLOTS:
  148. void setBlurRadius(qreal blurRadius);
  149. void setBlurHints(BlurHints hints);
  150. Q_SIGNALS:
  151. void blurRadiusChanged(qreal blurRadius);
  152. void blurHintsChanged(BlurHints hints);
  153. protected:
  154. void draw(QPainter *painter) Q_DECL_OVERRIDE;
  155. private:
  156. Q_DECLARE_PRIVATE(QGraphicsBlurEffect)
  157. Q_DISABLE_COPY(QGraphicsBlurEffect)
  158. };
  159. Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints)
  160. class QGraphicsDropShadowEffectPrivate;
  161. class Q_WIDGETS_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect
  162. {
  163. Q_OBJECT
  164. Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged)
  165. Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged)
  166. Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged)
  167. Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged)
  168. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
  169. public:
  170. QGraphicsDropShadowEffect(QObject *parent = Q_NULLPTR);
  171. ~QGraphicsDropShadowEffect();
  172. QRectF boundingRectFor(const QRectF &rect) const Q_DECL_OVERRIDE;
  173. QPointF offset() const;
  174. inline qreal xOffset() const
  175. { return offset().x(); }
  176. inline qreal yOffset() const
  177. { return offset().y(); }
  178. qreal blurRadius() const;
  179. QColor color() const;
  180. public Q_SLOTS:
  181. void setOffset(const QPointF &ofs);
  182. inline void setOffset(qreal dx, qreal dy)
  183. { setOffset(QPointF(dx, dy)); }
  184. inline void setOffset(qreal d)
  185. { setOffset(QPointF(d, d)); }
  186. inline void setXOffset(qreal dx)
  187. { setOffset(QPointF(dx, yOffset())); }
  188. inline void setYOffset(qreal dy)
  189. { setOffset(QPointF(xOffset(), dy)); }
  190. void setBlurRadius(qreal blurRadius);
  191. void setColor(const QColor &color);
  192. Q_SIGNALS:
  193. void offsetChanged(const QPointF &offset);
  194. void blurRadiusChanged(qreal blurRadius);
  195. void colorChanged(const QColor &color);
  196. protected:
  197. void draw(QPainter *painter) Q_DECL_OVERRIDE;
  198. private:
  199. Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect)
  200. Q_DISABLE_COPY(QGraphicsDropShadowEffect)
  201. };
  202. class QGraphicsOpacityEffectPrivate;
  203. class Q_WIDGETS_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect
  204. {
  205. Q_OBJECT
  206. Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
  207. Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged)
  208. public:
  209. QGraphicsOpacityEffect(QObject *parent = Q_NULLPTR);
  210. ~QGraphicsOpacityEffect();
  211. qreal opacity() const;
  212. QBrush opacityMask() const;
  213. public Q_SLOTS:
  214. void setOpacity(qreal opacity);
  215. void setOpacityMask(const QBrush &mask);
  216. Q_SIGNALS:
  217. void opacityChanged(qreal opacity);
  218. void opacityMaskChanged(const QBrush &mask);
  219. protected:
  220. void draw(QPainter *painter) Q_DECL_OVERRIDE;
  221. private:
  222. Q_DECLARE_PRIVATE(QGraphicsOpacityEffect)
  223. Q_DISABLE_COPY(QGraphicsOpacityEffect)
  224. };
  225. QT_END_NAMESPACE
  226. #endif //QT_NO_GRAPHICSEFFECT
  227. #endif // QGRAPHICSEFFECT_H