Changeset View
Changeset View
Standalone View
Standalone View
src/kitemviews/private/kitemlistviewanimation.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
54 | { | 54 | { | ||
55 | const qreal diff = m_scrollOffset - offset; | 55 | const qreal diff = m_scrollOffset - offset; | ||
56 | m_scrollOffset = offset; | 56 | m_scrollOffset = offset; | ||
57 | 57 | | |||
58 | // The change of the offset requires that the position of all | 58 | // The change of the offset requires that the position of all | ||
59 | // animated QGraphicsWidgets get adjusted. An exception is made | 59 | // animated QGraphicsWidgets get adjusted. An exception is made | ||
60 | // for the delete animation that should just fade away on the | 60 | // for the delete animation that should just fade away on the | ||
61 | // existing position. | 61 | // existing position. | ||
62 | for (int type = 0; type < AnimationTypeCount; ++type) { | 62 | for (int type = static_cast<int>(AnimationType::Moving); type <= static_cast<int>(AnimationType::Resize); ++type) { | ||
63 | if (type == DeleteAnimation) { | 63 | if (AnimationType(type) == AnimationType::Delete) { | ||
64 | continue; | 64 | continue; | ||
65 | } | 65 | } | ||
66 | 66 | | |||
67 | QHashIterator<QGraphicsWidget*, QPropertyAnimation*> it(m_animation[type]); | 67 | QHashIterator<QGraphicsWidget*, QPropertyAnimation*> it(m_animation[type]); | ||
68 | while (it.hasNext()) { | 68 | while (it.hasNext()) { | ||
69 | it.next(); | 69 | it.next(); | ||
70 | 70 | | |||
71 | QGraphicsWidget* widget = it.key(); | 71 | QGraphicsWidget* widget = it.key(); | ||
72 | QPropertyAnimation* propertyAnim = it.value(); | 72 | QPropertyAnimation* propertyAnim = it.value(); | ||
73 | 73 | | |||
74 | QPointF currentPos = widget->pos(); | 74 | QPointF currentPos = widget->pos(); | ||
75 | if (m_scrollOrientation == Qt::Vertical) { | 75 | if (m_scrollOrientation == Qt::Vertical) { | ||
76 | currentPos.ry() += diff; | 76 | currentPos.ry() += diff; | ||
77 | } else { | 77 | } else { | ||
78 | currentPos.rx() += diff; | 78 | currentPos.rx() += diff; | ||
79 | } | 79 | } | ||
80 | 80 | | |||
81 | if (type == MovingAnimation) { | 81 | if (AnimationType(type) == AnimationType::Moving) { | ||
82 | // Stop the animation, calculate the moved start- and end-value | 82 | // Stop the animation, calculate the moved start- and end-value | ||
83 | // and restart the animation for the remaining duration. | 83 | // and restart the animation for the remaining duration. | ||
84 | const int remainingDuration = propertyAnim->duration() | 84 | const int remainingDuration = propertyAnim->duration() | ||
85 | - propertyAnim->currentTime(); | 85 | - propertyAnim->currentTime(); | ||
86 | 86 | | |||
87 | const bool block = propertyAnim->signalsBlocked(); | 87 | const bool block = propertyAnim->signalsBlocked(); | ||
88 | propertyAnim->blockSignals(true); | 88 | propertyAnim->blockSignals(true); | ||
89 | propertyAnim->stop(); | 89 | propertyAnim->stop(); | ||
Show All 25 Lines | |||||
115 | void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue) | 115 | void KItemListViewAnimation::start(QGraphicsWidget* widget, AnimationType type, const QVariant& endValue) | ||
116 | { | 116 | { | ||
117 | stop(widget, type); | 117 | stop(widget, type); | ||
118 | 118 | | |||
119 | QPropertyAnimation* propertyAnim = nullptr; | 119 | QPropertyAnimation* propertyAnim = nullptr; | ||
120 | const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; | 120 | const int animationDuration = widget->style()->styleHint(QStyle::SH_Widget_Animate) ? 200 : 1; | ||
121 | 121 | | |||
122 | switch (type) { | 122 | switch (type) { | ||
123 | case MovingAnimation: { | 123 | case AnimationType::Moving: { | ||
124 | const QPointF newPos = endValue.toPointF(); | 124 | const QPointF newPos = endValue.toPointF(); | ||
125 | if (newPos == widget->pos()) { | 125 | if (newPos == widget->pos()) { | ||
126 | return; | 126 | return; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | propertyAnim = new QPropertyAnimation(widget, "pos"); | 129 | propertyAnim = new QPropertyAnimation(widget, "pos"); | ||
130 | propertyAnim->setDuration(animationDuration); | 130 | propertyAnim->setDuration(animationDuration); | ||
131 | propertyAnim->setEndValue(newPos); | 131 | propertyAnim->setEndValue(newPos); | ||
132 | break; | 132 | break; | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | case CreateAnimation: { | 135 | case AnimationType::Create: { | ||
136 | propertyAnim = new QPropertyAnimation(widget, "opacity"); | 136 | propertyAnim = new QPropertyAnimation(widget, "opacity"); | ||
137 | propertyAnim->setEasingCurve(QEasingCurve::InQuart); | 137 | propertyAnim->setEasingCurve(QEasingCurve::InQuart); | ||
138 | propertyAnim->setDuration(animationDuration); | 138 | propertyAnim->setDuration(animationDuration); | ||
139 | propertyAnim->setStartValue(0.0); | 139 | propertyAnim->setStartValue(0.0); | ||
140 | propertyAnim->setEndValue(1.0); | 140 | propertyAnim->setEndValue(1.0); | ||
141 | break; | 141 | break; | ||
142 | } | 142 | } | ||
143 | 143 | | |||
144 | case DeleteAnimation: { | 144 | case AnimationType::Delete: { | ||
145 | propertyAnim = new QPropertyAnimation(widget, "opacity"); | 145 | propertyAnim = new QPropertyAnimation(widget, "opacity"); | ||
146 | propertyAnim->setEasingCurve(QEasingCurve::OutQuart); | 146 | propertyAnim->setEasingCurve(QEasingCurve::OutQuart); | ||
147 | propertyAnim->setDuration(animationDuration); | 147 | propertyAnim->setDuration(animationDuration); | ||
148 | propertyAnim->setStartValue(1.0); | 148 | propertyAnim->setStartValue(1.0); | ||
149 | propertyAnim->setEndValue(0.0); | 149 | propertyAnim->setEndValue(0.0); | ||
150 | break; | 150 | break; | ||
151 | } | 151 | } | ||
152 | 152 | | |||
153 | case ResizeAnimation: { | 153 | case AnimationType::Resize: { | ||
154 | const QSizeF newSize = endValue.toSizeF(); | 154 | const QSizeF newSize = endValue.toSizeF(); | ||
155 | if (newSize == widget->size()) { | 155 | if (newSize == widget->size()) { | ||
156 | return; | 156 | return; | ||
157 | } | 157 | } | ||
158 | 158 | | |||
159 | propertyAnim = new QPropertyAnimation(widget, "size"); | 159 | propertyAnim = new QPropertyAnimation(widget, "size"); | ||
160 | propertyAnim->setDuration(animationDuration); | 160 | propertyAnim->setDuration(animationDuration); | ||
161 | propertyAnim->setEndValue(newSize); | 161 | propertyAnim->setEndValue(newSize); | ||
162 | break; | 162 | break; | ||
163 | } | 163 | } | ||
164 | 164 | | |||
165 | default: | 165 | default: | ||
166 | break; | 166 | break; | ||
167 | } | 167 | } | ||
168 | 168 | | |||
169 | Q_ASSERT(propertyAnim); | 169 | Q_ASSERT(propertyAnim); | ||
170 | connect(propertyAnim, &QPropertyAnimation::finished, this, &KItemListViewAnimation::slotFinished); | 170 | connect(propertyAnim, &QPropertyAnimation::finished, this, &KItemListViewAnimation::slotFinished); | ||
171 | m_animation[type].insert(widget, propertyAnim); | 171 | m_animation[static_cast<int>(type)].insert(widget, propertyAnim); | ||
172 | 172 | | |||
173 | propertyAnim->start(); | 173 | propertyAnim->start(); | ||
174 | } | 174 | } | ||
175 | 175 | | |||
176 | void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type) | 176 | void KItemListViewAnimation::stop(QGraphicsWidget* widget, AnimationType type) | ||
177 | { | 177 | { | ||
178 | QPropertyAnimation* propertyAnim = m_animation[type].value(widget); | 178 | QPropertyAnimation* propertyAnim = m_animation[static_cast<int>(type)].value(widget); | ||
179 | if (propertyAnim) { | 179 | if (propertyAnim) { | ||
180 | propertyAnim->stop(); | 180 | propertyAnim->stop(); | ||
181 | 181 | | |||
182 | switch (type) { | 182 | switch (type) { | ||
183 | case MovingAnimation: break; | 183 | case AnimationType::Moving: break; | ||
184 | case CreateAnimation: widget->setOpacity(1.0); break; | 184 | case AnimationType::Create: widget->setOpacity(1.0); break; | ||
185 | case DeleteAnimation: widget->setOpacity(0.0); break; | 185 | case AnimationType::Delete: widget->setOpacity(0.0); break; | ||
186 | case ResizeAnimation: break; | 186 | case AnimationType::Resize: break; | ||
187 | default: break; | 187 | default: break; | ||
188 | } | 188 | } | ||
189 | 189 | | |||
190 | m_animation[type].remove(widget); | 190 | m_animation[static_cast<int>(type)].remove(widget); | ||
191 | delete propertyAnim; | 191 | delete propertyAnim; | ||
192 | 192 | | |||
193 | emit finished(widget, type); | 193 | emit finished(widget, type); | ||
194 | } | 194 | } | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | void KItemListViewAnimation::stop(QGraphicsWidget* widget) | 197 | void KItemListViewAnimation::stop(QGraphicsWidget* widget) | ||
198 | { | 198 | { | ||
199 | for (int type = 0; type < AnimationTypeCount; ++type) { | 199 | for (int type = 0; type < AnimationTypeCount; ++type) { | ||
200 | stop(widget, static_cast<AnimationType>(type)); | 200 | stop(widget, static_cast<AnimationType>(type)); | ||
201 | } | 201 | } | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget, AnimationType type) const | 204 | bool KItemListViewAnimation::isStarted(QGraphicsWidget *widget, AnimationType type) const | ||
205 | { | 205 | { | ||
206 | return m_animation[type].value(widget); | 206 | return m_animation[static_cast<int>(type)].value(widget); | ||
207 | } | 207 | } | ||
208 | 208 | | |||
209 | bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const | 209 | bool KItemListViewAnimation::isStarted(QGraphicsWidget* widget) const | ||
210 | { | 210 | { | ||
211 | for (int type = 0; type < AnimationTypeCount; ++type) { | 211 | for (int type = 0; type < AnimationTypeCount; ++type) { | ||
212 | if (isStarted(widget, static_cast<AnimationType>(type))) { | 212 | if (isStarted(widget, static_cast<AnimationType>(type))) { | ||
213 | return true; | 213 | return true; | ||
214 | } | 214 | } | ||
Show All 25 Lines |