/* 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" MaterialEditor::MaterialEditor(QWidget * parent): QWidget(parent) { setupUi(this); active = true; } void MaterialEditor::changeEvent(QEvent * e) { return; QWidget::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: retranslateUi(this); break; default: break; } } void MaterialEditor::setMaterial(const Material & m) { active = false; colorDiffuse->setColor(m.color_diffuse); colorSpecular->setColor(m.color_specular); colorSelfIllum->setColor(m.color_self_illumination); checkGlass->setChecked(m.glass); comboModel->setCurrentIndex((int)m.light_model); spinShine->setValue(m.shine); spinShineStrength->setValue(m.shine_strength); spinTransparent->setValue(m.transparency); spinReflect->setValue(m.reflectivity); spinBump->setValue(m.bump_scale); spinRelief->setValue(m.relief_scale); spinIOF->setValue(m.iof); spinDispersion->setValue(m.dispersion); lineDiffuse->setProperty("GLpath", m.diffuse.bitmap_path); lineDiffuse->setText(QFileInfo(m.diffuse.bitmap_path).fileName()); lineBump->setProperty("GLpath", m.bump.bitmap_path); lineBump->setText(QFileInfo(m.bump.bitmap_path).fileName()); lineRelief->setProperty("GLpath", m.relief.bitmap_path); lineRelief->setText(QFileInfo(m.relief.bitmap_path).fileName()); lineReflFront->setProperty("GLpath", m.reflection.path(0)); lineReflFront->setText(QFileInfo(m.reflection.path(0)).fileName()); lineReflBack->setProperty("GLpath", m.reflection.path(1)); lineReflBack->setText(QFileInfo(m.reflection.path(1)).fileName()); lineReflLeft->setProperty("GLpath", m.reflection.path(2)); lineReflLeft->setText(QFileInfo(m.reflection.path(2)).fileName()); lineReflRight->setProperty("GLpath", m.reflection.path(3)); lineReflRight->setText(QFileInfo(m.reflection.path(3)).fileName()); lineReflTop->setProperty("GLpath", m.reflection.path(4)); lineReflTop->setText(QFileInfo(m.reflection.path(4)).fileName()); lineReflBottom->setProperty("GLpath", m.reflection.path(5)); lineReflBottom->setText(QFileInfo(m.reflection.path(5)).fileName()); active = true; } Material MaterialEditor::material() { Material m; m.color_diffuse = colorDiffuse->color(); m.color_specular = colorSpecular->color(); m.color_self_illumination = colorSelfIllum->color(); m.glass = checkGlass->isChecked(); m.light_model = (Material::LightModel)comboModel->currentIndex(); m.shine = spinShine->value(); m.shine_strength = spinShineStrength->value(); m.transparency = spinTransparent->value(); m.reflectivity = spinReflect->value(); m.bump_scale = spinBump->value(); m.relief_scale = spinRelief->value(); m.iof = spinIOF->value(); m.dispersion = spinDispersion->value(); m.diffuse.bitmap_path = lineDiffuse->property("GLpath").toString(); m.bump.bitmap_path = lineBump->property("GLpath").toString(); m.relief.bitmap_path = lineRelief->property("GLpath").toString(); m.reflection.setPath(0, lineReflFront->property("GLpath").toString()); m.reflection.setPath(1, lineReflBack->property("GLpath").toString()); m.reflection.setPath(2, lineReflLeft->property("GLpath").toString()); m.reflection.setPath(3, lineReflRight->property("GLpath").toString()); m.reflection.setPath(4, lineReflTop->property("GLpath").toString()); m.reflection.setPath(5, lineReflBottom->property("GLpath").toString()); return m; } void MaterialEditor::on_buttonDiffuseSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineDiffuse->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineDiffuse->setProperty("GLpath", str); lineDiffuse->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonBumpSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineBump->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineBump->setProperty("GLpath", str); lineBump->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReliefSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineRelief->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineRelief->setProperty("GLpath", str); lineRelief->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflFrontSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflFront->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflFront->setProperty("GLpath", str); lineReflFront->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflBackSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflBack->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflBack->setProperty("GLpath", str); lineReflBack->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflLeftSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflLeft->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflLeft->setProperty("GLpath", str); lineReflLeft->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflRightSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflRight->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflRight->setProperty("GLpath", str); lineReflRight->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflTopSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflTop->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflTop->setProperty("GLpath", str); lineReflTop->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonReflBottomSelect_clicked() { QString str = QFileDialog::getOpenFileName(this, "Select image", lineReflBottom->property("GLpath").toString(), "Images(*.bmp *.jpg *.jpeg *.png *.tif *.tiff *.tga);;All files(*)"); if (str.isEmpty()) return; lineReflBottom->setProperty("GLpath", str); lineReflBottom->setText(QFileInfo(str).fileName()); materialChanged(); } void MaterialEditor::on_buttonLoadCubeDir_clicked() { QString dir = QFileDialog::getExistingDirectory(this, "Select directory", lineReflFront->property("GLpath").toString()); if (dir.isEmpty()) return; GLCubeTexture cb(0); cb.loadPathesFromDirectory(dir); active = false; lineReflFront->setProperty("GLpath", cb.path(0)); lineReflFront->setText(QFileInfo(cb.path(0)).fileName()); lineReflBack->setProperty("GLpath", cb.path(1)); lineReflBack->setText(QFileInfo(cb.path(1)).fileName()); lineReflLeft->setProperty("GLpath", cb.path(2)); lineReflLeft->setText(QFileInfo(cb.path(2)).fileName()); lineReflRight->setProperty("GLpath", cb.path(3)); lineReflRight->setText(QFileInfo(cb.path(3)).fileName()); lineReflTop->setProperty("GLpath", cb.path(4)); lineReflTop->setText(QFileInfo(cb.path(4)).fileName()); lineReflBottom->setProperty("GLpath", cb.path(5)); lineReflBottom->setText(QFileInfo(cb.path(5)).fileName()); active = true; materialChanged(); }