1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the widgets module of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include "qsplashscreen.h"
31
#ifndef QT_NO_SPLASHSCREEN
33
#include "qapplication.h"
34
#include "qdesktopwidget.h"
37
#include <private/qwidget_p.h>
39
class QSplashScreenPrivate : public QWidgetPrivate
41
Q_DECLARE_PUBLIC(QSplashScreen)
51
\class QSplashScreen qsplashscreen.h
52
\brief The QSplashScreen widget provides a splash screen that can
53
be shown during application startup.
58
A splash screen is a widget that is usually displayed when an
59
application is being started. Splash screens are often used for
60
applications that have long start up times (e.g. database or
61
networking applications that take time to establish connections) to
62
provide the user with feedback that the application is loading.
64
The splash screen appears centered on the screen. It may be useful to add
65
the \c Qt::WStyle_StaysOnTop if you desire to keep above all the windows in the
68
Some X11 window managers do not support the "stays on top" flag. A
69
solution is to set up a timer that periodically calls raise() on
70
the splash screen to simulate the "stays on top" effect.
72
The most common usage is to show a splash screen before the main
73
widget is displayed on the screen. This is illustrated in the
74
following code snippet.
77
int main(int argc, char **argv)
79
QApplication app(argc, argv);
80
QPixmap pixmap("splash.png");
81
QSplashScreen *splash = new QSplashScreen(pixmap);
83
QMainWindow *mainWin = new QMainWindow;
85
app.setMainWidget(mainWin);
87
splash->finish(mainWin);
93
It is sometimes useful to update the splash screen with messages,
94
for example, announcing connections established or modules loaded
95
as the application starts up. QSplashScreen supports this with the
96
showMessage() function. If you wish to do your own drawing you can
97
get a pointer to the pixmap used in the splash screen with pixmap().
98
Alternatively, you can subclass QSplashScreen and reimplement
101
The user can hide the splash screen by clicking on it with the
102
mouse. Since the splash screen is typically displayed before the
103
event loop has started running, it is necessary to periodically
104
call QApplication::processEvents() to receive the mouse clicks.
107
QSplashScreen *splash = new QSplashScreen("splash.png");
109
... // Loading some items
110
splash->showMessage("Loaded modules");
111
qApp->processEvents();
112
... // Establishing connections
113
splash->showMessage("Established connections");
114
qApp->processEvents();
120
Construct a splash screen that will display the \a pixmap.
122
There should be no need to set the widget flags, \a f, except
123
perhaps \c Qt::WStyle_StaysOnTop.
125
QSplashScreen::QSplashScreen(const QPixmap &pixmap, Qt::WFlags f)
126
: QWidget(*(new QSplashScreenPrivate()), 0, Qt::SplashScreen | f)
128
d_func()->pixmap = pixmap;
129
setPixmap(d_func()->pixmap); // Does an implicit repaint
135
This function allows you to specify a parent for your splashscreen. The
136
typical use for this constructor is if you have a multiple screens and
137
prefer to have the splash screen on a different screen than your primary
138
one. In that case pass the proper desktop() as the \a parent.
140
QSplashScreen::QSplashScreen(QWidget *parent, const QPixmap &pixmap, Qt::WFlags f)
141
: QWidget(*new QSplashScreenPrivate, parent, Qt::SplashScreen | f)
143
d_func()->pixmap = pixmap;
144
setPixmap(d_func()->pixmap); // Does an implicit repaint
150
QSplashScreen::~QSplashScreen()
157
void QSplashScreen::mousePressEvent(QMouseEvent *)
163
This overrides QWidget::repaint(). It differs from the standard
164
repaint function in that it also calls QApplication::flush() to
165
ensure the updates are displayed, even when there is no event loop
168
void QSplashScreen::repaint()
170
d_func()->drawContents();
172
QApplication::flush();
176
\fn QSplashScreen::messageChanged(const QString &message)
178
This signal is emitted when the message on the splash screen
179
changes. \a message is the new message and is a null-string
180
when the message has been removed.
182
\sa showMessage(), clearMessage()
188
Draws the \a message text onto the splash screen with color \a
189
color and aligns the text according to the flags in \a alignment.
191
\sa Qt::Alignment, clearMessage()
193
void QSplashScreen::showMessage(const QString &message, int alignment,
197
d->currStatus = message;
198
d->currAlign = alignment;
199
d->currColor = color;
200
emit messageChanged(d->currStatus);
205
Removes the message being displayed on the splash screen
209
void QSplashScreen::clearMessage()
211
d_func()->currStatus.clear();
212
emit messageChanged(d_func()->currStatus);
217
Makes the splash screen wait until the widget \a mainWin is displayed
218
before calling close() on itself.
220
void QSplashScreen::finish(QWidget *mainWin)
223
#if defined(Q_WS_X11)
224
extern void qt_x11_wait_for_window_manager(QWidget *mainWin);
225
qt_x11_wait_for_window_manager(mainWin);
232
Sets the pixmap that will be used as the splash screen's image to
235
void QSplashScreen::setPixmap(const QPixmap &pixmap)
239
QRect r(0, 0, d->pixmap.size().width(), d->pixmap.size().height());
240
resize(d->pixmap.size());
241
move(QApplication::desktop()->screenGeometry().center() - r.center());
249
Returns the pixmap that is used in the splash screen. The image
250
does not have any of the text drawn by showMessage() calls.
252
const QPixmap QSplashScreen::pixmap() const
254
return d_func()->pixmap;
260
void QSplashScreenPrivate::drawContents()
263
QPixmap textPix = pixmap;
264
QPainter painter(&textPix);
265
q->drawContents(&painter);
266
QPalette p = q->palette();
267
p.setBrush(q->backgroundRole(), QBrush(textPix));
272
Draw the contents of the splash screen using painter \a painter.
273
The default implementation draws the message passed by showMessage().
274
Reimplement this function if you want to do your own drawing on
277
void QSplashScreen::drawContents(QPainter *painter)
279
painter->setPen(d_func()->currColor);
281
r.setRect(r.x() + 5, r.y() + 5, r.width() - 10, r.height() - 10);
282
painter->drawText(r, d_func()->currAlign, d_func()->currStatus);
286
\fn void QSplashScreen::message(const QString &message, int alignment,
290
Use showMessage() instead.
294
\fn void QSplashScreen::clear()
297
Use clearMessage() instead.
300
#endif //QT_NO_SPLASHSCREEN