| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2013 Dominik Haumann <dhaumann@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #ifndef KATE_FADE_EFFECT_H |
| 8 | #define KATE_FADE_EFFECT_H |
| 9 | |
| 10 | #include <QObject> |
| 11 | #include <QPointer> |
| 12 | |
| 13 | class QWidget; |
| 14 | class QTimeLine; |
| 15 | class QGraphicsOpacityEffect; |
| 16 | /** |
| 17 | * This class provides a fade in/out effect for arbitrary QWidget%s. |
| 18 | * Example: |
| 19 | * \code |
| 20 | * KateFadeEffect* fadeEffect = new KateFadeEffect(someWidget); |
| 21 | * fadeEffect->fadeIn(); |
| 22 | * //... |
| 23 | * fadeEffect->fadeOut(); |
| 24 | * \endcode |
| 25 | */ |
| 26 | class KateFadeEffect : public QObject |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | |
| 30 | public: |
| 31 | /** |
| 32 | * Constructor. |
| 33 | * By default, the widget is fully opaque (opacity = 1.0). |
| 34 | */ |
| 35 | explicit KateFadeEffect(QWidget *widget = nullptr); |
| 36 | |
| 37 | /** |
| 38 | * Check whether the hide animation started by calling fadeOut() |
| 39 | * is still running. If animations are disabled, this function always |
| 40 | * returns @e false. |
| 41 | */ |
| 42 | bool isHideAnimationRunning() const; |
| 43 | |
| 44 | /** |
| 45 | * Check whether the show animation started by calling fadeIn() |
| 46 | * is still running. If animations are disabled, this function always |
| 47 | * returns @e false. |
| 48 | */ |
| 49 | bool isShowAnimationRunning() const; |
| 50 | |
| 51 | public Q_SLOTS: |
| 52 | /** |
| 53 | * Call to fade out and hide the widget. |
| 54 | */ |
| 55 | void fadeOut(); |
| 56 | |
| 57 | /** |
| 58 | * Call to show and fade in the widget |
| 59 | */ |
| 60 | void fadeIn(); |
| 61 | |
| 62 | Q_SIGNALS: |
| 63 | /** |
| 64 | * This signal is emitted when the fadeOut animation is finished, started by |
| 65 | * calling fadeOut(). If animations are disabled, this signal is |
| 66 | * emitted immediately. |
| 67 | */ |
| 68 | void hideAnimationFinished(); |
| 69 | |
| 70 | /** |
| 71 | * This signal is emitted when the fadeIn animation is finished, started by |
| 72 | * calling fadeIn(). If animations are disabled, this signal is |
| 73 | * emitted immediately. |
| 74 | */ |
| 75 | void showAnimationFinished(); |
| 76 | |
| 77 | protected Q_SLOTS: |
| 78 | /** |
| 79 | * Helper to update opacity value |
| 80 | */ |
| 81 | void opacityChanged(qreal value); |
| 82 | |
| 83 | /** |
| 84 | * When the animation is finished, hide the widget if fading out. |
| 85 | */ |
| 86 | void animationFinished(); |
| 87 | |
| 88 | private: |
| 89 | QPointer<QWidget> m_widget; ///< the fading widget |
| 90 | QTimeLine *m_timeLine; ///< update time line |
| 91 | QPointer<QGraphicsOpacityEffect> m_effect; ///< graphics opacity effect |
| 92 | }; |
| 93 | |
| 94 | #endif |
| 95 | |