(empty message)
[qanava.git] / src / can / canItemGeom.h
blob65fef9cc4d181de6cf23171d0ba630dd16819e3e
1 /*
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 //-----------------------------------------------------------------------------
29 #ifndef canItemGeom_h
30 #define canItemGeom_h
33 // Qanava headers
34 #include "canItem.h"
35 #include "canItemImpl.h"
36 #include "canAdvStyle.h"
39 // QT headers
40 #include <qobject.h>
41 #include <qcanvas.h>
42 #include <qimage.h>
43 #include <qsimplerichtext.h>
46 //-----------------------------------------------------------------------------
47 namespace qan { // ::qan
48 namespace can { // ::qan::can
50 //! Models a rectangle on a relation canvas.
51 /*!
52 \nosubgrouping
54 class RectangleItem : public ItemImpl< QCanvasRectangle >
56 /*! \name RectangleItem Constructor/Destructor *///--------------------
57 //@{
58 public:
60 //! RectangleItem constructor.
61 RectangleItem( Canvas& canvas, Item& parent, const QPoint& origin, const QPoint& dimension, AdvStyle& advStyle );
63 //! RectangleItem virtual destructor.
64 virtual ~RectangleItem( );
65 //@}
66 //---------------------------------------------------------------------
70 /*! \name Custom Drawing Management *///-------------------------------
71 //@{
72 public:
74 //! Create or update item geometry taking into account current settings and style.
75 void updateGeometry( const QPoint& origin, const QPoint& dimension );
77 //! .
78 void updateStyle( const AdvStyle& style );
80 //! Set a new background image for this rectangle item.
81 void setBackImage( const QImage& backImage );
83 protected:
85 //! Draw the item back image, border and background area.
86 void drawShape( QPainter& painter );
88 private:
90 QPoint _dimension;
92 QPoint _origin;
94 QPixmap _backPixmap;
96 QColor _borderColor;
98 QColor _backColor;
99 //@}
100 //---------------------------------------------------------------------
104 //! Models a centered and clipped line of text on a relation canvas.
106 \nosubgrouping
108 class TextItem : public ItemImpl< QCanvasText >
110 /*! \name TextItem Constructor/Destructor *///---------------------
111 //@{
112 public:
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( );
119 //@}
120 //-----------------------------------------------------------------
124 class RectangularItem;
127 //! Models a connexion between rectengular items on a relation canvas.
129 \nosubgrouping
131 class ArrowItem : public ItemImpl< QCanvasLine >
133 /*! \name ArrowItem Constructor/Destructor *///--------------------
134 //@{
135 public:
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.
144 void updateArrow( );
146 private:
148 //! Source rectangle.
149 RectangularItem& _a;
151 //! Destination rectangle.
152 RectangularItem& _b;
153 //@}
154 //-----------------------------------------------------------------
158 //! Models a rectangular item on a relation canvas.
160 The following style options are supported (see the RectangularItem() contructor for more details):
161 <ul>
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.
170 </ul>
172 An item with an empty style is transparent with no background nor border.
174 \nosubgrouping
176 class RectangularItem : public ItemImpl< QCanvasPolygon >
178 /*! \name RectangularItem Constructor/Destructor *///------------------
179 //@{
180 public:
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 );
197 protected:
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 );
205 private:
207 QPoint _origin;
209 QPoint _dimension;
211 std::string _label;
213 QSimpleRichText* _srt;
215 QPixmap _icon;
217 RectangleItem* _border;
219 RectangleItem* _shadow;
220 //@}
221 //---------------------------------------------------------------------
225 /*! \name Arrow Management *///----------------------------------------
226 //@{
227 public:
229 //! Add in arrow.
230 void addArrowIn( ArrowItem& arrow ) { _arrowsIn.push_back( &arrow ); }
232 //! Add out arrow.
233 void addArrowOut( ArrowItem& arrow ) { _arrowsOut.push_back( &arrow ); }
235 protected:
237 //! Update the arrow connected to this rectangular item.
238 void updateArrows( );
240 private:
242 //! Arrow array.
243 typedef std::vector< ArrowItem* > Arrows;
245 //! In arrows.
246 Arrows _arrowsIn;
248 //! Out arrows.
249 Arrows _arrowsOut;
250 //@}
251 //---------------------------------------------------------------------
253 } // ::qan::can
254 } // ::qan
255 //-----------------------------------------------------------------------------
258 #endif // canItem_h