From e87e265c420c209ca56c15eb1a1e9ddcf4e17bda Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 1 Jun 2013 02:43:27 +0200 Subject: [PATCH] Implemented some of the buttons of the GUI skeleton. --HG-- branch : gsoc2013-dfighter --- .../material_editor/material_properties.cpp | 46 ++++++- .../material_editor/material_properties.h | 2 + .../material_editor/material_properties.ui | 5 - .../material_property_editor.cpp | 25 ++++ .../material_property_editor.h | 14 +++ .../material_property_editor.ui | 79 +++++++++--- .../material_editor/material_widget.cpp | 25 ++++ .../plugins/material_editor/material_widget.h | 4 + .../plugins/material_editor/render_passes.cpp | 115 ++++++++++++++++++ .../plugins/material_editor/render_passes.h | 10 ++ .../plugins/material_editor/render_passes.ui | 23 +--- 11 files changed, 306 insertions(+), 42 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp index a36de1976..aa657996d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp @@ -24,9 +24,9 @@ namespace MaterialEditor QWidget( parent ) { setupUi( this ); - setupConnections(); - matPropEditWidget = new MatPropEditWidget(); + setupConnections(); + edit = false; } MatPropWidget::~MatPropWidget() @@ -42,16 +42,57 @@ namespace MaterialEditor void MatPropWidget::onAddClicked() { + edit = false; + matPropEditWidget->clear(); matPropEditWidget->show(); } void MatPropWidget::onEditClicked() { + QTreeWidgetItem *item = treeWidget->currentItem(); + if( item == NULL ) + return; + + MaterialProperty prop; + prop.prop = item->data( 0, Qt::DisplayRole ).toString(); + prop.label = item->data( 1, Qt::DisplayRole ).toString(); + prop.type = item->data( 2, Qt::DisplayRole ).toString(); + + edit = true; + matPropEditWidget->setProperty( prop ); matPropEditWidget->show(); } void MatPropWidget::onRemoveClicked() { + QTreeWidgetItem *item = treeWidget->currentItem(); + if( item == NULL ) + return; + + delete item; + } + + void MatPropWidget::onEditorOKClicked() + { + MaterialProperty prop; + matPropEditWidget->getProperty( prop ); + + if( edit ) + { + QTreeWidgetItem *item = treeWidget->currentItem(); + item->setData( 0, Qt::DisplayRole, prop.prop ); + item->setData( 1, Qt::DisplayRole, prop.label ); + item->setData( 2, Qt::DisplayRole, prop.type ); + } + else + { + QTreeWidgetItem *item = new QTreeWidgetItem(); + item->setData( 0, Qt::DisplayRole, prop.prop ); + item->setData( 1, Qt::DisplayRole, prop.label ); + item->setData( 2, Qt::DisplayRole, prop.type ); + treeWidget->addTopLevelItem( item ); + } + } void MatPropWidget::setupConnections() @@ -60,6 +101,7 @@ namespace MaterialEditor connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); connect( editButton, SIGNAL( clicked( bool ) ), this, SLOT( onEditClicked() ) ); connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); + connect( matPropEditWidget, SIGNAL( okClicked() ), this, SLOT( onEditorOKClicked() ) ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h index b87eb59cf..325612465 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.h @@ -36,9 +36,11 @@ namespace MaterialEditor void onAddClicked(); void onEditClicked(); void onRemoveClicked(); + void onEditorOKClicked(); private: void setupConnections(); + bool edit; MatPropEditWidget *matPropEditWidget; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.ui index fdbdc654d..e825fcc23 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.ui @@ -36,11 +36,6 @@ Type - - - Default - - diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.cpp index e0f57dd6a..d16a80734 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.cpp @@ -29,9 +29,34 @@ namespace MaterialEditor { } + void MatPropEditWidget::getProperty( MaterialProperty &prop ) + { + prop.prop = propertyEdit->text(); + prop.label = labelEdit->text(); + prop.type = typeCB->currentText(); + } + + void MatPropEditWidget::setProperty( const MaterialProperty &prop ) + { + propertyEdit->setText( prop.prop ); + labelEdit->setText( prop.label ); + int i = typeCB->findText( prop.type ); + if( i != -1 ) + typeCB->setCurrentIndex( i ); + + } + + void MatPropEditWidget::clear() + { + propertyEdit->clear(); + labelEdit->clear(); + typeCB->setCurrentIndex( 0 ); + } + void MatPropEditWidget::onOKClicked() { close(); + Q_EMIT okClicked(); } void MatPropEditWidget::onCancelClicked() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h index 70861a96a..c54eb4012 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.h @@ -21,12 +21,26 @@ namespace MaterialEditor { + + struct MaterialProperty + { + QString prop; + QString label; + QString type; + }; + class MatPropEditWidget : public QWidget, public Ui::MatPropEditWidget { Q_OBJECT public: MatPropEditWidget( QWidget *parent = NULL ); ~MatPropEditWidget(); + void getProperty( MaterialProperty &prop ); + void setProperty( const MaterialProperty &prop ); + void clear(); + + Q_SIGNALS: + void okClicked(); private Q_SLOTS: void onOKClicked(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.ui index 0fdea20ad..2799eee3b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_property_editor.ui @@ -9,49 +9,92 @@ 0 0 - 538 - 282 + 300 + 145 Material property editor - - - + + + + Property + + + + + + + + + + Label + + + + + + + + + + Type + + + + + + + + 0 + 0 + + + + + Color + + + - Property + Vector4 - - + + + + Float + + + - Value + Int - + - Property + UInt - Label + Double - Type + Matrix4 - Default + Texture - + @@ -64,7 +107,7 @@ - + @@ -77,14 +120,14 @@ - + Qt::Horizontal - 355 + 117 20 diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp index f1dbbe9d2..33ba4debf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp @@ -37,11 +37,36 @@ namespace MaterialEditor void MaterialWidget::setupConnections() { connect( passButton, SIGNAL( clicked( bool ) ), this, SLOT( onPassEditClicked() ) ); + + connect( renderPassesWidget, SIGNAL( okClicked() ), this, SLOT( onPassOKClicked() ) ); + connect( renderPassesWidget, SIGNAL( passRenamed( const QString&, const QString& ) ), + this, SLOT( onPassRenamed( const QString&, const QString& ) ) ); + connect( renderPassesWidget, SIGNAL( passPushedUp( const QString& ) ), + this, SLOT( onPassPushedUp( const QString& ) ) ); + connect( renderPassesWidget, SIGNAL( passPushedDown( const QString& ) ), + this, SLOT( onPassPushedDown( const QString& ) ) ); } void MaterialWidget::onPassEditClicked() { renderPassesWidget->show(); } + + void MaterialWidget::onPassOKClicked() + { + } + + void MaterialWidget::onPassRenamed( const QString &from, const QString &to ) + { + } + + void MaterialWidget::onPassPushedUp( const QString &pass ) + { + } + + void MaterialWidget::onPassPushedDown( const QString &pass ) + { + } + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h index 18fef6891..332b779b7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h @@ -37,6 +37,10 @@ namespace MaterialEditor private Q_SLOTS: void onPassEditClicked(); + void onPassOKClicked(); + void onPassRenamed( const QString &from, const QString &to ); + void onPassPushedUp( const QString &pass ); + void onPassPushedDown( const QString &pass ); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp index 888ee550a..add812d84 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp @@ -15,6 +15,8 @@ // along with this program. If not, see . #include "render_passes.h" +#include +#include namespace MaterialEditor { @@ -29,6 +31,30 @@ namespace MaterialEditor { } + void RenderPassesWidget::fillList( const QStringList &list ) + { + listWidget->clear(); + + QStringListIterator itr( list ); + while( itr.hasNext() ) + { + listWidget->addItem( itr.next() ); + } + } + + void RenderPassesWidget::getList( QStringList &list ) + { + for( int i = 0; i < listWidget->count(); i++ ) + { + list.push_back( listWidget->item( i )->text() ); + } + } + + void RenderPassesWidget::clear() + { + listWidget->clear(); + } + void RenderPassesWidget::setupConnections() { connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ); @@ -43,6 +69,7 @@ namespace MaterialEditor void RenderPassesWidget::onOKClicked() { close(); + Q_EMIT okClicked(); } void RenderPassesWidget::onCancelClicked() @@ -52,22 +79,110 @@ namespace MaterialEditor void RenderPassesWidget::onAddClicked() { + QString label = + QInputDialog::getText( + NULL, + tr( "Pass label" ), + tr( "Please enter the new pass' label" ) + ); + + if( label.isEmpty() ) + return; + + int i = 0; + while( i < listWidget->count() ) + { + QListWidgetItem *item = listWidget->item( i ); + QString text = item->text(); + if( text == label ) + break; + i++; + } + + if( i < listWidget->count() ) + { + QMessageBox::warning( + NULL, + tr( "Pass label" ), + tr( "Pass label already exists!" ) + ); + + return; + } + + listWidget->addItem( label ); } void RenderPassesWidget::onRemoveClicked() { + int row = listWidget->currentRow(); + if( row == -1 ) + return; + + QListWidgetItem *item = listWidget->takeItem( row ); + delete item; } void RenderPassesWidget::onEditClicked() { + QListWidgetItem *item = listWidget->currentItem(); + if( item == NULL ) + return; + + QString from = item->text(); + QString to = + QInputDialog::getText( + NULL, + tr( "Editing pass label" ), + tr( "Please enter the new label" ), + QLineEdit::Normal, + from + ); + + if( to.isEmpty() ) + return; + + item->setText( to ); + + Q_EMIT passRenamed( from, to ); } void RenderPassesWidget::onUpClicked() { + QListWidgetItem *item = listWidget->currentItem(); + if( item == NULL ) + return; + + int row = listWidget->currentRow(); + if( row == 0 ) + return; + + item = listWidget->takeItem( row ); + listWidget->insertItem( row - 1, item ); + listWidget->setCurrentRow( row - 1 ); + + QString s = item->text(); + + Q_EMIT passPushedUp( s ); } void RenderPassesWidget::onDownClicked() { + QListWidgetItem *item = listWidget->currentItem(); + if( item == NULL ) + return; + + int row = listWidget->currentRow(); + if( row == ( listWidget->count() - 1 ) ) + return; + + item = listWidget->takeItem( row ); + listWidget->insertItem( row + 1, item ); + listWidget->setCurrentRow( row + 1 ); + + QString s = item->text(); + + Q_EMIT passPushedDown( s ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h index 1206079d1..1bdbe30f4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h @@ -18,6 +18,7 @@ #define RENDER_PASSES_H #include "ui_render_passes.h" +#include namespace MaterialEditor { @@ -27,6 +28,15 @@ namespace MaterialEditor public: RenderPassesWidget( QWidget *parent = NULL ); ~RenderPassesWidget(); + void fillList( const QStringList &list ); + void getList( QStringList &list ); + void clear(); + + Q_SIGNALS: + void okClicked(); + void passRenamed( const QString &from, const QString &to ); + void passPushedUp( const QString &pass ); + void passPushedDown( const QString &pass ); private: void setupConnections(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.ui index 6b4c66138..815f59810 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.ui @@ -9,29 +9,18 @@ 0 0 - 524 - 292 + 498 + 297 Rendering passes - - + + - - - - # - - - - - Label - - - + @@ -121,7 +110,7 @@ - +