| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qeffects.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 "qapplication.h" | - | ||||||||||||
| 41 | #ifndef QT_NO_EFFECTS | - | ||||||||||||
| 42 | #include "qdesktopwidget.h" | - | ||||||||||||
| 43 | #include "qeffects_p.h" | - | ||||||||||||
| 44 | #include "qevent.h" | - | ||||||||||||
| 45 | #include "qimage.h" | - | ||||||||||||
| 46 | #include "qpainter.h" | - | ||||||||||||
| 47 | #include "qscreen.h" | - | ||||||||||||
| 48 | #include "qpixmap.h" | - | ||||||||||||
| 49 | #include "qpointer.h" | - | ||||||||||||
| 50 | #include "qtimer.h" | - | ||||||||||||
| 51 | #include "qelapsedtimer.h" | - | ||||||||||||
| 52 | #include "qdebug.h" | - | ||||||||||||
| 53 | - | |||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | /* | - | ||||||||||||
| 57 | Internal class QAlphaWidget. | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | The QAlphaWidget is shown while the animation lasts | - | ||||||||||||
| 60 | and displays the pixmap resulting from the alpha blending. | - | ||||||||||||
| 61 | */ | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | class QAlphaWidget: public QWidget, private QEffects | - | ||||||||||||
| 64 | { | - | ||||||||||||
| 65 | Q_OBJECT | - | ||||||||||||
| 66 | public: | - | ||||||||||||
| 67 | QAlphaWidget(QWidget* w, Qt::WindowFlags f = 0); | - | ||||||||||||
| 68 | ~QAlphaWidget(); | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | void run(int time); | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | protected: | - | ||||||||||||
| 73 | void paintEvent(QPaintEvent* e) Q_DECL_OVERRIDE; | - | ||||||||||||
| 74 | void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
| 75 | void alphaBlend(); | - | ||||||||||||
| 76 | bool eventFilter(QObject *, QEvent *) Q_DECL_OVERRIDE; | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | protected slots: | - | ||||||||||||
| 79 | void render(); | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | private: | - | ||||||||||||
| 82 | QPixmap pm; | - | ||||||||||||
| 83 | double alpha; | - | ||||||||||||
| 84 | QImage backImage; | - | ||||||||||||
| 85 | QImage frontImage; | - | ||||||||||||
| 86 | QImage mixedImage; | - | ||||||||||||
| 87 | QPointer<QWidget> widget; | - | ||||||||||||
| 88 | int duration; | - | ||||||||||||
| 89 | int elapsed; | - | ||||||||||||
| 90 | bool showWidget; | - | ||||||||||||
| 91 | QTimer anim; | - | ||||||||||||
| 92 | QElapsedTimer checkTime; | - | ||||||||||||
| 93 | }; | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | static QAlphaWidget* q_blend = 0; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | /* | - | ||||||||||||
| 98 | Constructs a QAlphaWidget. | - | ||||||||||||
| 99 | */ | - | ||||||||||||
| 100 | QAlphaWidget::QAlphaWidget(QWidget* w, Qt::WindowFlags f) | - | ||||||||||||
| 101 | : QWidget(QApplication::desktop()->screen(QApplication::desktop()->screenNumber(w)), f) | - | ||||||||||||
| 102 | { | - | ||||||||||||
| 103 | #ifndef Q_OS_WIN | - | ||||||||||||
| 104 | setEnabled(false); | - | ||||||||||||
| 105 | #endif | - | ||||||||||||
| 106 | setAttribute(Qt::WA_NoSystemBackground, true); | - | ||||||||||||
| 107 | widget = w; | - | ||||||||||||
| 108 | alpha = 0; | - | ||||||||||||
| 109 | } never executed: end of block | 0 | ||||||||||||
| 110 | - | |||||||||||||
| 111 | QAlphaWidget::~QAlphaWidget() | - | ||||||||||||
| 112 | { | - | ||||||||||||
| 113 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
| 114 | // Restore user-defined opacity value | - | ||||||||||||
| 115 | if (widget) | - | ||||||||||||
| 116 | widget->setWindowOpacity(1); | - | ||||||||||||
| 117 | #endif | - | ||||||||||||
| 118 | } | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | /* | - | ||||||||||||
| 121 | \reimp | - | ||||||||||||
| 122 | */ | - | ||||||||||||
| 123 | void QAlphaWidget::paintEvent(QPaintEvent*) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | QPainter p(this); | - | ||||||||||||
| 126 | p.drawPixmap(0, 0, pm); | - | ||||||||||||
| 127 | } never executed: end of block | 0 | ||||||||||||
| 128 | - | |||||||||||||
| 129 | /* | - | ||||||||||||
| 130 | Starts the alphablending animation. | - | ||||||||||||
| 131 | The animation will take about \a time ms | - | ||||||||||||
| 132 | */ | - | ||||||||||||
| 133 | void QAlphaWidget::run(int time) | - | ||||||||||||
| 134 | { | - | ||||||||||||
| 135 | duration = time; | - | ||||||||||||
| 136 | - | |||||||||||||
| 137 | if (duration < 0)
| 0 | ||||||||||||
| 138 | duration = 150; never executed: duration = 150; | 0 | ||||||||||||
| 139 | - | |||||||||||||
| 140 | if (!widget)
| 0 | ||||||||||||
| 141 | return; never executed: return; | 0 | ||||||||||||
| 142 | - | |||||||||||||
| 143 | elapsed = 0; | - | ||||||||||||
| 144 | checkTime.start(); | - | ||||||||||||
| 145 | - | |||||||||||||
| 146 | showWidget = true; | - | ||||||||||||
| 147 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
| 148 | qApp->installEventFilter(this); | - | ||||||||||||
| 149 | widget->setWindowOpacity(0.0); | - | ||||||||||||
| 150 | widget->show(); | - | ||||||||||||
| 151 | connect(&anim, SIGNAL(timeout()), this, SLOT(render())); | - | ||||||||||||
| 152 | anim.start(1); | - | ||||||||||||
| 153 | #else | - | ||||||||||||
| 154 | //This is roughly equivalent to calling setVisible(true) without actually showing the widget | - | ||||||||||||
| 155 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - | ||||||||||||
| 156 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | qApp->installEventFilter(this); | - | ||||||||||||
| 159 | - | |||||||||||||
| 160 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
| 161 | resize(widget->size().width(), widget->size().height()); | - | ||||||||||||
| 162 | - | |||||||||||||
| 163 | frontImage = widget->grab().toImage(); | - | ||||||||||||
| 164 | backImage = QGuiApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(), | - | ||||||||||||
| 165 | widget->geometry().x(), widget->geometry().y(), | - | ||||||||||||
| 166 | widget->geometry().width(), widget->geometry().height()).toImage(); | - | ||||||||||||
| 167 | - | |||||||||||||
| 168 | if (!backImage.isNull() && checkTime.elapsed() < duration / 2) {
| 0 | ||||||||||||
| 169 | mixedImage = backImage.copy(); | - | ||||||||||||
| 170 | pm = QPixmap::fromImage(mixedImage); | - | ||||||||||||
| 171 | show(); | - | ||||||||||||
| 172 | setEnabled(false); | - | ||||||||||||
| 173 | - | |||||||||||||
| 174 | connect(&anim, SIGNAL(timeout()), this, SLOT(render())); | - | ||||||||||||
| 175 | anim.start(1); | - | ||||||||||||
| 176 | } else { never executed: end of block | 0 | ||||||||||||
| 177 | duration = 0; | - | ||||||||||||
| 178 | render(); | - | ||||||||||||
| 179 | } never executed: end of block | 0 | ||||||||||||
| 180 | #endif | - | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | /* | - | ||||||||||||
| 184 | \reimp | - | ||||||||||||
| 185 | */ | - | ||||||||||||
| 186 | bool QAlphaWidget::eventFilter(QObject *o, QEvent *e) | - | ||||||||||||
| 187 | { | - | ||||||||||||
| 188 | switch (e->type()) { | - | ||||||||||||
| 189 | case QEvent::Move: never executed: case QEvent::Move: | 0 | ||||||||||||
| 190 | if (o != widget)
| 0 | ||||||||||||
| 191 | break; never executed: break; | 0 | ||||||||||||
| 192 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
| 193 | update(); | - | ||||||||||||
| 194 | break; never executed: break; | 0 | ||||||||||||
| 195 | case QEvent::Hide: never executed: case QEvent::Hide: | 0 | ||||||||||||
| 196 | case QEvent::Close: never executed: case QEvent::Close: | 0 | ||||||||||||
| 197 | if (o != widget)
| 0 | ||||||||||||
| 198 | break; never executed: break; | 0 | ||||||||||||
| 199 | case QEvent::MouseButtonPress: code before this statement never executed: case QEvent::MouseButtonPress:never executed: case QEvent::MouseButtonPress: | 0 | ||||||||||||
| 200 | case QEvent::MouseButtonDblClick: never executed: case QEvent::MouseButtonDblClick: | 0 | ||||||||||||
| 201 | showWidget = false; | - | ||||||||||||
| 202 | render(); | - | ||||||||||||
| 203 | break; never executed: break; | 0 | ||||||||||||
| 204 | case QEvent::KeyPress: { never executed: case QEvent::KeyPress: | 0 | ||||||||||||
| 205 | QKeyEvent *ke = (QKeyEvent*)e; | - | ||||||||||||
| 206 | if (ke->matches(QKeySequence::Cancel)) {
| 0 | ||||||||||||
| 207 | showWidget = false; | - | ||||||||||||
| 208 | } else { never executed: end of block | 0 | ||||||||||||
| 209 | duration = 0; | - | ||||||||||||
| 210 | } never executed: end of block | 0 | ||||||||||||
| 211 | render(); | - | ||||||||||||
| 212 | break; never executed: break; | 0 | ||||||||||||
| 213 | } | - | ||||||||||||
| 214 | default: never executed: default: | 0 | ||||||||||||
| 215 | break; never executed: break; | 0 | ||||||||||||
| 216 | } | - | ||||||||||||
| 217 | return QWidget::eventFilter(o, e); never executed: return QWidget::eventFilter(o, e); | 0 | ||||||||||||
| 218 | } | - | ||||||||||||
| 219 | - | |||||||||||||
| 220 | /* | - | ||||||||||||
| 221 | \reimp | - | ||||||||||||
| 222 | */ | - | ||||||||||||
| 223 | void QAlphaWidget::closeEvent(QCloseEvent *e) | - | ||||||||||||
| 224 | { | - | ||||||||||||
| 225 | e->accept(); | - | ||||||||||||
| 226 | if (!q_blend)
| 0 | ||||||||||||
| 227 | return; never executed: return; | 0 | ||||||||||||
| 228 | - | |||||||||||||
| 229 | showWidget = false; | - | ||||||||||||
| 230 | render(); | - | ||||||||||||
| 231 | - | |||||||||||||
| 232 | QWidget::closeEvent(e); | - | ||||||||||||
| 233 | } never executed: end of block | 0 | ||||||||||||
| 234 | - | |||||||||||||
| 235 | /* | - | ||||||||||||
| 236 | Render alphablending for the time elapsed. | - | ||||||||||||
| 237 | - | |||||||||||||
| 238 | Show the blended widget and free all allocated source | - | ||||||||||||
| 239 | if the blending is finished. | - | ||||||||||||
| 240 | */ | - | ||||||||||||
| 241 | void QAlphaWidget::render() | - | ||||||||||||
| 242 | { | - | ||||||||||||
| 243 | int tempel = checkTime.elapsed(); | - | ||||||||||||
| 244 | if (elapsed >= tempel)
| 0 | ||||||||||||
| 245 | elapsed++; never executed: elapsed++; | 0 | ||||||||||||
| 246 | else | - | ||||||||||||
| 247 | elapsed = tempel; never executed: elapsed = tempel; | 0 | ||||||||||||
| 248 | - | |||||||||||||
| 249 | if (duration != 0)
| 0 | ||||||||||||
| 250 | alpha = tempel / double(duration); never executed: alpha = tempel / double(duration); | 0 | ||||||||||||
| 251 | else | - | ||||||||||||
| 252 | alpha = 1; never executed: alpha = 1; | 0 | ||||||||||||
| 253 | - | |||||||||||||
| 254 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
| 255 | if (alpha >= 1 || !showWidget) { | - | ||||||||||||
| 256 | anim.stop(); | - | ||||||||||||
| 257 | qApp->removeEventFilter(this); | - | ||||||||||||
| 258 | widget->setWindowOpacity(1); | - | ||||||||||||
| 259 | q_blend = 0; | - | ||||||||||||
| 260 | deleteLater(); | - | ||||||||||||
| 261 | } else { | - | ||||||||||||
| 262 | widget->setWindowOpacity(alpha); | - | ||||||||||||
| 263 | } | - | ||||||||||||
| 264 | #else | - | ||||||||||||
| 265 | if (alpha >= 1 || !showWidget) {
| 0 | ||||||||||||
| 266 | anim.stop(); | - | ||||||||||||
| 267 | qApp->removeEventFilter(this); | - | ||||||||||||
| 268 | - | |||||||||||||
| 269 | if (widget) {
| 0 | ||||||||||||
| 270 | if (!showWidget) {
| 0 | ||||||||||||
| 271 | #ifdef Q_OS_WIN | - | ||||||||||||
| 272 | setEnabled(true); | - | ||||||||||||
| 273 | setFocus(); | - | ||||||||||||
| 274 | #endif // Q_OS_WIN | - | ||||||||||||
| 275 | widget->hide(); | - | ||||||||||||
| 276 | } else { never executed: end of block | 0 | ||||||||||||
| 277 | //Since we are faking the visibility of the widget | - | ||||||||||||
| 278 | //we need to unset the hidden state on it before calling show | - | ||||||||||||
| 279 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - | ||||||||||||
| 280 | widget->show(); | - | ||||||||||||
| 281 | lower(); | - | ||||||||||||
| 282 | } never executed: end of block | 0 | ||||||||||||
| 283 | } | - | ||||||||||||
| 284 | q_blend = 0; | - | ||||||||||||
| 285 | deleteLater(); | - | ||||||||||||
| 286 | } else { never executed: end of block | 0 | ||||||||||||
| 287 | alphaBlend(); | - | ||||||||||||
| 288 | pm = QPixmap::fromImage(mixedImage); | - | ||||||||||||
| 289 | repaint(); | - | ||||||||||||
| 290 | } never executed: end of block | 0 | ||||||||||||
| 291 | #endif // defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||
| 292 | } | - | ||||||||||||
| 293 | - | |||||||||||||
| 294 | /* | - | ||||||||||||
| 295 | Calculate an alphablended image. | - | ||||||||||||
| 296 | */ | - | ||||||||||||
| 297 | void QAlphaWidget::alphaBlend() | - | ||||||||||||
| 298 | { | - | ||||||||||||
| 299 | const int a = qRound(alpha*256); | - | ||||||||||||
| 300 | const int ia = 256 - a; | - | ||||||||||||
| 301 | - | |||||||||||||
| 302 | const int sw = frontImage.width(); | - | ||||||||||||
| 303 | const int sh = frontImage.height(); | - | ||||||||||||
| 304 | const int bpl = frontImage.bytesPerLine(); | - | ||||||||||||
| 305 | switch(frontImage.depth()) { | - | ||||||||||||
| 306 | case 32: never executed: case 32: | 0 | ||||||||||||
| 307 | { | - | ||||||||||||
| 308 | uchar *mixed_data = mixedImage.bits(); | - | ||||||||||||
| 309 | const uchar *back_data = backImage.bits(); | - | ||||||||||||
| 310 | const uchar *front_data = frontImage.bits(); | - | ||||||||||||
| 311 | - | |||||||||||||
| 312 | for (int sy = 0; sy < sh; sy++) {
| 0 | ||||||||||||
| 313 | quint32* mixed = (quint32*)mixed_data; | - | ||||||||||||
| 314 | const quint32* back = (const quint32*)back_data; | - | ||||||||||||
| 315 | const quint32* front = (const quint32*)front_data; | - | ||||||||||||
| 316 | for (int sx = 0; sx < sw; sx++) {
| 0 | ||||||||||||
| 317 | quint32 bp = back[sx]; | - | ||||||||||||
| 318 | quint32 fp = front[sx]; | - | ||||||||||||
| 319 | - | |||||||||||||
| 320 | mixed[sx] = qRgb((qRed(bp)*ia + qRed(fp)*a)>>8, | - | ||||||||||||
| 321 | (qGreen(bp)*ia + qGreen(fp)*a)>>8, | - | ||||||||||||
| 322 | (qBlue(bp)*ia + qBlue(fp)*a)>>8); | - | ||||||||||||
| 323 | } never executed: end of block | 0 | ||||||||||||
| 324 | mixed_data += bpl; | - | ||||||||||||
| 325 | back_data += bpl; | - | ||||||||||||
| 326 | front_data += bpl; | - | ||||||||||||
| 327 | } never executed: end of block | 0 | ||||||||||||
| 328 | } | - | ||||||||||||
| 329 | default: code before this statement never executed: default:never executed: default: | 0 | ||||||||||||
| 330 | break; never executed: break; | 0 | ||||||||||||
| 331 | } | - | ||||||||||||
| 332 | } | - | ||||||||||||
| 333 | - | |||||||||||||
| 334 | /* | - | ||||||||||||
| 335 | Internal class QRollEffect | - | ||||||||||||
| 336 | - | |||||||||||||
| 337 | The QRollEffect widget is shown while the animation lasts | - | ||||||||||||
| 338 | and displays a scrolling pixmap. | - | ||||||||||||
| 339 | */ | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | class QRollEffect : public QWidget, private QEffects | - | ||||||||||||
| 342 | { | - | ||||||||||||
| 343 | Q_OBJECT | - | ||||||||||||
| 344 | public: | - | ||||||||||||
| 345 | QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient); | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | void run(int time); | - | ||||||||||||
| 348 | - | |||||||||||||
| 349 | protected: | - | ||||||||||||
| 350 | void paintEvent(QPaintEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
| 351 | void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; | - | ||||||||||||
| 352 | - | |||||||||||||
| 353 | private slots: | - | ||||||||||||
| 354 | void scroll(); | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | private: | - | ||||||||||||
| 357 | QPointer<QWidget> widget; | - | ||||||||||||
| 358 | - | |||||||||||||
| 359 | int currentHeight; | - | ||||||||||||
| 360 | int currentWidth; | - | ||||||||||||
| 361 | int totalHeight; | - | ||||||||||||
| 362 | int totalWidth; | - | ||||||||||||
| 363 | - | |||||||||||||
| 364 | int duration; | - | ||||||||||||
| 365 | int elapsed; | - | ||||||||||||
| 366 | bool done; | - | ||||||||||||
| 367 | bool showWidget; | - | ||||||||||||
| 368 | int orientation; | - | ||||||||||||
| 369 | - | |||||||||||||
| 370 | QTimer anim; | - | ||||||||||||
| 371 | QElapsedTimer checkTime; | - | ||||||||||||
| 372 | - | |||||||||||||
| 373 | QPixmap pm; | - | ||||||||||||
| 374 | }; | - | ||||||||||||
| 375 | - | |||||||||||||
| 376 | static QRollEffect* q_roll = 0; | - | ||||||||||||
| 377 | - | |||||||||||||
| 378 | /* | - | ||||||||||||
| 379 | Construct a QRollEffect widget. | - | ||||||||||||
| 380 | */ | - | ||||||||||||
| 381 | QRollEffect::QRollEffect(QWidget* w, Qt::WindowFlags f, DirFlags orient) | - | ||||||||||||
| 382 | : QWidget(0, f), orientation(orient) | - | ||||||||||||
| 383 | { | - | ||||||||||||
| 384 | #ifndef Q_OS_WIN | - | ||||||||||||
| 385 | setEnabled(false); | - | ||||||||||||
| 386 | #endif | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | widget = w; | - | ||||||||||||
| 389 | Q_ASSERT(widget); | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | setAttribute(Qt::WA_NoSystemBackground, true); | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | if (widget->testAttribute(Qt::WA_Resized)) {
| 0 | ||||||||||||
| 394 | totalWidth = widget->width(); | - | ||||||||||||
| 395 | totalHeight = widget->height(); | - | ||||||||||||
| 396 | } else { never executed: end of block | 0 | ||||||||||||
| 397 | totalWidth = widget->sizeHint().width(); | - | ||||||||||||
| 398 | totalHeight = widget->sizeHint().height(); | - | ||||||||||||
| 399 | } never executed: end of block | 0 | ||||||||||||
| 400 | - | |||||||||||||
| 401 | currentHeight = totalHeight; | - | ||||||||||||
| 402 | currentWidth = totalWidth; | - | ||||||||||||
| 403 | - | |||||||||||||
| 404 | if (orientation & (RightScroll|LeftScroll))
| 0 | ||||||||||||
| 405 | currentWidth = 0; never executed: currentWidth = 0; | 0 | ||||||||||||
| 406 | if (orientation & (DownScroll|UpScroll))
| 0 | ||||||||||||
| 407 | currentHeight = 0; never executed: currentHeight = 0; | 0 | ||||||||||||
| 408 | - | |||||||||||||
| 409 | pm = widget->grab(); | - | ||||||||||||
| 410 | } never executed: end of block | 0 | ||||||||||||
| 411 | - | |||||||||||||
| 412 | /* | - | ||||||||||||
| 413 | \reimp | - | ||||||||||||
| 414 | */ | - | ||||||||||||
| 415 | void QRollEffect::paintEvent(QPaintEvent*) | - | ||||||||||||
| 416 | { | - | ||||||||||||
| 417 | int x = orientation & RightScroll ? qMin(0, currentWidth - totalWidth) : 0;
| 0 | ||||||||||||
| 418 | int y = orientation & DownScroll ? qMin(0, currentHeight - totalHeight) : 0;
| 0 | ||||||||||||
| 419 | - | |||||||||||||
| 420 | QPainter p(this); | - | ||||||||||||
| 421 | p.drawPixmap(x, y, pm); | - | ||||||||||||
| 422 | } never executed: end of block | 0 | ||||||||||||
| 423 | - | |||||||||||||
| 424 | /* | - | ||||||||||||
| 425 | \reimp | - | ||||||||||||
| 426 | */ | - | ||||||||||||
| 427 | void QRollEffect::closeEvent(QCloseEvent *e) | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | e->accept(); | - | ||||||||||||
| 430 | if (done)
| 0 | ||||||||||||
| 431 | return; never executed: return; | 0 | ||||||||||||
| 432 | - | |||||||||||||
| 433 | showWidget = false; | - | ||||||||||||
| 434 | done = true; | - | ||||||||||||
| 435 | scroll(); | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | QWidget::closeEvent(e); | - | ||||||||||||
| 438 | } never executed: end of block | 0 | ||||||||||||
| 439 | - | |||||||||||||
| 440 | /* | - | ||||||||||||
| 441 | Start the animation. | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | The animation will take about \a time ms, or is | - | ||||||||||||
| 444 | calculated if \a time is negative | - | ||||||||||||
| 445 | */ | - | ||||||||||||
| 446 | void QRollEffect::run(int time) | - | ||||||||||||
| 447 | { | - | ||||||||||||
| 448 | if (!widget)
| 0 | ||||||||||||
| 449 | return; never executed: return; | 0 | ||||||||||||
| 450 | - | |||||||||||||
| 451 | duration = time; | - | ||||||||||||
| 452 | elapsed = 0; | - | ||||||||||||
| 453 | - | |||||||||||||
| 454 | if (duration < 0) {
| 0 | ||||||||||||
| 455 | int dist = 0; | - | ||||||||||||
| 456 | if (orientation & (RightScroll|LeftScroll))
| 0 | ||||||||||||
| 457 | dist += totalWidth - currentWidth; never executed: dist += totalWidth - currentWidth; | 0 | ||||||||||||
| 458 | if (orientation & (DownScroll|UpScroll))
| 0 | ||||||||||||
| 459 | dist += totalHeight - currentHeight; never executed: dist += totalHeight - currentHeight; | 0 | ||||||||||||
| 460 | duration = qMin(qMax(dist/3, 50), 120); | - | ||||||||||||
| 461 | } never executed: end of block | 0 | ||||||||||||
| 462 | - | |||||||||||||
| 463 | connect(&anim, SIGNAL(timeout()), this, SLOT(scroll())); | - | ||||||||||||
| 464 | - | |||||||||||||
| 465 | move(widget->geometry().x(),widget->geometry().y()); | - | ||||||||||||
| 466 | resize(qMin(currentWidth, totalWidth), qMin(currentHeight, totalHeight)); | - | ||||||||||||
| 467 | - | |||||||||||||
| 468 | //This is roughly equivalent to calling setVisible(true) without actually showing the widget | - | ||||||||||||
| 469 | widget->setAttribute(Qt::WA_WState_ExplicitShowHide, true); | - | ||||||||||||
| 470 | widget->setAttribute(Qt::WA_WState_Hidden, false); | - | ||||||||||||
| 471 | - | |||||||||||||
| 472 | show(); | - | ||||||||||||
| 473 | setEnabled(false); | - | ||||||||||||
| 474 | - | |||||||||||||
| 475 | showWidget = true; | - | ||||||||||||
| 476 | done = false; | - | ||||||||||||
| 477 | anim.start(1); | - | ||||||||||||
| 478 | checkTime.start(); | - | ||||||||||||
| 479 | } never executed: end of block | 0 | ||||||||||||
| 480 | - | |||||||||||||
| 481 | /* | - | ||||||||||||
| 482 | Roll according to the time elapsed. | - | ||||||||||||
| 483 | */ | - | ||||||||||||
| 484 | void QRollEffect::scroll() | - | ||||||||||||
| 485 | { | - | ||||||||||||
| 486 | if (!done && widget) {
| 0 | ||||||||||||
| 487 | int tempel = checkTime.elapsed(); | - | ||||||||||||
| 488 | if (elapsed >= tempel)
| 0 | ||||||||||||
| 489 | elapsed++; never executed: elapsed++; | 0 | ||||||||||||
| 490 | else | - | ||||||||||||
| 491 | elapsed = tempel; never executed: elapsed = tempel; | 0 | ||||||||||||
| 492 | - | |||||||||||||
| 493 | if (currentWidth != totalWidth) {
| 0 | ||||||||||||
| 494 | currentWidth = totalWidth * (elapsed/duration) | - | ||||||||||||
| 495 | + (2 * totalWidth * (elapsed%duration) + duration) | - | ||||||||||||
| 496 | / (2 * duration); | - | ||||||||||||
| 497 | // equiv. to int((totalWidth*elapsed) / duration + 0.5) | - | ||||||||||||
| 498 | done = (currentWidth >= totalWidth); | - | ||||||||||||
| 499 | } never executed: end of block | 0 | ||||||||||||
| 500 | if (currentHeight != totalHeight) {
| 0 | ||||||||||||
| 501 | currentHeight = totalHeight * (elapsed/duration) | - | ||||||||||||
| 502 | + (2 * totalHeight * (elapsed%duration) + duration) | - | ||||||||||||
| 503 | / (2 * duration); | - | ||||||||||||
| 504 | // equiv. to int((totalHeight*elapsed) / duration + 0.5) | - | ||||||||||||
| 505 | done = (currentHeight >= totalHeight); | - | ||||||||||||
| 506 | } never executed: end of block | 0 | ||||||||||||
| 507 | done = (currentHeight >= totalHeight) &&
| 0 | ||||||||||||
| 508 | (currentWidth >= totalWidth);
| 0 | ||||||||||||
| 509 | - | |||||||||||||
| 510 | int w = totalWidth; | - | ||||||||||||
| 511 | int h = totalHeight; | - | ||||||||||||
| 512 | int x = widget->geometry().x(); | - | ||||||||||||
| 513 | int y = widget->geometry().y(); | - | ||||||||||||
| 514 | - | |||||||||||||
| 515 | if (orientation & RightScroll || orientation & LeftScroll)
| 0 | ||||||||||||
| 516 | w = qMin(currentWidth, totalWidth); never executed: w = qMin(currentWidth, totalWidth); | 0 | ||||||||||||
| 517 | if (orientation & DownScroll || orientation & UpScroll)
| 0 | ||||||||||||
| 518 | h = qMin(currentHeight, totalHeight); never executed: h = qMin(currentHeight, totalHeight); | 0 | ||||||||||||
| 519 | - | |||||||||||||
| 520 | setUpdatesEnabled(false); | - | ||||||||||||
| 521 | if (orientation & UpScroll)
| 0 | ||||||||||||
| 522 | y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); never executed: y = widget->geometry().y() + qMax(0, totalHeight - currentHeight); | 0 | ||||||||||||
| 523 | if (orientation & LeftScroll)
| 0 | ||||||||||||
| 524 | x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); never executed: x = widget->geometry().x() + qMax(0, totalWidth - currentWidth); | 0 | ||||||||||||
| 525 | if (orientation & UpScroll || orientation & LeftScroll)
| 0 | ||||||||||||
| 526 | move(x, y); never executed: move(x, y); | 0 | ||||||||||||
| 527 | - | |||||||||||||
| 528 | resize(w, h); | - | ||||||||||||
| 529 | setUpdatesEnabled(true); | - | ||||||||||||
| 530 | repaint(); | - | ||||||||||||
| 531 | } never executed: end of block | 0 | ||||||||||||
| 532 | if (done || !widget) {
| 0 | ||||||||||||
| 533 | anim.stop(); | - | ||||||||||||
| 534 | if (widget) {
| 0 | ||||||||||||
| 535 | if (!showWidget) {
| 0 | ||||||||||||
| 536 | #ifdef Q_OS_WIN | - | ||||||||||||
| 537 | setEnabled(true); | - | ||||||||||||
| 538 | setFocus(); | - | ||||||||||||
| 539 | #endif | - | ||||||||||||
| 540 | widget->hide(); | - | ||||||||||||
| 541 | } else { never executed: end of block | 0 | ||||||||||||
| 542 | //Since we are faking the visibility of the widget | - | ||||||||||||
| 543 | //we need to unset the hidden state on it before calling show | - | ||||||||||||
| 544 | widget->setAttribute(Qt::WA_WState_Hidden, true); | - | ||||||||||||
| 545 | widget->show(); | - | ||||||||||||
| 546 | lower(); | - | ||||||||||||
| 547 | } never executed: end of block | 0 | ||||||||||||
| 548 | } | - | ||||||||||||
| 549 | q_roll = 0; | - | ||||||||||||
| 550 | deleteLater(); | - | ||||||||||||
| 551 | } never executed: end of block | 0 | ||||||||||||
| 552 | } never executed: end of block | 0 | ||||||||||||
| 553 | - | |||||||||||||
| 554 | /*! | - | ||||||||||||
| 555 | Scroll widget \a w in \a time ms. \a orient may be 1 (vertical), 2 | - | ||||||||||||
| 556 | (horizontal) or 3 (diagonal). | - | ||||||||||||
| 557 | */ | - | ||||||||||||
| 558 | void qScrollEffect(QWidget* w, QEffects::DirFlags orient, int time) | - | ||||||||||||
| 559 | { | - | ||||||||||||
| 560 | if (q_roll) {
| 0 | ||||||||||||
| 561 | q_roll->deleteLater(); | - | ||||||||||||
| 562 | q_roll = 0; | - | ||||||||||||
| 563 | } never executed: end of block | 0 | ||||||||||||
| 564 | - | |||||||||||||
| 565 | if (!w)
| 0 | ||||||||||||
| 566 | return; never executed: return; | 0 | ||||||||||||
| 567 | - | |||||||||||||
| 568 | QApplication::sendPostedEvents(w, QEvent::Move); | - | ||||||||||||
| 569 | QApplication::sendPostedEvents(w, QEvent::Resize); | - | ||||||||||||
| 570 | Qt::WindowFlags flags = Qt::ToolTip; | - | ||||||||||||
| 571 | - | |||||||||||||
| 572 | // those can be popups - they would steal the focus, but are disabled | - | ||||||||||||
| 573 | q_roll = new QRollEffect(w, flags, orient); | - | ||||||||||||
| 574 | q_roll->run(time); | - | ||||||||||||
| 575 | } never executed: end of block | 0 | ||||||||||||
| 576 | - | |||||||||||||
| 577 | /*! | - | ||||||||||||
| 578 | Fade in widget \a w in \a time ms. | - | ||||||||||||
| 579 | */ | - | ||||||||||||
| 580 | void qFadeEffect(QWidget* w, int time) | - | ||||||||||||
| 581 | { | - | ||||||||||||
| 582 | if (q_blend) {
| 0 | ||||||||||||
| 583 | q_blend->deleteLater(); | - | ||||||||||||
| 584 | q_blend = 0; | - | ||||||||||||
| 585 | } never executed: end of block | 0 | ||||||||||||
| 586 | - | |||||||||||||
| 587 | if (!w)
| 0 | ||||||||||||
| 588 | return; never executed: return; | 0 | ||||||||||||
| 589 | - | |||||||||||||
| 590 | QApplication::sendPostedEvents(w, QEvent::Move); | - | ||||||||||||
| 591 | QApplication::sendPostedEvents(w, QEvent::Resize); | - | ||||||||||||
| 592 | - | |||||||||||||
| 593 | Qt::WindowFlags flags = Qt::ToolTip; | - | ||||||||||||
| 594 | - | |||||||||||||
| 595 | // those can be popups - they would steal the focus, but are disabled | - | ||||||||||||
| 596 | q_blend = new QAlphaWidget(w, flags); | - | ||||||||||||
| 597 | - | |||||||||||||
| 598 | q_blend->run(time); | - | ||||||||||||
| 599 | } never executed: end of block | 0 | ||||||||||||
| 600 | - | |||||||||||||
| 601 | QT_END_NAMESPACE | - | ||||||||||||
| 602 | - | |||||||||||||
| 603 | /* | - | ||||||||||||
| 604 | Delete this after timeout | - | ||||||||||||
| 605 | */ | - | ||||||||||||
| 606 | - | |||||||||||||
| 607 | #include "qeffects.moc" | - | ||||||||||||
| 608 | - | |||||||||||||
| 609 | #endif //QT_NO_EFFECTS | - | ||||||||||||
| Source code | Switch to Preprocessed file |