nodeeditor_doxy
src/Core/NodeConnectorBase.h
Go to the documentation of this file.
00001 #ifndef NODE_CONNECTOR_BASE_H
00002 #define NODE_CONNECTOR__BASE_H
00003 
00004 class NodeConnectorBase;
00005 class NodeItemBase;
00006 
00007 
00008 typedef QList<NodeConnectionBase*> ConnectionList;
00009 
00010 
00011 class NodeConnectorBase: public QObject 
00012 {
00013         Q_OBJECT
00014         Q_FLAGS(LoadHint LoadHints)
00015 public:
00016 
00017         friend class NodeItemBase;
00018 
00019         NodeConnectorBase(ConnectorFlag cf = 0, QWidget* widgetToConnect = 0): QObject(parent), mConnections(0), ConnectorFlags(cf), mpParentNodeItem(0), mpWidget(widgetToConnect) {};
00020         virtual ~NodeConnectorBase() {};
00021         enum ConnectorFlag { All = -1, singleConnection = 1, selfConnections = 2, highlighted = 4, disableWidgetOnConnection = 8, allignLeft = 16, allignRight = 32, allignTop = 64, allignBottom = 128, ConnectorFlagsUserType = allignBottom + 1 };
00022         Q_DECLARE_FLAGS(ConnectorFlags, ConnectorFlag)
00023 
00024         virtual ConnectorFlag connectorFlags() { return ConnectorFlags; };
00025         virtual void setConnectorFlags(ConnectorFlag cf) {
00026                 ConnectorFlags = cf;
00027         };
00028 
00029         virtual NodeItemBase* parentNodeItem() {
00030                 return mpParentNodeItem;
00031         };
00032 
00033         widgetToConnect() {
00034                 return mpWidget;
00035         };
00036 
00037 
00038 
00039         
00040         virtual bool addConnection(NodeConnectionBase *c) {
00041                 if (!mConnections.contains(c)) {
00042                         mConnections.push_back(c);
00043                         emit connectionAdded(c);
00044                         if (mpParentItem) {
00045                                 emit mpParentItem->connectionAdded(c);
00046                         }
00047                         return true;
00048                 }
00049                 return false;
00050         };
00051         virtual bool deleteConnection(NodeConnectionBase *c) {
00052                 if (mConnections.removeFirst(c)) {
00053                         delete c;
00054                         emit connectionRemoved(c);
00055                         if (mpParentItem) {
00056                                 emit mpParentItem->connectionDeleted(c);
00057                         }
00058                         return true;
00059                 }
00060                 return false;
00061         }
00062         void deleteConnections();
00063         void removeConnection(NodeConnection *arrow);
00064 
00065         
00066 
00067 //private:
00068         int mRadius;
00069         ConnectorType mConnectorType;
00070         NodeItem *parent;
00071         QWidget* mWidget;
00072         //QWidget* label;
00073         //bool right;
00074         ConnectorAlignment mConnectorAlignment;
00075         QList<NodeConnection *> arrows;
00076         QColor darkColor;
00077         bool highlight;
00078         bool mSingleConnection;
00079         bool mSelfConnections;
00080         bool mDisableWidgetOnConnection;
00081 
00082         //ugly, but node ctor is called after wiget is removed, but delete of connector would otherwise activate label widget
00083     void removeWidget();
00084 
00085 protected:
00086         NodeItemBase* mpParentNodeItem;
00087         ConnectionList mConnections;
00088 
00089         virtual setParentNodeItem(NodeItemBase* parent) {
00090                 mpParentNodeItem = parent;
00091         };
00092         QWidget* mpWidget;
00093 
00094         void setHighlight(bool highlight);
00095 };
00096 
00097 Q_DECLARE_OPERATORS_FOR_FLAGS(NodeConnectorBase::ConnectorFlags)
00098 
00099 #endif