1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the demonstration applications of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
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.
|
---|
22 | **
|
---|
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.
|
---|
27 | **
|
---|
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.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "mainwindow.h"
|
---|
43 | #include "menumanager.h"
|
---|
44 | #include "colors.h"
|
---|
45 | #include "dockitem.h"
|
---|
46 | #include "demotextitem.h"
|
---|
47 | #include "imageitem.h"
|
---|
48 | #include "demoitem.h"
|
---|
49 | #include "demoscene.h"
|
---|
50 |
|
---|
51 | #ifndef QT_NO_OPENGL
|
---|
52 | #include <QGLWidget>
|
---|
53 | #endif
|
---|
54 | //#define QT_NO_OPENGL
|
---|
55 |
|
---|
56 | MainWindow::MainWindow(QWidget *parent) : QGraphicsView(parent), updateTimer(this)
|
---|
57 | {
|
---|
58 | this->currentFps = Colors::fps;
|
---|
59 | this->loop = false;
|
---|
60 | this->fpsMedian = -1;
|
---|
61 | this->fpsLabel = 0;
|
---|
62 | this->pausedLabel = 0;
|
---|
63 | this->doneAdapt = false;
|
---|
64 | this->useTimer = false;
|
---|
65 | this->updateTimer.setSingleShot(true);
|
---|
66 | this->trolltechLogo = 0;
|
---|
67 | this->qtLogo = 0;
|
---|
68 | this->setupWidget();
|
---|
69 | this->setupScene();
|
---|
70 | this->setupSceneItems();
|
---|
71 | this->drawBackgroundToPixmap();
|
---|
72 | }
|
---|
73 |
|
---|
74 | MainWindow::~MainWindow()
|
---|
75 | {
|
---|
76 | delete this->trolltechLogo;
|
---|
77 | delete this->qtLogo;
|
---|
78 | }
|
---|
79 |
|
---|
80 | void MainWindow::setupWidget()
|
---|
81 | {
|
---|
82 | QRect screenRect = QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen());
|
---|
83 | QRect windowRect(0, 0, 800, 600);
|
---|
84 | if (screenRect.width() < 800)
|
---|
85 | windowRect.setWidth(screenRect.width());
|
---|
86 | if (screenRect.height() < 600)
|
---|
87 | windowRect.setHeight(screenRect.height());
|
---|
88 | windowRect.moveCenter(screenRect.center());
|
---|
89 | this->setGeometry(windowRect);
|
---|
90 | this->setMinimumSize(80, 60);
|
---|
91 | setWindowTitle(tr("Qt Examples and Demos"));
|
---|
92 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
93 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
---|
94 | setFrameStyle(QFrame::NoFrame);
|
---|
95 | this->setRenderingSystem();
|
---|
96 | connect(&this->updateTimer, SIGNAL(timeout()), this, SLOT(tick()));
|
---|
97 | }
|
---|
98 |
|
---|
99 | void MainWindow::setRenderingSystem()
|
---|
100 | {
|
---|
101 | QWidget *viewport = 0;
|
---|
102 |
|
---|
103 | if (Colors::direct3dRendering){
|
---|
104 | viewport->setAttribute(Qt::WA_MSWindowsUseDirect3D);
|
---|
105 | setCacheMode(QGraphicsView::CacheNone);
|
---|
106 | if (Colors::verbose)
|
---|
107 | qDebug() << "- using Direct3D";
|
---|
108 | }
|
---|
109 | #ifndef QT_NO_OPENGL
|
---|
110 | else if (Colors::openGlRendering){
|
---|
111 | QGLWidget *glw = new QGLWidget(QGLFormat(QGL::SampleBuffers));
|
---|
112 | if (Colors::noScreenSync)
|
---|
113 | glw->format().setSwapInterval(0);
|
---|
114 | glw->setAutoFillBackground(false);
|
---|
|
---|