| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstyleanimation.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 5 | ** | - | ||||||||||||
| 6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||
| 7 | ** | - | ||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 15 | ** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General | - | ||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 35 | ** | - | ||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 37 | ** | - | ||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||
| 39 | - | |||||||||||||
| 40 | #include "qstyleanimation_p.h" | - | ||||||||||||
| 41 | - | |||||||||||||
| 42 | #ifndef QT_NO_ANIMATION | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | #include <qcoreapplication.h> | - | ||||||||||||
| 45 | #include <qwidget.h> | - | ||||||||||||
| 46 | #include <qevent.h> | - | ||||||||||||
| 47 | - | |||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 49 | - | |||||||||||||
| 50 | static const qreal ScrollBarFadeOutDuration = 200.0; | - | ||||||||||||
| 51 | static const qreal ScrollBarFadeOutDelay = 450.0; | - | ||||||||||||
| 52 | - | |||||||||||||
| 53 | QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), | - | ||||||||||||
| 54 | _delay(0), _duration(-1), _startTime(QTime::currentTime()), _fps(ThirtyFps), _skip(0) | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | } never executed: end of block | 0 | ||||||||||||
| 57 | - | |||||||||||||
| 58 | QStyleAnimation::~QStyleAnimation() | - | ||||||||||||
| 59 | { | - | ||||||||||||
| 60 | } | - | ||||||||||||
| 61 | - | |||||||||||||
| 62 | QObject *QStyleAnimation::target() const | - | ||||||||||||
| 63 | { | - | ||||||||||||
| 64 | return parent(); never executed: return parent(); | 0 | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | int QStyleAnimation::duration() const | - | ||||||||||||
| 68 | { | - | ||||||||||||
| 69 | return _duration; never executed: return _duration; | 0 | ||||||||||||
| 70 | } | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | void QStyleAnimation::setDuration(int duration) | - | ||||||||||||
| 73 | { | - | ||||||||||||
| 74 | _duration = duration; | - | ||||||||||||
| 75 | } never executed: end of block | 0 | ||||||||||||
| 76 | - | |||||||||||||
| 77 | int QStyleAnimation::delay() const | - | ||||||||||||
| 78 | { | - | ||||||||||||
| 79 | return _delay; never executed: return _delay; | 0 | ||||||||||||
| 80 | } | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | void QStyleAnimation::setDelay(int delay) | - | ||||||||||||
| 83 | { | - | ||||||||||||
| 84 | _delay = delay; | - | ||||||||||||
| 85 | } never executed: end of block | 0 | ||||||||||||
| 86 | - | |||||||||||||
| 87 | QTime QStyleAnimation::startTime() const | - | ||||||||||||
| 88 | { | - | ||||||||||||
| 89 | return _startTime; never executed: return _startTime; | 0 | ||||||||||||
| 90 | } | - | ||||||||||||
| 91 | - | |||||||||||||
| 92 | void QStyleAnimation::setStartTime(const QTime &time) | - | ||||||||||||
| 93 | { | - | ||||||||||||
| 94 | _startTime = time; | - | ||||||||||||
| 95 | } never executed: end of block | 0 | ||||||||||||
| 96 | - | |||||||||||||
| 97 | QStyleAnimation::FrameRate QStyleAnimation::frameRate() const | - | ||||||||||||
| 98 | { | - | ||||||||||||
| 99 | return _fps; never executed: return _fps; | 0 | ||||||||||||
| 100 | } | - | ||||||||||||
| 101 | - | |||||||||||||
| 102 | void QStyleAnimation::setFrameRate(FrameRate fps) | - | ||||||||||||
| 103 | { | - | ||||||||||||
| 104 | _fps = fps; | - | ||||||||||||
| 105 | } never executed: end of block | 0 | ||||||||||||
| 106 | - | |||||||||||||
| 107 | void QStyleAnimation::updateTarget() | - | ||||||||||||
| 108 | { | - | ||||||||||||
| 109 | QEvent event(QEvent::StyleAnimationUpdate); | - | ||||||||||||
| 110 | event.setAccepted(false); | - | ||||||||||||
| 111 | QCoreApplication::sendEvent(target(), &event); | - | ||||||||||||
| 112 | if (!event.isAccepted())
| 0 | ||||||||||||
| 113 | stop(); never executed: stop(); | 0 | ||||||||||||
| 114 | } never executed: end of block | 0 | ||||||||||||
| 115 | - | |||||||||||||
| 116 | void QStyleAnimation::start() | - | ||||||||||||
| 117 | { | - | ||||||||||||
| 118 | _skip = 0; | - | ||||||||||||
| 119 | QAbstractAnimation::start(DeleteWhenStopped); | - | ||||||||||||
| 120 | } never executed: end of block | 0 | ||||||||||||
| 121 | - | |||||||||||||
| 122 | bool QStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | return currentTime() > _delay; never executed: return currentTime() > _delay; | 0 | ||||||||||||
| 125 | } | - | ||||||||||||
| 126 | - | |||||||||||||
| 127 | void QStyleAnimation::updateCurrentTime(int) | - | ||||||||||||
| 128 | { | - | ||||||||||||
| 129 | if (++_skip >= _fps) {
| 0 | ||||||||||||
| 130 | _skip = 0; | - | ||||||||||||
| 131 | if (target() && isUpdateNeeded())
| 0 | ||||||||||||
| 132 | updateTarget(); never executed: updateTarget(); | 0 | ||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||
| 134 | } never executed: end of block | 0 | ||||||||||||
| 135 | - | |||||||||||||
| 136 | QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : | - | ||||||||||||
| 137 | QStyleAnimation(target), _speed(speed), _step(-1) | - | ||||||||||||
| 138 | { | - | ||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | int QProgressStyleAnimation::animationStep() const | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | return currentTime() / (1000.0 / _speed); never executed: return currentTime() / (1000.0 / _speed); | 0 | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | int QProgressStyleAnimation::progressStep(int width) const | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | int step = animationStep(); | - | ||||||||||||
| 149 | int progress = (step * width / _speed) % width; | - | ||||||||||||
| 150 | if (((step * width / _speed) % (2 * width)) >= width)
| 0 | ||||||||||||
| 151 | progress = width - progress; never executed: progress = width - progress; | 0 | ||||||||||||
| 152 | return progress; never executed: return progress; | 0 | ||||||||||||
| 153 | } | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | int QProgressStyleAnimation::speed() const | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | return _speed; never executed: return _speed; | 0 | ||||||||||||
| 158 | } | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | void QProgressStyleAnimation::setSpeed(int speed) | - | ||||||||||||
| 161 | { | - | ||||||||||||
| 162 | _speed = speed; | - | ||||||||||||
| 163 | } never executed: end of block | 0 | ||||||||||||
| 164 | - | |||||||||||||
| 165 | bool QProgressStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 166 | { | - | ||||||||||||
| 167 | if (QStyleAnimation::isUpdateNeeded()) {
| 0 | ||||||||||||
| 168 | int current = animationStep(); | - | ||||||||||||
| 169 | if (_step == -1 || _step != current)
| 0 | ||||||||||||
| 170 | { | - | ||||||||||||
| 171 | _step = current; | - | ||||||||||||
| 172 | return true; never executed: return true; | 0 | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | } never executed: end of block | 0 | ||||||||||||
| 175 | return false; never executed: return false; | 0 | ||||||||||||
| 176 | } | - | ||||||||||||
| 177 | - | |||||||||||||
| 178 | QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : | - | ||||||||||||
| 179 | QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) | - | ||||||||||||
| 180 | { | - | ||||||||||||
| 181 | setDuration(250); | - | ||||||||||||
| 182 | } never executed: end of block | 0 | ||||||||||||
| 183 | - | |||||||||||||
| 184 | qreal QNumberStyleAnimation::startValue() const | - | ||||||||||||
| 185 | { | - | ||||||||||||
| 186 | return _start; never executed: return _start; | 0 | ||||||||||||
| 187 | } | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | void QNumberStyleAnimation::setStartValue(qreal value) | - | ||||||||||||
| 190 | { | - | ||||||||||||
| 191 | _start = value; | - | ||||||||||||
| 192 | } never executed: end of block | 0 | ||||||||||||
| 193 | - | |||||||||||||
| 194 | qreal QNumberStyleAnimation::endValue() const | - | ||||||||||||
| 195 | { | - | ||||||||||||
| 196 | return _end; never executed: return _end; | 0 | ||||||||||||
| 197 | } | - | ||||||||||||
| 198 | - | |||||||||||||
| 199 | void QNumberStyleAnimation::setEndValue(qreal value) | - | ||||||||||||
| 200 | { | - | ||||||||||||
| 201 | _end = value; | - | ||||||||||||
| 202 | } never executed: end of block | 0 | ||||||||||||
| 203 | - | |||||||||||||
| 204 | qreal QNumberStyleAnimation::currentValue() const | - | ||||||||||||
| 205 | { | - | ||||||||||||
| 206 | qreal step = qreal(currentTime() - delay()) / (duration() - delay()); | - | ||||||||||||
| 207 | return _start + qMax(qreal(0), step) * (_end - _start); never executed: return _start + qMax(qreal(0), step) * (_end - _start); | 0 | ||||||||||||
| 208 | } | - | ||||||||||||
| 209 | - | |||||||||||||
| 210 | bool QNumberStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 211 | { | - | ||||||||||||
| 212 | if (QStyleAnimation::isUpdateNeeded()) {
| 0 | ||||||||||||
| 213 | qreal current = currentValue(); | - | ||||||||||||
| 214 | if (!qFuzzyCompare(_prev, current))
| 0 | ||||||||||||
| 215 | { | - | ||||||||||||
| 216 | _prev = current; | - | ||||||||||||
| 217 | return true; never executed: return true; | 0 | ||||||||||||
| 218 | } | - | ||||||||||||
| 219 | } never executed: end of block | 0 | ||||||||||||
| 220 | return false; never executed: return false; | 0 | ||||||||||||
| 221 | } | - | ||||||||||||
| 222 | - | |||||||||||||
| 223 | QBlendStyleAnimation::QBlendStyleAnimation(Type type, QObject *target) : | - | ||||||||||||
| 224 | QStyleAnimation(target), _type(type) | - | ||||||||||||
| 225 | { | - | ||||||||||||
| 226 | setDuration(250); | - | ||||||||||||
| 227 | } never executed: end of block | 0 | ||||||||||||
| 228 | - | |||||||||||||
| 229 | QImage QBlendStyleAnimation::startImage() const | - | ||||||||||||
| 230 | { | - | ||||||||||||
| 231 | return _start; never executed: return _start; | 0 | ||||||||||||
| 232 | } | - | ||||||||||||
| 233 | - | |||||||||||||
| 234 | void QBlendStyleAnimation::setStartImage(const QImage& image) | - | ||||||||||||
| 235 | { | - | ||||||||||||
| 236 | _start = image; | - | ||||||||||||
| 237 | } never executed: end of block | 0 | ||||||||||||
| 238 | - | |||||||||||||
| 239 | QImage QBlendStyleAnimation::endImage() const | - | ||||||||||||
| 240 | { | - | ||||||||||||
| 241 | return _end; never executed: return _end; | 0 | ||||||||||||
| 242 | } | - | ||||||||||||
| 243 | - | |||||||||||||
| 244 | void QBlendStyleAnimation::setEndImage(const QImage& image) | - | ||||||||||||
| 245 | { | - | ||||||||||||
| 246 | _end = image; | - | ||||||||||||
| 247 | } never executed: end of block | 0 | ||||||||||||
| 248 | - | |||||||||||||
| 249 | QImage QBlendStyleAnimation::currentImage() const | - | ||||||||||||
| 250 | { | - | ||||||||||||
| 251 | return _current; never executed: return _current; | 0 | ||||||||||||
| 252 | } | - | ||||||||||||
| 253 | - | |||||||||||||
| 254 | /*! \internal | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | A helper function to blend two images. | - | ||||||||||||
| 257 | - | |||||||||||||
| 258 | The result consists of ((alpha)*startImage) + ((1-alpha)*endImage) | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | */ | - | ||||||||||||
| 261 | static QImage blendedImage(const QImage &start, const QImage &end, float alpha) | - | ||||||||||||
| 262 | { | - | ||||||||||||
| 263 | if (start.isNull() || end.isNull())
| 0 | ||||||||||||
| 264 | return QImage(); never executed: return QImage(); | 0 | ||||||||||||
| 265 | - | |||||||||||||
| 266 | QImage blended; | - | ||||||||||||
| 267 | const int a = qRound(alpha*256); | - | ||||||||||||
| 268 | const int ia = 256 - a; | - | ||||||||||||
| 269 | const int sw = start.width(); | - | ||||||||||||
| 270 | const int sh = start.height(); | - | ||||||||||||
| 271 | const int bpl = start.bytesPerLine(); | - | ||||||||||||
| 272 | switch (start.depth()) { | - | ||||||||||||
| 273 | case 32: never executed: case 32: | 0 | ||||||||||||
| 274 | { | - | ||||||||||||
| 275 | blended = QImage(sw, sh, start.format()); | - | ||||||||||||
| 276 | blended.setDevicePixelRatio(start.devicePixelRatio()); | - | ||||||||||||
| 277 | uchar *mixed_data = blended.bits(); | - | ||||||||||||
| 278 | const uchar *back_data = start.bits(); | - | ||||||||||||
| 279 | const uchar *front_data = end.bits(); | - | ||||||||||||
| 280 | for (int sy = 0; sy < sh; sy++) {
| 0 | ||||||||||||
| 281 | quint32* mixed = (quint32*)mixed_data; | - | ||||||||||||
| 282 | const quint32* back = (const quint32*)back_data; | - | ||||||||||||
| 283 | const quint32* front = (const quint32*)front_data; | - | ||||||||||||
| 284 | for (int sx = 0; sx < sw; sx++) {
| 0 | ||||||||||||
| 285 | quint32 bp = back[sx]; | - | ||||||||||||
| 286 | quint32 fp = front[sx]; | - | ||||||||||||
| 287 | mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8, | - | ||||||||||||
| 288 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - | ||||||||||||
| 289 | (qBlue(bp)*ia + qBlue(fp)*a)>>8, | - | ||||||||||||
| 290 | (qAlpha(bp)*ia + qAlpha(fp)*a)>>8); | - | ||||||||||||
| 291 | } never executed: end of block | 0 | ||||||||||||
| 292 | mixed_data += bpl; | - | ||||||||||||
| 293 | back_data += bpl; | - | ||||||||||||
| 294 | front_data += bpl; | - | ||||||||||||
| 295 | } never executed: end of block | 0 | ||||||||||||
| 296 | } | - | ||||||||||||
| 297 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||
| 298 | break; never executed: break; | 0 | ||||||||||||
| 299 | } | - | ||||||||||||
| 300 | return blended; never executed: return blended; | 0 | ||||||||||||
| 301 | } | - | ||||||||||||
| 302 | - | |||||||||||||
| 303 | void QBlendStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
| 304 | { | - | ||||||||||||
| 305 | QStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
| 306 | - | |||||||||||||
| 307 | float alpha = 1.0; | - | ||||||||||||
| 308 | if (duration() > 0) {
| 0 | ||||||||||||
| 309 | if (_type == Pulse) {
| 0 | ||||||||||||
| 310 | time = time % duration() * 2; | - | ||||||||||||
| 311 | if (time > duration())
| 0 | ||||||||||||
| 312 | time = duration() * 2 - time; never executed: time = duration() * 2 - time; | 0 | ||||||||||||
| 313 | } never executed: end of block | 0 | ||||||||||||
| 314 | - | |||||||||||||
| 315 | alpha = time / static_cast<float>(duration()); | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | if (_type == Transition && time > duration()) {
| 0 | ||||||||||||
| 318 | alpha = 1.0; | - | ||||||||||||
| 319 | stop(); | - | ||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||
| 321 | } else if (time > 0) { never executed: end of block
| 0 | ||||||||||||
| 322 | stop(); | - | ||||||||||||
| 323 | } never executed: end of block | 0 | ||||||||||||
| 324 | - | |||||||||||||
| 325 | _current = blendedImage(_start, _end, alpha); | - | ||||||||||||
| 326 | } never executed: end of block | 0 | ||||||||||||
| 327 | - | |||||||||||||
| 328 | QScrollbarStyleAnimation::QScrollbarStyleAnimation(Mode mode, QObject *target) : QNumberStyleAnimation(target), _mode(mode), _active(false) | - | ||||||||||||
| 329 | { | - | ||||||||||||
| 330 | switch (mode) { | - | ||||||||||||
| 331 | case Activating: never executed: case Activating: | 0 | ||||||||||||
| 332 | setDuration(ScrollBarFadeOutDuration); | - | ||||||||||||
| 333 | setStartValue(0.0); | - | ||||||||||||
| 334 | setEndValue(1.0); | - | ||||||||||||
| 335 | break; never executed: break; | 0 | ||||||||||||
| 336 | case Deactivating: never executed: case Deactivating: | 0 | ||||||||||||
| 337 | setDuration(ScrollBarFadeOutDelay + ScrollBarFadeOutDuration); | - | ||||||||||||
| 338 | setDelay(ScrollBarFadeOutDelay); | - | ||||||||||||
| 339 | setStartValue(1.0); | - | ||||||||||||
| 340 | setEndValue(0.0); | - | ||||||||||||
| 341 | break; never executed: break; | 0 | ||||||||||||
| 342 | } | - | ||||||||||||
| 343 | } never executed: end of block | 0 | ||||||||||||
| 344 | - | |||||||||||||
| 345 | QScrollbarStyleAnimation::Mode QScrollbarStyleAnimation::mode() const | - | ||||||||||||
| 346 | { | - | ||||||||||||
| 347 | return _mode; never executed: return _mode; | 0 | ||||||||||||
| 348 | } | - | ||||||||||||
| 349 | - | |||||||||||||
| 350 | bool QScrollbarStyleAnimation::wasActive() const | - | ||||||||||||
| 351 | { | - | ||||||||||||
| 352 | return _active; never executed: return _active; | 0 | ||||||||||||
| 353 | } | - | ||||||||||||
| 354 | - | |||||||||||||
| 355 | void QScrollbarStyleAnimation::setActive(bool active) | - | ||||||||||||
| 356 | { | - | ||||||||||||
| 357 | _active = active; | - | ||||||||||||
| 358 | } never executed: end of block | 0 | ||||||||||||
| 359 | - | |||||||||||||
| 360 | void QScrollbarStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
| 361 | { | - | ||||||||||||
| 362 | QNumberStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
| 363 | if (_mode == Deactivating && qFuzzyIsNull(currentValue()))
| 0 | ||||||||||||
| 364 | target()->setProperty("visible", false); never executed: target()->setProperty("visible", false); | 0 | ||||||||||||
| 365 | } never executed: end of block | 0 | ||||||||||||
| 366 | - | |||||||||||||
| 367 | QT_END_NAMESPACE | - | ||||||||||||
| 368 | - | |||||||||||||
| 369 | #include "moc_qstyleanimation_p.cpp" | - | ||||||||||||
| 370 | - | |||||||||||||
| 371 | #endif //QT_NO_ANIMATION | - | ||||||||||||
| Source code | Switch to Preprocessed file |