git-svn-id: svn://db.shs.com.ru/libs@649 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -18,19 +18,56 @@
|
||||
|
||||
#include "object_editor.h"
|
||||
#include "ui_object_editor.h"
|
||||
#include "glcamera.h"
|
||||
#include "qglview.h"
|
||||
#include <spinslider.h>
|
||||
#include <scroll_spin_box.h>
|
||||
|
||||
|
||||
ObjectEditor::ObjectEditor(QWidget * parent): QWidget(parent) {
|
||||
ui = new Ui::ObjectEditor();
|
||||
ui->setupUi(this);
|
||||
view = 0;
|
||||
active = true;
|
||||
object = 0;
|
||||
rmodes << ObjectBase::View << ObjectBase::Point << ObjectBase::Line << ObjectBase::Fill;
|
||||
ui->groupLight->setEnabled(false);
|
||||
ui->groupLight->setVisible(false);
|
||||
ui->groupCamera->setEnabled(false);
|
||||
ui->groupCamera->setVisible(false);
|
||||
on_comboLightType_currentIndexChanged(0);
|
||||
ui->widgetMain->setEnabled(false);
|
||||
ui->labelAimDist->hide();
|
||||
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)
|
||||
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)
|
||||
connect(o, SIGNAL(valueChanged(double)), this, SLOT(spinLightChanged(double)));
|
||||
|
||||
ol.clear();
|
||||
ol << ui->spinCameraFOV << ui->spinCameraDepthStart << ui->spinAimDist;
|
||||
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)
|
||||
connect(o, SIGNAL(toggled(bool)), this, SLOT(checkChanged(bool)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::assignQGLView(QGLView * v) {
|
||||
view = v;
|
||||
connect(view, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
||||
connect(view, SIGNAL(objectsPositionChanged()), this, SLOT(selectionChanged()));
|
||||
connect(view->scene(), SIGNAL(treeChanged()), this, SLOT(selectionChanged()));
|
||||
selectionChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -46,38 +83,54 @@ void ObjectEditor::changeEvent(QEvent * e) {
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::setObject(ObjectBase * o) {
|
||||
object = o;
|
||||
if (object == 0) {
|
||||
ui->groupLight->setEnabled(false);
|
||||
ui->groupLight->setVisible(false);
|
||||
ui->groupCamera->setEnabled(false);
|
||||
ui->groupCamera->setVisible(false);
|
||||
void ObjectEditor::selectionChanged() {
|
||||
ui->widgetMain->setEnabled(false);
|
||||
if (!view) return;
|
||||
QList<ObjectBase*> sol = view->selectedObjects(true);
|
||||
if (sol.isEmpty()) {
|
||||
ui->labelTitle->setText(tr("[No selected]"));
|
||||
return;
|
||||
}
|
||||
ui->buttonDiscardRawMatrix->setEnabled(o->isRawMatrix());
|
||||
ui->widgetMain->setEnabled(true);
|
||||
if (sol.size() == 1) {
|
||||
setObject(sol[0]);
|
||||
return;
|
||||
}
|
||||
bool hl = !view->selectedLights().isEmpty(), hc = !view->selectedCameras().isEmpty();
|
||||
ui->groupLight ->setVisible(hl);
|
||||
ui->groupCamera ->setVisible(hc);
|
||||
ui->labelAimDist->setVisible(hl || hc);
|
||||
ui->spinAimDist ->setVisible(hl || hc);
|
||||
ui->labelTitle->setText(tr("[%1 objects]").arg(sol.size()));
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::setObject(ObjectBase * o) {
|
||||
active = false;
|
||||
ui->spinPosX->setValue(object->posX());
|
||||
ui->spinPosY->setValue(object->posY());
|
||||
ui->spinPosZ->setValue(object->posZ());
|
||||
ui->spinRotationX->setValue(object->rotationX());
|
||||
ui->spinRotationY->setValue(object->rotationY());
|
||||
ui->spinRotationZ->setValue(object->rotationZ());
|
||||
ui->spinScaleX->setValue(object->scaleX());
|
||||
ui->spinScaleY->setValue(object->scaleY());
|
||||
ui->spinScaleZ->setValue(object->scaleZ());
|
||||
ui->spinLineWidth->setValue(object->lineWidth());
|
||||
ui->checkVisible->setChecked(object->isVisible());
|
||||
ui->checkAcceptLight->setChecked(object->isAcceptLight());
|
||||
ui->checkAcceptFog->setChecked(object->isAcceptFog());
|
||||
ui->checkCastShadows->setChecked(object->isCastShadows());
|
||||
ui->checkReceiveShadows->setChecked(object->isReceiveShadows());
|
||||
ui->comboRenderMode->setCurrentIndex(rmodes.indexOf(object->renderMode()));
|
||||
ui->groupLight->setEnabled(object->type() == ObjectBase::glLight);
|
||||
ui->groupLight->setVisible(object->type() == ObjectBase::glLight);
|
||||
ui->buttonColor->setColor(object->color());
|
||||
if (object->type() == ObjectBase::glLight) {
|
||||
Light * l = globject_cast<Light * >(object);
|
||||
ui->labelTitle->setText(o->name());
|
||||
ui->spinPosX->setValue(o->posX());
|
||||
ui->spinPosY->setValue(o->posY());
|
||||
ui->spinPosZ->setValue(o->posZ());
|
||||
ui->spinRotationX->setValue(o->rotationX());
|
||||
ui->spinRotationY->setValue(o->rotationY());
|
||||
ui->spinRotationZ->setValue(o->rotationZ());
|
||||
ui->spinScaleX->setValue(o->scaleX());
|
||||
ui->spinScaleY->setValue(o->scaleY());
|
||||
ui->spinScaleZ->setValue(o->scaleZ());
|
||||
ui->checkVisible->setChecked(o->isVisible());
|
||||
ui->checkAcceptLight->setChecked(o->isAcceptLight());
|
||||
ui->checkAcceptFog->setChecked(o->isAcceptFog());
|
||||
ui->checkCastShadows->setChecked(o->isCastShadows());
|
||||
ui->checkReceiveShadows->setChecked(o->isReceiveShadows());
|
||||
ui->buttonColor->setColor(o->color());
|
||||
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);
|
||||
if (is_l) {
|
||||
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);
|
||||
@@ -86,70 +139,21 @@ void ObjectEditor::setObject(ObjectBase * o) {
|
||||
ui->spinLightDecayQuadratic->setValue(l->decay_quadratic);
|
||||
ui->spinLightAngleStart->setValue(l->angle_start);
|
||||
ui->spinLightAngleEnd->setValue(l->angle_end);
|
||||
ui->spinLightDirectionX->setValue(l->direction().x());
|
||||
ui->spinLightDirectionY->setValue(l->direction().y());
|
||||
ui->spinLightDirectionZ->setValue(l->direction().z());
|
||||
ui->spinAimDist->setValue(l->distance());
|
||||
on_comboLightType_currentIndexChanged(ui->comboLightType->currentIndex());
|
||||
}
|
||||
ui->groupCamera->setEnabled(object->type() == ObjectBase::glCamera);
|
||||
ui->groupCamera->setVisible(object->type() == ObjectBase::glCamera);
|
||||
if (object->type() == ObjectBase::glCamera) {
|
||||
Camera * c = globject_cast<Camera * >(object);
|
||||
if (is_c) {
|
||||
Camera * c = globject_cast<Camera * >(o);
|
||||
ui->checkCameraMirrorX->setChecked(c->isMirrorX());
|
||||
ui->checkCameraMirrorY->setChecked(c->isMirrorY());
|
||||
ui->spinCameraFOV->setValue(c->FOV());
|
||||
ui->spinCameraDepthStart->setValue(c->depthStart());
|
||||
ui->spinCameraDepthEnd->setValue(c->depthEnd());
|
||||
ui->spinAimDist->setValue(c->distance());
|
||||
}
|
||||
active = true;
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::objectChanged() {
|
||||
if (!active || object == 0) return;
|
||||
if (!object->isRawMatrix()) {
|
||||
object->setPosX(ui->spinPosX->value());
|
||||
object->setPosY(ui->spinPosY->value());
|
||||
object->setPosZ(ui->spinPosZ->value());
|
||||
object->setRotationX(ui->spinRotationX->value());
|
||||
object->setRotationY(ui->spinRotationY->value());
|
||||
object->setRotationZ(ui->spinRotationZ->value());
|
||||
object->setScaleX(ui->spinScaleX->value());
|
||||
object->setScaleY(ui->spinScaleY->value());
|
||||
object->setScaleZ(ui->spinScaleZ->value());
|
||||
}
|
||||
/*object->setLineWidth(ui->spinLineWidth->value());
|
||||
object->setVisible(ui->checkVisible->isChecked());
|
||||
object->setAcceptLight(ui->checkAcceptLight->isChecked());
|
||||
object->setAcceptFog(ui->checkAcceptFog->isChecked());
|
||||
object->setCastShadows(ui->checkCastShadows->isChecked());
|
||||
object->setReceiveShadows(ui->checkReceiveShadows->isChecked());
|
||||
object->setRenderMode((ObjectBase::RenderMode)rmodes[ui->comboRenderMode->currentIndex()]);*/
|
||||
object->setColor(ui->buttonColor->color());
|
||||
if (object->type() == ObjectBase::glLight) {
|
||||
Light * l = globject_cast<Light * >(object);
|
||||
//bool is_dir = l->light_type == Light::Directional, is_cone = l->light_type == Light::Cone;
|
||||
l->light_type = (Light::Type)ui->comboLightType->currentIndex();
|
||||
l->intensity = ui->spinLightIntensity->value();
|
||||
l->decay_const = ui->spinLightDecayConst->value();
|
||||
l->decay_linear = ui->spinLightDecayLinear->value();
|
||||
l->decay_quadratic = ui->spinLightDecayQuadratic->value();
|
||||
l->angle_start = ui->spinLightAngleStart->value();
|
||||
l->angle_end = ui->spinLightAngleEnd->value();
|
||||
//l->setDirection(QVector3D(ui->spinLightDirectionX->value(), ui->spinLightDirectionY->value(), ui->spinLightDirectionZ->value()).normalized());
|
||||
l->apply();
|
||||
}
|
||||
if (object->type() == ObjectBase::glCamera) {
|
||||
Camera * c = globject_cast<Camera * >(object);
|
||||
c->setMirrorX(ui->checkCameraMirrorX->isChecked());
|
||||
c->setMirrorY(ui->checkCameraMirrorY->isChecked());
|
||||
c->setFOV(ui->spinCameraFOV->value());
|
||||
c->setDepthStart(ui->spinCameraDepthStart->value());
|
||||
c->setDepthEnd(ui->spinCameraDepthEnd->value());
|
||||
}
|
||||
emit changed();
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_spinLightAngleStart_valueChanged(double v) {
|
||||
if (ui->spinLightAngleEnd->value() < v)
|
||||
ui->spinLightAngleEnd->setValue(v);
|
||||
@@ -162,16 +166,93 @@ void ObjectEditor::on_spinLightAngleEnd_valueChanged(double v) {
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_buttonDiscardRawMatrix_clicked() {
|
||||
if (!active || !object) return;
|
||||
object->setPosX(ui->spinPosX->value());
|
||||
object->setPosY(ui->spinPosY->value());
|
||||
object->setPosZ(ui->spinPosZ->value());
|
||||
object->setRotationX(ui->spinRotationX->value());
|
||||
object->setRotationY(ui->spinRotationY->value());
|
||||
object->setRotationZ(ui->spinRotationZ->value());
|
||||
object->setScaleX(ui->spinScaleX->value());
|
||||
object->setScaleY(ui->spinScaleY->value());
|
||||
object->setScaleZ(ui->spinScaleZ->value());
|
||||
ui->buttonDiscardRawMatrix->setEnabled(false);
|
||||
void ObjectEditor::on_comboLightType_currentIndexChanged(int index) {
|
||||
bool ang = (index == Light::Cone);
|
||||
ui->labelLightAngle ->setVisible(ang);
|
||||
ui->labelLightAngleDash->setVisible(ang);
|
||||
ui->spinLightAngleStart->setVisible(ang);
|
||||
ui->spinLightAngleEnd ->setVisible(ang);
|
||||
if (!view || !active) return;
|
||||
QList<Light*> sll = view->selectedLights();
|
||||
foreach (Light * o, sll) {
|
||||
o->light_type = (Light::Type)index;
|
||||
o->apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::on_buttonColor_colorChanged(const QColor & v) {
|
||||
if (!view || !active) return;
|
||||
QList<ObjectBase*> sol = view->selectedObjects();
|
||||
foreach (ObjectBase * o, sol)
|
||||
o->setColor(v);
|
||||
QList<Light*> sll = view->selectedLights();
|
||||
foreach (Light * o, sll)
|
||||
o->apply();
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::spinChanged(double v) {
|
||||
if (!view || !active) return;
|
||||
QList<ObjectBase*> 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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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);
|
||||
o->apply();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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->spinCameraDepthStart) o->setDepthStart(v);
|
||||
if (s == ui->spinAimDist ) o->setDistance(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ObjectEditor::checkChanged(bool v) {
|
||||
if (!view || !active) return;
|
||||
QList<ObjectBase*> 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);
|
||||
}
|
||||
foreach (Camera * o, scl) {
|
||||
if (s == ui->checkCameraMirrorX ) o->setMirrorX(v);
|
||||
if (s == ui->checkCameraMirrorY ) o->setMirrorY(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user