| 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 | |
| 40 | #ifndef QGRAPHICSEFFECT_H |
| 41 | #define QGRAPHICSEFFECT_H |
| 42 | |
| 43 | #include <QtWidgets/qtwidgetsglobal.h> |
| 44 | #include <QtCore/qobject.h> |
| 45 | #include <QtCore/qpoint.h> |
| 46 | #include <QtCore/qrect.h> |
| 47 | #include <QtGui/qcolor.h> |
| 48 | #include <QtGui/qbrush.h> |
| 49 | |
| 50 | QT_REQUIRE_CONFIG(graphicseffect); |
| 51 | |
| 52 | QT_BEGIN_NAMESPACE |
| 53 | |
| 54 | class QGraphicsItem; |
| 55 | class QStyleOption; |
| 56 | class QPainter; |
| 57 | class QPixmap; |
| 58 | |
| 59 | class QGraphicsEffectSource; |
| 60 | |
| 61 | class QGraphicsEffectPrivate; |
| 62 | class Q_WIDGETS_EXPORT QGraphicsEffect : public QObject |
| 63 | { |
| 64 | Q_OBJECT |
| 65 | Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) |
| 66 | public: |
| 67 | enum ChangeFlag { |
| 68 | SourceAttached = 0x1, |
| 69 | SourceDetached = 0x2, |
| 70 | SourceBoundingRectChanged = 0x4, |
| 71 | SourceInvalidated = 0x8 |
| 72 | }; |
| 73 | Q_DECLARE_FLAGS(ChangeFlags, ChangeFlag) |
| 74 | Q_FLAG(ChangeFlags) |
| 75 | |
| 76 | enum PixmapPadMode { |
| 77 | NoPad, |
| 78 | PadToTransparentBorder, |
| 79 | PadToEffectiveBoundingRect |
| 80 | }; |
| 81 | |
| 82 | QGraphicsEffect(QObject *parent = nullptr); |
| 83 | virtual ~QGraphicsEffect(); |
| 84 | |
| 85 | virtual QRectF boundingRectFor(const QRectF &sourceRect) const; |
| 86 | QRectF boundingRect() const; |
| 87 | |
| 88 | bool isEnabled() const; |
| 89 | |
| 90 | public Q_SLOTS: |
| 91 | void setEnabled(bool enable); |
| 92 | void update(); |
| 93 | |
| 94 | Q_SIGNALS: |
| 95 | void enabledChanged(bool enabled); |
| 96 | |
| 97 | protected: |
| 98 | QGraphicsEffect(QGraphicsEffectPrivate &d, QObject *parent = nullptr); |
| 99 | virtual void draw(QPainter *painter) = 0; |
| 100 | virtual void sourceChanged(ChangeFlags flags); |
| 101 | void updateBoundingRect(); |
| 102 | |
| 103 | bool sourceIsPixmap() const; |
| 104 | QRectF sourceBoundingRect(Qt::CoordinateSystem system = Qt::LogicalCoordinates) const; |
| 105 | void drawSource(QPainter *painter); |
| 106 | QPixmap sourcePixmap(Qt::CoordinateSystem system = Qt::LogicalCoordinates, |
| 107 | QPoint *offset = nullptr, |
| 108 | PixmapPadMode mode = PadToEffectiveBoundingRect) const; |
| 109 | |
| 110 | private: |
| 111 | Q_DECLARE_PRIVATE(QGraphicsEffect) |
| 112 | Q_DISABLE_COPY(QGraphicsEffect) |
| 113 | friend class QGraphicsItem; |
| 114 | friend class QGraphicsItemPrivate; |
| 115 | friend class QGraphicsScenePrivate; |
| 116 | friend class QWidget; |
| 117 | friend class QWidgetPrivate; |
| 118 | |
| 119 | public: |
| 120 | QGraphicsEffectSource *source() const; // internal |
| 121 | |
| 122 | }; |
| 123 | Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsEffect::ChangeFlags) |
| 124 | |
| 125 | class QGraphicsColorizeEffectPrivate; |
| 126 | class Q_WIDGETS_EXPORT QGraphicsColorizeEffect: public QGraphicsEffect |
| 127 | { |
| 128 | Q_OBJECT |
| 129 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
| 130 | Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) |
| 131 | public: |
| 132 | QGraphicsColorizeEffect(QObject *parent = nullptr); |
| 133 | ~QGraphicsColorizeEffect(); |
| 134 | |
| 135 | QColor color() const; |
| 136 | qreal strength() const; |
| 137 | |
| 138 | public Q_SLOTS: |
| 139 | void setColor(const QColor &c); |
| 140 | void setStrength(qreal strength); |
| 141 | |
| 142 | Q_SIGNALS: |
| 143 | void colorChanged(const QColor &color); |
| 144 | void strengthChanged(qreal strength); |
| 145 | |
| 146 | protected: |
| 147 | void draw(QPainter *painter) override; |
| 148 | |
| 149 | private: |
| 150 | Q_DECLARE_PRIVATE(QGraphicsColorizeEffect) |
| 151 | Q_DISABLE_COPY(QGraphicsColorizeEffect) |
| 152 | }; |
| 153 | |
| 154 | class QGraphicsBlurEffectPrivate; |
| 155 | class Q_WIDGETS_EXPORT QGraphicsBlurEffect: public QGraphicsEffect |
| 156 | { |
| 157 | Q_OBJECT |
| 158 | Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) |
| 159 | Q_PROPERTY(BlurHints blurHints READ blurHints WRITE setBlurHints NOTIFY blurHintsChanged) |
| 160 | public: |
| 161 | enum BlurHint { |
| 162 | PerformanceHint = 0x00, |
| 163 | QualityHint = 0x01, |
| 164 | AnimationHint = 0x02 |
| 165 | }; |
| 166 | Q_FLAG(BlurHint) |
| 167 | Q_DECLARE_FLAGS(BlurHints, BlurHint) |
| 168 | Q_FLAG(BlurHints) |
| 169 | |
| 170 | QGraphicsBlurEffect(QObject *parent = nullptr); |
| 171 | ~QGraphicsBlurEffect(); |
| 172 | |
| 173 | QRectF boundingRectFor(const QRectF &rect) const override; |
| 174 | qreal blurRadius() const; |
| 175 | BlurHints blurHints() const; |
| 176 | |
| 177 | public Q_SLOTS: |
| 178 | void setBlurRadius(qreal blurRadius); |
| 179 | void setBlurHints(BlurHints hints); |
| 180 | |
| 181 | Q_SIGNALS: |
| 182 | void blurRadiusChanged(qreal blurRadius); |
| 183 | void blurHintsChanged(BlurHints hints); |
| 184 | |
| 185 | protected: |
| 186 | void draw(QPainter *painter) override; |
| 187 | |
| 188 | private: |
| 189 | Q_DECLARE_PRIVATE(QGraphicsBlurEffect) |
| 190 | Q_DISABLE_COPY(QGraphicsBlurEffect) |
| 191 | }; |
| 192 | |
| 193 | Q_DECLARE_OPERATORS_FOR_FLAGS(QGraphicsBlurEffect::BlurHints) |
| 194 | |
| 195 | class QGraphicsDropShadowEffectPrivate; |
| 196 | class Q_WIDGETS_EXPORT QGraphicsDropShadowEffect: public QGraphicsEffect |
| 197 | { |
| 198 | Q_OBJECT |
| 199 | Q_PROPERTY(QPointF offset READ offset WRITE setOffset NOTIFY offsetChanged) |
| 200 | Q_PROPERTY(qreal xOffset READ xOffset WRITE setXOffset NOTIFY offsetChanged) |
| 201 | Q_PROPERTY(qreal yOffset READ yOffset WRITE setYOffset NOTIFY offsetChanged) |
| 202 | Q_PROPERTY(qreal blurRadius READ blurRadius WRITE setBlurRadius NOTIFY blurRadiusChanged) |
| 203 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
| 204 | public: |
| 205 | QGraphicsDropShadowEffect(QObject *parent = nullptr); |
| 206 | ~QGraphicsDropShadowEffect(); |
| 207 | |
| 208 | QRectF boundingRectFor(const QRectF &rect) const override; |
| 209 | QPointF offset() const; |
| 210 | |
| 211 | inline qreal xOffset() const |
| 212 | { return offset().x(); } |
| 213 | |
| 214 | inline qreal yOffset() const |
| 215 | { return offset().y(); } |
| 216 | |
| 217 | qreal blurRadius() const; |
| 218 | QColor color() const; |
| 219 | |
| 220 | public Q_SLOTS: |
| 221 | void setOffset(const QPointF &ofs); |
| 222 | |
| 223 | inline void setOffset(qreal dx, qreal dy) |
| 224 | { setOffset(QPointF(dx, dy)); } |
| 225 | |
| 226 | inline void setOffset(qreal d) |
| 227 | { setOffset(QPointF(d, d)); } |
| 228 | |
| 229 | inline void setXOffset(qreal dx) |
| 230 | { setOffset(QPointF(dx, yOffset())); } |
| 231 | |
| 232 | inline void setYOffset(qreal dy) |
| 233 | { setOffset(QPointF(xOffset(), dy)); } |
| 234 | |
| 235 | void setBlurRadius(qreal blurRadius); |
| 236 | void setColor(const QColor &color); |
| 237 | |
| 238 | Q_SIGNALS: |
| 239 | void offsetChanged(const QPointF &offset); |
| 240 | void blurRadiusChanged(qreal blurRadius); |
| 241 | void colorChanged(const QColor &color); |
| 242 | |
| 243 | protected: |
| 244 | void draw(QPainter *painter) override; |
| 245 | |
| 246 | private: |
| 247 | Q_DECLARE_PRIVATE(QGraphicsDropShadowEffect) |
| 248 | Q_DISABLE_COPY(QGraphicsDropShadowEffect) |
| 249 | }; |
| 250 | |
| 251 | class QGraphicsOpacityEffectPrivate; |
| 252 | class Q_WIDGETS_EXPORT QGraphicsOpacityEffect: public QGraphicsEffect |
| 253 | { |
| 254 | Q_OBJECT |
| 255 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) |
| 256 | Q_PROPERTY(QBrush opacityMask READ opacityMask WRITE setOpacityMask NOTIFY opacityMaskChanged) |
| 257 | public: |
| 258 | QGraphicsOpacityEffect(QObject *parent = nullptr); |
| 259 | ~QGraphicsOpacityEffect(); |
| 260 | |
| 261 | qreal opacity() const; |
| 262 | QBrush opacityMask() const; |
| 263 | |
| 264 | public Q_SLOTS: |
| 265 | void setOpacity(qreal opacity); |
| 266 | void setOpacityMask(const QBrush &mask); |
| 267 | |
| 268 | Q_SIGNALS: |
| 269 | void opacityChanged(qreal opacity); |
| 270 | void opacityMaskChanged(const QBrush &mask); |
| 271 | |
| 272 | protected: |
| 273 | void draw(QPainter *painter) override; |
| 274 | |
| 275 | private: |
| 276 | Q_DECLARE_PRIVATE(QGraphicsOpacityEffect) |
| 277 | Q_DISABLE_COPY(QGraphicsOpacityEffect) |
| 278 | }; |
| 279 | |
| 280 | QT_END_NAMESPACE |
| 281 | |
| 282 | #endif // QGRAPHICSEFFECT_H |
| 283 | |
| 284 | |