2 This file is part of Kig, a KDE program for Interactive Geometry...
3 Copyright (C) 2002-2003 Dominique Devriese <devriese@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 #include "coordinate.h"
27 #include "screeninfo.h"
36 class CoordinateSystem
;
37 class ObjectHierarchy
;
39 class CubicCartesianData
;
46 * KigPainter is an extended qpainter...
47 * currently the only difference is that it translates coordinates
48 * from and to the internal coordinates/ the widget coordinates...
49 * it calls KigWidget::appendOverlay() for all of the places it draws in...
55 // don't blaim me for this mutable hack. It's TT that hasn't got
56 // its consts correctly...
63 BrushStyle brushStyle
;
66 const KigDocument
& mdoc
;
73 * construct a new KigPainter:
74 * the ScreenInfo is used to map the document coordinates to the
75 * widget coordinates. This is done transparently to the objects.
76 * needOverlay sets whether we try to remember the places we're
77 * drawing on using the various overlay methods. @see overlay()
79 KigPainter( const ScreenInfo
& r
, QPaintDevice
* device
, const KigDocument
& doc
,
80 bool needOverlay
= true );
83 // what rect are we drawing on ?
86 QPoint
toScreen( const Coordinate p
) const;
87 QRect
toScreen( const Rect r
) const;
88 QRect
toScreenEnlarge( const Rect r
) const;
89 Coordinate
fromScreen( const QPoint
& p
) const;
90 Rect
fromScreen( const QRect
& r
) const;
92 // colors and stuff...
93 void setStyle( const PenStyle c
);
94 void setColor( const QColor
& c
);
95 void setWidth( const int c
); // setting this to -1 means to use
96 // the default width for the object
97 // being drawn.. a point -> 5, other
99 void setPointStyle( const int p
);
100 void setPen( const QPen
& p
);
101 void setBrushStyle( const BrushStyle c
);
102 void setBrush( const QBrush
& b
);
103 void setBrushColor( const QColor
& c
);
105 QColor
getColor() const;
106 bool getNightVision( ) const;
111 * this is called by some drawing functions that modify the 'entire'
112 * screen, i.e. they do so many changes that it's easier to just
113 * update the entire screen, or else i have been to lazy to
114 * implement an appropriate overlay function ;)
115 * it clears mOverlay, and sets it to the entire widget...
117 void setWholeWinOverlay();
120 * draw an object ( by calling its draw function.. )
122 void drawObject( const ObjectHolder
* o
, bool sel
);
123 void drawObjects( const std::vector
<ObjectHolder
*>& os
, bool sel
);
124 template<typename iter
>
125 void drawObjects( iter begin
, iter end
, bool sel
)
127 for ( ; begin
!= end
; ++begin
)
128 drawObject( *begin
, sel
);
132 * draw a generic curve...
134 void drawCurve( const CurveImp
* curve
);
137 * draws text in a standard manner, convenience function...
139 void drawTextStd( const QPoint
& p
, const QString
& s
);
142 * draws a rect filled up with a pattern of cyan lines...
144 void drawFilledRect( const QRect
& );
149 void drawRect( const Rect
& r
);
152 * overload, mainly for drawing the selection rectangle by
155 void drawRect( const QRect
& r
);
160 void drawCircle( const Coordinate
& center
, const double radius
);
165 void drawSegment ( const Coordinate
& from
, const Coordinate
& to
);
166 void drawSegment( const LineData
& d
);
171 void drawRay( const Coordinate
& a
, const Coordinate
& b
);
172 void drawRay( const LineData
& d
);
177 void drawLine ( const Coordinate
& p1
, const Coordinate
& p2
);
178 void drawLine( const LineData
& d
);
181 * draw a point... This means a single point, as in
182 * QPainter::drawPoint(), unlike drawFatPoint()...
184 void drawPoint( const Coordinate
& p
);
187 * draw a thick point.. This is what the user sees when he draws a
188 * point. In fact it isn't a point, but a filled circle of a
189 * certain @param radius...
191 void drawFatPoint( const Coordinate
& p
);
194 * draw a polygon defined by the points in pts...
196 void drawPolygon( const std::vector
<QPoint
>& pts
, bool winding
= false, int index
= 0, int npoints
= -1 );
197 void drawPolygon( const std::vector
<Coordinate
>& pts
, bool winding
= false, int index
= 0, int npoints
= -1 );
200 * draw an area defined by the points in pts filled with the set
203 void drawArea( const std::vector
<Coordinate
>& pts
, bool border
= true );
206 * draw the angle with center point, with size angle, starting
207 * at the angle startAngle.. Angles should be in radians.
209 void drawAngle( const Coordinate
& point
, const double startangle
,
210 const double angle
);
213 * draw the arc ( a part of a circle ), of the circle with center
214 * center, radius radius, with size angle, starting at the angle
215 * startAngle.. Angles should be in radians..
217 void drawArc( const Coordinate
& center
, const double radius
,
218 const double startangle
, const double angle
);
221 * draw a vector ( with an arrow etc. )
224 void drawVector( const Coordinate
& a
, const Coordinate
& b
);
228 * @see QPainter::drawText()
230 void drawText( const Rect r
, const QString s
, int textFlags
= 0,
232 void drawText( const Coordinate p
, const QString s
,
233 int textFlags
= 0, int len
= -1);
235 void drawSimpleText( const Coordinate
& c
, const QString s
);
236 void drawTextFrame( const Rect
& frame
, const QString
& s
, bool frame
);
238 const Rect
boundingRect( const Rect
& r
, const QString s
,
239 int f
= 0, int l
= -1 ) const;
241 const Rect
boundingRect( const Coordinate
& c
, const QString s
,
242 int f
= 0, int l
= -1 ) const;
244 const Rect
simpleBoundingRect( const Coordinate
& c
, const QString s
);
246 void drawGrid( const CoordinateSystem
& c
, bool showGrid
= true, bool showAxes
= true );
248 const std::vector
<QRect
>& overlay() { return mOverlay
; };
252 * adds a number of rects to mOverlay so that the rects entirely
253 * contain the circle...
256 void circleOverlay( const Coordinate
& centre
, double radius
);
257 // this works recursively...
258 void circleOverlayRecurse( const Coordinate
& centre
, double radius
, const Rect
& currentRect
);
261 * adds some rects to mOverlay, so that they cover the segment p1p2
263 * @see Object::getOverlay()
265 void segmentOverlay( const Coordinate
& p1
, const Coordinate
& p2
);
270 void pointOverlay( const Coordinate
& p1
);
274 * @see drawText(), QPainter::boundingRect()
276 void textOverlay( const QRect
& r
, const QString s
, int textFlags
, int len
);
278 // the size we want the overlay rects to be...
279 double overlayRectSize();
281 std::vector
<QRect
> mOverlay
;