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