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 "surfacegraph.h"
31
32#include <QtWidgets/QApplication>
33#include <QtWidgets/QWidget>
34#include <QtWidgets/QHBoxLayout>
35#include <QtWidgets/QVBoxLayout>
36#include <QtWidgets/QPushButton>
37#include <QtWidgets/QRadioButton>
38#include <QtWidgets/QSlider>
39#include <QtWidgets/QGroupBox>
40#include <QtWidgets/QComboBox>
41#include <QtWidgets/QLabel>
42#include <QtWidgets/QMessageBox>
43#include <QtGui/QPainter>
44#include <QtGui/QScreen>
45
46int main(int argc, char **argv)
47{
48 //! [0]
49 QApplication app(argc, argv);
50 Q3DSurface *graph = new Q3DSurface();
51 QWidget *container = QWidget::createWindowContainer(window: graph);
52 //! [0]
53
54 if (!graph->hasContext()) {
55 QMessageBox msgBox;
56 msgBox.setText("Couldn't initialize the OpenGL context.");
57 msgBox.exec();
58 return -1;
59 }
60
61 QSize screenSize = graph->screen()->size();
62 container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.6));
63 container->setMaximumSize(screenSize);
64 container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
65 container->setFocusPolicy(Qt::StrongFocus);
66
67 //! [1]
68 QWidget *widget = new QWidget;
69 QHBoxLayout *hLayout = new QHBoxLayout(widget);
70 QVBoxLayout *vLayout = new QVBoxLayout();
71 hLayout->addWidget(container, stretch: 1);
72 hLayout->addLayout(layout: vLayout);
73 vLayout->setAlignment(Qt::AlignTop);
74 //! [1]
75
76 widget->setWindowTitle(QStringLiteral("Surface example"));
77
78 QGroupBox *modelGroupBox = new QGroupBox(QStringLiteral("Model"));
79
80 QRadioButton *sqrtSinModelRB = new QRadioButton(widget);
81 sqrtSinModelRB->setText(QStringLiteral("Sqrt && Sin"));
82 sqrtSinModelRB->setChecked(false);
83
84 QRadioButton *heightMapModelRB = new QRadioButton(widget);
85 heightMapModelRB->setText(QStringLiteral("Height Map"));
86 heightMapModelRB->setChecked(false);
87
88 QVBoxLayout *modelVBox = new QVBoxLayout;
89 modelVBox->addWidget(sqrtSinModelRB);
90 modelVBox->addWidget(heightMapModelRB);
91 modelGroupBox->setLayout(modelVBox);
92
93 QGroupBox *selectionGroupBox = new QGroupBox(QStringLiteral("Selection Mode"));
94
95 QRadioButton *modeNoneRB = new QRadioButton(widget);
96 modeNoneRB->setText(QStringLiteral("No selection"));
97 modeNoneRB->setChecked(false);
98
99 QRadioButton *modeItemRB = new QRadioButton(widget);
100 modeItemRB->setText(QStringLiteral("Item"));
101 modeItemRB->setChecked(false);
102
103 QRadioButton *modeSliceRowRB = new QRadioButton(widget);
104 modeSliceRowRB->setText(QStringLiteral("Row Slice"));
105 modeSliceRowRB->setChecked(false);
106
107 QRadioButton *modeSliceColumnRB = new QRadioButton(widget);
108 modeSliceColumnRB->setText(QStringLiteral("Column Slice"));
109 modeSliceColumnRB->setChecked(false);
110
111 QVBoxLayout *selectionVBox = new QVBoxLayout;
112 selectionVBox->addWidget(modeNoneRB);
113 selectionVBox->addWidget(modeItemRB);
114 selectionVBox->addWidget(modeSliceRowRB);
115 selectionVBox->addWidget(modeSliceColumnRB);
116 selectionGroupBox->setLayout(selectionVBox);
117
118 QSlider *axisMinSliderX = new QSlider(Qt::Horizontal, widget);
119 axisMinSliderX->setMinimum(0);
120 axisMinSliderX->setTickInterval(1);
121 axisMinSliderX->setEnabled(true);
122 QSlider *axisMaxSliderX = new QSlider(Qt::Horizontal, widget);
123 axisMaxSliderX->setMinimum(1);
124 axisMaxSliderX->setTickInterval(1);
125 axisMaxSliderX->setEnabled(true);
126 QSlider *axisMinSliderZ = new QSlider(Qt::Horizontal, widget);
127 axisMinSliderZ->setMinimum(0);
128 axisMinSliderZ->setTickInterval(1);
129 axisMinSliderZ->setEnabled(true);
130 QSlider *axisMaxSliderZ = new QSlider(Qt::Horizontal, widget);
131 axisMaxSliderZ->setMinimum(1);
132 axisMaxSliderZ->setTickInterval(1);
133 axisMaxSliderZ->setEnabled(true);
134
135 QComboBox *themeList = new QComboBox(widget);
136 themeList->addItem(QStringLiteral("Qt"));
137 themeList->addItem(QStringLiteral("Primary Colors"));
138 themeList->addItem(QStringLiteral("Digia"));
139 themeList->addItem(QStringLiteral("Stone Moss"));
140 themeList->addItem(QStringLiteral("Army Blue"));
141 themeList->addItem(QStringLiteral("Retro"));
142 themeList->addItem(QStringLiteral("Ebony"));
143 themeList->addItem(QStringLiteral("Isabelle"));
144
145 QGroupBox *colorGroupBox = new QGroupBox(QStringLiteral("Custom gradient"));
146
147 QLinearGradient grBtoY(0, 0, 1, 100);
148 grBtoY.setColorAt(pos: 1.0, color: Qt::black);
149 grBtoY.setColorAt(pos: 0.67, color: Qt::blue);
150 grBtoY.setColorAt(pos: 0.33, color: Qt::red);
151 grBtoY.setColorAt(pos: 0.0, color: Qt::yellow);
152 QPixmap pm(24, 100);
153 QPainter pmp(&pm);
154 pmp.setBrush(QBrush(grBtoY));
155 pmp.setPen(Qt::NoPen);
156 pmp.drawRect(x: 0, y: 0, w: 24, h: 100);
157 QPushButton *gradientBtoYPB = new QPushButton(widget);
158 gradientBtoYPB->setIcon(QIcon(pm));
159 gradientBtoYPB->setIconSize(QSize(24, 100));
160
161 QLinearGradient grGtoR(0, 0, 1, 100);
162 grGtoR.setColorAt(pos: 1.0, color: Qt::darkGreen);
163 grGtoR.setColorAt(pos: 0.5, color: Qt::yellow);
164 grGtoR.setColorAt(pos: 0.2, color: Qt::red);
165 grGtoR.setColorAt(pos: 0.0, color: Qt::darkRed);
166 pmp.setBrush(QBrush(grGtoR));
167 pmp.drawRect(x: 0, y: 0, w: 24, h: 100);
168 QPushButton *gradientGtoRPB = new QPushButton(widget);
169 gradientGtoRPB->setIcon(QIcon(pm));
170 gradientGtoRPB->setIconSize(QSize(24, 100));
171
172 QHBoxLayout *colorHBox = new QHBoxLayout;
173 colorHBox->addWidget(gradientBtoYPB);
174 colorHBox->addWidget(gradientGtoRPB);
175 colorGroupBox->setLayout(colorHBox);
176
177 vLayout->addWidget(modelGroupBox);
178 vLayout->addWidget(selectionGroupBox);
179 vLayout->addWidget(new QLabel(QStringLiteral("Column range")));
180 vLayout->addWidget(axisMinSliderX);
181 vLayout->addWidget(axisMaxSliderX);
182 vLayout->addWidget(new QLabel(QStringLiteral("Row range")));
183 vLayout->addWidget(axisMinSliderZ);
184 vLayout->addWidget(axisMaxSliderZ);
185 vLayout->addWidget(new QLabel(QStringLiteral("Theme")));
186 vLayout->addWidget(themeList);
187 vLayout->addWidget(colorGroupBox);
188
189 widget->show();
190
191 SurfaceGraph *modifier = new SurfaceGraph(graph);
192
193 QObject::connect(sender: heightMapModelRB, signal: &QRadioButton::toggled,
194 receiver: modifier, slot: &SurfaceGraph::enableHeightMapModel);
195 QObject::connect(sender: sqrtSinModelRB, signal: &QRadioButton::toggled,
196 receiver: modifier, slot: &SurfaceGraph::enableSqrtSinModel);
197 QObject::connect(sender: modeNoneRB, signal: &QRadioButton::toggled,
198 receiver: modifier, slot: &SurfaceGraph::toggleModeNone);
199 QObject::connect(sender: modeItemRB, signal: &QRadioButton::toggled,
200 receiver: modifier, slot: &SurfaceGraph::toggleModeItem);
201 QObject::connect(sender: modeSliceRowRB, signal: &QRadioButton::toggled,
202 receiver: modifier, slot: &SurfaceGraph::toggleModeSliceRow);
203 QObject::connect(sender: modeSliceColumnRB, signal: &QRadioButton::toggled,
204 receiver: modifier, slot: &SurfaceGraph::toggleModeSliceColumn);
205 QObject::connect(sender: axisMinSliderX, signal: &QSlider::valueChanged,
206 receiver: modifier, slot: &SurfaceGraph::adjustXMin);
207 QObject::connect(sender: axisMaxSliderX, signal: &QSlider::valueChanged,
208 receiver: modifier, slot: &SurfaceGraph::adjustXMax);
209 QObject::connect(sender: axisMinSliderZ, signal: &QSlider::valueChanged,
210 receiver: modifier, slot: &SurfaceGraph::adjustZMin);
211 QObject::connect(sender: axisMaxSliderZ, signal: &QSlider::valueChanged,
212 receiver: modifier, slot: &SurfaceGraph::adjustZMax);
213 QObject::connect(sender: themeList, SIGNAL(currentIndexChanged(int)),
214 receiver: modifier, SLOT(changeTheme(int)));
215 QObject::connect(sender: gradientBtoYPB, signal: &QPushButton::pressed,
216 receiver: modifier, slot: &SurfaceGraph::setBlackToYellowGradient);
217 QObject::connect(sender: gradientGtoRPB, signal: &QPushButton::pressed,
218 receiver: modifier, slot: &SurfaceGraph::setGreenToRedGradient);
219
220 modifier->setAxisMinSliderX(axisMinSliderX);
221 modifier->setAxisMaxSliderX(axisMaxSliderX);
222 modifier->setAxisMinSliderZ(axisMinSliderZ);
223 modifier->setAxisMaxSliderZ(axisMaxSliderZ);
224
225 sqrtSinModelRB->setChecked(true);
226 modeItemRB->setChecked(true);
227 themeList->setCurrentIndex(2);
228
229 return app.exec();
230}
231

source code of qtdatavis3d/examples/datavisualization/surface/main.cpp