/
splashscreenwindow.cpp
176 lines (130 loc) · 5.08 KB
/
splashscreenwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://gnu.org/licenses>.
*******************************************************************************/
//==============================================================================
// Splash screen window
//==============================================================================
#include "cliutils.h"
#include "guiutils.h"
#include "splashscreenwindow.h"
//==============================================================================
#include "ui_splashscreenwindow.h"
//==============================================================================
#include <QCloseEvent>
#include <QElapsedTimer>
#include <QScreen>
#include <QTimer>
#include <QWindow>
//==============================================================================
#ifdef Q_OS_WIN
#include <qt_windows.h>
#else
#include <ctime>
#endif
//==============================================================================
namespace OpenCOR {
//==============================================================================
SplashScreenWindow::SplashScreenWindow() :
QWidget(nullptr, Qt::SplashScreen|Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint),
mGui(new Ui::SplashScreenWindow)
{
// Set up the GUI
mGui->setupUi(this);
QColor borderRgb = borderColor();
QString borderStyle = QString("1px solid rgb(%1, %2, %3)").arg(borderRgb.red())
.arg(borderRgb.green())
.arg(borderRgb.blue());
setStyleSheet(QString("QLabel#splashScreenImage {"
" background-color: white;"
"}"
#ifdef Q_OS_MAC
"QWidget#infoWidget {"
" border-top: %1;"
"}"
#else
"QLabel#splashScreenImage {"
" border-top: %1;"
" border-left: %1;"
" border-right: %1;"
"}"
""
"QWidget#infoWidget {"
" border: %1;"
"}"
#endif
).arg(borderStyle)
);
QFont newFont = mGui->infoWidget->font();
#if defined(Q_OS_WIN)
newFont.setPointSize(9);
#elif defined(Q_OS_LINUX)
newFont.setPointSize(8);
#else
newFont.setPointSize(11);
#endif
mGui->copyrightValue->setFont(newFont);
mGui->versionValue->setFont(newFont);
mGui->copyrightValue->setText(copyright());
mGui->versionValue->setText(shortVersion());
// Adjust the size of our splash screen and then move it to the center of
// our screen
adjustSize();
move(qApp->primaryScreen()->geometry().center()-rect().center());
}
//==============================================================================
SplashScreenWindow::~SplashScreenWindow()
{
// Delete the GUI
delete mGui;
}
//==============================================================================
void SplashScreenWindow::deleteLater(QWidget *pWindow)
{
// Wait for our window to expose itself
enum {
TimeOut = 1000,
ShortDelay = 10
};
QWindow *window = pWindow->windowHandle();
QElapsedTimer timer;
#ifndef Q_OS_WIN
struct timespec shortDelaySpec = { ShortDelay/1000, 1000000*(ShortDelay%1000) };
#endif
timer.start();
while (!window->isExposed()) {
int remaining = int(TimeOut-timer.elapsed());
if (remaining <= 0) {
break;
}
QCoreApplication::processEvents(QEventLoop::AllEvents, remaining);
QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete);
#ifdef Q_OS_WIN
Sleep(ShortDelay);
#else
nanosleep(&shortDelaySpec, nullptr);
#endif
}
// Have ourselves deleted, but with a bit of a delay
QTimer::singleShot(500, this, &QObject::deleteLater);
}
//==============================================================================
void SplashScreenWindow::closeEvent(QCloseEvent *pEvent)
{
// Prevent ourselves from being closed
pEvent->ignore();
}
//==============================================================================
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================