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 namespace MaterialEditor
{ {
ShaderEditorWidget::ShaderEditorWidget( QWidget *parent ) : ShaderEditorWidget::ShaderEditorWidget( QDialog *parent ) :
QWidget( parent ) QDialog( parent )
{ {
setupUi( this ); setupUi( this );
setupConnections(); setupConnections();
@ -86,6 +86,15 @@ namespace MaterialEditor
{ {
close(); close();
} }
void ShaderEditorWidget::reset()
{
QString empty;
nameEdit->setText( empty );
descriptionEdit->setPlainText( empty );
vsEdit->setPlainText( empty );
fsEdit->setPlainText( empty );
}
} }

@ -22,11 +22,11 @@
namespace MaterialEditor namespace MaterialEditor
{ {
class ShaderEditorWidget : public QWidget, public Ui::ShaderEditorWidget class ShaderEditorWidget : public QDialog, public Ui::ShaderEditorWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
ShaderEditorWidget( QWidget *parent = NULL ); ShaderEditorWidget( QDialog *parent = NULL );
~ShaderEditorWidget(); ~ShaderEditorWidget();
void getName( QString &name ); void getName( QString &name );
@ -39,6 +39,8 @@ namespace MaterialEditor
void setVertexShader( const QString &vs ); void setVertexShader( const QString &vs );
void setFragmentShader( const QString &fs ); void setFragmentShader( const QString &fs );
void reset();
private Q_SLOTS: private Q_SLOTS:
void onOKClicked(); void onOKClicked();
void onCancelClicked(); void onCancelClicked();

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

@ -15,6 +15,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "shader_widget.h" #include "shader_widget.h"
#include "shader_editor.h"
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
namespace MaterialEditor namespace MaterialEditor
{ {
@ -23,10 +27,14 @@ namespace MaterialEditor
{ {
setupUi( this ); setupUi( this );
setupConnections(); setupConnections();
shaderEditorWidget = new ShaderEditorWidget();
} }
ShaderWidget::~ShaderWidget() ShaderWidget::~ShaderWidget()
{ {
delete shaderEditorWidget;
shaderEditorWidget = NULL;
} }
void ShaderWidget::setupConnections() void ShaderWidget::setupConnections()
@ -44,20 +52,157 @@ namespace MaterialEditor
close(); 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() 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() void ShaderWidget::onAddClicked()
{ {
QString fn =
QFileDialog::getOpenFileName(
this,
tr( "Load shader" ),
"/",
tr( "Shader files ( *.nelshader )" )
);
} }
void ShaderWidget::onRemoveClicked() 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() 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 namespace MaterialEditor
{ {
class ShaderEditorWidget;
class ShaderWidget : public QWidget, public Ui::ShaderWidget class ShaderWidget : public QWidget, public Ui::ShaderWidget
{ {
Q_OBJECT Q_OBJECT
@ -32,6 +34,10 @@ namespace MaterialEditor
private: private:
void setupConnections(); void setupConnections();
bool nameExists( const QString &name );
void nameExistsMessage();
ShaderEditorWidget *shaderEditorWidget;
private Q_SLOTS: private Q_SLOTS:
void onOKClicked(); void onOKClicked();

Loading…
Cancel
Save