/* QGLView Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "material_editor.h" #include "ui_material_editor.h" MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) { ui = new Ui::MaterialEditor(); ui->setupUi(this); active = true; } void MaterialEditor::changeEvent(QEvent * e) { return; QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void MaterialEditor::setMaterial(const Material & m) { active = false; ui->colorDiffuse->setColor(m.color_diffuse); ui->colorSpecular->setColor(m.color_specular); ui->colorSelfIllum->setColor(m.color_self_illumination); ui->checkGlass->setChecked(m.glass); ui->comboModel->setCurrentIndex((int)m.light_model); ui->spinShine->setValue(m.shine); ui->spinShineStrength->setValue(m.shine_strength); ui->spinTransparent->setValue(m.transparency); ui->spinReflect->setValue(m.reflectivity); ui->spinBump->setValue(m.bump_scale); ui->spinRelief->setValue(m.relief_scale); ui->spinIOF->setValue(m.iof); ui->spinDispersion->setValue(m.dispersion); ui->lineDiffuse->setProperty("GLpath", m.diffuse.bitmap_path); ui->lineDiffuse->setText(QFileInfo(m.diffuse.bitmap_path).fileName()); ui->lineBump->setProperty("GLpath", m.bump.bitmap_path); ui->lineBump->setText(QFileInfo(m.bump.bitmap_path).fileName()); ui->lineRelief->setProperty("GLpath", m.relief.bitmap_path); ui->lineRelief->setText(QFileInfo(m.relief.bitmap_path).fileName()); ui->lineReflFront->setProperty("GLpath", m.reflection.path(0)); ui->lineReflFront->setText(QFileInfo(m.reflection.path(0)).fileName()); ui->lineReflBack->setProperty("GLpath", m.reflection.path(1)); ui->lineReflBack->setText(QFileInfo(m.reflection.path(1)).fileName()); ui->lineReflLeft->setProperty("GLpath", m.reflection.path(2)); ui->lineReflLeft->setText(QFileInfo(m.reflection.path(2)).fileName()); ui->lineReflRight->setProperty("GLpath", m.reflection.path(3)); ui->lineReflRight->setText(QFileInfo(m.reflection.path(3)).fileName()); ui->lineReflTop->setProperty("GLpath", m.reflection.path(4)); ui->lineReflTop->setText(QFileInfo(m.reflection.path(4)).fileName()); ui->lineReflBottom->setProperty("GLpath", m.reflection.path(5)); ui->lineReflBottom->setText(QFileInfo(m.reflection.path(5)).fileName()); active = true; } Material MaterialEditor::material() { Material m; m.color_diffuse = ui->colorDiffuse->color(); m.color_specular = ui->colorSpecular->color(); m.color_self_illumination = ui->colorSelfIllum->color(); m.glass = ui->checkGlass->isChecked(); m.light_model = (Material::LightModel)ui->comboModel->currentIndex(); m.shine = ui->spinShine->value(); m.shine_strength = ui->spinShineStrength->value(); m.transparency = ui->spinTransparent->value(); m.reflectivity = ui->spinReflect->value(); m.bump_scale = ui->spinBump->value(); m.relief_scale = ui->spinRelief->value(); m.iof = ui->spinIOF->value(); m.dispersion = ui->spinDispersion->value(); m.diffuse.bitmap_path = ui->lineDiffuse->property("GLpath").toString(); m.bump.bitmap_path = ui->lineBump->property("GLpath").toString(); m.relief.bitmap_path = ui->lineRelief->property("GLpath").toString(); m.reflection.setPath(0, ui->lineReflFront->property("GLpath").toString()); m.reflection.setPath(1, ui->lineReflBack->property("GLpath").toString()); m.reflection.setPath(2, ui->lineReflLeft->property("GLpath").toString()); m.reflection.setPath(3, ui->lineReflRight->property("GLpath").toString()); m.reflection.setPath(4, ui->lineReflTop->property("GLpath").toString()); m.reflection.setPath(5, ui->lineReflBottom->property("GLpath").toString()); return m; } void MaterialEditor::on_buttonDiffuseSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineDiffuse->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; ui->lineDiffuse->setProperty("GLpath", str); ui->lineDiffuse->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonBumpSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineBump->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; ui->lineBump->setProperty("GLpath", str); ui->lineBump->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReliefSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", ui->lineRelief->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; ui->lineRelief->setProperty("GLpath", str); ui->lineRelief->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflFront->setProperty("GLpath", str); ui->lineReflFront->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflBack->setProperty("GLpath", str); ui->lineReflBack->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflLeft->setProperty("GLpath", str); ui->lineReflLeft->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflRight->setProperty("GLpath", str); ui->lineReflRight->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflTop->setProperty("GLpath", str); ui->lineReflTop->setText(QFileInfo(str).fileName()); materialChanged(); } 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(*)"); if (str.isEmpty()) return; ui->lineReflBottom->setProperty("GLpath", str); ui->lineReflBottom->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonDiffuseClear_clicked() { ui->lineDiffuse->setText(""); ui->lineDiffuse->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonBumpClear_clicked() { ui->lineBump->setText(""); ui->lineBump->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReliefClear_clicked() { ui->lineRelief->setText(""); ui->lineRelief->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflFrontClear_clicked() { ui->lineReflFront->setText(""); ui->lineReflFront->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflBackClear_clicked() { ui->lineReflBack->setText(""); ui->lineReflBack->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflLeftClear_clicked() { ui->lineReflLeft->setText(""); ui->lineReflLeft->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflRightClear_clicked() { ui->lineReflRight->setText(""); ui->lineReflRight->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflTopClear_clicked() { ui->lineReflTop->setText(""); ui->lineReflTop->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonReflBottomClear_clicked() { ui->lineReflBottom->setText(""); ui->lineReflBottom->setProperty("GLpath", ""); materialChanged(); } void MaterialEditor::on_buttonLoadCubeDir_clicked() { QString dir = QFileDialog::getExistingDirectory(this, "Select directory", ui->lineReflFront->property("GLpath").toString()); if (dir.isEmpty()) return; GLCubeTexture cb(0); cb.loadPathesFromDirectory(dir); active = false; ui->lineReflFront->setProperty("GLpath", cb.path(0)); ui->lineReflFront->setText(QFileInfo(cb.path(0)).fileName()); ui->lineReflBack->setProperty("GLpath", cb.path(1)); ui->lineReflBack->setText(QFileInfo(cb.path(1)).fileName()); ui->lineReflLeft->setProperty("GLpath", cb.path(2)); ui->lineReflLeft->setText(QFileInfo(cb.path(2)).fileName()); ui->lineReflRight->setProperty("GLpath", cb.path(3)); ui->lineReflRight->setText(QFileInfo(cb.path(3)).fileName()); ui->lineReflTop->setProperty("GLpath", cb.path(4)); ui->lineReflTop->setText(QFileInfo(cb.path(4)).fileName()); ui->lineReflBottom->setProperty("GLpath", cb.path(5)); ui->lineReflBottom->setText(QFileInfo(cb.path(5)).fileName()); active = true; materialChanged(); }