code format
This commit is contained in:
@@ -1,40 +1,41 @@
|
||||
/*
|
||||
QGL MaterialEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialEditor
|
||||
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 "material_editor.h"
|
||||
#include "ui_material_editor.h"
|
||||
|
||||
#include "glmaterial.h"
|
||||
#include "ui_material_editor.h"
|
||||
|
||||
|
||||
MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) {
|
||||
ui = new Ui::MaterialEditor();
|
||||
ui->setupUi(this);
|
||||
ui->mapDiffuse ->configure(tr("Diffuse"), true);
|
||||
ui->mapNormal ->configure(tr("Normal"));
|
||||
ui->mapDiffuse->configure(tr("Diffuse"), true);
|
||||
ui->mapNormal->configure(tr("Normal"));
|
||||
ui->mapMetalness->configure(tr("Metalness"));
|
||||
ui->mapRoughness->configure(tr("Roughness"));
|
||||
ui->mapEmission ->configure(tr("Emission"), true);
|
||||
ui->mapRelief ->configure(tr("Relief"));
|
||||
ui->mapEmission->configure(tr("Emission"), true);
|
||||
ui->mapRelief->configure(tr("Relief"));
|
||||
ui->checkGlass->hide();
|
||||
ui->frameReflection->hide();
|
||||
ui->label_13->hide();
|
||||
mat = 0;
|
||||
active = true;
|
||||
mat = 0;
|
||||
active = true;
|
||||
ignore_next = 0;
|
||||
}
|
||||
|
||||
@@ -42,90 +43,94 @@ MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) {
|
||||
void MaterialEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MaterialEditor::materialChanged() {
|
||||
if (!active || !mat) return;
|
||||
ignore_next = 2;
|
||||
mat->_changed = true;
|
||||
mat->color_diffuse = ui->mapDiffuse ->color();
|
||||
ignore_next = 2;
|
||||
mat->_changed = true;
|
||||
mat->color_diffuse = ui->mapDiffuse->color();
|
||||
mat->color_emission = ui->mapEmission->color();
|
||||
mat->transparency = ui->spinTransparent->value();
|
||||
mat->reflectivity = ui->spinReflect->value();
|
||||
mat->iof = ui->spinIOF->value();
|
||||
mat->dispersion = ui->spinDispersion->value();
|
||||
mat->glass = ui->checkGlass->isChecked();
|
||||
//emit changed();
|
||||
mat->transparency = ui->spinTransparent->value();
|
||||
mat->reflectivity = ui->spinReflect->value();
|
||||
mat->iof = ui->spinIOF->value();
|
||||
mat->dispersion = ui->spinDispersion->value();
|
||||
mat->glass = ui->checkGlass->isChecked();
|
||||
// emit changed();
|
||||
}
|
||||
|
||||
|
||||
void MaterialEditor::setMaterial(Material * m) {
|
||||
if (ignore_next > 0) {
|
||||
//ignore_next = false;
|
||||
// ignore_next = false;
|
||||
return;
|
||||
}
|
||||
active = false;
|
||||
mat = m;
|
||||
mat = m;
|
||||
setEnabled(m);
|
||||
if (!mat) return;
|
||||
ui->mapDiffuse ->setColor(mat->color_diffuse );
|
||||
ui->mapDiffuse->setColor(mat->color_diffuse);
|
||||
ui->mapEmission->setColor(mat->color_emission);
|
||||
ui->spinTransparent->setValue(mat->transparency);
|
||||
ui->spinReflect->setValue(mat->reflectivity);
|
||||
ui->spinIOF->setValue(mat->iof);
|
||||
ui->spinDispersion->setValue(mat->dispersion);
|
||||
ui->checkGlass->setChecked(mat->glass);
|
||||
ui->mapDiffuse ->setMap(&(mat->map_diffuse ));
|
||||
ui->mapNormal ->setMap(&(mat->map_normal ));
|
||||
ui->mapDiffuse->setMap(&(mat->map_diffuse));
|
||||
ui->mapNormal->setMap(&(mat->map_normal));
|
||||
ui->mapMetalness->setMap(&(mat->map_metalness));
|
||||
ui->mapRoughness->setMap(&(mat->map_roughness));
|
||||
ui->mapEmission ->setMap(&(mat->map_emission ));
|
||||
ui->mapRelief ->setMap(&(mat->map_relief ));
|
||||
/*ui->lineReflFront->setProperty("GLpath", mat->map_reflection.path(0)); ui->lineReflFront->setText(QFileInfo(mat->map_reflection.path(0)).fileName());
|
||||
ui->lineReflBack->setProperty("GLpath", mat->map_reflection.path(1)); ui->lineReflBack->setText(QFileInfo(mat->map_reflection.path(1)).fileName());
|
||||
ui->lineReflLeft->setProperty("GLpath", mat->map_reflection.path(2)); ui->lineReflLeft->setText(QFileInfo(mat->map_reflection.path(2)).fileName());
|
||||
ui->lineReflRight->setProperty("GLpath", mat->map_reflection.path(3)); ui->lineReflRight->setText(QFileInfo(mat->map_reflection.path(3)).fileName());
|
||||
ui->lineReflTop->setProperty("GLpath", mat->map_reflection.path(4)); ui->lineReflTop->setText(QFileInfo(mat->map_reflection.path(4)).fileName());
|
||||
ui->lineReflBottom->setProperty("GLpath", mat->map_reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(mat->map_reflection.path(5)).fileName());
|
||||
*/active = true;
|
||||
ui->mapEmission->setMap(&(mat->map_emission));
|
||||
ui->mapRelief->setMap(&(mat->map_relief));
|
||||
/*ui->lineReflFront->setProperty("GLpath", mat->map_reflection.path(0));
|
||||
ui->lineReflFront->setText(QFileInfo(mat->map_reflection.path(0)).fileName()); ui->lineReflBack->setProperty("GLpath",
|
||||
mat->map_reflection.path(1)); ui->lineReflBack->setText(QFileInfo(mat->map_reflection.path(1)).fileName());
|
||||
ui->lineReflLeft->setProperty("GLpath", mat->map_reflection.path(2));
|
||||
ui->lineReflLeft->setText(QFileInfo(mat->map_reflection.path(2)).fileName()); ui->lineReflRight->setProperty("GLpath",
|
||||
mat->map_reflection.path(3)); ui->lineReflRight->setText(QFileInfo(mat->map_reflection.path(3)).fileName());
|
||||
ui->lineReflTop->setProperty("GLpath", mat->map_reflection.path(4));
|
||||
ui->lineReflTop->setText(QFileInfo(mat->map_reflection.path(4)).fileName()); ui->lineReflBottom->setProperty("GLpath",
|
||||
mat->map_reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(mat->map_reflection.path(5)).fileName());
|
||||
*/
|
||||
active = true;
|
||||
}
|
||||
|
||||
/*
|
||||
Material MaterialEditor::material() {
|
||||
Material m;
|
||||
mat->color_diffuse = ui->colorDiffuse ->color();
|
||||
mat->color_specular = ui->colorSpecular->color();
|
||||
mat->color_emission = ui->colorEmission->color();
|
||||
mat->transparency = ui->spinTransparent->value();
|
||||
mat->reflectivity = ui->spinReflect->value();
|
||||
mat->iof = ui->spinIOF->value();
|
||||
mat->dispersion = ui->spinDispersion->value();
|
||||
mat->glass = ui->checkGlass->isChecked();
|
||||
mat->map_diffuse = ui->mapDiffuse->map();
|
||||
mat->map_normal = ui->mapNormal->map();
|
||||
mat->map_specular = ui->mapSpecular->map();
|
||||
mat->map_roughness = ui->mapRoughness->map();
|
||||
mat->map_emission = ui->mapEmission->map();
|
||||
mat->map_relief = ui->mapRelief->map();
|
||||
mat->map_reflection.setPath(0, ui->lineReflFront->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(1, ui->lineReflBack->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(2, ui->lineReflLeft->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(3, ui->lineReflRight->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(4, ui->lineReflTop->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(5, ui->lineReflBottom->property("GLpath").toString());
|
||||
return m;
|
||||
Material m;
|
||||
mat->color_diffuse = ui->colorDiffuse ->color();
|
||||
mat->color_specular = ui->colorSpecular->color();
|
||||
mat->color_emission = ui->colorEmission->color();
|
||||
mat->transparency = ui->spinTransparent->value();
|
||||
mat->reflectivity = ui->spinReflect->value();
|
||||
mat->iof = ui->spinIOF->value();
|
||||
mat->dispersion = ui->spinDispersion->value();
|
||||
mat->glass = ui->checkGlass->isChecked();
|
||||
mat->map_diffuse = ui->mapDiffuse->map();
|
||||
mat->map_normal = ui->mapNormal->map();
|
||||
mat->map_specular = ui->mapSpecular->map();
|
||||
mat->map_roughness = ui->mapRoughness->map();
|
||||
mat->map_emission = ui->mapEmission->map();
|
||||
mat->map_relief = ui->mapRelief->map();
|
||||
mat->map_reflection.setPath(0, ui->lineReflFront->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(1, ui->lineReflBack->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(2, ui->lineReflLeft->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(3, ui->lineReflRight->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(4, ui->lineReflTop->property("GLpath").toString());
|
||||
mat->map_reflection.setPath(5, ui->lineReflBottom->property("GLpath").toString());
|
||||
return m;
|
||||
}
|
||||
*/
|
||||
|
||||
void MaterialEditor::on_buttonReflFrontSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflFront->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflFront->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflFront->setProperty("GLpath", str);
|
||||
ui->lineReflFront->setText(QFileInfo(str).fileName());
|
||||
@@ -134,7 +139,10 @@ void MaterialEditor::on_buttonReflFrontSelect_clicked() {
|
||||
|
||||
|
||||
void MaterialEditor::on_buttonReflBackSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBack->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflBack->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflBack->setProperty("GLpath", str);
|
||||
ui->lineReflBack->setText(QFileInfo(str).fileName());
|
||||
@@ -143,7 +151,10 @@ void MaterialEditor::on_buttonReflBackSelect_clicked() {
|
||||
|
||||
|
||||
void MaterialEditor::on_buttonReflLeftSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflLeft->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflLeft->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflLeft->setProperty("GLpath", str);
|
||||
ui->lineReflLeft->setText(QFileInfo(str).fileName());
|
||||
@@ -152,7 +163,10 @@ void MaterialEditor::on_buttonReflLeftSelect_clicked() {
|
||||
|
||||
|
||||
void MaterialEditor::on_buttonReflRightSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflRight->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflRight->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflRight->setProperty("GLpath", str);
|
||||
ui->lineReflRight->setText(QFileInfo(str).fileName());
|
||||
@@ -161,7 +175,10 @@ void MaterialEditor::on_buttonReflRightSelect_clicked() {
|
||||
|
||||
|
||||
void MaterialEditor::on_buttonReflTopSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflTop->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflTop->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflTop->setProperty("GLpath", str);
|
||||
ui->lineReflTop->setText(QFileInfo(str).fileName());
|
||||
@@ -170,7 +187,10 @@ void MaterialEditor::on_buttonReflTopSelect_clicked() {
|
||||
|
||||
|
||||
void MaterialEditor::on_buttonReflBottomSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineReflBottom->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->lineReflBottom->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->lineReflBottom->setProperty("GLpath", str);
|
||||
ui->lineReflBottom->setText(QFileInfo(str).fileName());
|
||||
|
||||
@@ -1,35 +1,36 @@
|
||||
/*
|
||||
QGL MaterialEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef MATERIAL_EDITOR_H
|
||||
#define MATERIAL_EDITOR_H
|
||||
|
||||
#include <QFileDialog>
|
||||
#include "gltypes.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace Ui {
|
||||
class MaterialEditor;
|
||||
class MaterialEditor;
|
||||
}
|
||||
|
||||
class MaterialEditor: public QWidget
|
||||
{
|
||||
class MaterialEditor: public QWidget {
|
||||
friend class MaterialsEditor;
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MaterialEditor(QWidget * parent = 0);
|
||||
|
||||
@@ -61,7 +62,6 @@ private slots:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // MATERIAL_EDITOR_H
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
/*
|
||||
QGL MaterialMapEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialMapEditor
|
||||
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 "material_map_editor.h"
|
||||
#include "ui_material_map_editor.h"
|
||||
#include "gltexture_manager.h"
|
||||
|
||||
#include "glmaterial.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include "ui_material_map_editor.h"
|
||||
|
||||
#include <qad_types.h>
|
||||
|
||||
|
||||
@@ -34,11 +36,8 @@ MaterialMapEditor::MaterialMapEditor(QWidget * parent): QWidget(parent) {
|
||||
void MaterialMapEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +56,7 @@ void MaterialMapEditor::updateIcon() {
|
||||
|
||||
void MaterialMapEditor::mapChanged() {
|
||||
if (!active || !map) return;
|
||||
active = false;
|
||||
active = false;
|
||||
map->use_bitmap = ui->checkMap->isChecked();
|
||||
if (ui->checkMap->isChecked()) {
|
||||
map->color_amount = ui->sliderAmount->value();
|
||||
@@ -75,7 +74,7 @@ void MaterialMapEditor::mapChanged() {
|
||||
|
||||
void MaterialMapEditor::setMap(Map * m) {
|
||||
active = false;
|
||||
map = m;
|
||||
map = m;
|
||||
setEnabled(m);
|
||||
if (!map) return;
|
||||
ui->stackedWidget->setCurrentIndex(map->use_bitmap ? 1 : 0);
|
||||
@@ -85,7 +84,8 @@ void MaterialMapEditor::setMap(Map * m) {
|
||||
ui->sliderOffset->setValue(map->color_offset);
|
||||
ui->spinScaleX->setValue(map->bitmap_scale.x());
|
||||
ui->spinScaleY->setValue(map->bitmap_scale.y());
|
||||
ui->linePath->setProperty("GLpath", map->bitmap_path); ui->linePath->setText(QFileInfo(map->bitmap_path).fileName());
|
||||
ui->linePath->setProperty("GLpath", map->bitmap_path);
|
||||
ui->linePath->setText(QFileInfo(map->bitmap_path).fileName());
|
||||
updateIcon();
|
||||
active = true;
|
||||
}
|
||||
@@ -110,18 +110,21 @@ QColor MaterialMapEditor::color() const {
|
||||
|
||||
/*
|
||||
Map MaterialMapEditor::map() {
|
||||
Map m;
|
||||
map->color_amount = ui->sliderAmount->value();
|
||||
map->color_offset = ui->sliderOffset->value();
|
||||
map->bitmap_scale.setX(ui->spinScaleX->value());
|
||||
map->bitmap_scale.setY(ui->spinScaleY->value());
|
||||
map->bitmap_path = ui->linePath->property("GLpath").toString();
|
||||
return m;
|
||||
Map m;
|
||||
map->color_amount = ui->sliderAmount->value();
|
||||
map->color_offset = ui->sliderOffset->value();
|
||||
map->bitmap_scale.setX(ui->spinScaleX->value());
|
||||
map->bitmap_scale.setY(ui->spinScaleY->value());
|
||||
map->bitmap_path = ui->linePath->property("GLpath").toString();
|
||||
return m;
|
||||
}
|
||||
*/
|
||||
|
||||
void MaterialMapEditor::on_buttonSelect_clicked() {
|
||||
QString str = QFileDialog::getOpenFileName(this, "Select image", ui->linePath->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
QString str = QFileDialog::getOpenFileName(this,
|
||||
"Select image",
|
||||
ui->linePath->property("GLpath").toString(),
|
||||
"Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)");
|
||||
if (str.isEmpty()) return;
|
||||
ui->linePath->setProperty("GLpath", str);
|
||||
ui->linePath->setText(QFileInfo(str).fileName());
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
/*
|
||||
QGL MaterialMapEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialMapEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef MATERIAL_MAP_EDITOR_H
|
||||
#define MATERIAL_MAP_EDITOR_H
|
||||
|
||||
#include <QFileDialog>
|
||||
#include "gltypes.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace Ui {
|
||||
class MaterialMapEditor;
|
||||
class MaterialMapEditor;
|
||||
}
|
||||
|
||||
class MaterialMapEditor: public QWidget
|
||||
{
|
||||
class MaterialMapEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MaterialMapEditor(QWidget * parent = 0);
|
||||
|
||||
@@ -54,7 +55,6 @@ private slots:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // MATERIAL_MAP_EDITOR_H
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
/*
|
||||
QGL MaterialsEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialsEditor
|
||||
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 "materials_editor.h"
|
||||
#include "ui_materials_editor.h"
|
||||
|
||||
#include "glmaterial.h"
|
||||
#include "material_editor.h"
|
||||
#include "qglview.h"
|
||||
#include "glmaterial.h"
|
||||
#include <qad_types.h>
|
||||
#include <ecombobox.h>
|
||||
#include "ui_materials_editor.h"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <ecombobox.h>
|
||||
#include <qad_types.h>
|
||||
|
||||
|
||||
MaterialsEditor::MaterialsEditor(QWidget * parent): QWidget(parent) {
|
||||
@@ -40,7 +42,7 @@ void MaterialsEditor::assignQGLView(QGLView * v) {
|
||||
view = v;
|
||||
connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
||||
connect(view, SIGNAL(materialsChanged()), this, SLOT(materialsChanged()));
|
||||
connect(view, SIGNAL(materialThumbnailCreated(Material*)), this, SLOT(materialThumbnailCreated(Material*)));
|
||||
connect(view, SIGNAL(materialThumbnailCreated(Material *)), this, SLOT(materialThumbnailCreated(Material *)));
|
||||
materialsChanged();
|
||||
}
|
||||
|
||||
@@ -50,11 +52,11 @@ bool MaterialsEditor::event(QEvent * e) {
|
||||
QSize sz = preferredIconSize(1.5, this);
|
||||
ui->comboMaterial->setIconSize(sz * 3);
|
||||
ui->buttonRename->setIconSize(sz);
|
||||
ui->buttonAdd ->setIconSize(sz);
|
||||
ui->buttonClone ->setIconSize(sz);
|
||||
ui->buttonAdd->setIconSize(sz);
|
||||
ui->buttonClone->setIconSize(sz);
|
||||
ui->buttonDelete->setIconSize(sz);
|
||||
ui->buttonAssign->setIconSize(sz);
|
||||
ui->buttonUnset ->setIconSize(sz);
|
||||
ui->buttonUnset->setIconSize(sz);
|
||||
}
|
||||
return QWidget::event(e);
|
||||
}
|
||||
@@ -63,19 +65,16 @@ bool MaterialsEditor::event(QEvent * e) {
|
||||
void MaterialsEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Material * MaterialsEditor::currentMaterial() {
|
||||
if (!view) return 0;
|
||||
int ind = ui->comboMaterial->currentIndex();
|
||||
QVector<Material*> mats = view->scene()->getMaterials();
|
||||
int ind = ui->comboMaterial->currentIndex();
|
||||
QVector<Material *> mats = view->scene()->getMaterials();
|
||||
if (ind < 0 || ind >= mats.size()) return 0;
|
||||
return mats[ind];
|
||||
}
|
||||
@@ -87,7 +86,7 @@ void MaterialsEditor::selectMaterial(Material * m) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < ui->comboMaterial->count(); ++i) {
|
||||
if ((Material*)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m) {
|
||||
if ((Material *)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m) {
|
||||
ui->comboMaterial->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
@@ -98,8 +97,7 @@ void MaterialsEditor::selectMaterial(Material * m) {
|
||||
int MaterialsEditor::indexByMaterial(Material * m) {
|
||||
if (!m) return -1;
|
||||
for (int i = 0; i < ui->comboMaterial->count(); ++i) {
|
||||
if ((Material*)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m)
|
||||
return i;
|
||||
if ((Material *)(ui->comboMaterial->itemData(i, Qt::UserRole + 1).value<quintptr>()) == m) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -107,7 +105,7 @@ int MaterialsEditor::indexByMaterial(Material * m) {
|
||||
|
||||
void MaterialsEditor::selectionChanged() {
|
||||
if (!view) return;
|
||||
//qDebug() << "selectionChanged";
|
||||
// qDebug() << "selectionChanged";
|
||||
ObjectBase * o = view->selectedObject();
|
||||
if (o) selectMaterial(o->material());
|
||||
}
|
||||
@@ -121,7 +119,7 @@ void MaterialsEditor::materialsChanged() {
|
||||
Material * cm = currentMaterial();
|
||||
ui->comboMaterial->clear();
|
||||
if (!view) return;
|
||||
QVector<Material*> mats = view->scene()->getMaterials();
|
||||
QVector<Material *> mats = view->scene()->getMaterials();
|
||||
for (int i = 0; i < mats.size(); ++i) {
|
||||
Material * m = mats[i];
|
||||
ui->comboMaterial->addItem(QString("[%1] " + m->name).arg(i + 1), QVariant(m->name));
|
||||
@@ -129,15 +127,14 @@ void MaterialsEditor::materialsChanged() {
|
||||
ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m))));
|
||||
if (cm == m) ui->comboMaterial->setCurrentIndex(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MaterialsEditor::materialThumbnailCreated(Material * m) {
|
||||
//qDebug() << "materialThumbnailCreated" << m;
|
||||
// qDebug() << "materialThumbnailCreated" << m;
|
||||
int i = indexByMaterial(m);
|
||||
if (i < 0 || !view) return;
|
||||
//qDebug() << "materialThumbnailCreated set to" << i;
|
||||
// qDebug() << "materialThumbnailCreated set to" << i;
|
||||
ui->comboMaterial->setItemIcon(i, QIcon(QPixmap::fromImage(view->materialThumbnail(m))));
|
||||
}
|
||||
|
||||
@@ -172,10 +169,10 @@ void MaterialsEditor::on_buttonClone_clicked() {
|
||||
Material * curm = currentMaterial();
|
||||
if (!curm) return;
|
||||
Material * m = view->scene()->newMaterial(curm->name);
|
||||
QString nm = m->name;
|
||||
*m = *curm;
|
||||
m->name = nm;
|
||||
m->_changed = true;
|
||||
QString nm = m->name;
|
||||
*m = *curm;
|
||||
m->name = nm;
|
||||
m->_changed = true;
|
||||
materialsChanged();
|
||||
selectMaterial(m);
|
||||
}
|
||||
@@ -192,9 +189,9 @@ void MaterialsEditor::on_buttonDelete_clicked() {
|
||||
|
||||
void MaterialsEditor::on_buttonAssign_clicked() {
|
||||
if (!view) return;
|
||||
Material * m = currentMaterial();
|
||||
Material * m = currentMaterial();
|
||||
ObjectBaseList ol = view->selectedObjects();
|
||||
foreach (ObjectBase * o, ol)
|
||||
foreach(ObjectBase * o, ol)
|
||||
o->setMaterial(m, true);
|
||||
}
|
||||
|
||||
@@ -202,6 +199,6 @@ void MaterialsEditor::on_buttonAssign_clicked() {
|
||||
void MaterialsEditor::on_buttonUnset_clicked() {
|
||||
if (!view) return;
|
||||
ObjectBaseList ol = view->selectedObjects();
|
||||
foreach (ObjectBase * o, ol)
|
||||
foreach(ObjectBase * o, ol)
|
||||
o->setMaterial(0, true);
|
||||
}
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
/*
|
||||
QGL MaterialsEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL MaterialsEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef MATERIALS_EDITOR_H
|
||||
#define MATERIALS_EDITOR_H
|
||||
|
||||
#include <QFileDialog>
|
||||
#include "gltypes.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
namespace Ui {
|
||||
class MaterialsEditor;
|
||||
class MaterialsEditor;
|
||||
}
|
||||
|
||||
class MaterialsEditor: public QWidget
|
||||
{
|
||||
class MaterialsEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MaterialsEditor(QWidget * parent = 0);
|
||||
|
||||
@@ -60,7 +61,6 @@ private slots:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // MATERIALS_EDITOR_H
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
/*
|
||||
QGL ObjectEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL ObjectEditor
|
||||
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 "object_editor.h"
|
||||
#include "ui_object_editor.h"
|
||||
|
||||
#include "qglview.h"
|
||||
#include <spinslider.h>
|
||||
#include "ui_object_editor.h"
|
||||
|
||||
#include <scroll_spin_box.h>
|
||||
#include <spinslider.h>
|
||||
|
||||
|
||||
ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
|
||||
ui = new Ui::ObjectEditor();
|
||||
ui->setupUi(this);
|
||||
view = 0;
|
||||
active = true;
|
||||
view = 0;
|
||||
active = true;
|
||||
ignore_next = false;
|
||||
on_comboLightType_currentIndexChanged(0);
|
||||
ui->widgetMain->setEnabled(false);
|
||||
@@ -35,31 +37,27 @@ ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
|
||||
ui->spinAimDist->hide();
|
||||
|
||||
QObjectList ol;
|
||||
ol << ui->spinPosX << ui->spinPosY << ui->spinPosZ <<
|
||||
ui->spinRotationX << ui->spinRotationY << ui->spinRotationZ <<
|
||||
ui->spinScaleX << ui->spinScaleY << ui->spinScaleZ;
|
||||
foreach (QObject * o, ol)
|
||||
ol << ui->spinPosX << ui->spinPosY << ui->spinPosZ << ui->spinRotationX << ui->spinRotationY << ui->spinRotationZ << ui->spinScaleX
|
||||
<< ui->spinScaleY << ui->spinScaleZ;
|
||||
foreach(QObject * o, ol)
|
||||
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinChanged(double)));
|
||||
|
||||
ol.clear();
|
||||
ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear <<
|
||||
ui->spinLightDecayQuadratic << ui->spinLightAngleStart << ui->spinLightAngleEnd <<
|
||||
ui->spinAimDist;
|
||||
foreach (QObject * o, ol)
|
||||
ol << ui->spinLightIntensity << ui->spinLightDecayConst << ui->spinLightDecayLinear << ui->spinLightDecayQuadratic
|
||||
<< ui->spinLightAngleStart << ui->spinLightAngleEnd << ui->spinAimDist;
|
||||
foreach(QObject * o, ol)
|
||||
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double)));
|
||||
|
||||
ol.clear();
|
||||
ol << ui->spinCameraFOV << ui->spinCameraDepthStart << ui->spinCameraRoll << ui->spinAimDist;
|
||||
foreach (QObject * o, ol)
|
||||
foreach(QObject * o, ol)
|
||||
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinCameraChanged(double)));
|
||||
|
||||
ol.clear();
|
||||
ol << ui->checkVisible << ui->checkCastShadows << ui->checkReceiveShadows <<
|
||||
ui->checkAcceptLight << ui->checkAcceptFog <<
|
||||
ui->checkCameraMirrorX << ui->checkCameraMirrorY;
|
||||
foreach (QObject * o, ol)
|
||||
ol << ui->checkVisible << ui->checkCastShadows << ui->checkReceiveShadows << ui->checkAcceptLight << ui->checkAcceptFog
|
||||
<< ui->checkCameraMirrorX << ui->checkCameraMirrorY;
|
||||
foreach(QObject * o, ol)
|
||||
connect(o, SIGNAL(toggled(bool)), this, SLOT(checkChanged(bool)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -75,11 +73,8 @@ void ObjectEditor::assignQGLView(QGLView * v) {
|
||||
void ObjectEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,10 +97,10 @@ void ObjectEditor::selectionChanged() {
|
||||
return;
|
||||
}
|
||||
bool hl = !view->selectedLights().isEmpty(), hc = !view->selectedCameras().isEmpty();
|
||||
ui->groupLight ->setVisible(hl);
|
||||
ui->groupCamera ->setVisible(hc);
|
||||
ui->groupLight->setVisible(hl);
|
||||
ui->groupCamera->setVisible(hc);
|
||||
ui->labelAimDist->setVisible(hl || hc);
|
||||
ui->spinAimDist ->setVisible(hl || hc);
|
||||
ui->spinAimDist->setVisible(hl || hc);
|
||||
ui->labelTitle->setText(tr("[%1 objects]").arg(sol.size()));
|
||||
}
|
||||
|
||||
@@ -131,12 +126,12 @@ void ObjectEditor::setObject(ObjectBase * o) {
|
||||
bool is_l = o->type() == ObjectBase::glLight;
|
||||
bool is_c = o->type() == ObjectBase::glCamera;
|
||||
ui->labelAimDist->setVisible(is_l || is_c);
|
||||
ui->spinAimDist ->setVisible(is_l || is_c);
|
||||
ui->groupLight ->setVisible(is_l);
|
||||
ui->groupCamera ->setVisible(is_c);
|
||||
ui->spinAimDist->setVisible(is_l || is_c);
|
||||
ui->groupLight->setVisible(is_l);
|
||||
ui->groupCamera->setVisible(is_c);
|
||||
if (is_l) {
|
||||
Light * l = globject_cast<Light * >(o);
|
||||
//bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone;
|
||||
Light * l = globject_cast<Light *>(o);
|
||||
// bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone;
|
||||
ui->comboLightType->setCurrentIndex(l->light_type);
|
||||
ui->spinLightIntensity->setValue(l->intensity);
|
||||
ui->spinLightDecayConst->setValue(l->decay_const);
|
||||
@@ -148,7 +143,7 @@ void ObjectEditor::setObject(ObjectBase * o) {
|
||||
on_comboLightType_currentIndexChanged(ui->comboLightType->currentIndex());
|
||||
}
|
||||
if (is_c) {
|
||||
Camera * c = globject_cast<Camera * >(o);
|
||||
Camera * c = globject_cast<Camera *>(o);
|
||||
ui->checkCameraMirrorX->setChecked(c->isMirrorX());
|
||||
ui->checkCameraMirrorY->setChecked(c->isMirrorY());
|
||||
ui->spinCameraFOV->setValue(c->FOV());
|
||||
@@ -161,26 +156,24 @@ void ObjectEditor::setObject(ObjectBase * o) {
|
||||
|
||||
|
||||
void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) {
|
||||
if (ui->spinLightAngleEnd->value() < v)
|
||||
ui->spinLightAngleEnd->setValue(v);
|
||||
if (ui->spinLightAngleEnd->value() < v) ui->spinLightAngleEnd->setValue(v);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) {
|
||||
if (ui->spinLightAngleStart->value() > v)
|
||||
ui->spinLightAngleStart->setValue(v);
|
||||
if (ui->spinLightAngleStart->value() > v) ui->spinLightAngleStart->setValue(v);
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_comboLightType_currentIndexChanged(int index) {
|
||||
bool ang = (index == Light::Cone);
|
||||
ui->labelLightAngle ->setVisible(ang);
|
||||
ui->labelLightAngle->setVisible(ang);
|
||||
ui->labelLightAngleDash->setVisible(ang);
|
||||
ui->spinLightAngleStart->setVisible(ang);
|
||||
ui->spinLightAngleEnd ->setVisible(ang);
|
||||
ui->spinLightAngleEnd->setVisible(ang);
|
||||
if (!view || !active) return;
|
||||
QList<Light*> sll = view->selectedLights();
|
||||
foreach (Light * o, sll) {
|
||||
QList<Light *> sll = view->selectedLights();
|
||||
foreach(Light * o, sll) {
|
||||
o->light_type = (Light::Type)index;
|
||||
o->apply();
|
||||
}
|
||||
@@ -190,10 +183,10 @@ void ObjectEditor::on_comboLightType_currentIndexChanged(int index) {
|
||||
void ObjectEditor::on_buttonColor_colorChanged(const QColor & v) {
|
||||
if (!view || !active) return;
|
||||
ObjectBaseList sol = view->selectedObjects();
|
||||
foreach (ObjectBase * o, sol)
|
||||
foreach(ObjectBase * o, sol)
|
||||
o->setColor(v);
|
||||
QList<Light*> sll = view->selectedLights();
|
||||
foreach (Light * o, sll)
|
||||
QList<Light *> sll = view->selectedLights();
|
||||
foreach(Light * o, sll)
|
||||
o->apply();
|
||||
}
|
||||
|
||||
@@ -201,17 +194,17 @@ void ObjectEditor::on_buttonColor_colorChanged(const QColor & v) {
|
||||
void ObjectEditor::spinChanged(double v) {
|
||||
if (!view || !active) return;
|
||||
ObjectBaseList sol = view->selectedObjects(true);
|
||||
QObject * s = sender();
|
||||
foreach (ObjectBase * o, sol) {
|
||||
if (s == ui->spinPosX ) o->setPosX (v);
|
||||
if (s == ui->spinPosY ) o->setPosY (v);
|
||||
if (s == ui->spinPosZ ) o->setPosZ (v);
|
||||
QObject * s = sender();
|
||||
foreach(ObjectBase * o, sol) {
|
||||
if (s == ui->spinPosX) o->setPosX(v);
|
||||
if (s == ui->spinPosY) o->setPosY(v);
|
||||
if (s == ui->spinPosZ) o->setPosZ(v);
|
||||
if (s == ui->spinRotationX) o->setRotationX(v);
|
||||
if (s == ui->spinRotationY) o->setRotationY(v);
|
||||
if (s == ui->spinRotationZ) o->setRotationZ(v);
|
||||
if (s == ui->spinScaleX ) o->setScaleX (v);
|
||||
if (s == ui->spinScaleY ) o->setScaleY (v);
|
||||
if (s == ui->spinScaleZ ) o->setScaleZ (v);
|
||||
if (s == ui->spinScaleX) o->setScaleX(v);
|
||||
if (s == ui->spinScaleY) o->setScaleY(v);
|
||||
if (s == ui->spinScaleZ) o->setScaleZ(v);
|
||||
}
|
||||
ignore_next = true;
|
||||
}
|
||||
@@ -219,16 +212,16 @@ void ObjectEditor::spinChanged(double v) {
|
||||
|
||||
void ObjectEditor::spinLightChanged(double v) {
|
||||
if (!view || !active) return;
|
||||
QList<Light*> sll = view->selectedLights();
|
||||
QObject * s = sender();
|
||||
foreach (Light * o, sll) {
|
||||
if (s == ui->spinLightIntensity ) o->intensity = v;
|
||||
if (s == ui->spinLightDecayConst ) o->decay_const = v;
|
||||
if (s == ui->spinLightDecayLinear ) o->decay_linear = v;
|
||||
QList<Light *> sll = view->selectedLights();
|
||||
QObject * s = sender();
|
||||
foreach(Light * o, sll) {
|
||||
if (s == ui->spinLightIntensity) o->intensity = v;
|
||||
if (s == ui->spinLightDecayConst) o->decay_const = v;
|
||||
if (s == ui->spinLightDecayLinear) o->decay_linear = v;
|
||||
if (s == ui->spinLightDecayQuadratic) o->decay_quadratic = v;
|
||||
if (s == ui->spinLightAngleStart ) o->angle_start = v;
|
||||
if (s == ui->spinLightAngleEnd ) o->angle_end = v;
|
||||
if (s == ui->spinAimDist ) o->setDistance(v);
|
||||
if (s == ui->spinLightAngleStart) o->angle_start = v;
|
||||
if (s == ui->spinLightAngleEnd) o->angle_end = v;
|
||||
if (s == ui->spinAimDist) o->setDistance(v);
|
||||
o->apply();
|
||||
}
|
||||
ignore_next = true;
|
||||
@@ -237,13 +230,13 @@ void ObjectEditor::spinLightChanged(double v) {
|
||||
|
||||
void ObjectEditor::spinCameraChanged(double v) {
|
||||
if (!view || !active) return;
|
||||
QList<Camera*> scl = view->selectedCameras();
|
||||
QObject * s = sender();
|
||||
foreach (Camera * o, scl) {
|
||||
if (s == ui->spinCameraFOV ) o->setFOV (v);
|
||||
if (s == ui->spinCameraRoll ) o->setAngleRoll (v);
|
||||
QList<Camera *> scl = view->selectedCameras();
|
||||
QObject * s = sender();
|
||||
foreach(Camera * o, scl) {
|
||||
if (s == ui->spinCameraFOV) o->setFOV(v);
|
||||
if (s == ui->spinCameraRoll) o->setAngleRoll(v);
|
||||
if (s == ui->spinCameraDepthStart) o->setDepthStart(v);
|
||||
if (s == ui->spinAimDist ) o->setDistance (v);
|
||||
if (s == ui->spinAimDist) o->setDistance(v);
|
||||
}
|
||||
ignore_next = true;
|
||||
}
|
||||
@@ -251,18 +244,18 @@ void ObjectEditor::spinCameraChanged(double v) {
|
||||
|
||||
void ObjectEditor::checkChanged(bool v) {
|
||||
if (!view || !active) return;
|
||||
ObjectBaseList sol = view->selectedObjects();
|
||||
QList<Camera*> scl = view->selectedCameras();
|
||||
QObject * s = sender();
|
||||
foreach (ObjectBase * o, sol) {
|
||||
if (s == ui->checkVisible ) o->setVisible (v);
|
||||
if (s == ui->checkCastShadows ) o->setCastShadows (v);
|
||||
ObjectBaseList sol = view->selectedObjects();
|
||||
QList<Camera *> scl = view->selectedCameras();
|
||||
QObject * s = sender();
|
||||
foreach(ObjectBase * o, sol) {
|
||||
if (s == ui->checkVisible) o->setVisible(v);
|
||||
if (s == ui->checkCastShadows) o->setCastShadows(v);
|
||||
if (s == ui->checkReceiveShadows) o->setReceiveShadows(v);
|
||||
if (s == ui->checkAcceptLight ) o->setAcceptLight (v);
|
||||
if (s == ui->checkAcceptFog ) o->setAcceptFog (v);
|
||||
if (s == ui->checkAcceptLight) o->setAcceptLight(v);
|
||||
if (s == ui->checkAcceptFog) o->setAcceptFog(v);
|
||||
}
|
||||
foreach (Camera * o, scl) {
|
||||
if (s == ui->checkCameraMirrorX ) o->setMirrorX(v);
|
||||
if (s == ui->checkCameraMirrorY ) o->setMirrorY(v);
|
||||
foreach(Camera * o, scl) {
|
||||
if (s == ui->checkCameraMirrorX) o->setMirrorX(v);
|
||||
if (s == ui->checkCameraMirrorY) o->setMirrorY(v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
/*
|
||||
QGL ObjectEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL ObjectEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef OBJECT_EDITOR_H
|
||||
#define OBJECT_EDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "globject.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class ObjectEditor;
|
||||
class ObjectEditor;
|
||||
}
|
||||
|
||||
class ObjectEditor: public QWidget
|
||||
{
|
||||
class ObjectEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ObjectEditor(QWidget * parent = 0);
|
||||
|
||||
@@ -48,7 +49,7 @@ private slots:
|
||||
void on_spinLightAngleEnd_valueChanged(double v);
|
||||
|
||||
void on_comboLightType_currentIndexChanged(int index);
|
||||
void on_buttonColor_colorChanged(const QColor &v);
|
||||
void on_buttonColor_colorChanged(const QColor & v);
|
||||
void spinChanged(double v);
|
||||
void spinLightChanged(double v);
|
||||
void spinCameraChanged(double v);
|
||||
@@ -56,7 +57,6 @@ private slots:
|
||||
|
||||
signals:
|
||||
void changed();
|
||||
|
||||
};
|
||||
|
||||
#endif // OBJECT_EDITOR_H
|
||||
|
||||
@@ -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>());
|
||||
|
||||
@@ -1,35 +1,37 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PRIMITIVEEDITOR_H
|
||||
#define PRIMITIVEEDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
namespace Ui {
|
||||
class PrimitiveEditor;
|
||||
}
|
||||
|
||||
|
||||
class PrimitiveEditor : public QWidget {
|
||||
class PrimitiveEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum PrimitiveType {
|
||||
Plane,
|
||||
@@ -42,7 +44,7 @@ public:
|
||||
};
|
||||
Q_ENUMS(PrimitiveType)
|
||||
|
||||
explicit PrimitiveEditor(QWidget *parent = nullptr);
|
||||
explicit PrimitiveEditor(QWidget * parent = nullptr);
|
||||
~PrimitiveEditor();
|
||||
|
||||
void assignQGLView(QGLView * v);
|
||||
@@ -51,9 +53,9 @@ protected:
|
||||
Mesh * createMesh(QVariantList & params);
|
||||
void showEditors();
|
||||
|
||||
Ui::PrimitiveEditor *ui;
|
||||
Ui::PrimitiveEditor * ui;
|
||||
QGLView * view;
|
||||
QMap<PrimitiveType, QList<QWidget *> > editors;
|
||||
QMap<PrimitiveType, QList<QWidget *>> editors;
|
||||
QList<QWidget *> all_editors;
|
||||
bool can_replace;
|
||||
|
||||
|
||||
@@ -1,57 +1,63 @@
|
||||
/*
|
||||
QGL PropertyEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL PropertyEditor
|
||||
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 "propertyeditor.h"
|
||||
|
||||
#include "clineedit.h"
|
||||
#include "colorbutton.h"
|
||||
#include "qpointedit.h"
|
||||
#include "qrectedit.h"
|
||||
#include "colorbutton.h"
|
||||
#include "clineedit.h"
|
||||
#include <QPainter>
|
||||
#include <QCheckBox>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & index) const {
|
||||
QWidget * w = nullptr;
|
||||
int type = 0;
|
||||
QWidget * w = nullptr;
|
||||
int type = 0;
|
||||
QVariant value = index.data(Qt::UserRole);
|
||||
if (index.data(Qt::UserRole + 2).toString() == "__flags") return nullptr;
|
||||
if (index.data(Qt::UserRole + 1).toString() == "__flag") {
|
||||
qulonglong key = index.data(Qt::UserRole).toULongLong();
|
||||
value = index.parent().data(Qt::UserRole);
|
||||
//QMetaProperty prop = index.parent().data(Qt::UserRole + 1).value<QMetaProperty>();
|
||||
w = new QCheckBox(parent); type = 14; ((QCheckBox*)w)->setChecked(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0));
|
||||
((QCheckBox*)w)->setText("0x" + QString::number(key, 16).toUpper());
|
||||
connect((QCheckBox*)w, SIGNAL(clicked(bool)), this, SLOT(changedFlag()));
|
||||
//qDebug() << prop.enumerator().name();
|
||||
value = index.parent().data(Qt::UserRole);
|
||||
// QMetaProperty prop = index.parent().data(Qt::UserRole + 1).value<QMetaProperty>();
|
||||
w = new QCheckBox(parent);
|
||||
type = 14;
|
||||
((QCheckBox *)w)->setChecked(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0));
|
||||
((QCheckBox *)w)->setText("0x" + QString::number(key, 16).toUpper());
|
||||
connect((QCheckBox *)w, SIGNAL(clicked(bool)), this, SLOT(changedFlag()));
|
||||
// qDebug() << prop.enumerator().name();
|
||||
} else {
|
||||
if (value.canConvert<PropertyValuePair>()) {
|
||||
PropertyValuePair prop = value.value<PropertyValuePair>();
|
||||
if (prop.first.isEnumType()) {
|
||||
w = new QComboBox(parent); type = 13; ((QComboBox*)w)->setCurrentIndex(value.toInt());
|
||||
w = new QComboBox(parent);
|
||||
type = 13;
|
||||
((QComboBox *)w)->setCurrentIndex(value.toInt());
|
||||
w->setProperty("__prop", QVariant::fromValue<QMetaProperty>(prop.first));
|
||||
QMetaEnum menum = prop.first.enumerator();
|
||||
for (int i = 0; i < menum.keyCount(); ++i) {
|
||||
((QComboBox*)w)->addItem(QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")", menum.value(i));
|
||||
if (menum.value(i) == prop.second.toInt())
|
||||
((QComboBox*)w)->setCurrentIndex(i);
|
||||
((QComboBox *)w)
|
||||
->addItem(QString(menum.key(i)) + " (0x" + QString::number(menum.value(i), 16).toUpper() + ")", menum.value(i));
|
||||
if (menum.value(i) == prop.second.toInt()) ((QComboBox *)w)->setCurrentIndex(i);
|
||||
}
|
||||
connect((QComboBox*)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
|
||||
connect((QComboBox *)w, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()));
|
||||
}
|
||||
} else {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
@@ -64,73 +70,129 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
|
||||
#else
|
||||
case QMetaType::Int:
|
||||
#endif
|
||||
w = new QSpinBox(parent); type = 2; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
|
||||
w = new QSpinBox(parent);
|
||||
type = 2;
|
||||
((QSpinBox *)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF);
|
||||
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::UInt:
|
||||
#else
|
||||
case QMetaType::UInt:
|
||||
#endif
|
||||
w = new QSpinBox(parent); type = 3; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
|
||||
w = new QSpinBox(parent);
|
||||
type = 3;
|
||||
((QSpinBox *)w)->setRange(0, 0xFFFFFFFF);
|
||||
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::LongLong:
|
||||
#else
|
||||
case QMetaType::LongLong:
|
||||
#endif
|
||||
w = new QSpinBox(parent); type = 4; ((QSpinBox*)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
|
||||
w = new QSpinBox(parent);
|
||||
type = 4;
|
||||
((QSpinBox *)w)->setRange(-0x7FFFFFFF, 0x7FFFFFFF);
|
||||
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::ULongLong:
|
||||
#else
|
||||
case QMetaType::ULongLong:
|
||||
#endif
|
||||
w = new QSpinBox(parent); type = 5; ((QSpinBox*)w)->setRange(0, 0xFFFFFFFF); connect((QSpinBox*)w, SIGNAL(valueChanged(int)), this, SLOT(changed())); break;
|
||||
w = new QSpinBox(parent);
|
||||
type = 5;
|
||||
((QSpinBox *)w)->setRange(0, 0xFFFFFFFF);
|
||||
connect((QSpinBox *)w, SIGNAL(valueChanged(int)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Double:
|
||||
#else
|
||||
case QMetaType::Double:
|
||||
#endif
|
||||
w = new QDoubleSpinBox(parent); type = 6; ((QDoubleSpinBox*)w)->setRange(-999999999, 999999999); ((QDoubleSpinBox*)w)->setDecimals(3); connect((QDoubleSpinBox*)w, SIGNAL(valueChanged(double)), this, SLOT(changed())); break;
|
||||
w = new QDoubleSpinBox(parent);
|
||||
type = 6;
|
||||
((QDoubleSpinBox *)w)->setRange(-999999999, 999999999);
|
||||
((QDoubleSpinBox *)w)->setDecimals(3);
|
||||
connect((QDoubleSpinBox *)w, SIGNAL(valueChanged(double)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Bool:
|
||||
#else
|
||||
case QMetaType::Bool:
|
||||
#endif
|
||||
w = new QCheckBox(parent); type = 7; ((QCheckBox*)w)->setChecked(value.toBool()); connect((QCheckBox*)w, SIGNAL(toggled(bool)), this, SLOT(changed())); break;
|
||||
w = new QCheckBox(parent);
|
||||
type = 7;
|
||||
((QCheckBox *)w)->setChecked(value.toBool());
|
||||
connect((QCheckBox *)w, SIGNAL(toggled(bool)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Color:
|
||||
#else
|
||||
case QMetaType::QColor:
|
||||
#endif
|
||||
w = new ColorButton(parent); type = 8; ((ColorButton*)w)->setUseAlphaChannel(true); ((ColorButton*)w)->setColor(value.value<QColor>()); connect((ColorButton*)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed())); break;
|
||||
w = new ColorButton(parent);
|
||||
type = 8;
|
||||
((ColorButton *)w)->setUseAlphaChannel(true);
|
||||
((ColorButton *)w)->setColor(value.value<QColor>());
|
||||
connect((ColorButton *)w, SIGNAL(colorChanged(QColor)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Point:
|
||||
#else
|
||||
case QMetaType::QPoint:
|
||||
#endif
|
||||
w = new QPointEdit(parent); type = 9; ((QPointEdit*)w)->setDecimals(0); ((QPointEdit*)w)->setValue(QPointF(value.toPoint())); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break;
|
||||
w = new QPointEdit(parent);
|
||||
type = 9;
|
||||
((QPointEdit *)w)->setDecimals(0);
|
||||
((QPointEdit *)w)->setValue(QPointF(value.toPoint()));
|
||||
connect((QPointEdit *)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::PointF:
|
||||
#else
|
||||
case QMetaType::QPointF:
|
||||
#endif
|
||||
w = new QPointEdit(parent); type = 10; ((QPointEdit*)w)->setDecimals(3); ((QPointEdit*)w)->setValue(value.toPointF()); connect((QPointEdit*)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed())); break;
|
||||
w = new QPointEdit(parent);
|
||||
type = 10;
|
||||
((QPointEdit *)w)->setDecimals(3);
|
||||
((QPointEdit *)w)->setValue(value.toPointF());
|
||||
connect((QPointEdit *)w, SIGNAL(valueChanged(QPointF)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Rect:
|
||||
#else
|
||||
case QMetaType::QRect:
|
||||
#endif
|
||||
w = new QRectEdit(parent); type = 11; ((QRectEdit*)w)->setDecimals(0); ((QRectEdit*)w)->setValue(QRectF(value.toRect())); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break;
|
||||
w = new QRectEdit(parent);
|
||||
type = 11;
|
||||
((QRectEdit *)w)->setDecimals(0);
|
||||
((QRectEdit *)w)->setValue(QRectF(value.toRect()));
|
||||
connect((QRectEdit *)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::RectF:
|
||||
#else
|
||||
case QMetaType::QRectF:
|
||||
#endif
|
||||
w = new QRectEdit(parent); type = 12; ((QRectEdit*)w)->setDecimals(3); ((QRectEdit*)w)->setValue(value.toRectF()); connect((QRectEdit*)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed())); break;
|
||||
w = new QRectEdit(parent);
|
||||
type = 12;
|
||||
((QRectEdit *)w)->setDecimals(3);
|
||||
((QRectEdit *)w)->setValue(value.toRectF());
|
||||
connect((QRectEdit *)w, SIGNAL(valueChanged(QRectF)), this, SLOT(changed()));
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::String: default:
|
||||
case QVariant::String:
|
||||
default:
|
||||
#else
|
||||
case QMetaType::QString: default:
|
||||
case QMetaType::QString:
|
||||
default:
|
||||
#endif
|
||||
w = new CLineEdit(parent); type = 1; ((CLineEdit*)w)->setDefaultText(value.toString()); connect((CLineEdit*)w, SIGNAL(textChanged(QString)), this, SLOT(changed())); break;
|
||||
w = new CLineEdit(parent);
|
||||
type = 1;
|
||||
((CLineEdit *)w)->setDefaultText(value.toString());
|
||||
connect((CLineEdit *)w, SIGNAL(textChanged(QString)), this, SLOT(changed()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -147,15 +209,18 @@ QWidget * Delegate::widgetForProperty(QWidget * parent, const QModelIndex & inde
|
||||
void Delegate::setWidgetProperty(QWidget * w, const QVariant & value) const {
|
||||
if (w == 0) return;
|
||||
switch (w->property("__type").toInt()) {
|
||||
case 1: ((CLineEdit*)w)->setText(value.toString()); break;
|
||||
case 2: case 3: case 4: case 5: ((QSpinBox*)w)->setValue(value.toInt()); break;
|
||||
case 6: ((QDoubleSpinBox*)w)->setValue(value.toDouble()); break;
|
||||
case 7: ((QCheckBox*)w)->setChecked(value.toBool()); break;
|
||||
case 8: ((ColorButton*)w)->setColor(value.value<QColor>()); break;
|
||||
case 9: ((QPointEdit*)w)->setValue(value.value<QPoint>()); break;
|
||||
case 10: ((QPointEdit*)w)->setValue(value.value<QPointF>()); break;
|
||||
case 11: ((QRectEdit*)w)->setValue(value.value<QRect>()); break;
|
||||
case 12: ((QRectEdit*)w)->setValue(value.value<QRectF>()); break;
|
||||
case 1: ((CLineEdit *)w)->setText(value.toString()); break;
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5: ((QSpinBox *)w)->setValue(value.toInt()); break;
|
||||
case 6: ((QDoubleSpinBox *)w)->setValue(value.toDouble()); break;
|
||||
case 7: ((QCheckBox *)w)->setChecked(value.toBool()); break;
|
||||
case 8: ((ColorButton *)w)->setColor(value.value<QColor>()); break;
|
||||
case 9: ((QPointEdit *)w)->setValue(value.value<QPoint>()); break;
|
||||
case 10: ((QPointEdit *)w)->setValue(value.value<QPointF>()); break;
|
||||
case 11: ((QRectEdit *)w)->setValue(value.value<QRect>()); break;
|
||||
case 12: ((QRectEdit *)w)->setValue(value.value<QRectF>()); break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,19 +228,22 @@ void Delegate::setWidgetProperty(QWidget * w, const QVariant & value) const {
|
||||
const QVariant Delegate::widgetProperty(QWidget * w) const {
|
||||
if (w == 0) return QVariant();
|
||||
switch (w->property("__type").toInt()) {
|
||||
case 1: return QVariant::fromValue<QString>(((CLineEdit*)w)->text()); break;
|
||||
case 2: return QVariant::fromValue<int>(((QSpinBox*)w)->value()); break;
|
||||
case 3: return QVariant::fromValue<uint>(((QSpinBox*)w)->value()); break;
|
||||
case 4: return QVariant::fromValue<qlonglong>(((QSpinBox*)w)->value()); break;
|
||||
case 5: return QVariant::fromValue<qulonglong>(((QSpinBox*)w)->value()); break;
|
||||
case 6: return QVariant::fromValue<double>(((QDoubleSpinBox*)w)->value()); break;
|
||||
case 7: return QVariant::fromValue<bool>(((QCheckBox*)w)->isChecked()); break;
|
||||
case 8: return QVariant::fromValue<QColor>(((ColorButton*)w)->color()); break;
|
||||
case 9: return QVariant::fromValue<QPoint>(((QPointEdit*)w)->value().toPoint()); break;
|
||||
case 10: return QVariant::fromValue<QPointF>(((QPointEdit*)w)->value()); break;
|
||||
case 11: return QVariant::fromValue<QRect>(((QRectEdit*)w)->value().toRect()); break;
|
||||
case 12: return QVariant::fromValue<QRectF>(((QRectEdit*)w)->value()); break;
|
||||
case 13: return QVariant::fromValue<PropertyValuePair>(PropertyValuePair(w->property("__prop").value<QMetaProperty>(), ((QComboBox*)w)->itemData(((QComboBox*)w)->currentIndex()))); break;
|
||||
case 1: return QVariant::fromValue<QString>(((CLineEdit *)w)->text()); break;
|
||||
case 2: return QVariant::fromValue<int>(((QSpinBox *)w)->value()); break;
|
||||
case 3: return QVariant::fromValue<uint>(((QSpinBox *)w)->value()); break;
|
||||
case 4: return QVariant::fromValue<qlonglong>(((QSpinBox *)w)->value()); break;
|
||||
case 5: return QVariant::fromValue<qulonglong>(((QSpinBox *)w)->value()); break;
|
||||
case 6: return QVariant::fromValue<double>(((QDoubleSpinBox *)w)->value()); break;
|
||||
case 7: return QVariant::fromValue<bool>(((QCheckBox *)w)->isChecked()); break;
|
||||
case 8: return QVariant::fromValue<QColor>(((ColorButton *)w)->color()); break;
|
||||
case 9: return QVariant::fromValue<QPoint>(((QPointEdit *)w)->value().toPoint()); break;
|
||||
case 10: return QVariant::fromValue<QPointF>(((QPointEdit *)w)->value()); break;
|
||||
case 11: return QVariant::fromValue<QRect>(((QRectEdit *)w)->value().toRect()); break;
|
||||
case 12: return QVariant::fromValue<QRectF>(((QRectEdit *)w)->value()); break;
|
||||
case 13:
|
||||
return QVariant::fromValue<PropertyValuePair>(
|
||||
PropertyValuePair(w->property("__prop").value<QMetaProperty>(), ((QComboBox *)w)->itemData(((QComboBox *)w)->currentIndex())));
|
||||
break;
|
||||
default: return QVariant(); break;
|
||||
}
|
||||
return QVariant();
|
||||
@@ -183,35 +251,44 @@ const QVariant Delegate::widgetProperty(QWidget * w) const {
|
||||
|
||||
|
||||
void Delegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const {
|
||||
if (index.data(Qt::UserRole + 1).toString() != "__flag")
|
||||
model->setData(index, widgetProperty(editor), Qt::UserRole);
|
||||
if (index.data(Qt::UserRole + 1).toString() != "__flag") model->setData(index, widgetProperty(editor), Qt::UserRole);
|
||||
}
|
||||
|
||||
|
||||
void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
QStyledItemDelegate::paint(painter, option, index);
|
||||
QVariant value = index.data(Qt::UserRole);
|
||||
QStyle * style = QApplication::style();
|
||||
QStyleOption * so = 0;
|
||||
QVariant value = index.data(Qt::UserRole);
|
||||
QStyle * style = QApplication::style();
|
||||
QStyleOption * so = 0;
|
||||
QStyleOptionComplex * soc = 0;
|
||||
QString text;
|
||||
QRect rect;
|
||||
QPalette::ColorRole role = (option.state.testFlag(QStyle::State_Selected) && option.state.testFlag(QStyle::State_Active) ? QPalette::HighlightedText : QPalette::WindowText);
|
||||
QPalette::ColorRole role =
|
||||
(option.state.testFlag(QStyle::State_Selected) && option.state.testFlag(QStyle::State_Active) ? QPalette::HighlightedText
|
||||
: QPalette::WindowText);
|
||||
if (index.data(Qt::UserRole + 2).toString() == "__flags") {
|
||||
text = "0x" + QString::number(value.toInt(), 16).toUpper();
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
return;
|
||||
}
|
||||
if (index.data(Qt::UserRole + 1) == "__flag") {
|
||||
qulonglong key = index.data(Qt::UserRole).toULongLong();
|
||||
value = index.parent().data(Qt::UserRole);
|
||||
so = new QStyleOptionButton();
|
||||
so->rect = option.rect;
|
||||
so->palette = option.palette;
|
||||
qulonglong key = index.data(Qt::UserRole).toULongLong();
|
||||
value = index.parent().data(Qt::UserRole);
|
||||
so = new QStyleOptionButton();
|
||||
so->rect = option.rect;
|
||||
so->palette = option.palette;
|
||||
so->fontMetrics = option.fontMetrics;
|
||||
((QStyleOptionButton*)so)->state = (((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0) ? QStyle::State_On : QStyle::State_Off) | option.state;
|
||||
((QStyleOptionButton*)so)->text = "0x" + QString::number(key, 16).toUpper();
|
||||
((QStyleOptionButton *)so)->state =
|
||||
(((value.toULongLong() & key) == key && key != 0) || (value.toULongLong() == 0 && key == 0) ? QStyle::State_On
|
||||
: QStyle::State_Off) |
|
||||
option.state;
|
||||
((QStyleOptionButton *)so)->text = "0x" + QString::number(key, 16).toUpper();
|
||||
if (option.state.testFlag(QStyle::State_Selected))
|
||||
so->palette.setColor(QPalette::WindowText, so->palette.color(QPalette::HighlightedText));
|
||||
style->drawControl(QStyle::CE_CheckBox, so, painter);
|
||||
@@ -226,8 +303,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
break;
|
||||
}
|
||||
}
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
}
|
||||
} else {
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
@@ -241,8 +323,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::Int:
|
||||
#endif
|
||||
text.setNum(value.toInt());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::UInt:
|
||||
@@ -250,8 +337,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::UInt:
|
||||
#endif
|
||||
text.setNum(value.toUInt());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::LongLong:
|
||||
@@ -259,8 +351,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::LongLong:
|
||||
#endif
|
||||
text.setNum(value.toLongLong());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::ULongLong:
|
||||
@@ -268,8 +365,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::ULongLong:
|
||||
#endif
|
||||
text.setNum(value.toULongLong());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Double:
|
||||
@@ -277,20 +379,25 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::Double:
|
||||
#endif
|
||||
text.setNum(value.toDouble(), 'f', 3);
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Bool:
|
||||
#else
|
||||
case QMetaType::Bool:
|
||||
#endif
|
||||
so = new QStyleOptionButton();
|
||||
so->rect = option.rect;
|
||||
so->state = option.state;
|
||||
so->palette = option.palette;
|
||||
so->fontMetrics = option.fontMetrics;
|
||||
((QStyleOptionButton*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off) | option.state;
|
||||
so = new QStyleOptionButton();
|
||||
so->rect = option.rect;
|
||||
so->state = option.state;
|
||||
so->palette = option.palette;
|
||||
so->fontMetrics = option.fontMetrics;
|
||||
((QStyleOptionButton *)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off) | option.state;
|
||||
style->drawControl(QStyle::CE_CheckBox, so, painter);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
@@ -298,7 +405,7 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
#else
|
||||
case QMetaType::QColor:
|
||||
#endif
|
||||
rect = option.rect;//style->subElementRect(QStyle::QStyle::SE_FrameContents, so);
|
||||
rect = option.rect; // style->subElementRect(QStyle::QStyle::SE_FrameContents, so);
|
||||
rect.setRect(rect.x() + 3, rect.y() + 3, rect.width() - 6, rect.height() - 6);
|
||||
painter->fillRect(rect, ab);
|
||||
painter->fillRect(rect, value.value<QColor>());
|
||||
@@ -309,8 +416,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::QPoint:
|
||||
#endif
|
||||
text = pointString(value.toPoint());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::PointF:
|
||||
@@ -318,8 +430,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::QPointF:
|
||||
#endif
|
||||
text = pointString(value.toPointF());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::Rect:
|
||||
@@ -327,8 +444,13 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::QRect:
|
||||
#endif
|
||||
text = rectString(value.toRect());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::RectF:
|
||||
@@ -336,40 +458,52 @@ void Delegate::paint(QPainter * painter, const QStyleOptionViewItem & option, co
|
||||
case QMetaType::QRectF:
|
||||
#endif
|
||||
text = rectString(value.toRectF());
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, role);
|
||||
style->drawItemText(painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, text),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
text,
|
||||
role);
|
||||
break;
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
case QVariant::String: default:
|
||||
case QVariant::String:
|
||||
default:
|
||||
#else
|
||||
case QMetaType::QString: default:
|
||||
case QMetaType::QString:
|
||||
default:
|
||||
#endif
|
||||
style->drawItemText(painter, style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()),
|
||||
Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, value.toString(), role);
|
||||
style->drawItemText(
|
||||
painter,
|
||||
style->itemTextRect(option.fontMetrics, option.rect, Qt::AlignLeft | Qt::AlignVCenter, true, value.toString()),
|
||||
Qt::AlignLeft | Qt::AlignVCenter,
|
||||
option.palette,
|
||||
true,
|
||||
value.toString(),
|
||||
role);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*so = new QStyleOptionFrame();
|
||||
so->rect = option.rect;
|
||||
so->state = option.state;
|
||||
so->palette = option.palette;
|
||||
so->fontMetrics = option.fontMetrics;
|
||||
((QStyleOptionFrame*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off);
|
||||
style->drawPrimitive(QStyle::PE_PanelLineEdit, so, painter);
|
||||
style->drawPrimitive(QStyle::PE_FrameLineEdit, so, painter);
|
||||
break;*/
|
||||
/*so = new QStyleOptionFrame();
|
||||
so->rect = option.rect;
|
||||
so->state = option.state;
|
||||
so->palette = option.palette;
|
||||
so->fontMetrics = option.fontMetrics;
|
||||
((QStyleOptionFrame*)so)->state = (value.toBool() ? QStyle::State_On : QStyle::State_Off);
|
||||
style->drawPrimitive(QStyle::PE_PanelLineEdit, so, painter);
|
||||
style->drawPrimitive(QStyle::PE_FrameLineEdit, so, painter);
|
||||
break;*/
|
||||
if (so != 0) delete so;
|
||||
if (soc != 0) delete soc;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Delegate::changedFlag() {
|
||||
QAbstractItemModel * model = const_cast<QAbstractItemModel * >(cmi.model());
|
||||
model->setData(cmi, qobject_cast<QCheckBox * >(sender())->isChecked(), Qt::UserRole + 3);
|
||||
QModelIndex p = cmi.parent(), mi;
|
||||
int row = 0;
|
||||
QAbstractItemModel * model = const_cast<QAbstractItemModel *>(cmi.model());
|
||||
model->setData(cmi, qobject_cast<QCheckBox *>(sender())->isChecked(), Qt::UserRole + 3);
|
||||
QModelIndex p = cmi.parent(), mi;
|
||||
int row = 0;
|
||||
qulonglong val = 0;
|
||||
QList<QModelIndex> chldr;
|
||||
mi = model->index(row, 1, p);
|
||||
@@ -378,26 +512,24 @@ void Delegate::changedFlag() {
|
||||
model->setData(mi, !mi.data(Qt::UserRole + 4).toBool(), Qt::UserRole + 4);
|
||||
mi = model->index(++row, 1, p);
|
||||
}
|
||||
bool cc = cmi.data(Qt::UserRole + 3).toBool();
|
||||
bool cc = cmi.data(Qt::UserRole + 3).toBool();
|
||||
qulonglong cv = cmi.data(Qt::UserRole).toULongLong();
|
||||
//qDebug() << "*****";
|
||||
// qDebug() << "*****";
|
||||
if (cc && cv == 0) {
|
||||
val = 0;
|
||||
//qDebug() << "null" << cv;
|
||||
// qDebug() << "null" << cv;
|
||||
} else {
|
||||
if (!cc && cv != 0) {
|
||||
//qDebug() << "uncheck" << cv;
|
||||
// qDebug() << "uncheck" << cv;
|
||||
for (int i = 0; i < chldr.size(); ++i) {
|
||||
if (chldr[i] == cmi) continue;
|
||||
//qDebug() << (chldr[i].data(Qt::UserRole).toULongLong() & cv);
|
||||
if (chldr[i].data(Qt::UserRole).toULongLong() & cv)
|
||||
model->setData(chldr[i], false, Qt::UserRole + 3);
|
||||
// qDebug() << (chldr[i].data(Qt::UserRole).toULongLong() & cv);
|
||||
if (chldr[i].data(Qt::UserRole).toULongLong() & cv) model->setData(chldr[i], false, Qt::UserRole + 3);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < chldr.size(); ++i) {
|
||||
//qDebug() << chldr[i].data(Qt::UserRole + 3).toBool();
|
||||
if (chldr[i].data(Qt::UserRole + 3).toBool())
|
||||
val |= chldr[i].data(Qt::UserRole).toULongLong();
|
||||
// qDebug() << chldr[i].data(Qt::UserRole + 3).toBool();
|
||||
if (chldr[i].data(Qt::UserRole + 3).toBool()) val |= chldr[i].data(Qt::UserRole).toULongLong();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < chldr.size(); ++i) {
|
||||
@@ -405,25 +537,22 @@ void Delegate::changedFlag() {
|
||||
cv = chldr[i].data(Qt::UserRole).toULongLong();
|
||||
model->setData(chldr[i], ((val & cv) == cv && cv != 0) || (val == 0 && cv == 0), Qt::UserRole + 3);
|
||||
}
|
||||
//qDebug() << val;
|
||||
// qDebug() << val;
|
||||
model->setData(p, val, Qt::UserRole);
|
||||
model->setData(p.sibling(p.row(), 1), val, Qt::UserRole);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PropertyEditor::PropertyEditor(QWidget * parent): QTreeWidget(parent) {
|
||||
object = 0;
|
||||
object = 0;
|
||||
active_ = false;
|
||||
configTree();
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem * , int)), this, SLOT(itemClicked(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem * , int)), this, SLOT(itemChanged(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *, int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(itemChanged(QTreeWidgetItem *, int)));
|
||||
}
|
||||
|
||||
|
||||
PropertyEditor::~PropertyEditor() {
|
||||
|
||||
}
|
||||
PropertyEditor::~PropertyEditor() {}
|
||||
|
||||
|
||||
void PropertyEditor::changeEvent(QEvent * e) {
|
||||
@@ -446,7 +575,6 @@ void PropertyEditor::configTree() {
|
||||
setHeaderLabels(lbls);
|
||||
setAlternatingRowColors(true);
|
||||
setItemDelegateForColumn(1, new Delegate());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -475,25 +603,25 @@ void PropertyEditor::rebuild() {
|
||||
clear();
|
||||
configTree();
|
||||
if (object == 0) return;
|
||||
active_ = false;
|
||||
active_ = false;
|
||||
const QMetaObject * mo = object->metaObject();
|
||||
QList<const QMetaObject * > mol;
|
||||
QList<const QMetaObject *> mol;
|
||||
while (mo != 0) {
|
||||
mol.push_front(mo);
|
||||
mo = mo->superClass();
|
||||
}
|
||||
int ps, pe;
|
||||
QTreeWidgetItem * ti, * tli, * tfi;
|
||||
QTreeWidgetItem *ti, *tli, *tfi;
|
||||
QVariant value;
|
||||
// QWidget * pw = 0;
|
||||
// QWidget * pw = 0;
|
||||
int chue = 0;
|
||||
QColor bc;
|
||||
font_b = font();
|
||||
font_b.setBold(true);
|
||||
foreach (const QMetaObject * o, mol) {
|
||||
ps = o->propertyOffset();
|
||||
pe = o->propertyCount();// - ps;
|
||||
//qDebug() << i->className() << ps << pe;
|
||||
foreach(const QMetaObject * o, mol) {
|
||||
ps = o->propertyOffset();
|
||||
pe = o->propertyCount(); // - ps;
|
||||
// qDebug() << i->className() << ps << pe;
|
||||
tli = new QTreeWidgetItem();
|
||||
tli->setText(0, o->className());
|
||||
tli->setFont(0, font_b);
|
||||
@@ -505,7 +633,7 @@ void PropertyEditor::rebuild() {
|
||||
for (int i = ps; i < pe; ++i) {
|
||||
props << o->property(i);
|
||||
value = o->property(i).read(object);
|
||||
ti = new QTreeWidgetItem();
|
||||
ti = new QTreeWidgetItem();
|
||||
ti->setSizeHint(1, QSize(20, 20));
|
||||
bc.setHsv(chue, 60, 245 + (i % 2) * 20 - 10);
|
||||
setItemBackColor(ti, bc);
|
||||
@@ -528,14 +656,13 @@ void PropertyEditor::rebuild() {
|
||||
ti->setData(1, Qt::UserRole, value);
|
||||
ti->setData(1, Qt::UserRole + 2, "__flags");
|
||||
ti->setData(0, Qt::UserRole + 1, QVariant::fromValue<QMetaProperty>(props.back()));
|
||||
}
|
||||
else if (props.back().isEnumType())
|
||||
} else if (props.back().isEnumType())
|
||||
value.setValue<PropertyValuePair>(PropertyValuePair(props.back(), value));
|
||||
//ti->setText(1, value.toString());
|
||||
// ti->setText(1, value.toString());
|
||||
ti->setData(1, Qt::UserRole, value);
|
||||
tli->addChild(ti);
|
||||
//const_cast<QModelIndex & >(indexFromItem(ti, 1)).;
|
||||
//if (pw != 0) setItemWidget(ti, 1, pw);
|
||||
// const_cast<QModelIndex & >(indexFromItem(ti, 1)).;
|
||||
// if (pw != 0) setItemWidget(ti, 1, pw);
|
||||
}
|
||||
chue += 60;
|
||||
chue %= 360;
|
||||
@@ -544,6 +671,4 @@ void PropertyEditor::rebuild() {
|
||||
}
|
||||
|
||||
|
||||
void PropertyEditor::refresh() {
|
||||
|
||||
}
|
||||
void PropertyEditor::refresh() {}
|
||||
|
||||
@@ -1,85 +1,104 @@
|
||||
/*
|
||||
QGL PropertyEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL PropertyEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef PROPERTYEDITOR_H
|
||||
#define PROPERTYEDITOR_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QMetaProperty>
|
||||
#include <QEvent>
|
||||
#include <QDebug>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTreeWidget>
|
||||
#include <qpiconfigwidget.h>
|
||||
|
||||
|
||||
class Delegate: public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Delegate(QObject * parent = 0): QStyledItemDelegate() {ab = QBrush(QImage(":/icons/alpha.png"));}
|
||||
|
||||
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {cmi = const_cast<QModelIndex & >(index); return widgetForProperty(parent, index);}
|
||||
void setEditorData(QWidget * editor, const QModelIndex & index) const {setWidgetProperty(editor, index.data(Qt::UserRole));}
|
||||
Delegate(QObject * parent = 0): QStyledItemDelegate() { ab = QBrush(QImage(":/icons/alpha.png")); }
|
||||
|
||||
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
cmi = const_cast<QModelIndex &>(index);
|
||||
return widgetForProperty(parent, index);
|
||||
}
|
||||
void setEditorData(QWidget * editor, const QModelIndex & index) const { setWidgetProperty(editor, index.data(Qt::UserRole)); }
|
||||
void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const;
|
||||
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {editor->setGeometry(option.rect);}
|
||||
void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const;
|
||||
|
||||
|
||||
private:
|
||||
QWidget * widgetForProperty(QWidget * parent, const QModelIndex & index) const;
|
||||
void setWidgetProperty(QWidget * w, const QVariant & value) const;
|
||||
const QVariant widgetProperty(QWidget * w) const;
|
||||
QString pointString(const QPoint & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());}
|
||||
QString pointString(const QPointF & p) const {return QString::number(p.x()) + " x " + QString::number(p.y());}
|
||||
QString rectString(const QRect & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " +
|
||||
QString::number(r.width()) + " x " + QString::number(r.height());}
|
||||
QString rectString(const QRectF & r) const {return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " +
|
||||
QString::number(r.width()) + " x " + QString::number(r.height());}
|
||||
|
||||
QString pointString(const QPoint & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); }
|
||||
QString pointString(const QPointF & p) const { return QString::number(p.x()) + " x " + QString::number(p.y()); }
|
||||
QString rectString(const QRect & r) const {
|
||||
return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString::number(r.width()) + " x " +
|
||||
QString::number(r.height());
|
||||
}
|
||||
QString rectString(const QRectF & r) const {
|
||||
return QString::number(r.x()) + " x " + QString::number(r.y()) + " : " + QString::number(r.width()) + " x " +
|
||||
QString::number(r.height());
|
||||
}
|
||||
|
||||
QBrush ab;
|
||||
mutable QModelIndex cmi;
|
||||
|
||||
|
||||
private slots:
|
||||
void changed() {setModelData((QWidget * )sender(), const_cast<QAbstractItemModel * >(cmi.model()), cmi);}
|
||||
void changed() { setModelData((QWidget *)sender(), const_cast<QAbstractItemModel *>(cmi.model()), cmi); }
|
||||
void changedFlag();
|
||||
|
||||
};
|
||||
|
||||
typedef QPair<QMetaProperty, QVariant> PropertyValuePair;
|
||||
Q_DECLARE_METATYPE (PropertyValuePair)
|
||||
Q_DECLARE_METATYPE(PropertyValuePair)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
Q_DECLARE_METATYPE (QMetaProperty)
|
||||
Q_DECLARE_METATYPE(QMetaProperty)
|
||||
#endif
|
||||
|
||||
class PropertyEditor: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PropertyEditor(QWidget * parent = 0);
|
||||
virtual ~PropertyEditor();
|
||||
|
||||
void assignObject(QObject * o) {object = o; rebuild();}
|
||||
void assignObject(QObject * o) {
|
||||
object = o;
|
||||
rebuild();
|
||||
}
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * e);
|
||||
|
||||
private:
|
||||
void configTree();
|
||||
void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {i->setBackground(0, c); i->setBackground(1, c);}
|
||||
void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {i->setForeground(0, c); i->setForeground(1, c);}
|
||||
void setItemBackColor(QTreeWidgetItem * i, const QColor & c) {
|
||||
i->setBackground(0, c);
|
||||
i->setBackground(1, c);
|
||||
}
|
||||
void setItemForeColor(QTreeWidgetItem * i, const QColor & c) {
|
||||
i->setForeground(0, c);
|
||||
i->setForeground(1, c);
|
||||
}
|
||||
void rebuild();
|
||||
void refresh();
|
||||
|
||||
@@ -91,7 +110,6 @@ private:
|
||||
private slots:
|
||||
void itemClicked(QTreeWidgetItem * item, int column);
|
||||
void itemChanged(QTreeWidgetItem * item, int column);
|
||||
|
||||
};
|
||||
|
||||
#endif // PROPERTYEDITOR_H
|
||||
|
||||
@@ -1,29 +1,31 @@
|
||||
/*
|
||||
QGL SceneTree
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL SceneTree
|
||||
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 "scene_tree.h"
|
||||
#include "ui_scene_tree.h"
|
||||
|
||||
#include "glcamera.h"
|
||||
#include "qglview.h"
|
||||
#include <QTreeWidget>
|
||||
#include <QScrollBar>
|
||||
#include "ui_scene_tree.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QTreeWidget>
|
||||
|
||||
enum Column {
|
||||
cName,
|
||||
@@ -65,13 +67,17 @@ SceneTree::SceneTree(QWidget * parent): QWidget(parent) {
|
||||
icon_vis[0] = QIcon(":/icons/layer-visible-off.png");
|
||||
icon_vis[1] = QIcon(":/icons/layer-visible-on.png");
|
||||
ui->treeObjects->addActions(actionsSelection());
|
||||
ui->treeObjects->addAction (newSeparator());
|
||||
ui->treeObjects->addAction(newSeparator());
|
||||
ui->treeObjects->addActions(actionsAdd());
|
||||
ui->buttonFilter->addActions(QList<QAction*>() << ui->actionFilter_node << ui->actionFilter_mesh << ui->actionFilter_light << ui->actionFilter_camera);
|
||||
view = 0;
|
||||
ui->buttonFilter->addActions(QList<QAction *>()
|
||||
<< ui->actionFilter_node << ui->actionFilter_mesh << ui->actionFilter_light << ui->actionFilter_camera);
|
||||
view = 0;
|
||||
hidden_by_filter = obj_count = 0;
|
||||
block_tree = false;
|
||||
connect(ui->treeObjects->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(treeObjects_selectionCnahged()));
|
||||
block_tree = false;
|
||||
connect(ui->treeObjects->selectionModel(),
|
||||
SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
|
||||
this,
|
||||
SLOT(treeObjects_selectionCnahged()));
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +93,7 @@ void SceneTree::assignQGLView(QGLView * v) {
|
||||
connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
||||
connect(view, SIGNAL(materialsChanged()), this, SLOT(materialsChanged()));
|
||||
connect(view->scene(), SIGNAL(treeChanged()), this, SLOT(objectsTreeChanged()));
|
||||
connect(view->scene(), SIGNAL(__objectDeleted(ObjectBase*)), this, SLOT(__objectDeleted(ObjectBase*)));
|
||||
connect(view->scene(), SIGNAL(__objectDeleted(ObjectBase *)), this, SLOT(__objectDeleted(ObjectBase *)));
|
||||
view->setContextActions(actionsSelection());
|
||||
checkActions();
|
||||
}
|
||||
@@ -102,12 +108,9 @@ QList<QAction *> SceneTree::actionsAdd() {
|
||||
|
||||
QList<QAction *> SceneTree::actionsSelection() {
|
||||
QList<QAction *> ret;
|
||||
ret << ui->actionFocus << newSeparator()
|
||||
<< ui->actionGroup << ui->actionClone << newSeparator()
|
||||
<< ui->actionSelect_parent << ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator()
|
||||
<< ui->actionTransfer_transform_to_children << newSeparator()
|
||||
<< ui->actionActive_camera << ui->actionDefault_camera << newSeparator()
|
||||
<< ui->actionRemove;
|
||||
ret << ui->actionFocus << newSeparator() << ui->actionGroup << ui->actionClone << newSeparator() << ui->actionSelect_parent
|
||||
<< ui->actionSelect_by_mesh << ui->actionSelect_by_material << newSeparator() << ui->actionTransfer_transform_to_children
|
||||
<< newSeparator() << ui->actionActive_camera << ui->actionDefault_camera << newSeparator() << ui->actionRemove;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -129,8 +132,7 @@ void SceneTree::changeEvent(QEvent * e) {
|
||||
void SceneTree::rememberExpanded(QTreeWidgetItem * ti) {
|
||||
for (int i = 0; i < ti->childCount(); ++i) {
|
||||
QTreeWidgetItem * ci = ti->child(i);
|
||||
if (ci->isExpanded())
|
||||
expanded_ << itemObject(ci);
|
||||
if (ci->isExpanded()) expanded_ << itemObject(ci);
|
||||
rememberExpanded(ci);
|
||||
}
|
||||
}
|
||||
@@ -148,13 +150,12 @@ void SceneTree::restoreExpanded(QTreeWidgetItem * ti) {
|
||||
void SceneTree::makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti) {
|
||||
++obj_count;
|
||||
for (int i = 0; i < o->childCount(); ++i) {
|
||||
ObjectBase * co = o->child(i);
|
||||
ObjectBase * co = o->child(i);
|
||||
QTreeWidgetItem * ci = new QTreeWidgetItem(ti);
|
||||
ci->setText(cName, co->name());
|
||||
ci->setCheckState(cVis, co->isVisible() ? Qt::Checked : Qt::Unchecked);
|
||||
ci->setIcon(cVis, icon_vis[co->isVisible(true)]);
|
||||
if (co->material())
|
||||
ci->setText(cMaterial, co->material()->name);
|
||||
if (co->material()) ci->setText(cMaterial, co->material()->name);
|
||||
ci->setFlags(ci->flags() | Qt::ItemIsEditable);
|
||||
ObjectType t = otNode;
|
||||
switch (co->type()) {
|
||||
@@ -189,7 +190,7 @@ void SceneTree::makeObjetTree(ObjectBase * o, QTreeWidgetItem * ti) {
|
||||
|
||||
ObjectBase * SceneTree::itemObject(QTreeWidgetItem * item) const {
|
||||
if (!item) return 0;
|
||||
return (ObjectBase*)(item->data(cName, irObject).toULongLong());
|
||||
return (ObjectBase *)(item->data(cName, irObject).toULongLong());
|
||||
}
|
||||
|
||||
|
||||
@@ -201,12 +202,11 @@ int SceneTree::itemType(QTreeWidgetItem * item) const {
|
||||
|
||||
void SceneTree::selectionChanged() {
|
||||
if (block_tree) return;
|
||||
block_tree = true;
|
||||
QList<QTreeWidgetItem*> il = ui->treeObjects->findItems("", Qt::MatchContains | Qt::MatchRecursive);
|
||||
const ObjectBase * fo = 0;
|
||||
if (view->selectedObjects().size() == 1)
|
||||
fo = view->selectedObject();
|
||||
foreach (QTreeWidgetItem * i, il) {
|
||||
block_tree = true;
|
||||
QList<QTreeWidgetItem *> il = ui->treeObjects->findItems("", Qt::MatchContains | Qt::MatchRecursive);
|
||||
const ObjectBase * fo = 0;
|
||||
if (view->selectedObjects().size() == 1) fo = view->selectedObject();
|
||||
foreach(QTreeWidgetItem * i, il) {
|
||||
ObjectBase * o = itemObject(i);
|
||||
i->setSelected(o->isSelected());
|
||||
if (fo && (fo == o)) {
|
||||
@@ -219,18 +219,17 @@ void SceneTree::selectionChanged() {
|
||||
|
||||
|
||||
void SceneTree::materialsChanged() {
|
||||
foreach (QTreeWidgetItem * i, geo_items) {
|
||||
foreach(QTreeWidgetItem * i, geo_items) {
|
||||
ObjectBase * o = itemObject(i);
|
||||
if (!o) continue;
|
||||
if (o->material())
|
||||
i->setText(cMaterial, o->material()->name);
|
||||
if (o->material()) i->setText(cMaterial, o->material()->name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneTree::cameraChanged() {
|
||||
if (!view) return;
|
||||
foreach (QTreeWidgetItem * i, cam_items) {
|
||||
foreach(QTreeWidgetItem * i, cam_items) {
|
||||
ObjectBase * o = itemObject(i);
|
||||
if (!o) continue;
|
||||
i->setText(cVis, (o == view->camera()) ? "*" : "");
|
||||
@@ -242,8 +241,8 @@ bool SceneTree::filterTree(QTreeWidgetItem * ti, const QString & filter, int typ
|
||||
bool ret = false;
|
||||
for (int i = 0; i < ti->childCount(); ++i) {
|
||||
QTreeWidgetItem * ci = ti->child(i);
|
||||
QString cit = ci->text(cName);
|
||||
int t = itemType(ci);
|
||||
QString cit = ci->text(cName);
|
||||
int t = itemType(ci);
|
||||
if (ci->childCount() > 0) {
|
||||
if (!filterTree(ci, filter, types)) {
|
||||
ci->setHidden(true);
|
||||
@@ -259,11 +258,12 @@ bool SceneTree::filterTree(QTreeWidgetItem * ti, const QString & filter, int typ
|
||||
} else {
|
||||
f = f || cit.contains(filter, Qt::CaseInsensitive);
|
||||
}
|
||||
if ((types & t) != t)
|
||||
f = false;
|
||||
if ((types & t) != t) f = false;
|
||||
ci->setHidden(!f);
|
||||
if (f) ret = true;
|
||||
else ++hidden_by_filter;
|
||||
if (f)
|
||||
ret = true;
|
||||
else
|
||||
++hidden_by_filter;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -272,23 +272,23 @@ bool SceneTree::filterTree(QTreeWidgetItem * ti, const QString & filter, int typ
|
||||
|
||||
void SceneTree::checkActions() {
|
||||
bool has_1 = false, has_m = false;
|
||||
bool has_cam = false;
|
||||
bool has_mesh = false;
|
||||
bool has_cam = false;
|
||||
bool has_mesh = false;
|
||||
bool is_def_cam = false;
|
||||
if (view) {
|
||||
is_def_cam = view->isDefaultCamera();
|
||||
is_def_cam = view->isDefaultCamera();
|
||||
ObjectBaseList slo = view->selectedObjects();
|
||||
has_1 = !slo.isEmpty();
|
||||
has_m = slo.size() > 1;
|
||||
for (ObjectBase * o : slo) {
|
||||
has_1 = !slo.isEmpty();
|
||||
has_m = slo.size() > 1;
|
||||
for (ObjectBase * o: slo) {
|
||||
if (o->type() == ObjectBase::glCamera) has_cam = (slo.size() == 1);
|
||||
if (o->type() == ObjectBase::glMesh) has_mesh = true;
|
||||
}
|
||||
}
|
||||
|
||||
ui->actionFocus ->setEnabled(has_mesh);
|
||||
ui->actionFocus->setEnabled(has_mesh);
|
||||
ui->actionRemove->setEnabled(has_1);
|
||||
ui->actionClone ->setEnabled(has_1);
|
||||
ui->actionClone->setEnabled(has_1);
|
||||
ui->actionGroup->setEnabled(has_m);
|
||||
ui->actionTransfer_transform_to_children->setEnabled(has_1);
|
||||
ui->actionSelect_parent->setEnabled(has_1);
|
||||
@@ -304,8 +304,8 @@ void SceneTree::treeObjects_selectionCnahged() {
|
||||
block_tree = true;
|
||||
view->scene()->clearSelection();
|
||||
ObjectBaseList sol;
|
||||
QList<QTreeWidgetItem*> til = ui->treeObjects->selectedItems();
|
||||
foreach (QTreeWidgetItem * i, til)
|
||||
QList<QTreeWidgetItem *> til = ui->treeObjects->selectedItems();
|
||||
foreach(QTreeWidgetItem * i, til)
|
||||
sol << itemObject(i);
|
||||
view->scene()->selectObjects(sol);
|
||||
block_tree = false;
|
||||
@@ -315,9 +315,9 @@ void SceneTree::treeObjects_selectionCnahged() {
|
||||
|
||||
void SceneTree::filter() {
|
||||
int types = 0;
|
||||
if (ui->actionFilter_node ->isChecked()) types |= otNode ;
|
||||
if (ui->actionFilter_mesh ->isChecked()) types |= otMesh ;
|
||||
if (ui->actionFilter_light ->isChecked()) types |= otLight ;
|
||||
if (ui->actionFilter_node->isChecked()) types |= otNode;
|
||||
if (ui->actionFilter_mesh->isChecked()) types |= otMesh;
|
||||
if (ui->actionFilter_light->isChecked()) types |= otLight;
|
||||
if (ui->actionFilter_camera->isChecked()) types |= otCamera;
|
||||
if (types == 0) types = 0xFF;
|
||||
hidden_by_filter = 0;
|
||||
@@ -348,14 +348,14 @@ void SceneTree::on_treeObjects_itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (o) o->setName(item->text(cName));
|
||||
}
|
||||
if (column == cVis) {
|
||||
bool vis = item->checkState(cVis) == Qt::Checked;
|
||||
QList<QTreeWidgetItem*> til = ui->treeObjects->selectedItems();
|
||||
bool vis = item->checkState(cVis) == Qt::Checked;
|
||||
QList<QTreeWidgetItem *> til = ui->treeObjects->selectedItems();
|
||||
if (!til.contains(item)) {
|
||||
til.clear();
|
||||
til << item;
|
||||
}
|
||||
foreach (QTreeWidgetItem * ti, til) {
|
||||
//itemObject(ti)->setVisible(vis);
|
||||
foreach(QTreeWidgetItem * ti, til) {
|
||||
// itemObject(ti)->setVisible(vis);
|
||||
itemObject(ti)->setVisible(vis);
|
||||
}
|
||||
}
|
||||
@@ -365,13 +365,12 @@ void SceneTree::on_treeObjects_itemChanged(QTreeWidgetItem * item, int column) {
|
||||
void SceneTree::on_treeObjects_itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent) {
|
||||
ObjectBase * co = itemObject(item);
|
||||
if (!co->hasParent()) return;
|
||||
//co->parent()->removeChild(co);
|
||||
// co->parent()->removeChild(co);
|
||||
if (new_parent == ui->treeObjects->invisibleRootItem()) {
|
||||
view->scene()->rootObject()->addChild(co);
|
||||
} else {
|
||||
ObjectBase * po = itemObject(new_parent);
|
||||
if (po)
|
||||
po->addChild(co);
|
||||
if (po) po->addChild(co);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -402,9 +401,9 @@ void SceneTree::on_actionAdd_camera_triggered() {
|
||||
|
||||
void SceneTree::on_actionClone_triggered() {
|
||||
if (!view) return;
|
||||
QList<QTreeWidgetItem*> sil = ui->treeObjects->selectedItems();
|
||||
QList<QTreeWidgetItem *> sil = ui->treeObjects->selectedItems();
|
||||
ObjectBaseList col;
|
||||
foreach (QTreeWidgetItem * i, sil) {
|
||||
foreach(QTreeWidgetItem * i, sil) {
|
||||
ObjectBase * o = itemObject(i);
|
||||
if (!o) continue;
|
||||
ObjectBase * no = o->clone();
|
||||
@@ -418,10 +417,10 @@ void SceneTree::on_actionClone_triggered() {
|
||||
void SceneTree::on_actionGroup_triggered() {
|
||||
if (!view) return;
|
||||
ObjectBaseList sol = view->scene()->selectedObjects(true);
|
||||
ObjectBase * cp = sol[0]->parent();
|
||||
ObjectBase * nr = new ObjectBase();
|
||||
ObjectBase * cp = sol[0]->parent();
|
||||
ObjectBase * nr = new ObjectBase();
|
||||
cp->addChild(nr);
|
||||
foreach (ObjectBase * o, sol)
|
||||
foreach(ObjectBase * o, sol)
|
||||
nr->addChild(o);
|
||||
view->scene()->selectObject(nr);
|
||||
}
|
||||
@@ -430,7 +429,7 @@ void SceneTree::on_actionGroup_triggered() {
|
||||
void SceneTree::on_actionTransfer_transform_to_children_triggered() {
|
||||
if (!view) return;
|
||||
ObjectBaseList sol = view->scene()->selectedObjects(true);
|
||||
foreach (ObjectBase * o, sol)
|
||||
foreach(ObjectBase * o, sol)
|
||||
o->transferTransformToChildren();
|
||||
}
|
||||
|
||||
@@ -455,11 +454,10 @@ void SceneTree::on_actionDefault_camera_triggered() {
|
||||
void SceneTree::on_actionSelect_parent_triggered() {
|
||||
if (!view) return;
|
||||
ObjectBaseList sol = view->scene()->selectedObjects(true);
|
||||
QSet<ObjectBase*> nsl;
|
||||
foreach (ObjectBase * o, sol) {
|
||||
QSet<ObjectBase *> nsl;
|
||||
foreach(ObjectBase * o, sol) {
|
||||
ObjectBase * po = o->parent();
|
||||
if (po != view->scene()->rootObject())
|
||||
o = po;
|
||||
if (po != view->scene()->rootObject()) o = po;
|
||||
nsl << o;
|
||||
}
|
||||
view->scene()->selectObjects(nsl.values());
|
||||
@@ -478,8 +476,8 @@ void SceneTree::on_actionSelect_by_material_triggered() {
|
||||
|
||||
void SceneTree::removeObjects() {
|
||||
if (!view) return;
|
||||
QList<QTreeWidgetItem*> sil = ui->treeObjects->selectedItems();
|
||||
foreach (QTreeWidgetItem * i, sil) {
|
||||
QList<QTreeWidgetItem *> sil = ui->treeObjects->selectedItems();
|
||||
foreach(QTreeWidgetItem * i, sil) {
|
||||
ObjectBase * o = itemObject(i);
|
||||
if (o->isSelected(true)) view->scene()->clearSelection();
|
||||
if (o) delete o;
|
||||
@@ -493,7 +491,7 @@ void SceneTree::focusObjects() {
|
||||
if (!view->camera()) return;
|
||||
Box3D bb;
|
||||
ObjectBaseList ol = view->selectedObjects();
|
||||
foreach (ObjectBase * o, ol) {
|
||||
foreach(ObjectBase * o, ol) {
|
||||
o->calculateBoundingBox();
|
||||
bb |= o->boundingBox();
|
||||
}
|
||||
@@ -512,7 +510,7 @@ void SceneTree::objectsTreeChanged() {
|
||||
block_tree = false;
|
||||
if (!view) return;
|
||||
block_tree = true;
|
||||
obj_count = 0;
|
||||
obj_count = 0;
|
||||
makeObjetTree(view->scene()->rootObject(), ui->treeObjects->invisibleRootItem());
|
||||
--obj_count;
|
||||
restoreExpanded(ui->treeObjects->invisibleRootItem());
|
||||
|
||||
@@ -1,44 +1,45 @@
|
||||
/*
|
||||
QGL SceneTree
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL SceneTree
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef SCENE_TREE_H
|
||||
#define SCENE_TREE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QIcon>
|
||||
#include "glscene.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QWidget>
|
||||
|
||||
class QTreeWidgetItem;
|
||||
|
||||
namespace Ui {
|
||||
class SceneTree;
|
||||
class SceneTree;
|
||||
}
|
||||
|
||||
class SceneTree: public QWidget
|
||||
{
|
||||
class SceneTree: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SceneTree(QWidget * parent = 0);
|
||||
~SceneTree();
|
||||
|
||||
void assignQGLView(QGLView * v);
|
||||
QList<QAction*> actionsAdd();
|
||||
QList<QAction*> actionsSelection();
|
||||
QList<QAction *> actionsAdd();
|
||||
QList<QAction *> actionsSelection();
|
||||
void expandItems();
|
||||
|
||||
private:
|
||||
@@ -55,21 +56,21 @@ private:
|
||||
bool block_tree;
|
||||
int hidden_by_filter, obj_count;
|
||||
QIcon icon_empty, icon_geo, icon_camera, icon_light, icon_vis[2];
|
||||
QSet<ObjectBase*> expanded_;
|
||||
QList<QTreeWidgetItem*> geo_items, cam_items;
|
||||
QSet<ObjectBase *> expanded_;
|
||||
QList<QTreeWidgetItem *> geo_items, cam_items;
|
||||
QGLView * view;
|
||||
|
||||
private slots:
|
||||
void treeObjects_selectionCnahged();
|
||||
void on_treeObjects_itemChanged(QTreeWidgetItem * item, int column);
|
||||
void on_treeObjects_itemMoved (QTreeWidgetItem * item, QTreeWidgetItem * new_parent);
|
||||
void on_treeObjects_itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent);
|
||||
|
||||
void on_actionAdd_node_triggered();
|
||||
void on_actionAdd_light_triggered();
|
||||
void on_actionAdd_camera_triggered();
|
||||
|
||||
void on_actionFocus_triggered() {focusObjects();}
|
||||
void on_actionRemove_triggered() {removeObjects();}
|
||||
void on_actionFocus_triggered() { focusObjects(); }
|
||||
void on_actionRemove_triggered() { removeObjects(); }
|
||||
void on_actionClone_triggered();
|
||||
void on_actionGroup_triggered();
|
||||
void on_actionTransfer_transform_to_children_triggered();
|
||||
@@ -95,7 +96,6 @@ public slots:
|
||||
signals:
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // SCENE_TREE_H
|
||||
|
||||
@@ -1,59 +1,58 @@
|
||||
/*
|
||||
QGL SceneTree
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL SceneTree
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef TREEWIDGET_H
|
||||
#define TREEWIDGET_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QDropEvent>
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QDropEvent>
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QTimer>
|
||||
#include <QTreeWidget>
|
||||
|
||||
class InternalMoveTreeWidget: public QTreeWidget
|
||||
{
|
||||
class InternalMoveTreeWidget: public QTreeWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {}
|
||||
|
||||
|
||||
protected:
|
||||
virtual void dropEvent(QDropEvent * e) {
|
||||
QList<QTreeWidgetItem*> sil = selectedItems();
|
||||
QList<QTreeWidgetItem *> sil = selectedItems();
|
||||
if (sil.isEmpty()) return;
|
||||
QTreeWidget::dropEvent(e);
|
||||
foreach (QTreeWidgetItem * ti, sil) {
|
||||
foreach(QTreeWidgetItem * ti, sil) {
|
||||
QTreeWidgetItem * ti_p = ti->parent();
|
||||
if (!ti_p) ti_p = invisibleRootItem();
|
||||
int ti_ppos = ti_p->indexOfChild(ti);
|
||||
emit itemMoved(ti, ti_p, ti_ppos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
signals:
|
||||
void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class NoEditDelegate: public QStyledItemDelegate {
|
||||
public:
|
||||
NoEditDelegate(QObject* parent=0): QStyledItemDelegate(parent) {}
|
||||
virtual QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
NoEditDelegate(QObject * parent = 0): QStyledItemDelegate(parent) {}
|
||||
virtual QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const {
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,23 +1,25 @@
|
||||
/*
|
||||
QGL ViewEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL ViewEditor
|
||||
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 "view_editor.h"
|
||||
|
||||
#include "ui_view_editor.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <colorbutton.h>
|
||||
#include <spinslider.h>
|
||||
@@ -26,10 +28,10 @@
|
||||
ViewEditor::ViewEditor(QWidget * parent): QWidget(parent) {
|
||||
ui = new Ui::ViewEditor();
|
||||
ui->setupUi(this);
|
||||
view = nullptr;
|
||||
view = nullptr;
|
||||
active = true;
|
||||
ui->checkCameraLight->setCheckState(Qt::PartiallyChecked);
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5,12,0)
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
|
||||
ui->spinDepthStart->setStepType(QAbstractSpinBox::AdaptiveDecimalStepType);
|
||||
#endif
|
||||
}
|
||||
@@ -64,11 +66,8 @@ void ViewEditor::assignQGLView(QGLView * v) {
|
||||
void ViewEditor::changeEvent(QEvent * e) {
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::LanguageChange: ui->retranslateUi(this); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +160,6 @@ void ViewEditor::on_checkService_clicked(bool val) {
|
||||
void ViewEditor::on_checkCameraLight_stateChanged(int s) {
|
||||
if (!view || !active) return;
|
||||
view->setCameraLightMode((QGLView::CameraLightMode)s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -205,4 +203,3 @@ void ViewEditor::on_checkVSync_clicked(bool val) {
|
||||
if (!view || !active) return;
|
||||
view->setVSync(val);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,35 @@
|
||||
/*
|
||||
QGL ViewEditor
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
QGL ViewEditor
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#ifndef VIEW_EDITOR_H
|
||||
#define VIEW_EDITOR_H
|
||||
|
||||
#include <QWidget>
|
||||
#include "qglview.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
class ViewEditor;
|
||||
class ViewEditor;
|
||||
}
|
||||
|
||||
class ViewEditor: public QWidget
|
||||
{
|
||||
class ViewEditor: public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ViewEditor(QWidget * parent = 0);
|
||||
|
||||
@@ -60,7 +61,7 @@ private slots:
|
||||
void on_checkVSync_clicked(bool val);
|
||||
void on_buttonHDRClear_clicked();
|
||||
void on_buttonHDRSelect_clicked();
|
||||
void on_colorFogBack_colorChanged(const QColor &color);
|
||||
void on_colorFogBack_colorChanged(const QColor & color);
|
||||
void on_spinFogDensity_valueChanged(double arg1);
|
||||
void on_spinFogDecay_valueChanged(double arg1);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user