| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/styles/qstyleanimation.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||
| 2 | - | |||||||||||||
| 3 | - | |||||||||||||
| 4 | - | |||||||||||||
| 5 | - | |||||||||||||
| 6 | - | |||||||||||||
| 7 | static const qreal ScrollBarFadeOutDuration = 200.0; | - | ||||||||||||
| 8 | static const qreal ScrollBarFadeOutDelay = 450.0; | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | QStyleAnimation::QStyleAnimation(QObject *target) : QAbstractAnimation(target), | - | ||||||||||||
| 11 | _delay(0), _duration(-1), _startTime(QTime::currentTime()), _fps(ThirtyFps), _skip(0) | - | ||||||||||||
| 12 | { | - | ||||||||||||
| 13 | } never executed: end of block | 0 | ||||||||||||
| 14 | - | |||||||||||||
| 15 | QStyleAnimation::~QStyleAnimation() | - | ||||||||||||
| 16 | { | - | ||||||||||||
| 17 | } | - | ||||||||||||
| 18 | - | |||||||||||||
| 19 | QObject *QStyleAnimation::target() const | - | ||||||||||||
| 20 | { | - | ||||||||||||
| 21 | return never executed: parent();return parent();never executed: return parent(); | 0 | ||||||||||||
| 22 | } | - | ||||||||||||
| 23 | - | |||||||||||||
| 24 | int QStyleAnimation::duration() const | - | ||||||||||||
| 25 | { | - | ||||||||||||
| 26 | return never executed: _duration;return _duration;never executed: return _duration; | 0 | ||||||||||||
| 27 | } | - | ||||||||||||
| 28 | - | |||||||||||||
| 29 | void QStyleAnimation::setDuration(int duration) | - | ||||||||||||
| 30 | { | - | ||||||||||||
| 31 | _duration = duration; | - | ||||||||||||
| 32 | } never executed: end of block | 0 | ||||||||||||
| 33 | - | |||||||||||||
| 34 | int QStyleAnimation::delay() const | - | ||||||||||||
| 35 | { | - | ||||||||||||
| 36 | return never executed: _delay;return _delay;never executed: return _delay; | 0 | ||||||||||||
| 37 | } | - | ||||||||||||
| 38 | - | |||||||||||||
| 39 | void QStyleAnimation::setDelay(int delay) | - | ||||||||||||
| 40 | { | - | ||||||||||||
| 41 | _delay = delay; | - | ||||||||||||
| 42 | } never executed: end of block | 0 | ||||||||||||
| 43 | - | |||||||||||||
| 44 | QTime QStyleAnimation::startTime() const | - | ||||||||||||
| 45 | { | - | ||||||||||||
| 46 | return never executed: _startTime;return _startTime;never executed: return _startTime; | 0 | ||||||||||||
| 47 | } | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | void QStyleAnimation::setStartTime(const QTime &time) | - | ||||||||||||
| 50 | { | - | ||||||||||||
| 51 | _startTime = time; | - | ||||||||||||
| 52 | } never executed: end of block | 0 | ||||||||||||
| 53 | - | |||||||||||||
| 54 | QStyleAnimation::FrameRate QStyleAnimation::frameRate() const | - | ||||||||||||
| 55 | { | - | ||||||||||||
| 56 | return never executed: _fps;return _fps;never executed: return _fps; | 0 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | void QStyleAnimation::setFrameRate(FrameRate fps) | - | ||||||||||||
| 60 | { | - | ||||||||||||
| 61 | _fps = fps; | - | ||||||||||||
| 62 | } never executed: end of block | 0 | ||||||||||||
| 63 | - | |||||||||||||
| 64 | void QStyleAnimation::updateTarget() | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | QEvent event(QEvent::StyleAnimationUpdate); | - | ||||||||||||
| 67 | event.setAccepted(false); | - | ||||||||||||
| 68 | QCoreApplication::sendEvent(target(), &event); | - | ||||||||||||
| 69 | if (!event.isAccepted()
| 0 | ||||||||||||
| 70 | stop(); never executed: stop(); | 0 | ||||||||||||
| 71 | } never executed: end of block | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | void QStyleAnimation::start() | - | ||||||||||||
| 74 | { | - | ||||||||||||
| 75 | _skip = 0; | - | ||||||||||||
| 76 | QAbstractAnimation::start(DeleteWhenStopped); | - | ||||||||||||
| 77 | } never executed: end of block | 0 | ||||||||||||
| 78 | - | |||||||||||||
| 79 | bool QStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 80 | { | - | ||||||||||||
| 81 | return never executed: currentTime() > _delay;return currentTime() > _delay;never executed: return currentTime() > _delay; | 0 | ||||||||||||
| 82 | } | - | ||||||||||||
| 83 | - | |||||||||||||
| 84 | void QStyleAnimation::updateCurrentTime(int) | - | ||||||||||||
| 85 | { | - | ||||||||||||
| 86 | if (++
| 0 | ||||||||||||
| 87 | _skip = 0; | - | ||||||||||||
| 88 | if (target()
| 0 | ||||||||||||
| 89 | updateTarget(); never executed: updateTarget(); | 0 | ||||||||||||
| 90 | } never executed: end of block | 0 | ||||||||||||
| 91 | } never executed: end of block | 0 | ||||||||||||
| 92 | - | |||||||||||||
| 93 | QProgressStyleAnimation::QProgressStyleAnimation(int speed, QObject *target) : | - | ||||||||||||
| 94 | QStyleAnimation(target), _speed(speed), _step(-1) | - | ||||||||||||
| 95 | { | - | ||||||||||||
| 96 | } never executed: end of block | 0 | ||||||||||||
| 97 | - | |||||||||||||
| 98 | int QProgressStyleAnimation::animationStep() const | - | ||||||||||||
| 99 | { | - | ||||||||||||
| 100 | return never executed: currentTime() / (1000.0 / _speed);return currentTime() / (1000.0 / _speed);never executed: return currentTime() / (1000.0 / _speed); | 0 | ||||||||||||
| 101 | } | - | ||||||||||||
| 102 | - | |||||||||||||
| 103 | int QProgressStyleAnimation::progressStep(int width) const | - | ||||||||||||
| 104 | { | - | ||||||||||||
| 105 | int step = animationStep(); | - | ||||||||||||
| 106 | int progress = (step * width / _speed) % width; | - | ||||||||||||
| 107 | if (((
| 0 | ||||||||||||
| 108 | progress = width - progress; never executed: progress = width - progress; | 0 | ||||||||||||
| 109 | return never executed: progress;return progress;never executed: return progress; | 0 | ||||||||||||
| 110 | } | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | int QProgressStyleAnimation::speed() const | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | return never executed: _speed;return _speed;never executed: return _speed; | 0 | ||||||||||||
| 115 | } | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | void QProgressStyleAnimation::setSpeed(int speed) | - | ||||||||||||
| 118 | { | - | ||||||||||||
| 119 | _speed = speed; | - | ||||||||||||
| 120 | } never executed: end of block | 0 | ||||||||||||
| 121 | - | |||||||||||||
| 122 | bool QProgressStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 123 | { | - | ||||||||||||
| 124 | if (QStyleAnimation::isUpdateNeeded()
| 0 | ||||||||||||
| 125 | int current = animationStep(); | - | ||||||||||||
| 126 | if (_step == -1
| 0 | ||||||||||||
| 127 | { | - | ||||||||||||
| 128 | _step = current; | - | ||||||||||||
| 129 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 130 | } | - | ||||||||||||
| 131 | } never executed: end of block | 0 | ||||||||||||
| 132 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | QNumberStyleAnimation::QNumberStyleAnimation(QObject *target) : | - | ||||||||||||
| 136 | QStyleAnimation(target), _start(0.0), _end(1.0), _prev(0.0) | - | ||||||||||||
| 137 | { | - | ||||||||||||
| 138 | setDuration(250); | - | ||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||
| 140 | - | |||||||||||||
| 141 | qreal QNumberStyleAnimation::startValue() const | - | ||||||||||||
| 142 | { | - | ||||||||||||
| 143 | return never executed: _start;return _start;never executed: return _start; | 0 | ||||||||||||
| 144 | } | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | void QNumberStyleAnimation::setStartValue(qreal value) | - | ||||||||||||
| 147 | { | - | ||||||||||||
| 148 | _start = value; | - | ||||||||||||
| 149 | } never executed: end of block | 0 | ||||||||||||
| 150 | - | |||||||||||||
| 151 | qreal QNumberStyleAnimation::endValue() const | - | ||||||||||||
| 152 | { | - | ||||||||||||
| 153 | return never executed: _end;return _end;never executed: return _end; | 0 | ||||||||||||
| 154 | } | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | void QNumberStyleAnimation::setEndValue(qreal value) | - | ||||||||||||
| 157 | { | - | ||||||||||||
| 158 | _end = value; | - | ||||||||||||
| 159 | } never executed: end of block | 0 | ||||||||||||
| 160 | - | |||||||||||||
| 161 | qreal QNumberStyleAnimation::currentValue() const | - | ||||||||||||
| 162 | { | - | ||||||||||||
| 163 | qreal step = qreal(currentTime() - delay()) / (duration() - delay()); | - | ||||||||||||
| 164 | return never executed: _start + qMax(qreal(0), step) * (_end - _start);return _start + qMax(qreal(0), step) * (_end - _start);never executed: return _start + qMax(qreal(0), step) * (_end - _start); | 0 | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | bool QNumberStyleAnimation::isUpdateNeeded() const | - | ||||||||||||
| 168 | { | - | ||||||||||||
| 169 | if (QStyleAnimation::isUpdateNeeded()
| 0 | ||||||||||||
| 170 | qreal current = currentValue(); | - | ||||||||||||
| 171 | if (!qFuzzyCompare(_prev, current)
| 0 | ||||||||||||
| 172 | { | - | ||||||||||||
| 173 | _prev = current; | - | ||||||||||||
| 174 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||
| 175 | } | - | ||||||||||||
| 176 | } never executed: end of block | 0 | ||||||||||||
| 177 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||
| 178 | } | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | QBlendStyleAnimation::QBlendStyleAnimation(Type type, QObject *target) : | - | ||||||||||||
| 181 | QStyleAnimation(target), _type(type) | - | ||||||||||||
| 182 | { | - | ||||||||||||
| 183 | setDuration(250); | - | ||||||||||||
| 184 | } never executed: end of block | 0 | ||||||||||||
| 185 | - | |||||||||||||
| 186 | QImage QBlendStyleAnimation::startImage() const | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | return never executed: _start;return _start;never executed: return _start; | 0 | ||||||||||||
| 189 | } | - | ||||||||||||
| 190 | - | |||||||||||||
| 191 | void QBlendStyleAnimation::setStartImage(const QImage& image) | - | ||||||||||||
| 192 | { | - | ||||||||||||
| 193 | _start = image; | - | ||||||||||||
| 194 | } never executed: end of block | 0 | ||||||||||||
| 195 | - | |||||||||||||
| 196 | QImage QBlendStyleAnimation::endImage() const | - | ||||||||||||
| 197 | { | - | ||||||||||||
| 198 | return never executed: _end;return _end;never executed: return _end; | 0 | ||||||||||||
| 199 | } | - | ||||||||||||
| 200 | - | |||||||||||||
| 201 | void QBlendStyleAnimation::setEndImage(const QImage& image) | - | ||||||||||||
| 202 | { | - | ||||||||||||
| 203 | _end = image; | - | ||||||||||||
| 204 | } never executed: end of block | 0 | ||||||||||||
| 205 | - | |||||||||||||
| 206 | QImage QBlendStyleAnimation::currentImage() const | - | ||||||||||||
| 207 | { | - | ||||||||||||
| 208 | return never executed: _current;return _current;never executed: return _current; | 0 | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | static QImage blendedImage(const QImage &start, const QImage &end, float alpha) | - | ||||||||||||
| 211 | { | - | ||||||||||||
| 212 | if (start.isNull()
| 0 | ||||||||||||
| 213 | return never executed: QImage();return QImage();never executed: return QImage(); | 0 | ||||||||||||
| 214 | - | |||||||||||||
| 215 | QImage blended; | - | ||||||||||||
| 216 | const int a = qRound(alpha*256); | - | ||||||||||||
| 217 | const int ia = 256 - a; | - | ||||||||||||
| 218 | const int sw = start.width(); | - | ||||||||||||
| 219 | const int sh = start.height(); | - | ||||||||||||
| 220 | const int bpl = start.bytesPerLine(); | - | ||||||||||||
| 221 | switch (start.depth()) { | - | ||||||||||||
| 222 | case never executed: 32:case 32:never executed: case 32: | 0 | ||||||||||||
| 223 | { | - | ||||||||||||
| 224 | blended = QImage(sw, sh, start.format()); | - | ||||||||||||
| 225 | blended.setDevicePixelRatio(start.devicePixelRatio()); | - | ||||||||||||
| 226 | uchar *mixed_data = blended.bits(); | - | ||||||||||||
| 227 | const uchar *back_data = start.bits(); | - | ||||||||||||
| 228 | const uchar *front_data = end.bits(); | - | ||||||||||||
| 229 | for (int sy = 0; sy < sh
| 0 | ||||||||||||
| 230 | quint32* mixed = (quint32*)mixed_data; | - | ||||||||||||
| 231 | const quint32* back = (const quint32*)back_data; | - | ||||||||||||
| 232 | const quint32* front = (const quint32*)front_data; | - | ||||||||||||
| 233 | for (int sx = 0; sx < sw
| 0 | ||||||||||||
| 234 | quint32 bp = back[sx]; | - | ||||||||||||
| 235 | quint32 fp = front[sx]; | - | ||||||||||||
| 236 | mixed[sx] = qRgba ((qRed(bp)*ia + qRed(fp)*a)>>8, | - | ||||||||||||
| 237 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - | ||||||||||||
| 238 | (qBlue(bp)*ia + qBlue(fp)*a)>>8, | - | ||||||||||||
| 239 | (qAlpha(bp)*ia + qAlpha(fp)*a)>>8); | - | ||||||||||||
| 240 | } never executed: end of block | 0 | ||||||||||||
| 241 | mixed_data += bpl; | - | ||||||||||||
| 242 | back_data += bpl; | - | ||||||||||||
| 243 | front_data += bpl; | - | ||||||||||||
| 244 | } never executed: end of block | 0 | ||||||||||||
| 245 | } | - | ||||||||||||
| 246 | default never executed: :default:never executed: default:code before this statement never executed: default: | 0 | ||||||||||||
| 247 | break; never executed: break; | 0 | ||||||||||||
| 248 | } | - | ||||||||||||
| 249 | return never executed: blended;return blended;never executed: return blended; | 0 | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | void QBlendStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
| 253 | { | - | ||||||||||||
| 254 | QStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
| 255 | - | |||||||||||||
| 256 | float alpha = 1.0; | - | ||||||||||||
| 257 | if (duration() > 0
| 0 | ||||||||||||
| 258 | if (_type == Pulse
| 0 | ||||||||||||
| 259 | time = time % duration() * 2; | - | ||||||||||||
| 260 | if (time > duration()
| 0 | ||||||||||||
| 261 | time = duration() * 2 - time; never executed: time = duration() * 2 - time; | 0 | ||||||||||||
| 262 | } never executed: end of block | 0 | ||||||||||||
| 263 | - | |||||||||||||
| 264 | alpha = time / static_cast<float>(duration()); | - | ||||||||||||
| 265 | - | |||||||||||||
| 266 | if (_type == Transition
| 0 | ||||||||||||
| 267 | alpha = 1.0; | - | ||||||||||||
| 268 | stop(); | - | ||||||||||||
| 269 | } never executed: end of block | 0 | ||||||||||||
| 270 | } never executed: else if (time > 0end of block
| 0 | ||||||||||||
| 271 | stop(); | - | ||||||||||||
| 272 | } never executed: end of block | 0 | ||||||||||||
| 273 | - | |||||||||||||
| 274 | _current = blendedImage(_start, _end, alpha); | - | ||||||||||||
| 275 | } never executed: end of block | 0 | ||||||||||||
| 276 | - | |||||||||||||
| 277 | QScrollbarStyleAnimation::QScrollbarStyleAnimation(Mode mode, QObject *target) : QNumberStyleAnimation(target), _mode(mode), _active(false) | - | ||||||||||||
| 278 | { | - | ||||||||||||
| 279 | switch (mode) { | - | ||||||||||||
| 280 | case never executed: Activating:case Activating:never executed: case Activating: | 0 | ||||||||||||
| 281 | setDuration(ScrollBarFadeOutDuration); | - | ||||||||||||
| 282 | setStartValue(0.0); | - | ||||||||||||
| 283 | setEndValue(1.0); | - | ||||||||||||
| 284 | break; never executed: break; | 0 | ||||||||||||
| 285 | case never executed: Deactivating:case Deactivating:never executed: case Deactivating: | 0 | ||||||||||||
| 286 | setDuration(ScrollBarFadeOutDelay + ScrollBarFadeOutDuration); | - | ||||||||||||
| 287 | setDelay(ScrollBarFadeOutDelay); | - | ||||||||||||
| 288 | setStartValue(1.0); | - | ||||||||||||
| 289 | setEndValue(0.0); | - | ||||||||||||
| 290 | break; never executed: break; | 0 | ||||||||||||
| 291 | } | - | ||||||||||||
| 292 | } never executed: end of block | 0 | ||||||||||||
| 293 | - | |||||||||||||
| 294 | QScrollbarStyleAnimation::Mode QScrollbarStyleAnimation::mode() const | - | ||||||||||||
| 295 | { | - | ||||||||||||
| 296 | return never executed: _mode;return _mode;never executed: return _mode; | 0 | ||||||||||||
| 297 | } | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | bool QScrollbarStyleAnimation::wasActive() const | - | ||||||||||||
| 300 | { | - | ||||||||||||
| 301 | return never executed: _active;return _active;never executed: return _active; | 0 | ||||||||||||
| 302 | } | - | ||||||||||||
| 303 | - | |||||||||||||
| 304 | void QScrollbarStyleAnimation::setActive(bool active) | - | ||||||||||||
| 305 | { | - | ||||||||||||
| 306 | _active = active; | - | ||||||||||||
| 307 | } never executed: end of block | 0 | ||||||||||||
| 308 | - | |||||||||||||
| 309 | void QScrollbarStyleAnimation::updateCurrentTime(int time) | - | ||||||||||||
| 310 | { | - | ||||||||||||
| 311 | QNumberStyleAnimation::updateCurrentTime(time); | - | ||||||||||||
| 312 | if (_mode == Deactivating
| 0 | ||||||||||||
| 313 | target()->setProperty("visible", false); never executed: target()->setProperty("visible", false); | 0 | ||||||||||||
| 314 | } never executed: end of block | 0 | ||||||||||||
| 315 | - | |||||||||||||
| 316 | - | |||||||||||||
| 317 | - | |||||||||||||
| Switch to Source code | Preprocessed file |