mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-17 04:51:52 +00:00
Improved linking
--HG-- branch : dfighter-tools
This commit is contained in:
parent
2e6a5bb1d6
commit
875cad3f72
9 changed files with 335 additions and 4 deletions
|
@ -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)
|
||||
|
|
122
code/studio/src/plugins/gui_editor/expr_link_dlg.cpp
Normal file
122
code/studio/src/plugins/gui_editor/expr_link_dlg.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "expr_link_dlg.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
49
code/studio/src/plugins/gui_editor/expr_link_dlg.h
Normal file
49
code/studio/src/plugins/gui_editor/expr_link_dlg.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef EXPR_LINK_DLG
|
||||
#define EXPR_LINK_DLG
|
||||
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#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
|
||||
|
58
code/studio/src/plugins/gui_editor/expr_link_dlg.ui
Normal file
58
code/studio/src/plugins/gui_editor/expr_link_dlg.ui
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ExprLinkDialog</class>
|
||||
<widget class="QDialog" name="ExprLinkDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>581</width>
|
||||
<height>388</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Linking nodes</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QListWidget" name="list1"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListWidget" name="list2"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>398</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="okButton">
|
||||
<property name="text">
|
||||
<string>Ok</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
32
code/studio/src/plugins/gui_editor/expr_slot_info.h
Normal file
32
code/studio/src/plugins/gui_editor/expr_slot_info.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
// Ryzom Core Studio - Georges Editor Plugin
|
||||
//
|
||||
// Copyright (C) 2014 Laszlo Kis-Adam
|
||||
// Copyright (C) 2010 Ryzom Core <http://ryzomcore.org/>
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#ifndef EXPR_SLOT_INFO
|
||||
#define EXPR_SLOT_INFO
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct SlotInfo
|
||||
{
|
||||
QString name;
|
||||
int slot;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "expression_node.h"
|
||||
#include "expression_link.h"
|
||||
#include "expr_link_dlg.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QGraphicsItem>
|
||||
#include <QList>
|
||||
#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;
|
||||
|
|
Loading…
Reference in a new issue