File indexing completed on 2024-05-19 05:35:19
0001 #ifndef oxygen_animationdata_h 0002 #define oxygen_animationdata_h 0003 0004 ////////////////////////////////////////////////////////////////////////////// 0005 // oxygenanimationdata.h 0006 // base class data container needed for widget 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 "oxygen.h" 0015 #include "oxygenanimation.h" 0016 0017 #include <QEvent> 0018 #include <QObject> 0019 #include <QWidget> 0020 #include <cmath> 0021 0022 namespace Oxygen 0023 { 0024 //* base class 0025 class AnimationData : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 //* constructor 0031 AnimationData(QObject *parent, QWidget *target) 0032 : QObject(parent) 0033 , _target(target) 0034 { 0035 } 0036 0037 //*@name accessors 0038 //@{ 0039 0040 //* enable state 0041 virtual bool enabled(void) const 0042 { 0043 return _enabled; 0044 } 0045 0046 //* target 0047 const WeakPointer<QWidget> &target(void) const 0048 { 0049 return _target; 0050 } 0051 0052 //@} 0053 0054 //*@name modifiers 0055 //@{ 0056 0057 //* duration 0058 virtual void setDuration(int) = 0; 0059 0060 //* steps 0061 static void setSteps(int value) 0062 { 0063 _steps = value; 0064 } 0065 0066 //* enability 0067 virtual void setEnabled(bool value) 0068 { 0069 _enabled = value; 0070 } 0071 0072 //@} 0073 0074 //* invalid opacity 0075 static const qreal OpacityInvalid; 0076 0077 protected: 0078 //* setup animation 0079 virtual void setupAnimation(const Animation::Pointer &animation, const QByteArray &property); 0080 0081 //* apply step 0082 virtual qreal digitize(const qreal &value) const 0083 { 0084 if (_steps > 0) 0085 return std::floor(value * _steps) / _steps; 0086 else 0087 return value; 0088 } 0089 0090 //* trigger target update 0091 virtual void setDirty(void) const 0092 { 0093 if (_target) 0094 _target.data()->update(); 0095 } 0096 0097 private: 0098 //* guarded target 0099 WeakPointer<QWidget> _target; 0100 0101 //* enability 0102 bool _enabled = true; 0103 0104 //* steps 0105 static int _steps; 0106 }; 0107 } 0108 0109 #endif