File indexing completed on 2024-05-19 05:35:25
0001 #ifndef oxygentransitiondata_h 0002 #define oxygentransitiondata_h 0003 0004 ////////////////////////////////////////////////////////////////////////////// 0005 // oxygentransitiondata.h 0006 // data container for generic transitions 0007 // ------------------- 0008 // 0009 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0010 // 0011 // SPDX-License-Identifier: MIT 0012 ////////////////////////////////////////////////////////////////////////////// 0013 0014 #include "oxygentransitionwidget.h" 0015 0016 #include <QElapsedTimer> 0017 #include <QObject> 0018 #include <QTime> 0019 #include <QWidget> 0020 0021 namespace Oxygen 0022 { 0023 //* generic data 0024 class TransitionData : public QObject 0025 { 0026 Q_OBJECT 0027 0028 public: 0029 //* constructor 0030 TransitionData(QObject *parent, QWidget *target, int); 0031 0032 //* destructor 0033 ~TransitionData(void) override; 0034 0035 //* enability 0036 virtual void setEnabled(bool value) 0037 { 0038 _enabled = value; 0039 } 0040 0041 //* enability 0042 virtual bool enabled(void) const 0043 { 0044 return _enabled; 0045 } 0046 0047 //* duration 0048 virtual void setDuration(int duration) 0049 { 0050 if (_transition) { 0051 _transition.data()->setDuration(duration); 0052 } 0053 } 0054 0055 //* max render time 0056 void setMaxRenderTime(int value) 0057 { 0058 _maxRenderTime = value; 0059 } 0060 0061 //* max renderTime 0062 const int &maxRenderTime(void) const 0063 { 0064 return _maxRenderTime; 0065 } 0066 0067 //* start clock 0068 void startClock(void) 0069 { 0070 if (!_timer.isValid()) { 0071 _timer.start(); 0072 } else { 0073 _timer.restart(); 0074 } 0075 } 0076 0077 //* check if rendering is too slow 0078 bool slow(void) const 0079 { 0080 return _timer.isValid() && _timer.elapsed() > maxRenderTime(); 0081 } 0082 0083 protected Q_SLOTS: 0084 0085 //* initialize animation 0086 virtual bool initializeAnimation(void) = 0; 0087 0088 //* animate 0089 virtual bool animate(void) = 0; 0090 0091 protected: 0092 //* returns true if one parent matches given class name 0093 inline bool hasParent(const QWidget *, const char *) const; 0094 0095 //* transition widget 0096 const TransitionWidget::Pointer &transition(void) const 0097 { 0098 return _transition; 0099 } 0100 0101 //* used to avoid recursion when grabbing widgets 0102 void setRecursiveCheck(bool value) 0103 { 0104 _recursiveCheck = value; 0105 } 0106 0107 //* used to avoid recursion when grabbing widgets 0108 bool recursiveCheck(void) const 0109 { 0110 return _recursiveCheck; 0111 } 0112 0113 private: 0114 //* enability 0115 bool _enabled = true; 0116 0117 //* used to avoid recursion when grabbing widgets 0118 bool _recursiveCheck = false; 0119 0120 //* timer used to detect slow rendering 0121 QElapsedTimer _timer; 0122 0123 //* max render time 0124 /** used to detect slow rendering */ 0125 int _maxRenderTime = 200; 0126 0127 //* animation handling 0128 TransitionWidget::Pointer _transition; 0129 }; 0130 0131 //_____________________________________________________________________________________ 0132 bool TransitionData::hasParent(const QWidget *widget, const char *className) const 0133 { 0134 if (!widget) 0135 return false; 0136 for (QWidget *parent = widget->parentWidget(); parent; parent = parent->parentWidget()) { 0137 if (parent->inherits(className)) 0138 return true; 0139 } 0140 0141 return false; 0142 } 0143 } 0144 0145 #endif