| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qsplashscreen.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | - | |||||||
| 10 | - | |||||||
| 11 | - | |||||||
| 12 | - | |||||||
| 13 | class QSplashScreenPrivate : public QWidgetPrivate | - | ||||||
| 14 | { | - | ||||||
| 15 | inline QSplashScreen* q_func() { return static_cast<QSplashScreen *>(q_ptr); } inline const QSplashScreen* q_func() const { return static_cast<const QSplashScreen *>(q_ptr); } friend class QSplashScreen; | - | ||||||
| 16 | public: | - | ||||||
| 17 | QPixmap pixmap; | - | ||||||
| 18 | QString currStatus; | - | ||||||
| 19 | QColor currColor; | - | ||||||
| 20 | int currAlign; | - | ||||||
| 21 | - | |||||||
| 22 | inline QSplashScreenPrivate(); | - | ||||||
| 23 | }; | - | ||||||
| 24 | QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) | - | ||||||
| 25 | : QWidget(*(new QSplashScreenPrivate()), 0, Qt::SplashScreen | Qt::FramelessWindowHint | f) | - | ||||||
| 26 | { | - | ||||||
| 27 | setPixmap(pixmap); | - | ||||||
| 28 | } never executed: end of block | 0 | ||||||
| 29 | QSplashScreen::QSplashScreen(QWidget *parent, const QPixmap &pixmap, Qt::WindowFlags f) | - | ||||||
| 30 | : QWidget(*new QSplashScreenPrivate, parent, Qt::SplashScreen | f) | - | ||||||
| 31 | { | - | ||||||
| 32 | d_func()->pixmap = pixmap; | - | ||||||
| 33 | setPixmap(d_func()->pixmap); | - | ||||||
| 34 | } never executed: end of block | 0 | ||||||
| 35 | - | |||||||
| 36 | - | |||||||
| 37 | - | |||||||
| 38 | - | |||||||
| 39 | QSplashScreen::~QSplashScreen() | - | ||||||
| 40 | { | - | ||||||
| 41 | } | - | ||||||
| 42 | - | |||||||
| 43 | - | |||||||
| 44 | - | |||||||
| 45 | - | |||||||
| 46 | void QSplashScreen::mousePressEvent(QMouseEvent *) | - | ||||||
| 47 | { | - | ||||||
| 48 | hide(); | - | ||||||
| 49 | } never executed: end of block | 0 | ||||||
| 50 | - | |||||||
| 51 | - | |||||||
| 52 | - | |||||||
| 53 | - | |||||||
| 54 | - | |||||||
| 55 | - | |||||||
| 56 | - | |||||||
| 57 | void QSplashScreen::repaint() | - | ||||||
| 58 | { | - | ||||||
| 59 | QWidget::repaint(); | - | ||||||
| 60 | QApplication::flush(); | - | ||||||
| 61 | } never executed: end of block | 0 | ||||||
| 62 | void QSplashScreen::showMessage(const QString &message, int alignment, | - | ||||||
| 63 | const QColor &color) | - | ||||||
| 64 | { | - | ||||||
| 65 | QSplashScreenPrivate * const d = d_func(); | - | ||||||
| 66 | d->currStatus = message; | - | ||||||
| 67 | d->currAlign = alignment; | - | ||||||
| 68 | d->currColor = color; | - | ||||||
| 69 | messageChanged(d->currStatus); | - | ||||||
| 70 | repaint(); | - | ||||||
| 71 | } never executed: end of block | 0 | ||||||
| 72 | QString QSplashScreen::message() const | - | ||||||
| 73 | { | - | ||||||
| 74 | const QSplashScreenPrivate * const d = d_func(); | - | ||||||
| 75 | return never executed: d->currStatus;return d->currStatus;never executed: return d->currStatus; | 0 | ||||||
| 76 | } | - | ||||||
| 77 | - | |||||||
| 78 | - | |||||||
| 79 | - | |||||||
| 80 | - | |||||||
| 81 | - | |||||||
| 82 | - | |||||||
| 83 | void QSplashScreen::clearMessage() | - | ||||||
| 84 | { | - | ||||||
| 85 | d_func()->currStatus.clear(); | - | ||||||
| 86 | messageChanged(d_func()->currStatus); | - | ||||||
| 87 | repaint(); | - | ||||||
| 88 | } never executed: end of block | 0 | ||||||
| 89 | - | |||||||
| 90 | - | |||||||
| 91 | inline static bool waitForWindowExposed(QWindow *window, int timeout = 1000) | - | ||||||
| 92 | { | - | ||||||
| 93 | enum { TimeOutMs = 10 }; | - | ||||||
| 94 | QElapsedTimer timer; | - | ||||||
| 95 | timer.start(); | - | ||||||
| 96 | while (!window->isExposed()
| 0 | ||||||
| 97 | const int remaining = timeout - int(timer.elapsed()); | - | ||||||
| 98 | if (remaining <= 0
| 0 | ||||||
| 99 | break; never executed: break; | 0 | ||||||
| 100 | QCoreApplication::processEvents(QEventLoop::AllEvents, remaining); | - | ||||||
| 101 | QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); | - | ||||||
| 102 | - | |||||||
| 103 | - | |||||||
| 104 | - | |||||||
| 105 | - | |||||||
| 106 | - | |||||||
| 107 | struct timespec ts = { TimeOutMs / 1000, (TimeOutMs % 1000) * 1000 * 1000 }; | - | ||||||
| 108 | nanosleep(&ts, __null); | - | ||||||
| 109 | - | |||||||
| 110 | } never executed: end of block | 0 | ||||||
| 111 | return never executed: window->isExposed();return window->isExposed();never executed: return window->isExposed(); | 0 | ||||||
| 112 | } | - | ||||||
| 113 | - | |||||||
| 114 | - | |||||||
| 115 | - | |||||||
| 116 | - | |||||||
| 117 | - | |||||||
| 118 | - | |||||||
| 119 | void QSplashScreen::finish(QWidget *mainWin) | - | ||||||
| 120 | { | - | ||||||
| 121 | if (mainWin
| 0 | ||||||
| 122 | if (!mainWin->windowHandle()
| 0 | ||||||
| 123 | mainWin->createWinId(); never executed: mainWin->createWinId(); | 0 | ||||||
| 124 | waitForWindowExposed(mainWin->windowHandle()); | - | ||||||
| 125 | } never executed: end of block | 0 | ||||||
| 126 | close(); | - | ||||||
| 127 | } never executed: end of block | 0 | ||||||
| 128 | - | |||||||
| 129 | - | |||||||
| 130 | - | |||||||
| 131 | - | |||||||
| 132 | - | |||||||
| 133 | void QSplashScreen::setPixmap(const QPixmap &pixmap) | - | ||||||
| 134 | { | - | ||||||
| 135 | QSplashScreenPrivate * const d = d_func(); | - | ||||||
| 136 | - | |||||||
| 137 | d->pixmap = pixmap; | - | ||||||
| 138 | setAttribute(Qt::WA_TranslucentBackground, pixmap.hasAlpha()); | - | ||||||
| 139 | - | |||||||
| 140 | QRect r(QPoint(), d->pixmap.size() / d->pixmap.devicePixelRatio()); | - | ||||||
| 141 | resize(r.size()); | - | ||||||
| 142 | move(QApplication::desktop()->screenGeometry().center() - r.center()); | - | ||||||
| 143 | if (isVisible()
| 0 | ||||||
| 144 | repaint(); never executed: repaint(); | 0 | ||||||
| 145 | } never executed: end of block | 0 | ||||||
| 146 | - | |||||||
| 147 | - | |||||||
| 148 | - | |||||||
| 149 | - | |||||||
| 150 | - | |||||||
| 151 | const QPixmap QSplashScreen::pixmap() const | - | ||||||
| 152 | { | - | ||||||
| 153 | return never executed: d_func()->pixmap;return d_func()->pixmap;never executed: return d_func()->pixmap; | 0 | ||||||
| 154 | } | - | ||||||
| 155 | - | |||||||
| 156 | - | |||||||
| 157 | - | |||||||
| 158 | - | |||||||
| 159 | inline QSplashScreenPrivate::QSplashScreenPrivate() : currAlign(Qt::AlignLeft) | - | ||||||
| 160 | { | - | ||||||
| 161 | } never executed: end of block | 0 | ||||||
| 162 | - | |||||||
| 163 | - | |||||||
| 164 | - | |||||||
| 165 | - | |||||||
| 166 | - | |||||||
| 167 | - | |||||||
| 168 | - | |||||||
| 169 | void QSplashScreen::drawContents(QPainter *painter) | - | ||||||
| 170 | { | - | ||||||
| 171 | QSplashScreenPrivate * const d = d_func(); | - | ||||||
| 172 | painter->setPen(d->currColor); | - | ||||||
| 173 | QRect r = rect().adjusted(5, 5, -5, -5); | - | ||||||
| 174 | if (Qt::mightBeRichText(d->currStatus)
| 0 | ||||||
| 175 | QTextDocument doc; | - | ||||||
| 176 | - | |||||||
| 177 | - | |||||||
| 178 | - | |||||||
| 179 | doc.setHtml(d->currStatus); | - | ||||||
| 180 | - | |||||||
| 181 | doc.setTextWidth(r.width()); | - | ||||||
| 182 | QTextCursor cursor(&doc); | - | ||||||
| 183 | cursor.select(QTextCursor::Document); | - | ||||||
| 184 | QTextBlockFormat fmt; | - | ||||||
| 185 | fmt.setAlignment(Qt::Alignment(d->currAlign)); | - | ||||||
| 186 | cursor.mergeBlockFormat(fmt); | - | ||||||
| 187 | painter->save(); | - | ||||||
| 188 | painter->translate(r.topLeft()); | - | ||||||
| 189 | doc.drawContents(painter); | - | ||||||
| 190 | painter->restore(); | - | ||||||
| 191 | } never executed: else {end of block | 0 | ||||||
| 192 | painter->drawText(r, d->currAlign, d->currStatus); | - | ||||||
| 193 | } never executed: end of block | 0 | ||||||
| 194 | } | - | ||||||
| 195 | - | |||||||
| 196 | - | |||||||
| 197 | bool QSplashScreen::event(QEvent *e) | - | ||||||
| 198 | { | - | ||||||
| 199 | if (e->type() == QEvent::Paint
| 0 | ||||||
| 200 | QSplashScreenPrivate * const d = d_func(); | - | ||||||
| 201 | QPainter painter(this); | - | ||||||
| 202 | if (!d->pixmap.isNull()
| 0 | ||||||
| 203 | painter.drawPixmap(QPoint(), d->pixmap); never executed: painter.drawPixmap(QPoint(), d->pixmap); | 0 | ||||||
| 204 | drawContents(&painter); | - | ||||||
| 205 | } never executed: end of block | 0 | ||||||
| 206 | return never executed: QWidget::event(e);return QWidget::event(e);never executed: return QWidget::event(e); | 0 | ||||||
| 207 | } | - | ||||||
| 208 | - | |||||||
| 209 | - | |||||||
| 210 | - | |||||||
| Switch to Source code | Preprocessed file |