|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the demonstration applications of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "colors.h" |
|
43 |
|
44 #ifndef QT_NO_OPENGL |
|
45 #include <QGLWidget> |
|
46 #endif |
|
47 //#define QT_NO_OPENGL |
|
48 |
|
49 // Colors: |
|
50 QColor Colors::sceneBg1(QColor(91, 91, 91)); |
|
51 QColor Colors::sceneBg1Line(QColor(114, 108, 104)); |
|
52 QColor Colors::sceneBg2(QColor(0, 0, 0)); |
|
53 QColor Colors::sceneLine(255, 255, 255); |
|
54 QColor Colors::paperBg(QColor(100, 100, 100)); |
|
55 QColor Colors::menuTextFg(QColor(255, 0, 0)); |
|
56 QColor Colors::buttonBgLow(QColor(255, 255, 255, 90)); |
|
57 QColor Colors::buttonBgHigh(QColor(255, 255, 255, 20)); |
|
58 QColor Colors::buttonText(QColor(255, 255, 255)); |
|
59 QColor Colors::tt_green(QColor(166, 206, 57)); |
|
60 QColor Colors::fadeOut(QColor(206, 246, 117, 0)); |
|
61 QColor Colors::heading(QColor(190,230,80)); |
|
62 QString Colors::contentColor("<font color='#eeeeee'>"); |
|
63 QString Colors::glVersion("Not detected!"); |
|
64 |
|
65 // Guides: |
|
66 int Colors::stageStartY = 8; |
|
67 int Colors::stageHeight = 536; |
|
68 int Colors::stageStartX = 8; |
|
69 int Colors::stageWidth = 785; |
|
70 int Colors::contentStartY = 22; |
|
71 int Colors::contentHeight = 510; |
|
72 |
|
73 // Properties: |
|
74 bool Colors::openGlRendering = false; |
|
75 bool Colors::softwareRendering = false; |
|
76 bool Colors::openGlAvailable = true; |
|
77 bool Colors::xRenderPresent = true; |
|
78 |
|
79 bool Colors::noTicker = false; |
|
80 bool Colors::noRescale = false; |
|
81 bool Colors::noAnimations = false; |
|
82 bool Colors::noBlending = false; |
|
83 bool Colors::noScreenSync = false; |
|
84 bool Colors::fullscreen = false; |
|
85 bool Colors::usePixmaps = false; |
|
86 bool Colors::useLoop = false; |
|
87 bool Colors::showBoundingRect = false; |
|
88 bool Colors::showFps = false; |
|
89 bool Colors::noAdapt = false; |
|
90 bool Colors::noWindowMask = true; |
|
91 bool Colors::useButtonBalls = false; |
|
92 bool Colors::useEightBitPalette = false; |
|
93 bool Colors::noTimerUpdate = false; |
|
94 bool Colors::noTickerMorph = false; |
|
95 bool Colors::adapted = false; |
|
96 bool Colors::verbose = false; |
|
97 bool Colors::pause = true; |
|
98 int Colors::fps = 60; |
|
99 int Colors::menuCount = 18; |
|
100 float Colors::animSpeed = 1.0; |
|
101 float Colors::animSpeedButtons = 1.0; |
|
102 float Colors::benchmarkFps = -1; |
|
103 int Colors::tickerLetterCount = 80; |
|
104 float Colors::tickerMoveSpeed = 0.4f; |
|
105 float Colors::tickerMorphSpeed = 2.5f; |
|
106 QString Colors::tickerText = ".EROM ETAERC .SSEL EDOC"; |
|
107 QString Colors::rootMenuName = "Qt Examples and Demos"; |
|
108 |
|
109 QFont Colors::contentFont() |
|
110 { |
|
111 QFont font; |
|
112 font.setStyleStrategy(QFont::PreferAntialias); |
|
113 #if defined(Q_OS_MAC) |
|
114 font.setPixelSize(14); |
|
115 font.setFamily("Arial"); |
|
116 #else |
|
117 font.setPixelSize(13); |
|
118 font.setFamily("Verdana"); |
|
119 #endif |
|
120 return font; |
|
121 } |
|
122 |
|
123 QFont Colors::headingFont() |
|
124 { |
|
125 QFont font; |
|
126 font.setStyleStrategy(QFont::PreferAntialias); |
|
127 font.setPixelSize(23); |
|
128 font.setBold(true); |
|
129 font.setFamily("Verdana"); |
|
130 return font; |
|
131 } |
|
132 |
|
133 QFont Colors::buttonFont() |
|
134 { |
|
135 QFont font; |
|
136 font.setStyleStrategy(QFont::PreferAntialias); |
|
137 #if 0//defined(Q_OS_MAC) |
|
138 font.setPixelSize(11); |
|
139 font.setFamily("Silom"); |
|
140 #else |
|
141 font.setPixelSize(11); |
|
142 font.setFamily("Verdana"); |
|
143 #endif |
|
144 return font; |
|
145 } |
|
146 |
|
147 QFont Colors::tickerFont() |
|
148 { |
|
149 QFont font; |
|
150 font.setStyleStrategy(QFont::PreferAntialias); |
|
151 #if defined(Q_OS_MAC) |
|
152 font.setPixelSize(11); |
|
153 font.setBold(true); |
|
154 font.setFamily("Arial"); |
|
155 #else |
|
156 font.setPixelSize(10); |
|
157 font.setBold(true); |
|
158 font.setFamily("sans serif"); |
|
159 #endif |
|
160 return font; |
|
161 } |
|
162 |
|
163 float parseFloat(const QString &argument, const QString &name) |
|
164 { |
|
165 if (name.length() == argument.length()){ |
|
166 QMessageBox::warning(0, "Arguments", |
|
167 QString("No argument number found for ") |
|
168 + name |
|
169 + ". Remember to put name and value adjacent! (e.g. -fps100)"); |
|
170 exit(0); |
|
171 } |
|
172 float value = argument.mid(name.length()).toFloat(); |
|
173 return value; |
|
174 } |
|
175 |
|
176 QString parseText(const QString &argument, const QString &name) |
|
177 { |
|
178 if (name.length() == argument.length()){ |
|
179 QMessageBox::warning(0, "Arguments", |
|
180 QString("No argument number found for ") |
|
181 + name |
|
182 + ". Remember to put name and value adjacent! (e.g. -fps100)"); |
|
183 exit(0); |
|
184 } |
|
185 QString value = argument.mid(name.length()); |
|
186 return value; |
|
187 } |
|
188 |
|
189 void Colors::parseArgs(int argc, char *argv[]) |
|
190 { |
|
191 // some arguments should be processed before |
|
192 // others. Handle them now: |
|
193 for (int i=1; i<argc; i++){ |
|
194 QString s(argv[i]); |
|
195 if (s == "-verbose") |
|
196 Colors::verbose = true; |
|
197 } |
|
198 |
|
199 Colors::detectSystemResources(); |
|
200 |
|
201 // Handle the rest of the arguments. They may |
|
202 // override attributes already set: |
|
203 for (int i=1; i<argc; i++){ |
|
204 QString s(argv[i]); |
|
205 if (s == "-opengl") |
|
206 Colors::openGlRendering = true; |
|
207 else if (s == "-software") |
|
208 Colors::softwareRendering = true; |
|
209 else if (s == "-no-opengl") // support old style |
|
210 Colors::softwareRendering = true; |
|
211 else if (s == "-no-ticker") // support old style |
|
212 Colors::noTicker = true; |
|
213 else if (s.startsWith("-ticker")) |
|
214 Colors::noTicker = !bool(parseFloat(s, "-ticker")); |
|
215 else if (s == "-no-animations") |
|
216 Colors::noAnimations = true; // support old style |
|
217 else if (s.startsWith("-animations")) |
|
218 Colors::noAnimations = !bool(parseFloat(s, "-animations")); |
|
219 else if (s == "-no-adapt") |
|
220 Colors::noAdapt = true; |
|
221 else if (s == "-low") |
|
222 Colors::setLowSettings(); |
|
223 else if (s == "-no-rescale") |
|
224 Colors::noRescale = true; |
|
225 else if (s == "-use-pixmaps") |
|
226 Colors::usePixmaps = true; |
|
227 else if (s == "-fullscreen") |
|
228 Colors::fullscreen = true; |
|
229 else if (s == "-show-br") |
|
230 Colors::showBoundingRect = true; |
|
231 else if (s == "-show-fps") |
|
232 Colors::showFps = true; |
|
233 else if (s == "-no-blending") |
|
234 Colors::noBlending = true; |
|
235 else if (s == "-no-sync") |
|
236 Colors::noScreenSync = true; |
|
237 else if (s.startsWith("-menu")) |
|
238 Colors::menuCount = int(parseFloat(s, "-menu")); |
|
239 else if (s.startsWith("-use-timer-update")) |
|
240 Colors::noTimerUpdate = !bool(parseFloat(s, "-use-timer-update")); |
|
241 else if (s.startsWith("-pause")) |
|
242 Colors::pause = bool(parseFloat(s, "-pause")); |
|
243 else if (s == "-no-ticker-morph") |
|
244 Colors::noTickerMorph = true; |
|
245 else if (s == "-use-window-mask") |
|
246 Colors::noWindowMask = false; |
|
247 else if (s == "-use-loop") |
|
248 Colors::useLoop = true; |
|
249 else if (s == "-use-8bit") |
|
250 Colors::useEightBitPalette = true; |
|
251 else if (s.startsWith("-8bit")) |
|
252 Colors::useEightBitPalette = bool(parseFloat(s, "-8bit")); |
|
253 else if (s == "-use-balls") |
|
254 Colors::useButtonBalls = true; |
|
255 else if (s.startsWith("-ticker-letters")) |
|
256 Colors::tickerLetterCount = int(parseFloat(s, "-ticker-letters")); |
|
257 else if (s.startsWith("-ticker-text")) |
|
258 Colors::tickerText = parseText(s, "-ticker-text"); |
|
259 else if (s.startsWith("-ticker-speed")) |
|
260 Colors::tickerMoveSpeed = parseFloat(s, "-ticker-speed"); |
|
261 else if (s.startsWith("-ticker-morph-speed")) |
|
262 Colors::tickerMorphSpeed = parseFloat(s, "-ticker-morph-speed"); |
|
263 else if (s.startsWith("-animation-speed")) |
|
264 Colors::animSpeed = parseFloat(s, "-animation-speed"); |
|
265 else if (s.startsWith("-fps")) |
|
266 Colors::fps = int(parseFloat(s, "-fps")); |
|
267 else if (s.startsWith("-h") || s.startsWith("-help")){ |
|
268 QMessageBox::warning(0, "Arguments", |
|
269 QString("Usage: qtdemo [-verbose] [-no-adapt] [-opengl] [-software] [-fullscreen] [-ticker[0|1]] ") |
|
270 + "[-animations[0|1]] [-no-blending] [-no-sync] [-use-timer-update[0|1]] [-pause[0|1]] " |
|
271 + "[-use-window-mask] [-no-rescale] " |
|
272 + "[-use-pixmaps] [-show-fps] [-show-br] [-8bit[0|1]] [-menu<int>] [-use-loop] [-use-balls] " |
|
273 + "[-animation-speed<float>] [-fps<int>] " |
|
274 + "[-low] [-ticker-letters<int>] [-ticker-speed<float>] [-no-ticker-morph] " |
|
275 + "[-ticker-morph-speed<float>] [-ticker-text<string>]"); |
|
276 exit(0); |
|
277 } else if (s == "-verbose") { |
|
278 // this option was already handled above |
|
279 } else{ |
|
280 QMessageBox::warning(0, "QtDemo", QString("Unrecognized argument:\n") + s); |
|
281 exit(0); |
|
282 } |
|
283 } |
|
284 |
|
285 Colors::postConfigure(); |
|
286 } |
|
287 |
|
288 void Colors::setLowSettings() |
|
289 { |
|
290 Colors::openGlRendering = false; |
|
291 Colors::softwareRendering = true; |
|
292 Colors::noTicker = true; |
|
293 Colors::noTimerUpdate = true; |
|
294 Colors::fps = 30; |
|
295 Colors::usePixmaps = true; |
|
296 Colors::noAnimations = true; |
|
297 Colors::noBlending = true; |
|
298 } |
|
299 |
|
300 void Colors::detectSystemResources() |
|
301 { |
|
302 #ifndef QT_NO_OPENGL |
|
303 if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) |
|
304 Colors::glVersion = "2.0 or higher"; |
|
305 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) |
|
306 Colors::glVersion = "1.5"; |
|
307 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_4) |
|
308 Colors::glVersion = "1.4"; |
|
309 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_3) |
|
310 Colors::glVersion = "1.3 or lower"; |
|
311 if (Colors::verbose) |
|
312 qDebug() << "- OpenGL version:" << Colors::glVersion; |
|
313 |
|
314 QGLWidget glw; |
|
315 if (!QGLFormat::hasOpenGL() |
|
316 || !glw.format().directRendering() |
|
317 || !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5) |
|
318 || glw.depth() < 24 |
|
319 ) |
|
320 #else |
|
321 if (Colors::verbose) |
|
322 qDebug() << "- OpenGL not supported by current build of Qt"; |
|
323 #endif |
|
324 { |
|
325 Colors::openGlAvailable = false; |
|
326 if (Colors::verbose) |
|
327 qDebug("- OpenGL not recommended on this system"); |
|
328 } |
|
329 |
|
330 #if defined(Q_WS_X11) |
|
331 // check if X render is present: |
|
332 QPixmap tmp(1, 1); |
|
333 if (!tmp.x11PictureHandle() && tmp.paintEngine()->type() == QPaintEngine::X11){ |
|
334 Colors::xRenderPresent = false; |
|
335 if (Colors::verbose) |
|
336 qDebug("- X render not present"); |
|
337 } |
|
338 |
|
339 #endif |
|
340 |
|
341 QWidget w; |
|
342 if (Colors::verbose) |
|
343 qDebug() << "- Color depth: " << QString::number(w.depth()); |
|
344 } |
|
345 |
|
346 void Colors::postConfigure() |
|
347 { |
|
348 if (!Colors::noAdapt){ |
|
349 QWidget w; |
|
350 if (w.depth() < 16){ |
|
351 Colors::useEightBitPalette = true; |
|
352 Colors::adapted = true; |
|
353 if (Colors::verbose) |
|
354 qDebug() << "- Adapt: Color depth less than 16 bit. Using 8 bit palette"; |
|
355 } |
|
356 |
|
357 if (!Colors::xRenderPresent){ |
|
358 Colors::setLowSettings(); |
|
359 Colors::adapted = true; |
|
360 if (Colors::verbose) |
|
361 qDebug() << "- Adapt: X renderer not present. Using low settings"; |
|
362 } |
|
363 } |
|
364 |
|
365 if (!Colors::openGlRendering && !Colors::softwareRendering){ |
|
366 // The user has not decided rendering system. So we do it instead: |
|
367 if (Colors::openGlAvailable) |
|
368 Colors::openGlRendering = true; |
|
369 else |
|
370 Colors::softwareRendering = true; |
|
371 } |
|
372 } |
|
373 |
|
374 |