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 "scatterdatamodifier.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/QCheckBox> |
38 | #include <QtWidgets/QComboBox> |
39 | #include <QtWidgets/QFontComboBox> |
40 | #include <QtWidgets/QLabel> |
41 | #include <QtWidgets/QMessageBox> |
42 | #include <QtGui/QScreen> |
43 | #include <QtGui/QFontDatabase> |
44 | |
45 | int main(int argc, char **argv) |
46 | { |
47 | //! [0] |
48 | QApplication app(argc, argv); |
49 | Q3DScatter *graph = new Q3DScatter(); |
50 | QWidget *container = QWidget::createWindowContainer(window: graph); |
51 | //! [0] |
52 | |
53 | if (!graph->hasContext()) { |
54 | QMessageBox msgBox; |
55 | msgBox.setText("Couldn't initialize the OpenGL context." ); |
56 | msgBox.exec(); |
57 | return -1; |
58 | } |
59 | |
60 | QSize screenSize = graph->screen()->size(); |
61 | container->setMinimumSize(QSize(screenSize.width() / 2, screenSize.height() / 1.5)); |
62 | container->setMaximumSize(screenSize); |
63 | container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding); |
64 | container->setFocusPolicy(Qt::StrongFocus); |
65 | |
66 | //! [1] |
67 | QWidget *widget = new QWidget; |
68 | QHBoxLayout *hLayout = new QHBoxLayout(widget); |
69 | QVBoxLayout *vLayout = new QVBoxLayout(); |
70 | hLayout->addWidget(container, stretch: 1); |
71 | hLayout->addLayout(layout: vLayout); |
72 | //! [1] |
73 | |
74 | widget->setWindowTitle(QStringLiteral("A Cosine Wave" )); |
75 | |
76 | //! [4] |
77 | QComboBox *themeList = new QComboBox(widget); |
78 | themeList->addItem(QStringLiteral("Qt" )); |
79 | themeList->addItem(QStringLiteral("Primary Colors" )); |
80 | themeList->addItem(QStringLiteral("Digia" )); |
81 | themeList->addItem(QStringLiteral("Stone Moss" )); |
82 | themeList->addItem(QStringLiteral("Army Blue" )); |
83 | themeList->addItem(QStringLiteral("Retro" )); |
84 | themeList->addItem(QStringLiteral("Ebony" )); |
85 | themeList->addItem(QStringLiteral("Isabelle" )); |
86 | themeList->setCurrentIndex(6); |
87 | |
88 | QPushButton *labelButton = new QPushButton(widget); |
89 | labelButton->setText(QStringLiteral("Change label style" )); |
90 | |
91 | QCheckBox *smoothCheckBox = new QCheckBox(widget); |
92 | smoothCheckBox->setText(QStringLiteral("Smooth dots" )); |
93 | smoothCheckBox->setChecked(true); |
94 | |
95 | QComboBox *itemStyleList = new QComboBox(widget); |
96 | itemStyleList->addItem(QStringLiteral("Sphere" ), auserData: int(QAbstract3DSeries::MeshSphere)); |
97 | itemStyleList->addItem(QStringLiteral("Cube" ), auserData: int(QAbstract3DSeries::MeshCube)); |
98 | itemStyleList->addItem(QStringLiteral("Minimal" ), auserData: int(QAbstract3DSeries::MeshMinimal)); |
99 | itemStyleList->addItem(QStringLiteral("Point" ), auserData: int(QAbstract3DSeries::MeshPoint)); |
100 | itemStyleList->setCurrentIndex(0); |
101 | |
102 | QPushButton *cameraButton = new QPushButton(widget); |
103 | cameraButton->setText(QStringLiteral("Change camera preset" )); |
104 | |
105 | QPushButton *itemCountButton = new QPushButton(widget); |
106 | itemCountButton->setText(QStringLiteral("Toggle item count" )); |
107 | |
108 | QCheckBox *backgroundCheckBox = new QCheckBox(widget); |
109 | backgroundCheckBox->setText(QStringLiteral("Show background" )); |
110 | backgroundCheckBox->setChecked(true); |
111 | |
112 | QCheckBox *gridCheckBox = new QCheckBox(widget); |
113 | gridCheckBox->setText(QStringLiteral("Show grid" )); |
114 | gridCheckBox->setChecked(true); |
115 | |
116 | QComboBox *shadowQuality = new QComboBox(widget); |
117 | shadowQuality->addItem(QStringLiteral("None" )); |
118 | shadowQuality->addItem(QStringLiteral("Low" )); |
119 | shadowQuality->addItem(QStringLiteral("Medium" )); |
120 | shadowQuality->addItem(QStringLiteral("High" )); |
121 | shadowQuality->addItem(QStringLiteral("Low Soft" )); |
122 | shadowQuality->addItem(QStringLiteral("Medium Soft" )); |
123 | shadowQuality->addItem(QStringLiteral("High Soft" )); |
124 | shadowQuality->setCurrentIndex(4); |
125 | |
126 | QFontComboBox *fontList = new QFontComboBox(widget); |
127 | fontList->setCurrentFont(QFont("Arial" )); |
128 | //! [4] |
129 | |
130 | //! [5] |
131 | vLayout->addWidget(labelButton, stretch: 0, alignment: Qt::AlignTop); |
132 | vLayout->addWidget(cameraButton, stretch: 0, alignment: Qt::AlignTop); |
133 | vLayout->addWidget(itemCountButton, stretch: 0, alignment: Qt::AlignTop); |
134 | vLayout->addWidget(backgroundCheckBox); |
135 | vLayout->addWidget(gridCheckBox); |
136 | vLayout->addWidget(smoothCheckBox, stretch: 0, alignment: Qt::AlignTop); |
137 | vLayout->addWidget(new QLabel(QStringLiteral("Change dot style" ))); |
138 | vLayout->addWidget(itemStyleList); |
139 | vLayout->addWidget(new QLabel(QStringLiteral("Change theme" ))); |
140 | vLayout->addWidget(themeList); |
141 | vLayout->addWidget(new QLabel(QStringLiteral("Adjust shadow quality" ))); |
142 | vLayout->addWidget(shadowQuality); |
143 | vLayout->addWidget(new QLabel(QStringLiteral("Change font" ))); |
144 | vLayout->addWidget(fontList, stretch: 1, alignment: Qt::AlignTop); |
145 | //! [5] |
146 | |
147 | //! [2] |
148 | ScatterDataModifier *modifier = new ScatterDataModifier(graph); |
149 | //! [2] |
150 | |
151 | //! [6] |
152 | QObject::connect(sender: cameraButton, signal: &QPushButton::clicked, receiver: modifier, |
153 | slot: &ScatterDataModifier::changePresetCamera); |
154 | QObject::connect(sender: labelButton, signal: &QPushButton::clicked, receiver: modifier, |
155 | slot: &ScatterDataModifier::changeLabelStyle); |
156 | QObject::connect(sender: itemCountButton, signal: &QPushButton::clicked, receiver: modifier, |
157 | slot: &ScatterDataModifier::toggleItemCount); |
158 | |
159 | QObject::connect(sender: backgroundCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier, |
160 | slot: &ScatterDataModifier::setBackgroundEnabled); |
161 | QObject::connect(sender: gridCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier, |
162 | slot: &ScatterDataModifier::setGridEnabled); |
163 | QObject::connect(sender: smoothCheckBox, signal: &QCheckBox::stateChanged, receiver: modifier, |
164 | slot: &ScatterDataModifier::setSmoothDots); |
165 | |
166 | QObject::connect(sender: modifier, signal: &ScatterDataModifier::backgroundEnabledChanged, |
167 | receiver: backgroundCheckBox, slot: &QCheckBox::setChecked); |
168 | QObject::connect(sender: modifier, signal: &ScatterDataModifier::gridEnabledChanged, |
169 | receiver: gridCheckBox, slot: &QCheckBox::setChecked); |
170 | QObject::connect(sender: itemStyleList, SIGNAL(currentIndexChanged(int)), receiver: modifier, |
171 | SLOT(changeStyle(int))); |
172 | |
173 | QObject::connect(sender: themeList, SIGNAL(currentIndexChanged(int)), receiver: modifier, |
174 | SLOT(changeTheme(int))); |
175 | |
176 | QObject::connect(sender: shadowQuality, SIGNAL(currentIndexChanged(int)), receiver: modifier, |
177 | SLOT(changeShadowQuality(int))); |
178 | |
179 | QObject::connect(sender: modifier, signal: &ScatterDataModifier::shadowQualityChanged, receiver: shadowQuality, |
180 | slot: &QComboBox::setCurrentIndex); |
181 | QObject::connect(sender: graph, signal: &Q3DScatter::shadowQualityChanged, receiver: modifier, |
182 | slot: &ScatterDataModifier::shadowQualityUpdatedByVisual); |
183 | |
184 | QObject::connect(sender: fontList, signal: &QFontComboBox::currentFontChanged, receiver: modifier, |
185 | slot: &ScatterDataModifier::changeFont); |
186 | |
187 | QObject::connect(sender: modifier, signal: &ScatterDataModifier::fontChanged, receiver: fontList, |
188 | slot: &QFontComboBox::setCurrentFont); |
189 | //! [6] |
190 | |
191 | //! [3] |
192 | widget->show(); |
193 | return app.exec(); |
194 | //! [3] |
195 | } |
196 | |