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 //-----------------------------------------------------------------------------
34 #include "./qanNode.h"
35 #include "./qanStyle.h"
39 #include <QGraphicsItem>
42 //-----------------------------------------------------------------------------
43 namespace qan
{ // ::qan
47 class GraphItem
: public QObject
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( ) ) );
64 connect( style
, SIGNAL( modified( ) ), this, SLOT( updateItem( ) ) );
68 Style
* getStyle( ) { return _style
; }
70 Style::Manager
& getStyleManager( ) { return _styleManager
; }
72 const Style::Manager
& getStyleManager( ) const { return _styleManager
; }
74 virtual QGraphicsItem
* getGraphicsItem( ) = 0;
78 virtual void updateItem( ) { }
84 Style::Manager
& _styleManager
;
88 class EdgeItem
: public GraphItem
, public QGraphicsItem
94 EdgeItem( Style::Manager
& styleManager
, Style
* style
, QGraphicsItem
* parent
, QGraphicsScene
* scene
,
95 Edge
& edge
, NodeItem
* src
, NodeItem
* dst
);
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
; }
115 void nodeDestroyed( );
125 QPointF _sourcePoint
;
127 QPointF _destinationPoint
;
140 //-----------------------------------------------------------------------------
143 #endif // qanEdgeItem_h