From f0e78b5fbba34670eb8dc2d232c8cff8ec47179c Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 16 Sep 2014 15:15:31 +0200 Subject: [PATCH] Allow to set and change values of value nodes. --HG-- branch : dfighter-tools --- .../plugins/gui_editor/expression_editor.cpp | 33 +++++++++++++++++++ .../plugins/gui_editor/expression_editor.h | 1 + .../src/plugins/gui_editor/expression_info.h | 7 ++++ .../plugins/gui_editor/expression_loader.cpp | 17 ++++++++++ .../plugins/gui_editor/expression_node.cpp | 15 +++++++++ .../src/plugins/gui_editor/expression_node.h | 9 +++++ 6 files changed, 82 insertions(+) diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp index df83a6732..502c135e1 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.cpp +++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp @@ -101,6 +101,12 @@ void ExpressionEditor::contextMenuEvent( QContextMenuEvent *e ) a = menu.addAction( "Change slot count" ); connect( a, SIGNAL( triggered() ), this, SLOT( onChangeSlotCount() ) ); } + + if( node->isValue() ) + { + a = menu.addAction( "Change value" ); + connect( a, SIGNAL( triggered() ), this, SLOT( onChangeValue() ) ); + } } } else @@ -219,6 +225,11 @@ void ExpressionEditor::onItemDblClicked( QTreeWidgetItem *item ) node->setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable ); node->setSlotNames( info->slotNames ); node->setVariable( info->variable ); + node->setIsValue( info->value ); + if( node->isValue() ) + { + node->setValue( "Value" ); + } m_scene->addItem( node ); } @@ -241,6 +252,28 @@ void ExpressionEditor::onChangeSlotCount() node->changeSlotCount( c ); } +void ExpressionEditor::onChangeValue() +{ + QList< QGraphicsItem* > l = m_scene->selectedItems(); + ExpressionNode *node = static_cast< ExpressionNode* >( l[ 0 ] ); + + QString oldValue = node->getValue(); + + QString newValue = QInputDialog::getText( this, + tr( "Change value" ), + tr( "Enter new value" ), + QLineEdit::Normal, + oldValue ); + + if( newValue.isEmpty() ) + return; + if( newValue == oldValue ) + return; + + node->setValue( newValue ); + node->update(); +} + void ExpressionEditor::addExpression( const ExpressionInfo *info ) { QTreeWidgetItem *item = findTopLevelItem( info->category ); diff --git a/code/studio/src/plugins/gui_editor/expression_editor.h b/code/studio/src/plugins/gui_editor/expression_editor.h index 79ff908f1..9380c6b29 100644 --- a/code/studio/src/plugins/gui_editor/expression_editor.h +++ b/code/studio/src/plugins/gui_editor/expression_editor.h @@ -46,6 +46,7 @@ private Q_SLOTS: void onUnLinkItems(); void onItemDblClicked( QTreeWidgetItem *item ); void onChangeSlotCount(); + void onChangeValue(); private: void addExpression( const ExpressionInfo *info ); diff --git a/code/studio/src/plugins/gui_editor/expression_info.h b/code/studio/src/plugins/gui_editor/expression_info.h index 854ea12c1..86218b6af 100644 --- a/code/studio/src/plugins/gui_editor/expression_info.h +++ b/code/studio/src/plugins/gui_editor/expression_info.h @@ -25,9 +25,16 @@ struct ExpressionInfo { QString name; + bool value; QString category; bool variable; QStringList slotNames; + + ExpressionInfo() + { + value = false; + variable = false; + } }; #endif diff --git a/code/studio/src/plugins/gui_editor/expression_loader.cpp b/code/studio/src/plugins/gui_editor/expression_loader.cpp index ee3346a0c..07db432e0 100644 --- a/code/studio/src/plugins/gui_editor/expression_loader.cpp +++ b/code/studio/src/plugins/gui_editor/expression_loader.cpp @@ -37,6 +37,20 @@ public: return true; } + bool parseValue() + { + QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement ); + if( reader.hasError() ) + return false; + + if( text.toLower() == "true" ) + m_info->value = true; + else + m_info->value = false; + + return true; + } + bool parseCategory() { QString text = reader.readElementText( QXmlStreamReader::ErrorOnUnexpectedElement ); @@ -136,6 +150,9 @@ public: if( name == "name" ) error = !parseName(); else + if( name == "value" ) + error = !parseValue(); + else if( name == "category" ) error = !parseCategory(); else diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp index 8c736c919..3a67a2d8d 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.cpp +++ b/code/studio/src/plugins/gui_editor/expression_node.cpp @@ -106,6 +106,7 @@ QGraphicsItem( parent ) m_hh = 20.0; m_variable = false; + m_isValue = false; m_name = name; @@ -152,6 +153,20 @@ void ExpressionNode::paint( QPainter *painter, const QStyleOptionGraphicsItem *o painter->setPen( p ); painter->drawText( header, Qt::AlignCenter, m_name ); + // Draw value if applicable + if( m_isValue ) + { + QRectF vbox; + vbox.setTopLeft( QPoint( 0.0, 20.0 ) ); + vbox.setWidth( header.width() ); + vbox.setHeight( header.height() ); + QPen vpen; + vpen.setColor( Qt::red ); + painter->setPen( vpen ); + painter->drawText( vbox, Qt::AlignCenter, m_value ); + painter->setPen( p ); + } + if( option->state & QStyle::State_Selected ) { p.setStyle( Qt::DotLine ); diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h index ebf2c9fd5..52d515bbb 100644 --- a/code/studio/src/plugins/gui_editor/expression_node.h +++ b/code/studio/src/plugins/gui_editor/expression_node.h @@ -58,6 +58,12 @@ public: void setVariable( bool b ){ m_variable = b; } bool variable() const{ return m_variable; } + void setValue( const QString &value ){ m_value = value; } + QString getValue() const{ return m_value; } + + bool isValue() const{ return m_isValue; } + void setIsValue( bool b ){ m_isValue = b; } + protected: void mouseMoveEvent( QGraphicsSceneMouseEvent *e ); @@ -75,6 +81,9 @@ private: QString m_name; bool m_variable; + + QString m_value; + bool m_isValue; }; #endif