]> Creatis software - cpPlugins.git/blobdiff - appli/cpPipelineEditor/Node.h
More on graph editor
[cpPlugins.git] / appli / cpPipelineEditor / Node.h
index 088ade7c16904e77dc548a66d3b12db013766003..41a68c35c0e5cbb0ef6ba1d477847568bca9f309 100644 (file)
@@ -1,82 +1,98 @@
-/****************************************************************************
- **
- ** Copyright (C) 2015 The Qt Company Ltd.
- ** Contact: http://www.qt.io/licensing/
- **
- ** This file is part of the examples of the Qt Toolkit.
- **
- ** $QT_BEGIN_LICENSE:BSD$
- ** You may use this file under the terms of the BSD license as follows:
- **
- ** "Redistribution and use in source and binary forms, with or without
- ** modification, are permitted provided that the following conditions are
- ** met:
- **   * Redistributions of source code must retain the above copyright
- **     notice, this list of conditions and the following disclaimer.
- **   * Redistributions in binary form must reproduce the above copyright
- **     notice, this list of conditions and the following disclaimer in
- **     the documentation and/or other materials provided with the
- **     distribution.
- **   * Neither the name of The Qt Company Ltd nor the names of its
- **     contributors may be used to endorse or promote products derived
- **     from this software without specific prior written permission.
- **
- **
- ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
- **
- ** $QT_END_LICENSE$
- **
- ****************************************************************************/
-
-#ifndef NODE_H
-#define NODE_H
+#ifndef __PIPELINEEDITOR__NODE__H__
+#define __PIPELINEEDITOR__NODE__H__
+
+#include <map>
+#include <set>
 
 #include <QGraphicsItem>
 #include <QList>
 
-class Edge;
-class GraphWidget;
+
+#include <iostream>
+
+
+// Some forward declarations
 class QGraphicsSceneMouseEvent;
+class QGraphicsSceneHoverEvent;
+
+// Some forward declarations
+namespace cpPlugins
+{
+  namespace Interface
+  {
+    class Object;
+  }
+}
 
-class Node : public QGraphicsItem
+namespace PipelineEditor
 {
-public:
-  Node(GraphWidget *graphWidget, const std::string& label );
+  // Some other forward declarations
+  class Edge;
+  class GraphCanvas;
+
+  /**
+   */
+  class Node
+    : public QGraphicsItem
+  {
+  public:
+    Node( GraphCanvas* canvas, cpPlugins::Interface::Object* object );
+    virtual ~Node( );
+
+    void addEdge( Edge* edge );
+    QList< Edge* > edges( ) const;
+
+    void updateRepresentation( );
+
+    QRectF boundingRect( ) const;
+    QPainterPath shape( ) const;
+    void paint(
+      QPainter* painter,
+      const QStyleOptionGraphicsItem* option,
+      QWidget* widget
+      );
+    void moveBy(qreal dx, qreal dy)
+      {
+        std::cout << "move: " << dx << " " << dy << std::endl;
+        this->QGraphicsItem::moveBy( dx, dy );
+      }
+
+  protected:
+    QVariant itemChange( GraphicsItemChange change, const QVariant& value );
 
-  void addEdge(Edge *edge);
-  QList<Edge *> edges() const;
+    void mousePressEvent( QGraphicsSceneMouseEvent* event );
+    void mouseReleaseEvent( QGraphicsSceneMouseEvent* event );
+    void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* event );
+    void hoverMoveEvent( QGraphicsSceneHoverEvent* event );
+    void hoverLeaveEvent( QGraphicsSceneHoverEvent* event );
+    void dragMoveEvent( QGraphicsSceneDragDropEvent* event );
+    void dragLeaveEvent( QGraphicsSceneDragDropEvent* event );
+    void dropEvent( QGraphicsSceneDragDropEvent* event );
 
-  enum { Type = UserType + 1 };
-  int type() const { return Type; }
+    void _selectPort( const QPointF& pos );
+    void _deselectPort( );
 
-  void calculateForces();
-  bool advance();
+  private:
+    GraphCanvas*   m_Canvas;
+    QList< Edge* > m_Edges;
+    cpPlugins::Interface::Object* m_Object;
 
-  QRectF boundingRect() const;
-  QPainterPath shape() const;
-  void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+    // Graphical objects
+    QString m_Label;
+    QRectF m_Bounds;
+    std::set< std::string > m_Inputs;
+    std::set< std::string > m_Outputs;
+    std::map< std::string, QRectF > m_InputPorts;
+    std::map< std::string, QRectF > m_OutputPorts;
 
-protected:
-  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
+    // Interaction objects
+    const QRectF* m_SelectedPort;
+    bool m_SelectedPortIsInput;
+    bool m_DraggingPort;
+  };
 
-  void mousePressEvent(QGraphicsSceneMouseEvent *event);
-  void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
+} // ecapseman
 
-private:
-  QList<Edge *> edgeList;
-  QPointF newPos;
-  GraphWidget *graph;
-  std::string m_Label;
-};
+#endif // __PIPELINEEDITOR__NODE__H__
 
-#endif
+// eof - $RCSfile$