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/QGroupBox>
37#include <QtWidgets/QCheckBox>
38#include <QtWidgets/QLabel>
39#include <QtWidgets/QMessageBox>
40#include <QtGui/QScreen>
41#include <QtGui/QPainter>
42
43int main(int argc, char **argv)
44{
45 QApplication app(argc, argv);
46 Q3DSurface *graph = new Q3DSurface();
47 QWidget *container = QWidget::createWindowContainer(window: graph);
48
49 if (!graph->hasContext()) {
50 QMessageBox msgBox;
51 msgBox.setText("Couldn't initialize the OpenGL context.");
52 msgBox.exec();
53 return -1;
54 }
55
56 QSize screenSize = graph->screen()->size();
57 container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.6));
58 container->setMaximumSize(screenSize);
59 container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding);
60 container->setFocusPolicy(Qt::StrongFocus);
61
62 QWidget *widget = new QWidget;
63 QHBoxLayout *hLayout = new QHBoxLayout(widget);
64 QVBoxLayout *vLayout = new QVBoxLayout();
65 hLayout->addWidget(container, stretch: 1);
66 hLayout->addLayout(layout: vLayout);
67 vLayout->setAlignment(Qt::AlignTop);
68
69 widget->setWindowTitle(QStringLiteral("Textured surface example"));
70
71 QCheckBox *enableTexture = new QCheckBox(widget);
72 enableTexture->setText(QStringLiteral("Surface texture"));
73
74 int height = 400;
75 int width = 100;
76 int border = 10;
77 QLinearGradient gr(0, 0, 1, height - 2 * border);
78 gr.setColorAt(pos: 1.0f, color: Qt::black);
79 gr.setColorAt(pos: 0.8f, color: Qt::darkGreen);
80 gr.setColorAt(pos: 0.6f, color: Qt::green);
81 gr.setColorAt(pos: 0.4f, color: Qt::yellow);
82 gr.setColorAt(pos: 0.2f, color: Qt::red);
83 gr.setColorAt(pos: 0.0f, color: Qt::darkRed);
84
85 QPixmap pm(width, height);
86 pm.fill(fillColor: Qt::transparent);
87 QPainter pmp(&pm);
88 pmp.setBrush(QBrush(gr));
89 pmp.setPen(Qt::NoPen);
90 pmp.drawRect(x: border, y: border, w: 35, h: height - 2 * border);
91 pmp.setPen(Qt::black);
92 int step = (height - 2 * border) / 5;
93 for (int i = 0; i < 6; i++) {
94 int yPos = i * step + border;
95 pmp.drawLine(x1: border, y1: yPos, x2: 55, y2: yPos);
96 pmp.drawText(x: 60, y: yPos + 2, s: QString("%1 m").arg(a: 550 - (i * 110)));
97 }
98
99 QLabel *label = new QLabel(widget);
100 label->setPixmap(pm);
101
102 QGroupBox *heightMapGroupBox = new QGroupBox(QStringLiteral("Highlight color map"));
103 QVBoxLayout *colorMapVBox = new QVBoxLayout;
104 colorMapVBox->addWidget(label);
105 heightMapGroupBox->setLayout(colorMapVBox);
106
107 vLayout->addWidget(enableTexture);
108 vLayout->addWidget(heightMapGroupBox);
109
110 widget->show();
111
112 SurfaceGraph *modifier = new SurfaceGraph(graph);
113
114 QObject::connect(sender: enableTexture, signal: &QCheckBox::stateChanged,
115 receiver: modifier, slot: &SurfaceGraph::toggleSurfaceTexture);
116
117 enableTexture->setChecked(true);
118
119 return app.exec();
120}
121

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