1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qquickstacktransition_p_p.h"
38#include "qquickstackelement_p_p.h"
39#include "qquickstackview_p_p.h"
40
41QT_BEGIN_NAMESPACE
42
43static QQuickStackTransition exitTransition(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
44{
45 QQuickStackTransition st;
46 st.status = QQuickStackView::Deactivating;
47 st.element = element;
48
49 const QQuickItemViewTransitioner *transitioner = QQuickStackViewPrivate::get(view)->transitioner;
50
51 switch (operation) {
52 case QQuickStackView::PushTransition:
53 st.type = QQuickItemViewTransitioner::AddTransition;
54 if (transitioner)
55 st.transition = transitioner->addDisplacedTransition;
56 break;
57 case QQuickStackView::ReplaceTransition:
58 st.type = QQuickItemViewTransitioner::MoveTransition;
59 if (transitioner)
60 st.transition = transitioner->moveDisplacedTransition;
61 break;
62 case QQuickStackView::PopTransition:
63 st.target = true;
64 st.type = QQuickItemViewTransitioner::RemoveTransition;
65 st.viewBounds = view->boundingRect();
66 if (transitioner)
67 st.transition = transitioner->removeTransition;
68 break;
69 default:
70 Q_UNREACHABLE();
71 break;
72 }
73
74 return st;
75}
76
77static QQuickStackTransition enterTransition(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
78{
79 QQuickStackTransition st;
80 st.status = QQuickStackView::Activating;
81 st.element = element;
82
83 const QQuickItemViewTransitioner *transitioner = QQuickStackViewPrivate::get(view)->transitioner;
84
85 switch (operation) {
86 case QQuickStackView::PushTransition:
87 st.target = true;
88 st.type = QQuickItemViewTransitioner::AddTransition;
89 st.viewBounds = view->boundingRect();
90 if (transitioner)
91 st.transition = transitioner->addTransition;
92 break;
93 case QQuickStackView::ReplaceTransition:
94 st.target = true;
95 st.type = QQuickItemViewTransitioner::MoveTransition;
96 st.viewBounds = view->boundingRect();
97 if (transitioner)
98 st.transition = transitioner->moveTransition;
99 break;
100 case QQuickStackView::PopTransition:
101 st.type = QQuickItemViewTransitioner::RemoveTransition;
102 if (transitioner)
103 st.transition = transitioner->removeDisplacedTransition;
104 break;
105 default:
106 Q_UNREACHABLE();
107 break;
108 }
109
110 return st;
111}
112
113static QQuickStackView::Operation operationTransition(QQuickStackView::Operation operation, QQuickStackView::Operation transition)
114{
115 if (operation == QQuickStackView::Immediate || operation == QQuickStackView::Transition)
116 return transition;
117 return operation;
118}
119
120QQuickStackTransition QQuickStackTransition::popExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
121{
122 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::PopTransition), element, view);
123}
124
125QQuickStackTransition QQuickStackTransition::popEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
126{
127 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::PopTransition), element, view);
128}
129
130QQuickStackTransition QQuickStackTransition::pushExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
131{
132 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::PushTransition), element, view);
133}
134
135QQuickStackTransition QQuickStackTransition::pushEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
136{
137 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::PushTransition), element, view);
138}
139
140QQuickStackTransition QQuickStackTransition::replaceExit(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
141{
142 return exitTransition(operation: operationTransition(operation, transition: QQuickStackView::ReplaceTransition), element, view);
143}
144
145QQuickStackTransition QQuickStackTransition::replaceEnter(QQuickStackView::Operation operation, QQuickStackElement *element, QQuickStackView *view)
146{
147 return enterTransition(operation: operationTransition(operation, transition: QQuickStackView::ReplaceTransition), element, view);
148}
149
150QT_END_NAMESPACE
151

source code of qtquickcontrols2/src/quicktemplates2/qquickstacktransition.cpp