Commit 5ac1f205 authored by skiunke's avatar skiunke

[DOC&STYLE&FIX] connect 2 ports works now properly

parent 15be24f8
......@@ -47,16 +47,6 @@ WQtNetworkArrow::WQtNetworkArrow( WQtNetworkOutputPort *startPort, WQtNetworkInp
setAcceptsHoverEvents( true );
}
WQtNetworkArrow::WQtNetworkArrow()
: QGraphicsLineItem()
{
setFlag( QGraphicsItem::ItemIsSelectable, true );
setPen( QPen( Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
setAcceptsHoverEvents( true );
}
WQtNetworkArrow::~WQtNetworkArrow()
{
......@@ -150,12 +140,16 @@ QPainterPath WQtNetworkArrow::shape() const
void WQtNetworkArrow::hoverEnterEvent( QGraphicsSceneHoverEvent * event )
{
Q_UNUSED( event );
changeColor( Qt::green );
updatePosition();
}
void WQtNetworkArrow::hoverLeaveEvent( QGraphicsSceneHoverEvent * event )
{
Q_UNUSED( event );
changeColor( Qt::black );
}
......@@ -164,8 +158,3 @@ void WQtNetworkArrow::changeColor( QColor color )
m_color = color;
setPen( QPen( m_color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
}
void WQtNetworkArrow::addConnection( boost::shared_ptr< WModuleConnector > in, boost::shared_ptr< WModuleConnector > out )
{
}
......@@ -35,12 +35,8 @@
#include <boost/shared_ptr.hpp>
#include "../../../kernel/WModuleConnector.h"
//#include "WQtNetworkPort.h"
//#include "WQtNetworkInputPort.h"
//#include "WQtNetworkOutputPort.h"
// forward declaration
//class WQtNetworkPort;
class WQtNetworkOutputPort;
class WQtNetworkInputPort;
......@@ -62,10 +58,11 @@ class WQtNetworkArrow : public QGraphicsLineItem
/**
* Constructor
*
* \param outPort the outputport that provide the data
* \param inPort the inputport that recive the data
*/
explicit WQtNetworkArrow( WQtNetworkOutputPort *outPort, WQtNetworkInputPort *inPort );
WQtNetworkArrow();
/**
* Destructor
......@@ -85,14 +82,14 @@ class WQtNetworkArrow : public QGraphicsLineItem
void updatePosition();
/**
* Returns the start port.
*\return the port where the connection starts
* Returns the WQtNetworkOutputPort where the arrow starts.
*\return the WQtNetworkInputPort where the connection starts
*/
WQtNetworkOutputPort* getStartPort();
/**
* Returns the end port.
*\return the port where the connection ends
* Returns the WQtNetworkInputPort where the arrow ends.
*\return the WQtNetworkInputPort where the connection ends
*/
WQtNetworkInputPort* getEndPort();
......@@ -100,14 +97,14 @@ class WQtNetworkArrow : public QGraphicsLineItem
* Reimplementation form QGraphicsItem, because the arrowhead is added
* to the line. Its needed that QGraphicsView knows which area needs to
* be redrawn.
* \return a rect that bounds the drawn object
* \return a QRectF that bounds the drawn object
*/
QRectF boundingRect() const;
/**
* Reimplementation from QGraphicsItem.
* Return the shape of this item as a QPainterPath in local coordinates
* \return shape of this
* \return shape as QPainterPath of this object
*/
QPainterPath shape() const;
......@@ -120,9 +117,6 @@ class WQtNetworkArrow : public QGraphicsLineItem
*/
QVariant itemChange( GraphicsItemChange change, const QVariant &value );
void addConnection( boost::shared_ptr< WModuleConnector > in, boost::shared_ptr< WModuleConnector > out );
protected:
/**
......@@ -158,9 +152,11 @@ class WQtNetworkArrow : public QGraphicsLineItem
void changeColor( QColor color );
WQtNetworkOutputPort *m_startPort; //!< the start port
WQtNetworkInputPort *m_endPort; //!< the end port
QColor m_color; //!< the current color
QPolygonF arrowHead; //!< the arrowhead
};
#endif // WQTNETWORKARROW_H
......@@ -25,14 +25,12 @@
#ifndef WQTNETWORKEDITOR_H
#define WQTNETWORKEDITOR_H
#include <time.h>
#include <string>
#include <list>
#include <time.h>
#include <boost/shared_ptr.hpp>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsView>
#include <QtGui/QWidget>
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
......@@ -46,14 +44,14 @@
class WMainWindow;
/**
* container widget to hold the qgraphicsscene
*
* Container widget to hold the WQtNetworkScene
*/
class WQtNetworkEditor : public QDockWidget
{
Q_OBJECT
public:
/**
* default constructor
*
......@@ -68,14 +66,28 @@ public:
virtual ~WQtNetworkEditor();
/**
* Simple method to create static test "modules"
* Create a new WQtNetworkItem for a given WModule
* \param a new WModule
*/
void addModule( boost::shared_ptr< WModule > module );
/**
* Simple search the WQtNetworkItem that belongs to the WModule
* \param module a WModule
* \return WQtNetworkItem belongs to the WModule
*/
WQtNetworkItem* findItemByModule( boost::shared_ptr< WModule > module );
/**
* Connect SIGNALS with SLOTS
*/
void connectSlots();
/**
* This Method is everytime called when a new Module is inserted or an
* WQtNetworkItem is moved manually. A Timer is set for calculating the new
* forces.
*/
void itemMoved();
protected:
......@@ -85,10 +97,22 @@ protected:
*/
WMainWindow* m_mainWindow;
/**
* Everytime a module is associated, ready, connected, disconnected, removed or
* deleted the kernels emits a signal and here we look how to behave.
*/
virtual bool event( QEvent* event );
/**
* Determines compatible prototypes
* \return list of modules without possible input connectors
*/
WQtCombinerToolbar* createCompatibleButtons( boost::shared_ptr< WModule >module );
/**
* This event is called every 'timerID' in ms. If the WQtNetworkItems don't
* move as result of the calculated forces the timer won't be reseted.
*/
void timerEvent( QTimerEvent *event );
private:
......@@ -101,7 +125,7 @@ private:
QVBoxLayout* m_layout; //!< layout
std::list< WQtNetworkItem* > m_items;
QList< WQtNetworkItem* > m_items; //!< a list of the WQtNetworkItems in the WQtNetworkScene
/**
* Action which uses a compatibles list (submenu) to connect a selected item with other existing modules.
......@@ -118,12 +142,21 @@ private:
*/
QAction* m_disconnectAction;
/**
* Is needed for random position of the WQtNetworkItems.
*/
time_t m_time;
/**
* Certain time span in ms in which timerEvent gets called.
*/
int timerId;
private slots:
/**
* Determines possible Connections and the propertytab.
*/
void selectItem();
};
......
......@@ -26,12 +26,7 @@
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsRectItem>
#include <QtGui/QGraphicsLineItem>
#include "WQtNetworkOutputPort.h"
#include "WQtNetworkInputPort.h"
......@@ -50,14 +45,15 @@ WQtNetworkInputPort::WQtNetworkInputPort( boost::shared_ptr<WModuleInputConnecto
setOutPort( connector.get()->isOutputConnector() );
m_connector = connector;
// create tooltip
QString tmp;
if( isOutPort() == true ) tmp = "output";
else if( isOutPort() == false ) tmp = "input";
else
tmp = "undefined";
//TODO
QString str = "Name: " + getPortName() + "\nPortType: " + tmp;
QString str = "<b>Name: </b> " + getPortName() +
"<br/><b>PortType: </b>" + tmp;
if( toolTip() != str )
{
setToolTip( str );
......@@ -112,8 +108,6 @@ boost::shared_ptr<WModuleInputConnector> WQtNetworkInputPort::getConnector()
return m_connector;
}
//private
void WQtNetworkInputPort::removeArrows()
{
foreach( WQtNetworkArrow *arrow, m_arrows )
......@@ -122,7 +116,6 @@ void WQtNetworkInputPort::removeArrows()
if ( index != -1 )
{
m_arrows.removeAt( index );
//delete arrow;
}
}
}
......@@ -144,116 +137,3 @@ bool WQtNetworkInputPort::isOutPort()
{
return m_isOutPort;
}
/*
void WQtNetworkInputPort::mousePressEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
line = new QGraphicsLineItem( QLineF( mouseEvent->scenePos(), mouseEvent->scenePos() ) );
line->setPen( QPen( Qt::black, 2 ) );
scene()->addItem( line );
}
void WQtNetworkInputPort::mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
if( line != 0 )
{
QLineF newLine( line->line().p1(), mouseEvent->scenePos() );
QList<QGraphicsItem *> endItem = scene()->items( mouseEvent->scenePos() );
// because line is first item below the curser
if( !endItem.isEmpty() &&
endItem.first()->type() == QGraphicsLineItem::Type )
{
endItem.removeFirst();
}
if( !endItem.isEmpty() )
{
if( endItem.first()->type() == WQtNetworkInputPort::Type )
{
//TODO!!!
WQtNetworkInputPort *endPort = qgraphicsitem_cast<WQtNetworkInputPort *>( endItem.first() );
if( //endPort->isOutPort() == false &&
endPort->parentItem() != this->parentItem() &&
//endPort->getPortName() == this->getPortName() &&
endPort->getNumberOfArrows() < 1
)
{
line->setPen( QPen( Qt::green, 2 ) );
}
else
{
line->setPen( QPen( Qt::red, 2 ) );
}
}
else if( endItem.first()->type() == WQtNetworkOutputPort::Type )
{
line->setPen( QPen( Qt::red, 2 ) );
}
else
{
line->setPen( QPen( Qt::black, 2 ) );
}
}
else
{
line->setPen( QPen( Qt::black, 2 ) );
}
line->setLine( newLine );
}
}
void WQtNetworkInputPort::mouseReleaseEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
if( line != 0 )
{
QList<QGraphicsItem *> startItems = scene()->items( line->line().p1() );
QList<QGraphicsItem *> endItems = scene()->items( line->line().p2() );
// because line is first item below the curser
if( startItems.first()->type() == QGraphicsLineItem::Type )
{
startItems.removeFirst();
}
// because line is first item below the curser
if( endItems.first()->type() == QGraphicsLineItem::Type )
{
endItems.removeFirst();
}
// remove current line for real connection
scene()->removeItem( line );
delete line;
if( !endItems.isEmpty() &&
!startItems.isEmpty() &&
endItems.first()->type() == WQtNetworkInputPort::Type &&
startItems.first()->parentItem() != endItems.first()->parentItem() )
{
WQtNetworkOutputPort *startPort = qgraphicsitem_cast<WQtNetworkOutputPort *>( startItems.first() );
WQtNetworkInputPort *endPort = qgraphicsitem_cast<WQtNetworkInputPort *>( endItems.first() );
std::cout << "PORTS CONNECTBAR: " << endPort->getConnector()->connectable( startPort->getConnector() ) << std::endl;
//TODO skiunke: isOutput realy needed?
if( endPort->getNumberOfArrows() < 1 &&
endPort->isOutPort() == false &&
startPort->isOutPort() == true &&
//endPort->getPortName() == startPort->getPortName() )
endPort->getConnector()->connectable( startPort->getConnector() ) == true )
{
WQtNetworkArrow *arrow = new WQtNetworkArrow( startPort, endPort );
arrow->setZValue( -1000.0 );
startPort->addArrow( arrow );
endPort->addArrow( arrow );
scene()->addItem( arrow );
arrow->updatePosition();
}
}
}
}
*/
......@@ -26,8 +26,6 @@
#define WQTNETWORKINPUTPORT_H
#include <QtGui/QGraphicsRectItem>
#include <QtGui/QGraphicsLineItem>
#include <QtGui/QGraphicsScene>
#include "../../../kernel/WModuleInputConnector.h"
#include "WQtNetworkPort.h"
......@@ -35,7 +33,6 @@
// forward declaration
class WQtNetworkArrow;
//class WQtNetworkPort;
/**
* This class represents the ports a module have. Two ports from different
......@@ -47,6 +44,7 @@ class WQtNetworkInputPort : public WQtNetworkPort
/**
* Constructor
* \param connector the related WModuleInputConnector
*/
explicit WQtNetworkInputPort( boost::shared_ptr<WModuleInputConnector> connector );
......@@ -122,46 +120,37 @@ class WQtNetworkInputPort : public WQtNetworkPort
*/
void setPortName( QString str );
int getNumberOfArrows();
boost::shared_ptr<WModuleInputConnector> getConnector();
/**
* Adds an arrow to the port
* Return the number of connections
* \return number of connections
*/
void addArrow( WQtNetworkArrow *arrow );
QList< WQtNetworkArrow *> getArrowList();
protected:
int getNumberOfArrows();
/**
* Start drawing an arrow
*
* \param mouseEvent the mouse event
* Returns the WModuleInputConnecter that belongs to this object.
* \return a WModuleInputConnector
*/
// void mousePressEvent( QGraphicsSceneMouseEvent *mouseEvent );
boost::shared_ptr<WModuleInputConnector> getConnector();
/**
* Updates the arrows endpoint.
*
* \param mouseEvent the mouse event
* Adds an arrow to the port
*/
// void mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent );
void addArrow( WQtNetworkArrow *arrow );
/**
* Draw the arrow if its the correct port
*
* \param mouseEvent the mouse event
* Get a QList of all arrows connected to this port
* \return a QList of WQtNetworkArrows
*/
// void mouseReleaseEvent( QGraphicsSceneMouseEvent *mouseEvent );
QList< WQtNetworkArrow *> getArrowList();
private:
QGraphicsLineItem *line; //!< the temporary line when u connect two ports
bool m_isOutPort; //!< is the port an outport
QList< WQtNetworkArrow *> m_arrows; //!< the connected arrows
QString m_name; //!< the portname
boost::shared_ptr<WModuleInputConnector> m_connector;
boost::shared_ptr<WModuleInputConnector> m_connector; //!< the related WModuleInputConnector
};
#endif // WQTNETWORKINPUTPORT_H
......@@ -26,12 +26,8 @@
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <QtGui/QGraphicsSceneMouseEvent>
#include <QtGui/QGraphicsScene>
#include <QtGui/QGraphicsRectItem>
#include <QtGui/QStyleOptionGraphicsItem>
#include <QtGui/QGraphicsWidget>
#include "WQtNetworkArrow.h"
#include "WQtNetworkItem.h"
......@@ -80,15 +76,15 @@ WQtNetworkItem::WQtNetworkItem( WQtNetworkEditor *editor, boost::shared_ptr< WMo
WQtNetworkItem::~WQtNetworkItem()
{
/* foreach( WQtNetworkPort *port, m_inPorts )
{
delete port;
}
foreach( WQtNetworkPort *port, m_outPorts )
{
delete port;
}*/
// foreach( WQtNetworkPort *port, m_inPorts )
// {
// delete port;
// }
//
// foreach( WQtNetworkPort *port, m_outPorts )
// {
// delete port;
// }
}
int WQtNetworkItem::type() const
......@@ -98,6 +94,8 @@ int WQtNetworkItem::type() const
void WQtNetworkItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
{
Q_UNUSED( event );
if( m_color != Qt::darkBlue )
{
changeColor( Qt::darkBlue );
......@@ -144,6 +142,7 @@ void WQtNetworkItem::hoverEnterEvent( QGraphicsSceneHoverEvent *event )
void WQtNetworkItem::hoverLeaveEvent( QGraphicsSceneHoverEvent *event )
{
Q_UNUSED( event );
if( m_color != Qt::gray )
{
changeColor( Qt::gray );
......@@ -170,12 +169,6 @@ void WQtNetworkItem::paint( QPainter* painter, const QStyleOptionGraphicsItem* o
painter->drawRect( rect );
}
//void WQtNetworkItem::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
//{
// QGraphicsItem::mousePressEvent( mouseEvent );
//}
void WQtNetworkItem::mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent )
{
QGraphicsItem::mouseMoveEvent( mouseEvent );
......@@ -191,15 +184,9 @@ void WQtNetworkItem::mouseMoveEvent( QGraphicsSceneMouseEvent *mouseEvent )
m_networkEditor->itemMoved();
}
//void WQtNetworkItem::mouseReleaseEvent( QGraphicsSceneMouseEvent *mouseEvent )
//{
// QGraphicsItem::mouseReleaseEvent( mouseEvent );
//}
QVariant WQtNetworkItem::itemChange( GraphicsItemChange change,
const QVariant &value )
{
std::cout << "change" << change << std::endl;
switch( change )
{
case ItemSelectedHasChanged:
......@@ -221,7 +208,6 @@ QVariant WQtNetworkItem::itemChange( GraphicsItemChange change,
return QGraphicsItem::itemChange( change, value );
}
//TODO
void WQtNetworkItem::addInputPort( WQtNetworkInputPort *port )
{
m_inPorts.append( port );
......@@ -231,23 +217,6 @@ void WQtNetworkItem::addOutputPort( WQtNetworkOutputPort * port )
{
m_outPorts.append( port );
}
/*
void WQtNetworkItem::removePort( WQtNetworkPort *port )
{
int index = m_ports.indexOf( port );
if ( index != -1 )
m_ports.removeAt( index );
}
void WQtNetworkItem::removePorts()
{
foreach( WQtNetworkPort *port, m_ports )
{
port->update();
}
}
*/
QList< WQtNetworkInputPort *> WQtNetworkItem::getInPorts()
{
......@@ -352,19 +321,20 @@ void WQtNetworkItem::calculateForces()
// Sum up all forces pushing this item away
qreal xvel = 0;
qreal yvel = 0;
foreach ( QGraphicsItem *item, scene()->items() )
foreach( QGraphicsItem *item, scene()->items() )
{
WQtNetworkItem *networkItem = qgraphicsitem_cast<WQtNetworkItem *>(item);
WQtNetworkItem *networkItem = qgraphicsitem_cast<WQtNetworkItem *>( item );
if ( !networkItem )
continue;
QLineF line( mapFromItem( networkItem, 0, 0 ), QPointF( 0, 0) );
QLineF line( mapFromItem( networkItem, 0, 0 ), QPointF( 0, 0 ) );
qreal dx = line.dx();
qreal dy = line.dy();
double l = 2.0 * (dx * dx + dy * dy);
if (l > 0) {
xvel += (dx * 250.0) / l;
yvel += (dy * 250.0) / l;
double l = 2.0 * ( dx * dx + dy * dy );
if ( l > 0 )
{
xvel += ( dx * 250.0 ) / l;
yvel += ( dy * 250.0 ) / l;
}
}
......@@ -380,7 +350,7 @@ void WQtNetworkItem::calculateForces()
{
weight += port->getNumberOfArrows();
}
weight *= 100;
weight *= 50;
foreach( WQtNetworkPort *port, m_inPorts )
......@@ -404,28 +374,24 @@ void WQtNetworkItem::calculateForces()
yvel += pos.y() / weight;
}
}
WQtNetworkScene *scn = dynamic_cast< WQtNetworkScene *>( this->scene() );
if ( scn != NULL )
{
std::cout << "xvel" << std::endl;
pos = mapFromItem( scn->getFakeItem(), 0, 0 );
xvel += pos.x() / weight;
yvel += pos.y() / weight;