File indexing completed on 2024-05-19 05:28:48

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