| 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 "customitemgraph.h" |
| 31 | |
| 32 | #include <QtWidgets/QApplication> |
| 33 | #include <QtWidgets/QWidget> |
| 34 | #include <QtWidgets/QHBoxLayout> |
| 35 | #include <QtWidgets/QVBoxLayout> |
| 36 | #include <QtWidgets/QCheckBox> |
| 37 | #include <QtWidgets/QLabel> |
| 38 | #include <QtWidgets/QMessageBox> |
| 39 | |
| 40 | int main(int argc, char **argv) |
| 41 | { |
| 42 | QApplication app(argc, argv); |
| 43 | Q3DSurface *graph = new Q3DSurface(); |
| 44 | QWidget *container = QWidget::createWindowContainer(window: graph); |
| 45 | |
| 46 | if (!graph->hasContext()) { |
| 47 | QMessageBox msgBox; |
| 48 | msgBox.setText("Couldn't initialize the OpenGL context." ); |
| 49 | msgBox.exec(); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | container->setMinimumSize(QSize(800, 600)); |
| 54 | container->setSizePolicy(hor: QSizePolicy::Expanding, ver: QSizePolicy::Expanding); |
| 55 | container->setFocusPolicy(Qt::StrongFocus); |
| 56 | |
| 57 | QWidget *widget = new QWidget; |
| 58 | QHBoxLayout *hLayout = new QHBoxLayout(widget); |
| 59 | QVBoxLayout *vLayoutLeft = new QVBoxLayout(); |
| 60 | vLayoutLeft->setAlignment(Qt::AlignTop); |
| 61 | QVBoxLayout *vLayoutRight = new QVBoxLayout(); |
| 62 | vLayoutRight->setAlignment(Qt::AlignTop); |
| 63 | hLayout->addLayout(layout: vLayoutLeft); |
| 64 | hLayout->addWidget(container, stretch: 1); |
| 65 | hLayout->addLayout(layout: vLayoutRight); |
| 66 | |
| 67 | QFont font = QFont("Century Gothic" , 14); |
| 68 | QLabel *label = new QLabel("Show:" ); |
| 69 | font.setBold(true); |
| 70 | label->setFont(font); |
| 71 | vLayoutLeft->addWidget(label); |
| 72 | |
| 73 | font.setBold(false); |
| 74 | QCheckBox *checkboxOne = new QCheckBox("Oil Rig 1" ); |
| 75 | checkboxOne->setChecked(true); |
| 76 | checkboxOne->setFont(font); |
| 77 | vLayoutLeft->addWidget(checkboxOne); |
| 78 | |
| 79 | QCheckBox *checkboxTwo = new QCheckBox("Oil Rig 2" ); |
| 80 | checkboxTwo->setChecked(true); |
| 81 | checkboxTwo->setFont(font); |
| 82 | vLayoutLeft->addWidget(checkboxTwo); |
| 83 | |
| 84 | QCheckBox *checkboxThree = new QCheckBox("Refinery" ); |
| 85 | checkboxThree->setFont(font); |
| 86 | vLayoutLeft->addWidget(checkboxThree); |
| 87 | |
| 88 | QLabel *label2 = new QLabel("Visuals:" ); |
| 89 | font.setBold(true); |
| 90 | label2->setFont(font); |
| 91 | vLayoutRight->addWidget(label2); |
| 92 | |
| 93 | QCheckBox *checkboxOneRight = new QCheckBox("See-Through" ); |
| 94 | font.setBold(false); |
| 95 | checkboxOneRight->setFont(font); |
| 96 | vLayoutRight->addWidget(checkboxOneRight); |
| 97 | |
| 98 | QCheckBox *checkboxTwoRight = new QCheckBox("Highlight Oil" ); |
| 99 | checkboxTwoRight->setFont(font); |
| 100 | vLayoutRight->addWidget(checkboxTwoRight); |
| 101 | |
| 102 | QCheckBox *checkboxThreeRight = new QCheckBox("Shadows" ); |
| 103 | checkboxThreeRight->setFont(font); |
| 104 | checkboxThreeRight->setChecked(true); |
| 105 | vLayoutRight->addWidget(checkboxThreeRight); |
| 106 | |
| 107 | QLabel *label3 = new QLabel("Selection:" ); |
| 108 | font.setBold(true); |
| 109 | label3->setFont(font); |
| 110 | vLayoutRight->addWidget(label3); |
| 111 | |
| 112 | QLabel *label4 = new QLabel("Nothing" ); |
| 113 | font.setBold(false); |
| 114 | font.setPointSize(11); |
| 115 | label4->setFont(font); |
| 116 | vLayoutRight->addWidget(label4); |
| 117 | |
| 118 | widget->setWindowTitle(QStringLiteral("Custom Items Example" )); |
| 119 | |
| 120 | widget->show(); |
| 121 | |
| 122 | CustomItemGraph *modifier = new CustomItemGraph(graph, label4); |
| 123 | |
| 124 | QObject::connect(sender: checkboxOne, signal: &QCheckBox::stateChanged, |
| 125 | receiver: modifier, slot: &CustomItemGraph::toggleItemOne); |
| 126 | QObject::connect(sender: checkboxTwo, signal: &QCheckBox::stateChanged, |
| 127 | receiver: modifier, slot: &CustomItemGraph::toggleItemTwo); |
| 128 | QObject::connect(sender: checkboxThree, signal: &QCheckBox::stateChanged, |
| 129 | receiver: modifier, slot: &CustomItemGraph::toggleItemThree); |
| 130 | |
| 131 | QObject::connect(sender: checkboxOneRight, signal: &QCheckBox::stateChanged, |
| 132 | receiver: modifier, slot: &CustomItemGraph::toggleSeeThrough); |
| 133 | QObject::connect(sender: checkboxTwoRight, signal: &QCheckBox::stateChanged, |
| 134 | receiver: modifier, slot: &CustomItemGraph::toggleOilHighlight); |
| 135 | QObject::connect(sender: checkboxThreeRight, signal: &QCheckBox::stateChanged, |
| 136 | receiver: modifier, slot: &CustomItemGraph::toggleShadows); |
| 137 | |
| 138 | return app.exec(); |
| 139 | } |
| 140 | |