File indexing completed on 2024-05-05 12:22:54
0001 /* 0002 SPDX-FileCopyrightText: 2013 Dominik Haumann <dhaumann@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KATE_FADE_EFFECT_H 0008 #define KATE_FADE_EFFECT_H 0009 0010 #include <QObject> 0011 #include <QPointer> 0012 0013 class QWidget; 0014 class QTimeLine; 0015 class QGraphicsOpacityEffect; 0016 /** 0017 * This class provides a fade in/out effect for arbitrary QWidget%s. 0018 * Example: 0019 * \code 0020 * KateFadeEffect* fadeEffect = new KateFadeEffect(someWidget); 0021 * fadeEffect->fadeIn(); 0022 * //... 0023 * fadeEffect->fadeOut(); 0024 * \endcode 0025 */ 0026 class KateFadeEffect : public QObject 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 /** 0032 * Constructor. 0033 * By default, the widget is fully opaque (opacity = 1.0). 0034 */ 0035 explicit KateFadeEffect(QWidget *widget = nullptr); 0036 0037 /** 0038 * Check whether the hide animation started by calling fadeOut() 0039 * is still running. If animations are disabled, this function always 0040 * returns @e false. 0041 */ 0042 bool isHideAnimationRunning() const; 0043 0044 /** 0045 * Check whether the show animation started by calling fadeIn() 0046 * is still running. If animations are disabled, this function always 0047 * returns @e false. 0048 */ 0049 bool isShowAnimationRunning() const; 0050 0051 public Q_SLOTS: 0052 /** 0053 * Call to fade out and hide the widget. 0054 */ 0055 void fadeOut(); 0056 0057 /** 0058 * Call to show and fade in the widget 0059 */ 0060 void fadeIn(); 0061 0062 Q_SIGNALS: 0063 /** 0064 * This signal is emitted when the fadeOut animation is finished, started by 0065 * calling fadeOut(). If animations are disabled, this signal is 0066 * emitted immediately. 0067 */ 0068 void hideAnimationFinished(); 0069 0070 /** 0071 * This signal is emitted when the fadeIn animation is finished, started by 0072 * calling fadeIn(). If animations are disabled, this signal is 0073 * emitted immediately. 0074 */ 0075 void showAnimationFinished(); 0076 0077 protected Q_SLOTS: 0078 /** 0079 * Helper to update opacity value 0080 */ 0081 void opacityChanged(qreal value); 0082 0083 /** 0084 * When the animation is finished, hide the widget if fading out. 0085 */ 0086 void animationFinished(); 0087 0088 private: 0089 QPointer<QWidget> m_widget; ///< the fading widget 0090 QTimeLine *m_timeLine; ///< update time line 0091 QPointer<QGraphicsOpacityEffect> m_effect; ///< graphics opacity effect 0092 }; 0093 0094 #endif