1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickstacktransition_p_p.h"
5#include "qquickstackelement_p_p.h"
6#include "qquickstackview_p_p.h"
7
8QT_BEGIN_NAMESPACE
9
10static QQuickStackTransition exitTransition(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
11{
12 QQuickStackTransition st;
13 st.status = QQuickStackView::Deactivating;
14 st.element = element;
15
16 const QQuickItemViewTransitioner *transitioner = QQuickStackViewPrivate::get(view)->transitioner;
17
18 switch (operation) {
19 case QQuickStackView::PushTransition:
20 st.type = QQuickItemViewTransitioner::AddTransition;
21 if (transitioner)
22 st.transition = transitioner->addDisplacedTransition;
23 break;
24 case QQuickStackView::ReplaceTransition:
25 st.type = QQuickItemViewTransitioner::MoveTransition;
26 if (transitioner)
27 st.transition = transitioner->moveDisplacedTransition;
28 break;
29 case QQuickStackView::PopTransition:
30 st.target = true;
31 st.type = QQuickItemViewTransitioner::RemoveTransition;
32 st.viewBounds = view->boundingRect();
33 if (transitioner)
34 st.transition = transitioner->removeTransition;
35 break;
36 default:
37 Q_UNREACHABLE();
38 break;
39 }
40
41 return st;
42}
43
44static QQuickStackTransition enterTransition(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
45{
46 QQuickStackTransition st;
47 st.status = QQuickStackView::Activating;
48 st.element = element;
49
50 const QQuickItemViewTransitioner *transitioner = QQuickStackViewPrivate::get(view)->transitioner;
51
52 switch (operation) {
53 case QQuickStackView::PushTransition:
54 st.target = true;
55 st.type = QQuickItemViewTransitioner::AddTransition;
56 st.viewBounds = view->boundingRect();
57 if (transitioner)
58 st.transition = transitioner->addTransition;
59 break;
60 case QQuickStackView::ReplaceTransition:
61 st.target = true;
62 st.type = QQuickItemViewTransitioner::MoveTransition;
63 st.viewBounds = view->boundingRect();
64 if (transitioner)
65 st.transition = transitioner->moveTransition;
66 break;
67 case QQuickStackView::PopTransition:
68 st.type = QQuickItemViewTransitioner::RemoveTransition;
69 if (transitioner)
70 st.transition = transitioner->removeDisplacedTransition;
71 break;
72 default:
73 Q_UNREACHABLE();
74 break;
75 }
76
77 return st;
78}
79
80static QQuickStackView::Operation operationTransition(QQuickStackView::Operation operation, QQuickStackView::Operation transition)
81{
82 if (operation == QQuickStackView::Immediate || operation == QQuickStackView::Transition)
83 return transition;
84 return operation;
85}
86
87QQuickStackTransition QQuickStackTransition::popExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
88{
89 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::PopTransition), element, view);
90}
91
92QQuickStackTransition QQuickStackTransition::popEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
93{
94 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::PopTransition), element, view);
95}
96
97QQuickStackTransition QQuickStackTransition::pushExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
98{
99 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::PushTransition), element, view);
100}
101
102QQuickStackTransition QQuickStackTransition::pushEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
103{
104 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::PushTransition), element, view);
105}
106
107QQuickStackTransition QQuickStackTransition::replaceExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
108{
109 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::ReplaceTransition), element, view);
110}
111
112QQuickStackTransition QQuickStackTransition::replaceEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
113{
114 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::ReplaceTransition), element, view);
115}
116
117QT_END_NAMESPACE
118

source code of qtdeclarative/src/quicktemplates/qquickstacktransition.cpp