-
Notifications
You must be signed in to change notification settings - Fork 7
/
rotatestackedwidget.h
81 lines (62 loc) · 1.88 KB
/
rotatestackedwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Animation Stacked Widget
* @brief 翻转动画 Stacked Widget
* @anchor Ho229
* @date 2020/12/12
*/
#ifndef ROTATESTACKEDWIDGET_H
#define ROTATESTACKEDWIDGET_H
#include <QEasingCurve>
#include <QStackedWidget>
class QVariantAnimation;
class RotateStackedWidget Q_DECL_FINAL : public QStackedWidget
{
Q_OBJECT
Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
Q_PROPERTY(QEasingCurve animationEasingCurve READ animationEasingCurve WRITE setAnimationEasingCurve)
public:
/**
* @brief RotateStackedWidget
* @param parent 父对象
*/
explicit RotateStackedWidget(QWidget *parent = nullptr);
~RotateStackedWidget() Q_DECL_OVERRIDE;
/**
* @brief 翻转到 index
* @param index 目标 index
* @param exec 是否启用局部事件循环
*/
void rotate(int index, bool exec = true);
/**
* @brief 设置动画持续时间
* @param duration 持续时间(msecs)
*/
void setAnimationDuration(int duration);
/**
* @return 动画持续时间
*/
int animationDuration();
/**
* @brief 设置动画缓和曲线
* @param easing 动画缓和曲线
*/
void setAnimationEasingCurve(const QEasingCurve& easing);
/**
* @return 动画缓和曲线
*/
QEasingCurve animationEasingCurve();
private slots:
void on_finished();
private:
QVariantAnimation *m_animation = nullptr;
int m_nextIndex;
qreal m_rotateValue = 0;
QPixmap m_currentPixmap;
QPixmap m_nextPixmap;
QWidget *m_currentWidget = nullptr;
QWidget *m_nextWidget = nullptr;
inline void updateFrame();
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
};
#endif // ROTATESTACKEDWIDGET_H