1 /* Copyright (c) 2012, STANISLAW ADASZEWSKI
\r
4 Redistribution and use in source and binary forms, with or without
\r
5 modification, are permitted provided that the following conditions are met:
\r
6 * Redistributions of source code must retain the above copyright
\r
7 notice, this list of conditions and the following disclaimer.
\r
8 * Redistributions in binary form must reproduce the above copyright
\r
9 notice, this list of conditions and the following disclaimer in the
\r
10 documentation and/or other materials provided with the distribution.
\r
11 * Neither the name of STANISLAW ADASZEWSKI nor the
\r
12 names of its contributors may be used to endorse or promote products
\r
13 derived from this software without specific prior written permission.
\r
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
\r
16 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
17 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
18 DISCLAIMED. IN NO EVENT SHALL STANISLAW ADASZEWSKI BE LIABLE FOR ANY
\r
19 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
20 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
21 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
22 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
24 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
27 #include "QNodesEditor.h"
\r
29 #include <QGraphicsScene>
\r
31 #include <QGraphicsSceneMouseEvent>
\r
33 #include "QNEPort.h"
\r
34 #include "QNEConnection.h"
\r
35 #include "QNEBlock.h"
\r
37 // -------------------------------------------------------------------------
\r
38 PipelineEditor::QNodesEditor::
\r
39 QNodesEditor( QObject* parent )
\r
40 : Superclass( parent )
\r
42 this->m_Conn = NULL;
\r
45 // -------------------------------------------------------------------------
\r
46 PipelineEditor::QNodesEditor::
\r
51 // -------------------------------------------------------------------------
\r
52 void PipelineEditor::QNodesEditor::
\r
53 install( QGraphicsScene* s )
\r
55 s->installEventFilter( this );
\r
59 // -------------------------------------------------------------------------
\r
60 QGraphicsItem* PipelineEditor::QNodesEditor::
\r
61 itemAt( const QPointF& pos )
\r
63 QList< QGraphicsItem* > items =
\r
64 this->m_Scene->items( QRectF( pos - QPointF( 1, 1 ), QSize( 3, 3 ) ) );
\r
66 foreach( QGraphicsItem* item, items )
\r
67 if( item->type( ) > QGraphicsItem::UserType )
\r
72 // -------------------------------------------------------------------------
\r
73 bool PipelineEditor::QNodesEditor::
\r
74 eventFilter( QObject* o, QEvent* e )
\r
76 QGraphicsSceneMouseEvent* me = ( QGraphicsSceneMouseEvent* ) e;
\r
78 switch ( ( int ) e->type( ) )
\r
80 case QEvent::GraphicsSceneMousePress:
\r
82 switch ( ( int ) me->button( ) )
\r
84 case Qt::LeftButton:
\r
86 QGraphicsItem* item = this->itemAt( me->scenePos( ) );
\r
87 if( item && item->type( ) == QNEPort::Type )
\r
89 this->m_Conn = new QNEConnection( 0, this->m_Scene );
\r
90 this->m_Conn->setPort1( ( QNEPort* ) item );
\r
91 this->m_Conn->setPos1( item->scenePos( ) );
\r
92 this->m_Conn->setPos2( me->scenePos( ) );
\r
93 this->m_Conn->updatePath( );
\r
97 else if( item && item->type( ) == QNEBlock::Type )
\r
100 selBlock->setSelected( ); */
\r
101 // selBlock = ( QNEBlock* ) item;
\r
106 case Qt::RightButton:
\r
108 QGraphicsItem* item = itemAt( me->scenePos( ) );
\r
109 if( item && ( item->type( ) == QNEConnection::Type || item->type( ) == QNEBlock::Type ) )
\r
111 // if( selBlock == ( QNEBlock* ) item )
\r
117 case QEvent::GraphicsSceneMouseMove:
\r
121 this->m_Conn->setPos2( me->scenePos( ) );
\r
122 this->m_Conn->updatePath( );
\r
127 case QEvent::GraphicsSceneMouseRelease:
\r
129 if( this->m_Conn && me->button( ) == Qt::LeftButton )
\r
131 QGraphicsItem* item = itemAt( me->scenePos( ) );
\r
132 if( item && item->type( ) == QNEPort::Type )
\r
134 QNEPort* port1 = this->m_Conn->port1( );
\r
135 QNEPort* port2 = ( QNEPort* ) item;
\r
137 if( port1->block( ) != port2->block( ) && port1->isOutput( ) != port2->isOutput( ) && !port1->isConnected( port2 ) )
\r
139 this->m_Conn->setPos2( port2->scenePos( ) );
\r
140 this->m_Conn->setPort2( port2 );
\r
141 this->m_Conn->updatePath( );
\r
142 this->m_Conn = NULL;
\r
147 delete this->m_Conn;
\r
148 this->m_Conn = NULL;
\r
154 return( this->Superclass::eventFilter( o, e ) );
\r