File indexing completed on 2024-04-21 04:50:16

0001 /*
0002     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0003 
0004     Based on the effects in popupMessage.cpp
0005     SPDX-FileCopyrightText: 2005 Max Howell <max.howell@methylblue.com>
0006     SPDX-FileCopyrightText: 2005 Seb Ruiz <me@sebruiz.net>
0007 
0008     Dissolve Mask (c) Kicker Authors kickertip.cpp, 2005/08/17
0009 
0010     SPDX-License-Identifier: GPL-2.0-or-later
0011 */
0012 
0013 #ifndef _K3B_WIDGET_SHOW_EFFECT_H_
0014 #define _K3B_WIDGET_SHOW_EFFECT_H_
0015 
0016 #include <QObject>
0017 #include <QBitmap>
0018 
0019 
0020 class QTimerEvent;
0021 
0022 /**
0023  * Helper class to show and hide a widget in a fancy way.
0024  */
0025 namespace K3b {
0026 class WidgetShowEffect : public QObject
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     // FIXME: add an effect direction
0032     enum Effect {
0033         Dissolve = 1,
0034         Slide
0035     };
0036 
0037     explicit WidgetShowEffect( QWidget* widget, Effect e = Slide );
0038     ~WidgetShowEffect() override;
0039 
0040     void setEffect( Effect e ) { m_effect = e; }
0041 
0042     /**
0043      * Using the widget effects the easy way.
0044      * \returns the WidgetShowEffect instance used to show the widget.
0045      * Can be used to connect to signals.
0046      */
0047     static WidgetShowEffect* showWidget( QWidget* w, Effect );
0048 
0049     /**
0050      * Using the widget effects the easy way.
0051      * \returns the WidgetShowEffect instance used to hide the widget.
0052      * Can be used to connect to signals.
0053      */
0054     static WidgetShowEffect* hideWidget( QWidget* w, Effect );
0055 
0056 Q_SIGNALS:
0057     void widgetShown( QWidget* );
0058     void widgetHidden( QWidget* );
0059 
0060 public Q_SLOTS:
0061     /**
0062      * \param effectOnly If true WidgetShowEffect will not call QWidget::show().
0063      *                   This is only useful in case onw uses WidgetShowEffect
0064      *                   to reimplement QWidget::show(). In that case the caller
0065      *                   has to take care of showing the widget.
0066      */
0067     void show( bool effectOnly = false );
0068 
0069     /**
0070      * \param effectOnly If true WidgetShowEffect will not call QWidget::hide().
0071      *                   This is only useful in case onw uses WidgetShowEffect
0072      *                   to reimplement QWidget::hide(). In that case the caller
0073      *                   has to take care of hiding the widget by connecting to
0074      *                   WidgetShowEffect::widgetHidden()
0075      */
0076     void hide( bool effectOnly = false );
0077 
0078 private:
0079     void timerEvent( QTimerEvent* ) override;
0080   
0081     /**
0082      * @short Gradually show widget by dissolving from background
0083      */
0084     void dissolveMask();
0085   
0086     /**
0087      * @short animation to slide the widget into view
0088      */
0089     void slideMask();
0090 
0091     Effect m_effect;
0092     QWidget* m_widget;
0093 
0094     QBitmap m_mask;
0095 
0096     int m_dissolveSize;
0097     int m_dissolveDelta;
0098 
0099     int m_offset;
0100     int m_timerId;
0101 
0102     // if true we show, otherwise we hide the widget
0103     bool m_bShow;
0104 
0105     bool m_deleteSelf;
0106     bool m_bEffectOnly;
0107 };
0108 }
0109 
0110 #endif