Changed the shader editor widget into a dialog. Implemented some of the button functions of Shader widget.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent abbc09e19c
commit 40c95e82ff

@ -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 );
}
}

@ -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();

@ -1,23 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShaderEditorWidget</class>
<widget class="QWidget" name="ShaderEditorWidget">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<widget class="QDialog" name="ShaderEditorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>729</height>
<width>861</width>
<height>735</height>
</rect>
</property>
<property name="windowTitle">
<string>Shader Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="nameLayout">
<item>
<widget class="QLabel" name="label">
@ -31,7 +31,7 @@
</item>
</layout>
</item>
<item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="descrLayout">
<item>
<widget class="QLabel" name="label_2">
@ -45,7 +45,7 @@
</item>
</layout>
</item>
<item>
<item row="2" column="0">
<layout class="QVBoxLayout" name="vsLayout">
<item>
<widget class="QLabel" name="label_3">
@ -59,7 +59,7 @@
</item>
</layout>
</item>
<item>
<item row="3" column="0">
<layout class="QVBoxLayout" name="fsLayout">
<item>
<widget class="QLabel" name="label_4">
@ -73,7 +73,7 @@
</item>
</layout>
</item>
<item>
<item row="4" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="okButton">
@ -117,6 +117,13 @@
</layout>
</item>
</layout>
<zorder>layoutWidget</zorder>
<zorder>layoutWidget_2</zorder>
<zorder>layoutWidget_3</zorder>
<zorder>layoutWidget_4</zorder>
<zorder>layoutWidget_5</zorder>
<zorder>vsEdit</zorder>
<zorder>label_3</zorder>
</widget>
<resources/>
<connections/>

@ -15,6 +15,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "shader_widget.h"
#include "shader_editor.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
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
}
}

@ -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();

Loading…
Cancel
Save