0.3.1
[qanava.git] / src / qanEdgeItem.h
bloba73b3b4fb29cec0796901df440def3439e3e316b
1 /*
2 Qanava - Graph drawing library for QT
3 Copyright (C) 2006 Benoit AUTHEMAN
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //-----------------------------------------------------------------------------
21 // This file is a part of the Qanava software.
23 // \file qanEdgeItem.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2007 February 08
26 //-----------------------------------------------------------------------------
29 #ifndef qanEdgeItem_h
30 #define qanEdgeItem_h
33 // Qanava headers
34 #include "./qanNode.h"
35 #include "./qanStyle.h"
38 // QT headers
39 #include <QGraphicsItem>
42 //-----------------------------------------------------------------------------
43 namespace qan { // ::qan
45 class NodeItem;
47 class GraphItem : public QObject
49 Q_OBJECT
51 public:
53 GraphItem( Style::Manager& styleManager ) :
54 _styleManager( styleManager ), _style( 0 ) { }
56 GraphItem( Style::Manager& styleManager, Style* style ) :
57 _styleManager( styleManager ), _style( 0 ) { setStyle( style ); }
59 void setStyle( Style* style )
61 if ( _style != 0 ) // Disconnect the previous style from this item slots
62 _style->disconnect( SIGNAL( modified( ) ), this, SLOT( updateItem( ) ) );
63 if ( style != 0 )
64 connect( style, SIGNAL( modified( ) ), this, SLOT( updateItem( ) ) );
65 _style = style;
68 Style* getStyle( ) { return _style; }
70 Style::Manager& getStyleManager( ) { return _styleManager; }
72 const Style::Manager& getStyleManager( ) const { return _styleManager; }
74 virtual QGraphicsItem* getGraphicsItem( ) = 0;
76 protected slots:
78 virtual void updateItem( ) { }
80 protected:
82 Style* _style;
84 Style::Manager& _styleManager;
88 class EdgeItem : public GraphItem, public QGraphicsItem
90 Q_OBJECT
92 public:
94 EdgeItem( Style::Manager& styleManager, Style* style, QGraphicsItem* parent, QGraphicsScene* scene,
95 Edge& edge, NodeItem* src, NodeItem* dst );
97 virtual ~EdgeItem( );
99 virtual QGraphicsItem* getGraphicsItem( ) { return this; }
101 QRectF boundingRect( ) const;
103 void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0 );
105 virtual void updateItem( );
107 void disconnectEdge( );
109 NodeItem* getSrc( ) { return _src; }
111 NodeItem* getDst( ) { return _dst; }
113 public slots:
115 void nodeDestroyed( );
117 private:
119 Edge& _edge;
121 NodeItem* _src;
123 NodeItem* _dst;
125 QPointF _sourcePoint;
127 QPointF _destinationPoint;
129 bool _hasArrow;
131 int _arrowSize;
133 int _lineType;
135 int _lineWeight;
137 QRectF _labelRect;
139 } // ::qan
140 //-----------------------------------------------------------------------------
143 #endif // qanEdgeItem_h