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

0001 #ifndef oxygendockseparator_data_h
0002 #define oxygendockseparator_data_h
0003 
0004 //////////////////////////////////////////////////////////////////////////////
0005 // oxygendockseparatordata.h
0006 // generic data container for widgetstate hover (mouse-over) 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 "oxygenanimation.h"
0015 #include "oxygengenericdata.h"
0016 
0017 namespace Oxygen
0018 {
0019 //* dock widget splitters hover effect
0020 class DockSeparatorData : public AnimationData
0021 {
0022     Q_OBJECT
0023 
0024     //* declare opacity property
0025     Q_PROPERTY(qreal verticalOpacity READ verticalOpacity WRITE setVerticalOpacity)
0026     Q_PROPERTY(qreal horizontalOpacity READ horizontalOpacity WRITE setHorizontalOpacity)
0027 
0028 public:
0029     //* constructor
0030     DockSeparatorData(QObject *parent, QWidget *target, int duration);
0031 
0032     //@}
0033 
0034     /*!
0035     returns true if hover has Changed
0036     and starts timer accordingly
0037     */
0038     void updateRect(const QRect &, const Qt::Orientation &, bool hovered);
0039 
0040     //* returns true if current splitter is animated
0041     bool isAnimated(QRect r, const Qt::Orientation &orientation) const
0042     {
0043         return orientation == Qt::Vertical ? _verticalData.isAnimated(r) : _horizontalData.isAnimated(r);
0044     }
0045 
0046     //* opacity for given orientation
0047     qreal opacity(const Qt::Orientation &orientation) const
0048     {
0049         return orientation == Qt::Vertical ? verticalOpacity() : horizontalOpacity();
0050     }
0051 
0052     //* duration
0053     void setDuration(int duration) override
0054     {
0055         horizontalAnimation().data()->setDuration(duration);
0056         verticalAnimation().data()->setDuration(duration);
0057     }
0058 
0059     //*@name horizontal splitter data
0060     //@{
0061 
0062     Animation::Pointer horizontalAnimation(void) const
0063     {
0064         return _horizontalData._animation;
0065     }
0066 
0067     const QRect &horizontalRect(void) const
0068     {
0069         return _horizontalData._rect;
0070     }
0071 
0072     void setHorizontalRect(const QRect &r)
0073     {
0074         _horizontalData._rect = r;
0075     }
0076 
0077     qreal horizontalOpacity(void) const
0078     {
0079         return _horizontalData._opacity;
0080     }
0081 
0082     void setHorizontalOpacity(qreal value)
0083     {
0084         value = digitize(value);
0085         if (_horizontalData._opacity == value)
0086             return;
0087         _horizontalData._opacity = value;
0088         if (target() && !horizontalRect().isEmpty())
0089             target().data()->update(horizontalRect());
0090     }
0091 
0092     //@}
0093 
0094     //*@name vertical splitter data
0095     //@{
0096 
0097     Animation::Pointer verticalAnimation(void) const
0098     {
0099         return _verticalData._animation;
0100     }
0101 
0102     const QRect &verticalRect(void) const
0103     {
0104         return _verticalData._rect;
0105     }
0106 
0107     void setVerticalRect(const QRect &r)
0108     {
0109         _verticalData._rect = r;
0110     }
0111 
0112     qreal verticalOpacity(void) const
0113     {
0114         return _verticalData._opacity;
0115     }
0116 
0117     void setVerticalOpacity(qreal value)
0118     {
0119         value = digitize(value);
0120         if (_verticalData._opacity == value)
0121             return;
0122         _verticalData._opacity = value;
0123         if (target() && !verticalRect().isEmpty())
0124             target().data()->update(verticalRect());
0125     }
0126 
0127     //@}
0128 
0129 private:
0130     //* stores data needed for animation
0131     class Data
0132     {
0133     public:
0134         //* constructor
0135         Data(void)
0136             : _opacity(AnimationData::OpacityInvalid)
0137         {
0138         }
0139 
0140         //* true if is animated
0141         bool isAnimated(QRect r) const
0142         {
0143             return r == _rect && _animation.data()->isRunning();
0144         }
0145 
0146         //* animation pointer
0147         Animation::Pointer _animation;
0148 
0149         //* opacity variable
0150         qreal _opacity;
0151 
0152         //* stores active separator rect
0153         QRect _rect;
0154     };
0155 
0156     //* horizontal
0157     Data _horizontalData;
0158 
0159     //* vertical
0160     Data _verticalData;
0161 };
0162 }
0163 
0164 #endif