code format

This commit is contained in:
2022-12-14 14:14:44 +03:00
parent 1dfca0aeab
commit cb944b62e4
85 changed files with 4451 additions and 3744 deletions

View File

@@ -1,34 +1,36 @@
/*
QGL PrimitiveEditor
Ivan Pelipenko peri4ko@yandex.ru
QGL PrimitiveEditor
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "primitiveeditor.h"
#include "glmesh.h"
#include "glprimitives.h"
#include "ui_primitiveeditor.h"
#include <QMetaEnum>
#include <qad_types.h>
#include "glprimitives.h"
#include "glmesh.h"
PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui::PrimitiveEditor) {
view = 0;
PrimitiveEditor::PrimitiveEditor(QWidget * parent): QWidget(parent), ui(new Ui::PrimitiveEditor) {
view = 0;
can_replace = false;
ui->setupUi(this);
#if QT_VERSION >= QT_VERSION_CHECK(5,12,0)
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
ui->spinSegments->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
ui->spinSegments2->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
#endif
@@ -58,12 +60,12 @@ PrimitiveEditor::PrimitiveEditor(QWidget *parent) : QWidget(parent), ui(new Ui::
editors[Torus] << ui->widgetAngle;
QSet<QWidget *> all;
QMetaEnum me = metaObject()->enumerator(0);
for (int i=0; i<me.keyCount(); ++i) {
for (int i = 0; i < me.keyCount(); ++i) {
ui->comboPrimitives->addItem(me.key(i));
all.unite(QList2QSet(editors[(PrimitiveType)me.value(i)]));
}
all_editors = all.values();
foreach (QWidget * w, all_editors) {
foreach(QWidget * w, all_editors) {
if (w->layout()) w->layout()->setContentsMargins(0, layout()->spacing(), 0, 0);
}
@@ -85,93 +87,65 @@ void PrimitiveEditor::assignQGLView(QGLView * v) {
Mesh * PrimitiveEditor::createMesh(QVariantList & params) {
Mesh * m = 0;
Mesh * m = 0;
PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex();
params << pt;
switch (pt) {
case Plane:
m = Primitive::plane(ui->spinWidth->value(),
ui->spinLength->value());
params << ui->spinWidth->value()
<< ui->spinLength->value();
break;
case Cube:
m = Primitive::cube(ui->spinWidth->value(),
ui->spinLength->value(),
ui->spinHeight->value());
params << ui->spinWidth->value()
<< ui->spinLength->value()
<< ui->spinHeight->value();
break;
case Ellipsoid:
m = Primitive::ellipsoid(ui->spinSegments->value(),
ui->spinSegments2->value(),
ui->spinRadius->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinSegments2->value()
<< ui->spinRadius->value()
<< ui->spinAngle->value();
break;
case Disc:
m = Primitive::disc(ui->spinSegments->value(),
ui->spinRadius->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinAngle->value();
break;
case Cone:
m = Primitive::cone(ui->spinSegments->value(),
ui->spinRadius->value(),
ui->spinHeight->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinHeight->value();
break;
case Cylinder:
m = Primitive::cylinder(ui->spinSegments->value(),
ui->spinRadius->value(),
ui->spinHeight->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinRadius->value()
<< ui->spinHeight->value()
<< ui->spinAngle->value();
break;
case Torus:
m = Primitive::torus(ui->spinSegments->value(),
ui->spinSegments2->value(),
ui->spinRadius->value(),
ui->spinRadius2->value(),
ui->spinAngle->value());
params << ui->spinSegments->value()
<< ui->spinSegments2->value()
<< ui->spinRadius->value()
<< ui->spinRadius2->value()
<< ui->spinAngle->value();
break;
default: return 0;
case Plane:
m = Primitive::plane(ui->spinWidth->value(), ui->spinLength->value());
params << ui->spinWidth->value() << ui->spinLength->value();
break;
case Cube:
m = Primitive::cube(ui->spinWidth->value(), ui->spinLength->value(), ui->spinHeight->value());
params << ui->spinWidth->value() << ui->spinLength->value() << ui->spinHeight->value();
break;
case Ellipsoid:
m = Primitive::ellipsoid(ui->spinSegments->value(), ui->spinSegments2->value(), ui->spinRadius->value(), ui->spinAngle->value());
params << ui->spinSegments->value() << ui->spinSegments2->value() << ui->spinRadius->value() << ui->spinAngle->value();
break;
case Disc:
m = Primitive::disc(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinAngle->value());
params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinAngle->value();
break;
case Cone:
m = Primitive::cone(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinHeight->value());
params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinHeight->value();
break;
case Cylinder:
m = Primitive::cylinder(ui->spinSegments->value(), ui->spinRadius->value(), ui->spinHeight->value(), ui->spinAngle->value());
params << ui->spinSegments->value() << ui->spinRadius->value() << ui->spinHeight->value() << ui->spinAngle->value();
break;
case Torus:
m = Primitive::torus(ui->spinSegments->value(),
ui->spinSegments2->value(),
ui->spinRadius->value(),
ui->spinRadius2->value(),
ui->spinAngle->value());
params << ui->spinSegments->value() << ui->spinSegments2->value() << ui->spinRadius->value() << ui->spinRadius2->value()
<< ui->spinAngle->value();
break;
default: return 0;
}
params << ui->flipNormals->isChecked();
params << ui->colorButton->color();
if (ui->flipNormals->isChecked())
m->flipNormals();
if (ui->flipNormals->isChecked()) m->flipNormals();
return m;
}
void PrimitiveEditor::showEditors() {
foreach (QWidget * w, all_editors) w->hide();
PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex();
foreach(QWidget * w, all_editors)
w->hide();
PrimitiveType pt = (PrimitiveType)ui->comboPrimitives->currentIndex();
QList<QWidget *> wds = editors[pt];
foreach (QWidget * w, wds) w->show();
foreach(QWidget * w, wds)
w->show();
}
void PrimitiveEditor::selectionChanged() {
ObjectBase * so = view->selectedObject();\
can_replace = false;
ObjectBase * so = view->selectedObject();
can_replace = false;
if (so) {
QVariantList vl = so->property("primitive", &can_replace).toList();
if (can_replace && !vl.isEmpty()) {
@@ -181,41 +155,41 @@ void PrimitiveEditor::selectionChanged() {
case Plane:
ui->spinWidth->setValue(vl.takeFirst().toDouble());
ui->spinLength->setValue(vl.takeFirst().toDouble());
break;
break;
case Cube:
ui->spinWidth->setValue(vl.takeFirst().toDouble());
ui->spinLength->setValue(vl.takeFirst().toDouble());
ui->spinHeight->setValue(vl.takeFirst().toDouble());
break;
break;
case Ellipsoid:
ui->spinSegments->setValue(vl.takeFirst().toDouble());
ui->spinSegments2->setValue(vl.takeFirst().toDouble());
ui->spinRadius->setValue(vl.takeFirst().toDouble());
ui->spinAngle->setValue(vl.takeFirst().toDouble());
break;
break;
case Disc:
ui->spinSegments->setValue(vl.takeFirst().toDouble());
ui->spinRadius->setValue(vl.takeFirst().toDouble());
ui->spinAngle->setValue(vl.takeFirst().toDouble());
break;
break;
case Cone:
ui->spinSegments->setValue(vl.takeFirst().toDouble());
ui->spinRadius->setValue(vl.takeFirst().toDouble());
ui->spinHeight->setValue(vl.takeFirst().toDouble());
break;
break;
case Cylinder:
ui->spinSegments->setValue(vl.takeFirst().toDouble());
ui->spinRadius->setValue(vl.takeFirst().toDouble());
ui->spinHeight->setValue(vl.takeFirst().toDouble());
ui->spinAngle->setValue(vl.takeFirst().toDouble());
break;
break;
case Torus:
ui->spinSegments->setValue(vl.takeFirst().toDouble());
ui->spinSegments2->setValue(vl.takeFirst().toDouble());
ui->spinRadius->setValue(vl.takeFirst().toDouble());
ui->spinRadius2->setValue(vl.takeFirst().toDouble());
ui->spinAngle->setValue(vl.takeFirst().toDouble());
break;
break;
}
ui->flipNormals->setChecked(vl.takeFirst().toBool());
ui->colorButton->setColor(vl.takeFirst().value<QColor>());