1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "data.h"
31
32#include <QApplication>
33#include <QWidget>
34#include <QHBoxLayout>
35#include <QVBoxLayout>
36#include <QPushButton>
37#include <QLabel>
38#include <QComboBox>
39#include <QSlider>
40#include <QTextEdit>
41#include <QScreen>
42#include <QPainter>
43
44int main(int argc, char **argv)
45{
46 QApplication app(argc, argv);
47
48 QWidget *widget = new QWidget();
49 QHBoxLayout *hLayout = new QHBoxLayout(widget);
50 QVBoxLayout *vLayout = new QVBoxLayout();
51
52 Q3DSurface *surface = new Q3DSurface();
53 Q3DScatter *scatter = new Q3DScatter();
54 Q3DBars *bars = new Q3DBars();
55
56 QSize screenSize = surface->screen()->size();
57
58 QWidget *containerSurface = QWidget::createWindowContainer(window: surface);
59 containerSurface->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2));
60 containerSurface->setMaximumSize(screenSize);
61 containerSurface->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
62 containerSurface->setFocusPolicy(Qt::StrongFocus);
63
64 QWidget *containerScatter = QWidget::createWindowContainer(window: scatter);
65 containerScatter->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2));
66 containerScatter->setMaximumSize(screenSize);
67 containerScatter->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
68 containerScatter->setFocusPolicy(Qt::StrongFocus);
69 containerScatter->setVisible(false);
70
71 QWidget *containerBars = QWidget::createWindowContainer(window: bars);
72 containerBars->setMinimumSize(QSize(screenSize.height() / 1.2, screenSize.height() / 1.2));
73 containerBars->setMaximumSize(screenSize);
74 containerBars->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
75 containerBars->setFocusPolicy(Qt::StrongFocus);
76 containerBars->setVisible(false);
77
78 widget->setWindowTitle(QStringLiteral("Test switching graphs on the fly"));
79
80 hLayout->addWidget(containerSurface, stretch: 1);
81 hLayout->addWidget(containerScatter, stretch: 1);
82 hLayout->addWidget(containerBars, stretch: 1);
83 hLayout->addLayout(layout: vLayout);
84
85 QPushButton *startButton = new QPushButton(widget);
86 startButton->setText(QStringLiteral("Start"));
87
88 QPushButton *stopButton = new QPushButton(widget);
89 stopButton->setText(QStringLiteral("Stop"));
90
91 QComboBox *resolutionBox = new QComboBox(widget);
92 resolutionBox->addItem(QStringLiteral("Low"));
93 resolutionBox->addItem(QStringLiteral("Medium"));
94 resolutionBox->addItem(QStringLiteral("High"));
95 resolutionBox->addItem(QStringLiteral("Max")); // Comment this out if demo machine is low-perf
96 resolutionBox->setCurrentIndex(0);
97
98 QComboBox *modeBox = new QComboBox(widget);
99 modeBox->addItem(QStringLiteral("Surface Plot"));
100 modeBox->addItem(QStringLiteral("Scatter Chart"));
101 modeBox->addItem(QStringLiteral("Bar Chart"));
102 modeBox->setCurrentIndex(0);
103
104 QLinearGradient gradientOne(0, 0, 200, 1);
105 gradientOne.setColorAt(pos: 0.0, color: Qt::black);
106 gradientOne.setColorAt(pos: 0.33, color: Qt::blue);
107 gradientOne.setColorAt(pos: 0.67, color: Qt::red);
108 gradientOne.setColorAt(pos: 1.0, color: Qt::yellow);
109
110 QPixmap pm(200, 24);
111 QPainter pmp(&pm);
112 pmp.setBrush(QBrush(gradientOne));
113 pmp.setPen(Qt::NoPen);
114 pmp.drawRect(x: 0, y: 0, w: 200, h: 24);
115
116 QPushButton *gradientOneButton = new QPushButton(widget);
117 gradientOneButton->setIcon(QIcon(pm));
118 gradientOneButton->setIconSize(QSize(200, 24));
119 gradientOneButton->setToolTip(QStringLiteral("Colors: Thermal Imitation"));
120
121 QLinearGradient gradientTwo(0, 0, 200, 1);
122 gradientTwo.setColorAt(pos: 0.0, color: Qt::white);
123 gradientTwo.setColorAt(pos: 0.8, color: Qt::red);
124 gradientTwo.setColorAt(pos: 1.0, color: Qt::green);
125
126 pmp.setBrush(QBrush(gradientTwo));
127 pmp.setPen(Qt::NoPen);
128 pmp.drawRect(x: 0, y: 0, w: 200, h: 24);
129
130 QPushButton *gradientTwoButton = new QPushButton(widget);
131 gradientTwoButton->setIcon(QIcon(pm));
132 gradientTwoButton->setIconSize(QSize(200, 24));
133 gradientTwoButton->setToolTip(QStringLiteral("Colors: Highlight Foreground"));
134
135 QTextEdit *status = new QTextEdit(QStringLiteral("<b>Ready</b><br>"), widget);
136 status->setReadOnly(true);
137
138 vLayout->addWidget(startButton);
139 vLayout->addWidget(stopButton);
140 vLayout->addWidget(new QLabel(QStringLiteral("Change resolution")));
141 vLayout->addWidget(resolutionBox);
142 vLayout->addWidget(new QLabel(QStringLiteral("Change visualization type")));
143 vLayout->addWidget(modeBox);
144 vLayout->addWidget(new QLabel(QStringLiteral("Change color scheme")));
145 vLayout->addWidget(gradientOneButton);
146 vLayout->addWidget(gradientTwoButton);
147 vLayout->addWidget(status, stretch: 1, alignment: Qt::AlignBottom);
148
149 widget->show();
150
151 Data datagen(surface, scatter, bars, status, widget);
152 ContainerChanger changer(containerSurface, containerScatter, containerBars,
153 gradientOneButton, gradientTwoButton);
154
155 QObject::connect(sender: startButton, signal: &QPushButton::clicked, receiver: &datagen, slot: &Data::start);
156 QObject::connect(sender: stopButton, signal: &QPushButton::clicked, receiver: &datagen, slot: &Data::stop);
157 QObject::connect(sender: resolutionBox, SIGNAL(activated(int)), receiver: &datagen, SLOT(setResolution(int)));
158 QObject::connect(sender: modeBox, SIGNAL(activated(int)), receiver: &changer, SLOT(changeContainer(int)));
159 QObject::connect(sender: modeBox, SIGNAL(activated(int)), receiver: &datagen, SLOT(changeMode(int)));
160 QObject::connect(sender: status, signal: &QTextEdit::textChanged, receiver: &datagen, slot: &Data::scrollDown);
161 QObject::connect(sender: gradientOneButton, signal: &QPushButton::clicked, receiver: &datagen,
162 slot: &Data::useGradientOne);
163 QObject::connect(sender: gradientTwoButton, signal: &QPushButton::clicked, receiver: &datagen,
164 slot: &Data::useGradientTwo);
165
166 return app.exec();
167}
168

source code of qtdatavis3d/tests/manual/multigraphs/main.cpp