code format
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user