summaryrefslogtreecommitdiffstats
path: root/kig/objects/object_drawer.cc
blob: d6e4114483bf6cd3223e3ba281310f1ce1622216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (C)  2003  Dominique Devriese <devriese@kde.org>

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

#include "object_drawer.h"

#include "object_imp.h"
#include "../misc/kigpainter.h"

#include <tqpen.h>
#include <tqnamespace.h>
#include <cassert>

#include <kdebug.h>

void ObjectDrawer::draw( const ObjectImp& imp, KigPainter& p, bool sel ) const
{
  bool nv = p.getNightVision( );
  if ( mshown || nv )
  {
    p.setBrushStyle( Qt::NoBrush );
    p.setBrushColor( sel ? TQt::red : ( mshown?mcolor:TQt::gray ) );
    p.setPen( TQPen ( sel ? TQt::red : ( mshown?mcolor:TQt::gray ),  1) );
    p.setWidth( mwidth );
    p.setStyle( mstyle );
    p.setPointStyle( mpointstyle );
    imp.draw( p );
  }
}

bool ObjectDrawer::contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv ) const
{
  bool shownornv = mshown || nv;
  return shownornv && imp.contains( pt, mwidth, w );
}

bool ObjectDrawer::shown( ) const
{
  return mshown;
}

TQColor ObjectDrawer::color() const
{
  return mcolor;
}

ObjectDrawer* ObjectDrawer::getCopyShown( bool s ) const
{
  ObjectDrawer* ret = new ObjectDrawer;
  ret->mcolor = mcolor;
  ret->mshown = s;
  ret->mwidth = mwidth;
  ret->mstyle = mstyle;
  ret->mpointstyle = mpointstyle;
  return ret;
}

ObjectDrawer* ObjectDrawer::getCopyColor( const TQColor& c ) const
{
  ObjectDrawer* ret = new ObjectDrawer;
  ret->mcolor = c;
  ret->mshown = mshown;
  ret->mwidth = mwidth;
  ret->mstyle = mstyle;
  ret->mpointstyle = mpointstyle;
  return ret;
}

ObjectDrawer* ObjectDrawer::getCopyWidth( int w ) const
{
  ObjectDrawer* ret = new ObjectDrawer;
  ret->mcolor = mcolor;
  ret->mshown = mshown;
  ret->mwidth = w;
  ret->mstyle = mstyle;
  ret->mpointstyle = mpointstyle;
  return ret;
}

ObjectDrawer* ObjectDrawer::getCopyStyle( Qt::PenStyle s ) const
{
  ObjectDrawer* ret = new ObjectDrawer;
  ret->mcolor = mcolor;
  ret->mshown = mshown;
  ret->mwidth = mwidth;
  ret->mstyle = s;
  ret->mpointstyle = mpointstyle;
  return ret;
}

ObjectDrawer* ObjectDrawer::getCopyPointStyle( int p ) const
{
  ObjectDrawer* ret = new ObjectDrawer;
  ret->mcolor = mcolor;
  ret->mshown = mshown;
  ret->mwidth = mwidth;
  ret->mstyle = mstyle;
  ret->mpointstyle = p;
  return ret;
}

int ObjectDrawer::width() const
{
  return mwidth;
}

Qt::PenStyle ObjectDrawer::style() const
{
  return mstyle;
}

int ObjectDrawer::pointStyle() const
{
  return mpointstyle;
}

ObjectDrawer::ObjectDrawer( const TQColor& color, int width, bool shown, Qt::PenStyle style, int pointStyle )
  : mcolor( color ), mshown( shown ), mwidth( width ), mstyle( style ), mpointstyle( pointStyle )
{
}

ObjectDrawer::ObjectDrawer()
  : mcolor( TQt::blue ), mshown( true ), mwidth( -1 ), mstyle( Qt::SolidLine ), mpointstyle( 0 )
{
}

bool ObjectDrawer::inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const
{
  return mshown && imp.inRect( r, mwidth, w );
}

int ObjectDrawer::pointStyleFromString( const TQString& style )
{
  if ( style == "Round" )
    return 0;
  else if ( style == "RoundEmpty" )
    return 1;
  else if ( style == "Rectangular" )
    return 2;
  else if ( style == "RectangularEmpty" )
    return 3;
  else if ( style == "Cross" )
    return 4;
  return 0;
}

TQString ObjectDrawer::pointStyleToString() const
{
  if ( mpointstyle == 0 )
    return "Round";
  else if ( mpointstyle == 1 )
    return "RoundEmpty";
  else if ( mpointstyle == 2 )
    return "Rectangular";
  else if ( mpointstyle == 3 )
    return "RectangularEmpty";
  else if ( mpointstyle == 4 )
    return "Cross";
  assert( false );
  return TQString();
}

Qt::PenStyle ObjectDrawer::styleFromString( const TQString& style )
{
  if ( style == "SolidLine" )
    return Qt::SolidLine;
  else if ( style == "DashLine" )
    return Qt::DashLine;
  else if ( style == "DotLine" )
    return Qt::DotLine;
  else if ( style == "DashDotLine" )
    return Qt::DashDotLine;
  else if ( style == "DashDotDotLine" )
    return Qt::DashDotDotLine;
  else return Qt::SolidLine;
}

TQString ObjectDrawer::styleToString() const
{
  if ( mstyle == TQt::SolidLine )
    return "SolidLine";
  else if ( mstyle == TQt::DashLine )
    return "DashLine";
  else if ( mstyle == TQt::DotLine )
    return "DotLine";
  else if ( mstyle == TQt::DashDotLine )
    return "DashDotLine";
  else if ( mstyle == TQt::DashDotDotLine )
    return "DashDotDotLine";
  return "SolidLine";
}