2 Qanava - Graph drawing library for QT
3 Copyright (C) 2005 Benoit AUTHEMAN
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program 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
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; 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 canItemGeom.h
24 // \author Benoit Autheman (benoit@faktiss.net)
25 // \date 2004 October 13
26 //-----------------------------------------------------------------------------
35 #include "canItemImpl.h"
36 #include "canAdvStyle.h"
43 #include <qsimplerichtext.h>
46 //-----------------------------------------------------------------------------
47 namespace qan
{ // ::qan
48 namespace can
{ // ::qan::can
50 //! Models a rectangle on a relation canvas.
54 class RectangleItem
: public ItemImpl
< QCanvasRectangle
>
56 /*! \name RectangleItem Constructor/Destructor *///--------------------
60 //! RectangleItem constructor.
61 RectangleItem( Canvas
& canvas
, Item
& parent
, const QPoint
& origin
, const QPoint
& dimension
, AdvStyle
& advStyle
);
63 //! RectangleItem virtual destructor.
64 virtual ~RectangleItem( );
66 //---------------------------------------------------------------------
70 /*! \name Custom Drawing Management *///-------------------------------
74 //! Create or update item geometry taking into account current settings and style.
75 void updateGeometry( const QPoint
& origin
, const QPoint
& dimension
);
78 void updateStyle( const AdvStyle
& style
);
80 //! Set a new background image for this rectangle item.
81 void setBackImage( const QImage
& backImage
);
85 //! Draw the item back image, border and background area.
86 void drawShape( QPainter
& painter
);
100 //---------------------------------------------------------------------
104 //! Models a centered and clipped line of text on a relation canvas.
108 class TextItem
: public ItemImpl
< QCanvasText
>
110 /*! \name TextItem Constructor/Destructor *///---------------------
114 //! TextItem constructor.
115 TextItem( Canvas
& canvas
, Item
& parent
, const QPoint
& origin
, const QPoint
& dimension
, const QString
& content
, AdvStyle
& advStyle
, QFont::Weight weight
);
117 //! TextItem virtual destructor.
118 virtual ~TextItem( );
120 //-----------------------------------------------------------------
124 class RectangularItem
;
127 //! Models a connexion between rectengular items on a relation canvas.
131 class ArrowItem
: public ItemImpl
< QCanvasLine
>
133 /*! \name ArrowItem Constructor/Destructor *///--------------------
137 //! ArrowItem constructor.
138 ArrowItem( Canvas
& canvas
, RectangularItem
& a
, RectangularItem
& b
);
140 //! ArrowItem virtual destructor.
141 virtual ~ArrowItem( );
143 //! Update the arrow according to the connected rectangle position.
148 //! Source rectangle.
151 //! Destination rectangle.
154 //-----------------------------------------------------------------
158 //! Models a rectangular item on a relation canvas.
160 The following style options are supported (see the RectangularItem() contructor for more details):
162 <li> <b>'backcolor':</b> Background color, when there is no background image defined.
163 <li> <b>'bordercolor':</b> Color of the item border.
164 <li> <b>'backimage':</b> Background image (scaled to fit the item size).
165 <li> <b>'maximumwidth':</b> Maximum width of the item, content is cropped to fit this with limit.
166 <li> <b>'maximumheight':</b> Maximum height of the item, content is cropped to fit this height limit.
167 <li> <b>'fontsize':</b> Base size for the font used to display the item label.
168 <li> <b>'icon':</b> Display an icon centered in the left of the item.
169 <li> <b>'noshadow':</b> Set this value to 1 to supress the node shadow.
172 An item with an empty style is transparent with no background nor border.
176 class RectangularItem
: public ItemImpl
< QCanvasPolygon
>
178 /*! \name RectangularItem Constructor/Destructor *///------------------
182 //! RectangularItem constructor with style initialization.
183 RectangularItem( Canvas
& canvas
, Item
* parent
, QPoint origin
, const std::string
& label
, AdvStyle
& advStyle
);
185 //! RectangularItem virtual destructor.
186 virtual ~RectangularItem( );
188 //! Reimplemented to allow updating connected arrow's position.
189 virtual void move( double x
, double y
);
191 //! Reimplemented to allow updating connected arrow's position.
192 virtual void moveBy( double dx
, double dy
);
194 //! Update the node according to the given style.
195 virtual void updateStyle( const AdvStyle
& style
);
199 //! Create or update the node geometry (position, dimension, according to its actual content and the given style).
200 void updateGeometry( const AdvStyle
& advStyle
);
202 //! Draw the item text.
203 void drawShape( QPainter
& painter
);
213 QSimpleRichText
* _srt
;
217 RectangleItem
* _border
;
219 RectangleItem
* _shadow
;
221 //---------------------------------------------------------------------
225 /*! \name Arrow Management *///----------------------------------------
230 void addArrowIn( ArrowItem
& arrow
) { _arrowsIn
.push_back( &arrow
); }
233 void addArrowOut( ArrowItem
& arrow
) { _arrowsOut
.push_back( &arrow
); }
237 //! Update the arrow connected to this rectangular item.
238 void updateArrows( );
243 typedef std::vector
< ArrowItem
* > Arrows
;
251 //---------------------------------------------------------------------
255 //-----------------------------------------------------------------------------