src/activeqt: Remove QT_WA and non-Unicode code paths, dropping Win9x and NT support
[qt-netbsd.git] / demos / qtdemo / colors.cpp
blobc8e67e41e3e613ead2b41c688a4296117f6aa46f
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: Nokia Corporation (qt-info@nokia.com)
5 **
6 ** This file is part of the demonstration applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** No Commercial Usage
10 ** This file contains pre-release code and may not be distributed.
11 ** You may use this file in accordance with the terms and conditions
12 ** contained in the either Technology Preview License Agreement or the
13 ** Beta Release License Agreement.
15 ** GNU Lesser General Public License Usage
16 ** Alternatively, this file may be used under the terms of the GNU Lesser
17 ** General Public License version 2.1 as published by the Free Software
18 ** Foundation and appearing in the file LICENSE.LGPL included in the
19 ** packaging of this file. Please review the following information to
20 ** ensure the GNU Lesser General Public License version 2.1 requirements
21 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 ** In addition, as a special exception, Nokia gives you certain
24 ** additional rights. These rights are described in the Nokia Qt LGPL
25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26 ** package.
28 ** GNU General Public License Usage
29 ** Alternatively, this file may be used under the terms of the GNU
30 ** General Public License version 3.0 as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL included in the
32 ** packaging of this file. Please review the following information to
33 ** ensure the GNU General Public License version 3.0 requirements will be
34 ** met: http://www.gnu.org/copyleft/gpl.html.
36 ** If you are unsure which license is appropriate for your use, please
37 ** contact the sales department at http://www.qtsoftware.com/contact.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "colors.h"
44 #ifndef QT_NO_OPENGL
45 #include <QGLWidget>
46 #endif
47 //#define QT_NO_OPENGL
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!");
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;
73 // Properties:
74 bool Colors::openGlRendering = false;
75 bool Colors::softwareRendering = false;
76 bool Colors::openGlAvailable = true;
77 bool Colors::xRenderPresent = true;
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";
109 QFont Colors::contentFont()
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;
123 QFont Colors::headingFont()
125 QFont font;
126 font.setStyleStrategy(QFont::PreferAntialias);
127 font.setPixelSize(23);
128 font.setBold(true);
129 font.setFamily("Verdana");
130 return font;
133 QFont Colors::buttonFont()
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;
147 QFont Colors::tickerFont()
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;
163 float parseFloat(const QString &argument, const QString &name)
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);
172 float value = argument.mid(name.length()).toFloat();
173 return value;
176 QString parseText(const QString &argument, const QString &name)
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);
185 QString value = argument.mid(name.length());
186 return value;
189 void Colors::parseArgs(int argc, char *argv[])
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;
199 Colors::detectSystemResources();
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{
278 QMessageBox::warning(0, "QtDemo", QString("Unrecognized argument:\n") + s);
279 exit(0);
283 Colors::postConfigure();
286 void Colors::setLowSettings()
288 Colors::openGlRendering = false;
289 Colors::softwareRendering = true;
290 Colors::noTicker = true;
291 Colors::noTimerUpdate = true;
292 Colors::fps = 30;
293 Colors::usePixmaps = true;
294 Colors::noAnimations = true;
295 Colors::noBlending = true;
298 void Colors::detectSystemResources()
300 #ifndef QT_NO_OPENGL
301 if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0)
302 Colors::glVersion = "2.0 or higher";
303 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5)
304 Colors::glVersion = "1.5";
305 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_4)
306 Colors::glVersion = "1.4";
307 else if (QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_3)
308 Colors::glVersion = "1.3 or lower";
309 if (Colors::verbose)
310 qDebug() << "- OpenGL version:" << Colors::glVersion;
312 QGLWidget glw;
313 if (!QGLFormat::hasOpenGL()
314 || !glw.format().directRendering()
315 || !(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_5)
316 || glw.depth() < 24
318 #else
319 if (Colors::verbose)
320 qDebug() << "- OpenGL not supported by current build of Qt";
321 #endif
323 Colors::openGlAvailable = false;
324 if (Colors::verbose)
325 qDebug("- OpenGL not recommended on this system");
328 #if defined(Q_WS_X11)
329 // check if X render is present:
330 QPixmap tmp(1, 1);
331 if (!tmp.x11PictureHandle() && tmp.paintEngine()->type() == QPaintEngine::X11){
332 Colors::xRenderPresent = false;
333 if (Colors::verbose)
334 qDebug("- X render not present");
337 #endif
339 QWidget w;
340 if (Colors::verbose)
341 qDebug() << "- Color depth: " << QString::number(w.depth());
344 void Colors::postConfigure()
346 if (!Colors::noAdapt){
347 QWidget w;
348 if (w.depth() < 16){
349 Colors::useEightBitPalette = true;
350 Colors::adapted = true;
351 if (Colors::verbose)
352 qDebug() << "- Adapt: Color depth less than 16 bit. Using 8 bit palette";
355 if (!Colors::xRenderPresent){
356 Colors::setLowSettings();
357 Colors::adapted = true;
358 if (Colors::verbose)
359 qDebug() << "- Adapt: X renderer not present. Using low settings";
363 if (!Colors::openGlRendering && !Colors::softwareRendering){
364 // The user has not decided rendering system. So we do it instead:
365 if (Colors::openGlAvailable)
366 Colors::openGlRendering = true;
367 else
368 Colors::softwareRendering = true;