From 40c95e82ff5e4566010a941a0d6e9f1848049982 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sun, 30 Jun 2013 02:37:39 +0200 Subject: [PATCH] Changed the shader editor widget into a dialog. Implemented some of the button functions of Shader widget. --HG-- branch : gsoc2013-dfighter --- .../plugins/material_editor/shader_editor.cpp | 13 +- .../plugins/material_editor/shader_editor.h | 6 +- .../plugins/material_editor/shader_editor.ui | 31 ++-- .../plugins/material_editor/shader_widget.cpp | 145 ++++++++++++++++++ .../plugins/material_editor/shader_widget.h | 6 + 5 files changed, 185 insertions(+), 16 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp index 2430c0b2e..a9a3e4d3f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.cpp @@ -19,8 +19,8 @@ namespace MaterialEditor { - ShaderEditorWidget::ShaderEditorWidget( QWidget *parent ) : - QWidget( parent ) + ShaderEditorWidget::ShaderEditorWidget( QDialog *parent ) : + QDialog( parent ) { setupUi( this ); setupConnections(); @@ -86,6 +86,15 @@ namespace MaterialEditor { close(); } + + void ShaderEditorWidget::reset() + { + QString empty; + nameEdit->setText( empty ); + descriptionEdit->setPlainText( empty ); + vsEdit->setPlainText( empty ); + fsEdit->setPlainText( empty ); + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h index b63032aa4..0045e0ae5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.h @@ -22,11 +22,11 @@ namespace MaterialEditor { - class ShaderEditorWidget : public QWidget, public Ui::ShaderEditorWidget + class ShaderEditorWidget : public QDialog, public Ui::ShaderEditorWidget { Q_OBJECT public: - ShaderEditorWidget( QWidget *parent = NULL ); + ShaderEditorWidget( QDialog *parent = NULL ); ~ShaderEditorWidget(); void getName( QString &name ); @@ -39,6 +39,8 @@ namespace MaterialEditor void setVertexShader( const QString &vs ); void setFragmentShader( const QString &fs ); + void reset(); + private Q_SLOTS: void onOKClicked(); void onCancelClicked(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.ui index db0ca7fd7..48f87f534 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_editor.ui @@ -1,23 +1,23 @@ ShaderEditorWidget - - - Qt::ApplicationModal - + 0 0 - 750 - 729 + 861 + 735 Shader Editor - - + + true + + + @@ -31,7 +31,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -59,7 +59,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -117,6 +117,13 @@ + layoutWidget + layoutWidget_2 + layoutWidget_3 + layoutWidget_4 + layoutWidget_5 + vsEdit + label_3 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp index 90c5585d2..81a756d7d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.cpp @@ -15,6 +15,10 @@ // along with this program. If not, see . #include "shader_widget.h" +#include "shader_editor.h" +#include +#include +#include namespace MaterialEditor { @@ -23,10 +27,14 @@ namespace MaterialEditor { setupUi( this ); setupConnections(); + + shaderEditorWidget = new ShaderEditorWidget(); } ShaderWidget::~ShaderWidget() { + delete shaderEditorWidget; + shaderEditorWidget = NULL; } void ShaderWidget::setupConnections() @@ -44,20 +52,157 @@ namespace MaterialEditor close(); } + bool ShaderWidget::nameExists( const QString &name ) + { + QTreeWidgetItem *item = NULL; + for( int i = 0; i < shaderListWidget->topLevelItemCount(); i++ ) + { + item = shaderListWidget->topLevelItem( i ); + if( item->text( 0 ) == name ) + return true; + } + + return false; + } + + void ShaderWidget::nameExistsMessage() + { + QMessageBox::critical( + this, + tr( "Shader already exists" ), + tr( "A shader with that name already exists!" ), + QMessageBox::Ok + ); + } + void ShaderWidget::onNewClicked() { + bool ok = false; + QString def; + QString name = + QInputDialog::getText( + this, + tr( "Shader name" ), + tr( "New shader's name?" ), + QLineEdit::Normal, + def, + &ok + ); + + if( nameExists( name ) ) + { + nameExistsMessage(); + return; + } + + QString fname = QFileDialog::getSaveFileName( + this, + tr( "New shader's path" ), + "/", + tr( "Shader files ( *.nelshader )" ) + ); + + shaderEditorWidget->reset(); + shaderEditorWidget->setName( name ); + + QString sname; + do{ + ok = true; + shaderEditorWidget->exec(); + shaderEditorWidget->getName( sname ); + + if( sname != name ) + { + if( nameExists( sname ) ) + { + ok = false; + nameExistsMessage(); + } + } + + }while( !ok ); + + QString descr; + shaderEditorWidget->getDescription( descr ); + + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setText( 0, sname ); + item->setText( 1, descr ); + item->setText( 2, fname ); + shaderListWidget->addTopLevelItem( item ); + shaderListWidget->sortItems( 0, Qt::AscendingOrder ); + + // save it } void ShaderWidget::onAddClicked() { + QString fn = + QFileDialog::getOpenFileName( + this, + tr( "Load shader" ), + "/", + tr( "Shader files ( *.nelshader )" ) + ); + } void ShaderWidget::onRemoveClicked() { + QTreeWidgetItem *item = shaderListWidget->currentItem(); + if( item == NULL ) + return; + + int selection = + QMessageBox::question( + this, + tr( "Removing shader" ), + tr( "Are you sure you want to remove this shader?" ), + QMessageBox::Yes, + QMessageBox::Cancel + ); + + if( selection == QMessageBox::Yes ) + delete item; } void ShaderWidget::onEditClicked() { + QTreeWidgetItem *item = shaderListWidget->currentItem(); + if( item == NULL ) + return; + + QString name = item->text( 0 ); + QString description = item->text( 1 ); + + shaderEditorWidget->reset(); + shaderEditorWidget->setName( name ); + shaderEditorWidget->setDescription( description ); + + QString sname; + bool ok; + do{ + ok = true; + shaderEditorWidget->exec(); + shaderEditorWidget->getName( sname ); + + if( sname != name ) + { + if( nameExists( sname ) ) + { + ok = false; + nameExistsMessage(); + } + } + + }while( !ok ); + + shaderEditorWidget->getDescription( description ); + item->setText( 0, sname ); + item->setText( 1, description ); + + // save + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h index ce7c869f8..d4d2f672a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/shader_widget.h @@ -22,6 +22,8 @@ namespace MaterialEditor { + class ShaderEditorWidget; + class ShaderWidget : public QWidget, public Ui::ShaderWidget { Q_OBJECT @@ -32,6 +34,10 @@ namespace MaterialEditor private: void setupConnections(); + bool nameExists( const QString &name ); + void nameExistsMessage(); + + ShaderEditorWidget *shaderEditorWidget; private Q_SLOTS: void onOKClicked();