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 qanNodeItem.h
24 // \author Benoit Autheman (benoit@libqanava.org)
25 // \date 2004 October 13
26 //-----------------------------------------------------------------------------
34 #include "./qanNode.h"
35 #include "./qanStyle.h"
36 #include "./qanEdgeItem.h"
40 #include <QGraphicsItem>
41 #include <QGraphicsRectItem>
42 #include <QGraphicsTextItem>
45 //-----------------------------------------------------------------------------
46 namespace qan
{ // ::qan
48 class AbstractNodeItem
: public GraphItem
54 AbstractNodeItem( Node
& node
, Style::Manager
& styleManager
, Style
* style
) :
55 GraphItem( styleManager
, style
),
61 virtual ~AbstractNodeItem( )
65 //! Usually, return this casted to QGraphicsItem.
66 virtual QGraphicsItem
* getGraphicsItem( ) = 0;
70 Node
& getNode( ) { return _node
; }
78 void addEdge( EdgeItem
* edge
)
81 connect( this, SIGNAL( destroyed( ) ), edge
, SLOT( nodeDestroyed( ) ) );
84 void removeEdge( EdgeItem
* edge
) { _edges
.removeAll( edge
); }
88 foreach ( EdgeItem
* edge
, _edges
)
94 QList
< EdgeItem
* > _edges
;
102 AbstractFactory( int nodeType
, bool defaultFactory
= false ) :
103 _nodeType( nodeType
),
104 _defaultFactory( defaultFactory
) { };
106 virtual ~AbstractFactory( ) { }
108 virtual AbstractNodeItem
* create( Node
& node
, Style::Manager
& styleManager
,
109 QGraphicsItem
* parent
, QGraphicsScene
* scene
, Style
* style
,
110 QPoint origin
, const QString
& label
) = 0;
112 int getNodeType( ) const { return _nodeType
; }
114 bool isDefaultFactory( ) const { return _defaultFactory
; }
116 typedef QList
< AbstractFactory
* > List
;
122 bool _defaultFactory
;
125 template < typename T
>
126 class Factory
: public AbstractFactory
130 Factory( int nodeType
, bool defaultFactory
= false ) :
131 AbstractFactory( nodeType
, defaultFactory
) { }
133 virtual AbstractNodeItem
* create( Node
& node
, Style::Manager
& styleManager
, QGraphicsItem
* parent
, QGraphicsScene
* scene
, Style
* style
,
134 QPoint origin
, const QString
& label
)
136 return new T( node
, styleManager
, *style
, parent
, scene
, origin
, label
);
143 //! Model a rectangular node item on a QT graphics view.
145 The following style options are supported:
147 <li> <b>'backcolor':</b> Background color, when there is no background image defined.
148 <li> <b>'bordercolor':</b> Color of the item border.
149 <li> <b>'backimage':</b> Background image (scaled to fit the item size).
150 <li> <b>'maximumwidth':</b> Maximum width of the item, content is cropped to fit this with limit.
151 <li> <b>'maximumheight':</b> Maximum height of the item, content is cropped to fit this height limit.
152 <li> <b>'fontsize':</b> Base size for the font used to display the item label.
153 <li> <b>'icon':</b> Display an icon centered in the left of the item.
154 <li> <b>'hasshadow':</b> Set this value to false to supress the node shadow.
158 class NodeItem
: public AbstractNodeItem
, public QGraphicsRectItem
164 NodeItem( Node
& node
, Style::Manager
& styleManager
, Style
& style
,
165 QGraphicsItem
* parent
, QGraphicsScene
* scene
,
166 QPointF origin
, const QString
& label
);
168 virtual ~NodeItem( );
170 void paint( QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
= 0 );
172 struct DefaultFactory
: public AbstractNodeItem::Factory
< NodeItem
>
174 DefaultFactory( ) : AbstractNodeItem::Factory
< NodeItem
>( -1, true ) { }
179 virtual void updateItem( );
181 virtual QGraphicsItem
* getGraphicsItem( ) { return static_cast< QGraphicsItem
* >( this ); }
193 double _shadowOffset
;
195 QGraphicsTextItem
* _labelItem
;
201 QVariant
itemChange( QGraphicsItem::GraphicsItemChange change
, const QVariant
& value
);
204 //-----------------------------------------------------------------------------
207 #endif // qanNodeItem_h