diff --git a/code/studio/src/plugins/gui_editor/CMakeLists.txt b/code/studio/src/plugins/gui_editor/CMakeLists.txt
index 77ca5a335..2b46e2cdc 100644
--- a/code/studio/src/plugins/gui_editor/CMakeLists.txt
+++ b/code/studio/src/plugins/gui_editor/CMakeLists.txt
@@ -35,6 +35,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_HDR
action_property_manager.h
texture_property_manager.h
expression_editor.h
+ expr_link_dlg.h
)
SET(OVQT_PLUGIN_GUI_EDITOR_UIS
@@ -53,6 +54,7 @@ SET(OVQT_PLUGIN_GUI_EDITOR_UIS
action_list.ui
texture_chooser.ui
expression_editor.ui
+ expr_link_dlg.ui
)
SET(QT_USE_QTGUI TRUE)
diff --git a/code/studio/src/plugins/gui_editor/expr_link_dlg.cpp b/code/studio/src/plugins/gui_editor/expr_link_dlg.cpp
new file mode 100644
index 000000000..44cf29d74
--- /dev/null
+++ b/code/studio/src/plugins/gui_editor/expr_link_dlg.cpp
@@ -0,0 +1,122 @@
+// Ryzom Core Studio - Georges Editor Plugin
+//
+// Copyright (C) 2014 Laszlo Kis-Adam
+// Copyright (C) 2010 Ryzom Core
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+
+#include "expr_link_dlg.h"
+#include
+
+ExprLinkDlg::ExprLinkDlg( QWidget *parent ) :
+QDialog( parent )
+{
+ m_ui.setupUi( this );
+
+ connect( m_ui.okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) );
+ connect( m_ui.cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) );
+}
+
+ExprLinkDlg::~ExprLinkDlg()
+{
+}
+
+void ExprLinkDlg::load( const QList< SlotInfo > &a, const QList< SlotInfo > &b )
+{
+ QListIterator< SlotInfo > itra( a );
+ QListIterator< SlotInfo > itrb( b );
+
+ while( itra.hasNext() )
+ {
+ const SlotInfo &info = itra.next();
+
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText( info.name );
+ item->setData( Qt::UserRole, info.slot );
+
+ m_ui.list1->addItem( item );
+ }
+
+ while( itrb.hasNext() )
+ {
+ const SlotInfo &info = itrb.next();
+
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setText( info.name );
+ item->setData( Qt::UserRole, info.slot );
+
+ m_ui.list2->addItem( item );
+ }
+
+}
+
+int ExprLinkDlg::getSlotA() const
+{
+ QListWidgetItem *item = m_ui.list1->currentItem();
+ if( item == NULL )
+ return -1;
+
+ int slot = item->data( Qt::UserRole ).toInt();
+ return slot;
+}
+
+int ExprLinkDlg::getSlotB() const
+{
+ QListWidgetItem *item = m_ui.list2->currentItem();
+ if( item == NULL )
+ return -1;
+
+ int slot = item->data( Qt::UserRole ).toInt();
+ return slot;
+}
+
+void ExprLinkDlg::onOKClicked()
+{
+ int slotA = getSlotA();
+ int slotB = getSlotB();
+
+ if( ( slotA == -1 ) || ( slotB == -1 ) )
+ {
+ QMessageBox::information( this,
+ tr( "No slots selected" ),
+ tr( "You need to select a slot on both sides." ) );
+ return;
+ }
+
+ if( ( slotA == 0 ) && ( slotB == 0 ) )
+ {
+ QMessageBox::information( this,
+ tr( "Wrong slots selected" ),
+ tr( "You can only select the 'Out' slot on one of the sides." ) );
+ return;
+ }
+
+ if( ( slotA != 0 ) && ( slotB != 0 ) )
+ {
+ QMessageBox::information( this,
+ tr( "Wrong slots selected" ),
+ tr( "One of the slots selected must be the 'Out' slot!" ) );
+ return;
+ }
+
+ accept();
+}
+
+void ExprLinkDlg::onCancelClicked()
+{
+ reject();
+}
+
+
diff --git a/code/studio/src/plugins/gui_editor/expr_link_dlg.h b/code/studio/src/plugins/gui_editor/expr_link_dlg.h
new file mode 100644
index 000000000..d53d528c5
--- /dev/null
+++ b/code/studio/src/plugins/gui_editor/expr_link_dlg.h
@@ -0,0 +1,49 @@
+// Ryzom Core Studio - Georges Editor Plugin
+//
+// Copyright (C) 2014 Laszlo Kis-Adam
+// Copyright (C) 2010 Ryzom Core
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+
+#ifndef EXPR_LINK_DLG
+#define EXPR_LINK_DLG
+
+#include
+#include
+#include "ui_expr_link_dlg.h"
+#include "expr_slot_info.h"
+
+class ExprLinkDlg : public QDialog
+{
+ Q_OBJECT
+public:
+ ExprLinkDlg( QWidget *parent = NULL );
+ ~ExprLinkDlg();
+
+ void load( const QList< SlotInfo > &a, const QList< SlotInfo > &b );
+
+ int getSlotA() const;
+ int getSlotB() const;
+
+private Q_SLOTS:
+ void onOKClicked();
+ void onCancelClicked();
+
+private:
+ Ui::ExprLinkDialog m_ui;
+};
+
+#endif
+
diff --git a/code/studio/src/plugins/gui_editor/expr_link_dlg.ui b/code/studio/src/plugins/gui_editor/expr_link_dlg.ui
new file mode 100644
index 000000000..32e610352
--- /dev/null
+++ b/code/studio/src/plugins/gui_editor/expr_link_dlg.ui
@@ -0,0 +1,58 @@
+
+
+ ExprLinkDialog
+
+
+
+ 0
+ 0
+ 581
+ 388
+
+
+
+ Linking nodes
+
+
+ -
+
+
-
+
+
+ -
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 398
+ 20
+
+
+
+
+ -
+
+
+ Ok
+
+
+
+ -
+
+
+ Cancel
+
+
+
+
+
+
+
+
diff --git a/code/studio/src/plugins/gui_editor/expr_slot_info.h b/code/studio/src/plugins/gui_editor/expr_slot_info.h
new file mode 100644
index 000000000..9614cd96a
--- /dev/null
+++ b/code/studio/src/plugins/gui_editor/expr_slot_info.h
@@ -0,0 +1,32 @@
+// Ryzom Core Studio - Georges Editor Plugin
+//
+// Copyright (C) 2014 Laszlo Kis-Adam
+// Copyright (C) 2010 Ryzom Core
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+
+#ifndef EXPR_SLOT_INFO
+#define EXPR_SLOT_INFO
+
+#include
+
+struct SlotInfo
+{
+ QString name;
+ int slot;
+};
+
+#endif
+
diff --git a/code/studio/src/plugins/gui_editor/expression_editor.cpp b/code/studio/src/plugins/gui_editor/expression_editor.cpp
index cca3b29ae..c4d5c1948 100644
--- a/code/studio/src/plugins/gui_editor/expression_editor.cpp
+++ b/code/studio/src/plugins/gui_editor/expression_editor.cpp
@@ -25,6 +25,7 @@
#include "expression_node.h"
#include "expression_link.h"
+#include "expr_link_dlg.h"
#include
@@ -119,16 +120,32 @@ void ExpressionEditor::onLinkItems()
ExpressionNode *from = static_cast< ExpressionNode* >( l[ 0 ] );
ExpressionNode *to = static_cast< ExpressionNode* >( l[ 1 ] );
- if( ( from->link( 0 ) != NULL ) || ( to->link( 0 ) != NULL ) )
+ QList< SlotInfo > froml;
+ QList< SlotInfo > tol;
+
+ from->getSlots( froml );
+ to->getSlots( tol );
+
+ // If there are no free slots, or both "Out" slots are taken we can't link
+ if( froml.isEmpty() || tol.isEmpty() || ( !from->slotEmpty( 0 ) && !to->slotEmpty( 0 ) ) )
{
QMessageBox::information( this,
tr( "Failed to link nodes" ),
- tr( "Unfortunately those nodes are already linked." ) );
+ tr( "Unfortunately those nodes are full." ) );
return;
}
+ ExprLinkDlg d;
+ d.load( froml, tol );
+ int result = d.exec();
+ if( result == QDialog::Rejected )
+ return;
+
+ int slotA = d.getSlotA();
+ int slotB = d.getSlotB();
+
ExpressionLink *link = new ExpressionLink();
- link->link( from, to, 0, 0 );
+ link->link( from, to, slotA, slotB );
m_scene->addItem( link );
}
diff --git a/code/studio/src/plugins/gui_editor/expression_link.cpp b/code/studio/src/plugins/gui_editor/expression_link.cpp
index 8e461960e..66ddffd7f 100644
--- a/code/studio/src/plugins/gui_editor/expression_link.cpp
+++ b/code/studio/src/plugins/gui_editor/expression_link.cpp
@@ -50,13 +50,19 @@ void ExpressionLink::link( ExpressionNode *from, ExpressionNode *to, int fromSlo
void ExpressionLink::unlink()
{
+ if( m_from == NULL )
+ return;
+
m_from->setLink( NULL, m_fromSlot );
m_to->setLink( NULL, m_toSlot );
+
+ m_from = NULL;
+ m_to = NULL;
}
void ExpressionLink::nodeMoved()
{
- setLine( QLineF( m_from->slotPos( 0 ), m_to->slotPos( 0 ) ) );
+ setLine( QLineF( m_from->slotPos( m_fromSlot ), m_to->slotPos( m_toSlot ) ) );
}
void ExpressionLink::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget )
diff --git a/code/studio/src/plugins/gui_editor/expression_node.cpp b/code/studio/src/plugins/gui_editor/expression_node.cpp
index bcde92423..90d132d91 100644
--- a/code/studio/src/plugins/gui_editor/expression_node.cpp
+++ b/code/studio/src/plugins/gui_editor/expression_node.cpp
@@ -89,6 +89,8 @@ public:
painter->drawText( tbox, Qt::AlignRight, m_info.text );
}
+ QString text() const{ return m_info.text; }
+
private:
NodeSlotInfo m_info;
};
@@ -109,6 +111,8 @@ QGraphicsItem( parent )
ExpressionNode::~ExpressionNode()
{
+ clearLinks();
+
qDeleteAll( m_slots );
m_slots.clear();
}
@@ -169,6 +173,29 @@ QPointF ExpressionNode::slotPos( int slot ) const
return mp;
}
+bool ExpressionNode::slotEmpty( int slot ) const
+{
+ if( m_links[ 0 ] == NULL )
+ return true;
+ else
+ return false;
+}
+
+void ExpressionNode::getSlots( QList< SlotInfo > &l )
+{
+ SlotInfo info;
+
+ for( int i = 0; i < m_slots.count(); i++ )
+ {
+ if( m_links[ i ] != NULL )
+ continue;
+
+ info.name = m_slots[ i ]->text();
+ info.slot = i;
+ l.push_back( info );
+ }
+}
+
void ExpressionNode::setLink( ExpressionLink *link, int slot )
{
m_links[ slot ] = link;
@@ -239,3 +266,15 @@ void ExpressionNode::paintSlots( QPainter *painter )
}
+void ExpressionNode::clearLinks()
+{
+ for( int i = 0; i < m_links.count(); i++ )
+ {
+ ExpressionLink *link = m_links[ i ];
+ if( link == NULL )
+ continue;
+
+ link->unlink();
+ }
+}
+
diff --git a/code/studio/src/plugins/gui_editor/expression_node.h b/code/studio/src/plugins/gui_editor/expression_node.h
index 991057731..704804b55 100644
--- a/code/studio/src/plugins/gui_editor/expression_node.h
+++ b/code/studio/src/plugins/gui_editor/expression_node.h
@@ -22,6 +22,7 @@
#include
#include
+#include "expr_slot_info.h"
class ExpressionLink;
class NodeSlot;
@@ -42,12 +43,17 @@ public:
int slotCount() const{ return m_slots.count(); }
+ bool slotEmpty( int slot ) const;
+
+ void getSlots( QList< SlotInfo > &l );
+
protected:
void mouseMoveEvent( QGraphicsSceneMouseEvent *e );
private:
void createSlots();
void paintSlots( QPainter *painter );
+ void clearLinks();
qreal m_w;
qreal m_h;