DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dstackwidget.h
1// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSTACKWIDGET_H
6#define DSTACKWIDGET_H
7
8#include <QWidget>
9#include <QVariantAnimation>
10
11#include <DObject>
12#include <dtkwidget_global.h>
13
14DWIDGET_BEGIN_NAMESPACE
15
16class DStackWidget;
17class DAbstractStackWidgetTransitionPrivate;
18class DAbstractStackWidgetTransition : public QObject, public DTK_CORE_NAMESPACE::DObject
19{
20public:
21 enum TransitionType{
22 Push,
23 Pop
24 };
25
27 TransitionType type;
28 DStackWidget *stackWidget = nullptr;
29 QWidget *oldWidget = nullptr;
30 QWidget *newWidget = nullptr;
31 };
32
33 explicit DAbstractStackWidgetTransition(QObject *parent = 0);
34
35 virtual void beginTransition(const TransitionInfo &info);
36 virtual QVariantAnimation *animation() const;
37
38protected:
39 virtual void updateVariant(const QVariant& variant) = 0;
40
41protected:
43 QObject *parent = 0);
44
45 const TransitionInfo &info() const;
46
47private:
48 D_DECLARE_PRIVATE(DAbstractStackWidgetTransition)
49};
50
52{
53 Q_OBJECT
54
55public:
56 explicit DSlideStackWidgetTransition(QObject *parent = 0);
57
58 void beginTransition(const TransitionInfo &info) Q_DECL_OVERRIDE;
59
60private Q_SLOTS:
61 void updateVariant(const QVariant &variant) Q_DECL_OVERRIDE;
62};
63
65class DStackWidget : public QWidget, public DTK_CORE_NAMESPACE::DObject
66{
67 Q_OBJECT
68
70 Q_PROPERTY(bool busy READ busy NOTIFY busyChanged FINAL)
72 Q_PROPERTY(int depth READ depth NOTIFY depthChanged FINAL)
73 Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged)
74 Q_PROPERTY(QWidget* currentWidget READ currentWidget NOTIFY currentWidgetChanged)
75 Q_PROPERTY(DAbstractStackWidgetTransition* transition READ transition WRITE setTransition)
76 Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
77 Q_PROPERTY(QEasingCurve::Type animationType READ animationType WRITE setAnimationType)
78
79public:
80 explicit DStackWidget(QWidget *parent = 0);
81
82 bool busy() const;
83 int depth() const;
84
85 int currentIndex() const;
86 QWidget* currentWidget() const;
87
88 DAbstractStackWidgetTransition* transition() const;
89 int animationDuration() const;
90 QEasingCurve::Type animationType() const;
91
92public Q_SLOTS:
93 int pushWidget(QWidget *widget, bool enableTransition = true);
94 void insertWidget(int index, QWidget *widget, bool enableTransition = true);
95
98 void popWidget(QWidget *widget = nullptr, bool isDelete = true,
99 int count = 1, bool enableTransition = true);
100 void clear();
101
102 int indexOf(QWidget *widget) const;
103 QWidget* getWidgetByIndex(int index) const;
104
105 void setTransition(DAbstractStackWidgetTransition* transition);
106 void setAnimationDuration(int animationDuration);
107 void setAnimationType(QEasingCurve::Type animationType);
108
109Q_SIGNALS:
110 void busyChanged(bool busy);
111 void depthChanged(int depth);
112
113 void currentIndexChanged(int currentIndex);
114 void currentWidgetChanged(QWidget* currentWidget);
115
116 void widgetDepthChanged(QWidget *widget, int depth);
117
118 void switchWidgetFinished();
119
120protected:
121 explicit DStackWidget(DStackWidgetPrivate &dd, QWidget *parent = 0);
122
123 void setCurrentIndex(int currentIndex,
125 bool enableTransition = true);
126 void setCurrentWidget(QWidget* currentWidget,
128 bool enableTransition = true);
129
130private:
131 Q_DISABLE_COPY(DStackWidget)
132 D_DECLARE_PRIVATE(DStackWidget)
133};
134
135DWIDGET_END_NAMESPACE
136
137#endif // DSTACKWIDGET_H
Definition dstackwidget.h:52
Definition dstackwidget_p.h:30
一个可定制切换动画的容器控件.
Definition dstackwidget.h:66