Implemented some of the buttons of the GUI skeleton.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 5aec012c5f
commit e87e265c42

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

@ -36,9 +36,11 @@ namespace MaterialEditor
void onAddClicked();
void onEditClicked();
void onRemoveClicked();
void onEditorOKClicked();
private:
void setupConnections();
bool edit;
MatPropEditWidget *matPropEditWidget;
};

@ -36,11 +36,6 @@
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Default</string>
</property>
</column>
</widget>
</item>
<item>

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

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

@ -9,49 +9,92 @@
<rect>
<x>0</x>
<y>0</y>
<width>538</width>
<height>282</height>
<width>300</width>
<height>145</height>
</rect>
</property>
<property name="windowTitle">
<string>Material property editor</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QTreeWidget" name="treeWidget">
<column>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Property</string>
</property>
</column>
<column>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="propertyEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Value</string>
<string>Label</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="labelEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Type</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QComboBox" name="typeCB">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</column>
<item>
<property name="text">
<string>Property</string>
<string>Color</string>
</property>
</item>
<item>
<property name="text">
<string>Label</string>
<string>Vector4</string>
</property>
</item>
<item>
<property name="text">
<string>Type</string>
<string>Float</string>
</property>
</item>
<item>
<property name="text">
<string>Int</string>
</property>
</item>
<item>
<property name="text">
<string>UInt</string>
</property>
</item>
<item>
<property name="text">
<string>Default</string>
<string>Double</string>
</property>
</item>
<item>
<property name="text">
<string>Matrix4</string>
</property>
</item>
<item>
<property name="text">
<string>Texture</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QPushButton" name="okButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -64,7 +107,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QPushButton" name="cancelButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -77,14 +120,14 @@
</property>
</widget>
</item>
<item row="1" column="2">
<item row="3" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>355</width>
<width>117</width>
<height>20</height>
</size>
</property>

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

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

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

@ -18,6 +18,7 @@
#define RENDER_PASSES_H
#include "ui_render_passes.h"
#include <QStringList>
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();

@ -9,29 +9,18 @@
<rect>
<x>0</x>
<y>0</y>
<width>524</width>
<height>292</height>
<width>498</width>
<height>297</height>
</rect>
</property>
<property name="windowTitle">
<string>Rendering passes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="treeWidget">
<column>
<property name="text">
<string>#</string>
</property>
</column>
<column>
<property name="text">
<string>Label</string>
</property>
</column>
</widget>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -121,7 +110,7 @@
</item>
</layout>
</item>
<item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="okButton">

Loading…
Cancel
Save