1
// Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
3
// This program is free software; you can redistribute it and/or
4
// modify it under the terms of the GNU General Public License
5
// as published by the Free Software Foundation; either version 2
6
// of the License, or (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
#include "object_drawer.h"
20
#include "object_imp.h"
21
#include "../misc/kigpainter.h"
24
#include <qnamespace.h>
29
void ObjectDrawer::draw( const ObjectImp& imp, KigPainter& p, bool sel ) const
31
bool nv = p.getNightVision( );
34
p.setBrushStyle( Qt::NoBrush );
35
p.setBrushColor( sel ? Qt::red : ( mshown?mcolor:Qt::gray ) );
36
p.setPen( QPen ( sel ? Qt::red : ( mshown?mcolor:Qt::gray ), 1) );
39
p.setPointStyle( mpointstyle );
46
bool ObjectDrawer::contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv ) const
48
bool shownornv = mshown || nv;
49
return shownornv && imp.contains( pt, mwidth, w );
52
bool ObjectDrawer::shown( ) const
57
QColor ObjectDrawer::color() const
62
ObjectDrawer* ObjectDrawer::getCopyShown( bool s ) const
64
ObjectDrawer* ret = new ObjectDrawer;
69
ret->mpointstyle = mpointstyle;
74
ObjectDrawer* ObjectDrawer::getCopyColor( const QColor& c ) const
76
ObjectDrawer* ret = new ObjectDrawer;
81
ret->mpointstyle = mpointstyle;
86
ObjectDrawer* ObjectDrawer::getCopyWidth( int w ) const
88
ObjectDrawer* ret = new ObjectDrawer;
93
ret->mpointstyle = mpointstyle;
98
ObjectDrawer* ObjectDrawer::getCopyStyle( Qt::PenStyle s ) const
100
ObjectDrawer* ret = new ObjectDrawer;
101
ret->mcolor = mcolor;
102
ret->mshown = mshown;
103
ret->mwidth = mwidth;
105
ret->mpointstyle = mpointstyle;
110
ObjectDrawer* ObjectDrawer::getCopyPointStyle( int p ) const
112
ObjectDrawer* ret = new ObjectDrawer;
113
ret->mcolor = mcolor;
114
ret->mshown = mshown;
115
ret->mwidth = mwidth;
116
ret->mstyle = mstyle;
117
ret->mpointstyle = p;
122
ObjectDrawer* ObjectDrawer::getCopyFont( const QFont& f ) const
124
ObjectDrawer* ret = new ObjectDrawer;
125
ret->mcolor = mcolor;
126
ret->mshown = mshown;
127
ret->mwidth = mwidth;
128
ret->mstyle = mstyle;
129
ret->mpointstyle = mpointstyle;
134
int ObjectDrawer::width() const
139
Qt::PenStyle ObjectDrawer::style() const
144
int ObjectDrawer::pointStyle() const
149
QFont ObjectDrawer::font() const
154
ObjectDrawer::ObjectDrawer( const QColor& color, int width, bool shown, Qt::PenStyle style, int pointStyle, const QFont& f )
155
: mcolor( color ), mshown( shown ), mwidth( width ), mstyle( style ), mpointstyle( pointStyle ), mfont( f )
159
ObjectDrawer::ObjectDrawer()
160
: mcolor( Qt::blue ), mshown( true ), mwidth( -1 ), mstyle( Qt::SolidLine ), mpointstyle( 0 ), mfont( QFont() )
164
bool ObjectDrawer::inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const
166
return mshown && imp.inRect( r, mwidth, w );
169
int ObjectDrawer::pointStyleFromString( const QString& style )
171
if ( style == "Round" )
173
else if ( style == "RoundEmpty" )
175
else if ( style == "Rectangular" )
177
else if ( style == "RectangularEmpty" )
179
else if ( style == "Cross" )
184
QString ObjectDrawer::pointStyleToString() const
186
if ( mpointstyle == 0 )
188
else if ( mpointstyle == 1 )
190
else if ( mpointstyle == 2 )
191
return "Rectangular";
192
else if ( mpointstyle == 3 )
193
return "RectangularEmpty";
194
else if ( mpointstyle == 4 )
200
Qt::PenStyle ObjectDrawer::styleFromString( const QString& style )
202
if ( style == "SolidLine" )
203
return Qt::SolidLine;
204
else if ( style == "DashLine" )
206
else if ( style == "DotLine" )
208
else if ( style == "DashDotLine" )
209
return Qt::DashDotLine;
210
else if ( style == "DashDotDotLine" )
211
return Qt::DashDotDotLine;
212
else return Qt::SolidLine;
215
QString ObjectDrawer::styleToString() const
217
if ( mstyle == Qt::SolidLine )
219
else if ( mstyle == Qt::DashLine )
221
else if ( mstyle == Qt::DotLine )
223
else if ( mstyle == Qt::DashDotLine )
224
return "DashDotLine";
225
else if ( mstyle == Qt::DashDotDotLine )
226
return "DashDotDotLine";