File indexing completed on 2024-05-19 05:35:20

0001 #ifndef oxygenheaderview_data_h
0002 #define oxygenheaderview_data_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygenheaderviewdata.h
0006 // data container for QHeaderView animations
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0010 //
0011 // SPDX-License-Identifier: MIT
0012 //////////////////////////////////////////////////////////////////////////////
0013 
0014 #include "oxygenanimationdata.h"
0015 #include <QHeaderView>
0016 
0017 namespace Oxygen
0018 {
0019 //* headerviews
0020 class HeaderViewData : public AnimationData
0021 {
0022     Q_OBJECT
0023 
0024     //* declare opacity property
0025     Q_PROPERTY(qreal currentOpacity READ currentOpacity WRITE setCurrentOpacity)
0026     Q_PROPERTY(qreal previousOpacity READ previousOpacity WRITE setPreviousOpacity)
0027 
0028 public:
0029     //* constructor
0030     HeaderViewData(QObject *parent, QWidget *target, int duration);
0031 
0032     //* duration
0033     void setDuration(int duration) override
0034     {
0035         currentIndexAnimation().data()->setDuration(duration);
0036         previousIndexAnimation().data()->setDuration(duration);
0037     }
0038 
0039     //* update state
0040     bool updateState(const QPoint &, bool);
0041 
0042     //*@name current index handling
0043     //@{
0044 
0045     //* current opacity
0046     qreal currentOpacity(void) const
0047     {
0048         return _current._opacity;
0049     }
0050 
0051     //* current opacity
0052     void setCurrentOpacity(qreal value)
0053     {
0054         value = digitize(value);
0055         if (_current._opacity == value)
0056             return;
0057         _current._opacity = value;
0058         setDirty();
0059     }
0060 
0061     //* current index
0062     int currentIndex(void) const
0063     {
0064         return _current._index;
0065     }
0066 
0067     //* current index
0068     void setCurrentIndex(int index)
0069     {
0070         _current._index = index;
0071     }
0072 
0073     //* current index animation
0074     const Animation::Pointer &currentIndexAnimation(void) const
0075     {
0076         return _current._animation;
0077     }
0078 
0079     //@}
0080 
0081     //*@name previous index handling
0082     //@{
0083 
0084     //* previous opacity
0085     qreal previousOpacity(void) const
0086     {
0087         return _previous._opacity;
0088     }
0089 
0090     //* previous opacity
0091     void setPreviousOpacity(qreal value)
0092     {
0093         value = digitize(value);
0094         if (_previous._opacity == value)
0095             return;
0096         _previous._opacity = value;
0097         setDirty();
0098     }
0099 
0100     //* previous index
0101     int previousIndex(void) const
0102     {
0103         return _previous._index;
0104     }
0105 
0106     //* previous index
0107     void setPreviousIndex(int index)
0108     {
0109         _previous._index = index;
0110     }
0111 
0112     //* previous index Animation
0113     const Animation::Pointer &previousIndexAnimation(void) const
0114     {
0115         return _previous._animation;
0116     }
0117 
0118     //@}
0119 
0120     //* return Animation associated to action at given position, if any
0121     Animation::Pointer animation(const QPoint &position) const;
0122 
0123     //* return opacity associated to action at given position, if any
0124     qreal opacity(const QPoint &position) const;
0125 
0126 protected:
0127     //* dirty
0128     void setDirty(void) const override;
0129 
0130 private:
0131     //* container for needed animation data
0132     class Data
0133     {
0134     public:
0135         //* default constructor
0136         Data(void) = default;
0137 
0138         Animation::Pointer _animation;
0139         qreal _opacity = 0;
0140         int _index = -1;
0141     };
0142 
0143     //* current tab animation data (for hover enter animations)
0144     Data _current;
0145 
0146     //* previous tab animations data (for hover leave animations)
0147     Data _previous;
0148 };
0149 }
0150 
0151 #endif