~ubuntu-branches/ubuntu/oneiric/kig/oneiric

« back to all changes in this revision

Viewing changes to objects/object_drawer.cc

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:57:38 UTC
  • Revision ID: james.westby@ubuntu.com-20110710115738-gdjnn1kctr49lmy9
Tags: upstream-4.6.90+repack
ImportĀ upstreamĀ versionĀ 4.6.90+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C)  2003  Dominique Devriese <devriese@kde.org>
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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
 
16
// 02110-1301, USA.
 
17
 
 
18
#include "object_drawer.h"
 
19
 
 
20
#include "object_imp.h"
 
21
#include "../misc/kigpainter.h"
 
22
 
 
23
#include <qpen.h>
 
24
#include <qnamespace.h>
 
25
#include <cassert>
 
26
 
 
27
#include <kdebug.h>
 
28
 
 
29
void ObjectDrawer::draw( const ObjectImp& imp, KigPainter& p, bool sel ) const
 
30
{
 
31
  bool nv = p.getNightVision( );
 
32
  if ( mshown || nv )
 
33
  {
 
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) );
 
37
    p.setWidth( mwidth );
 
38
    p.setStyle( mstyle );
 
39
    p.setPointStyle( mpointstyle );
 
40
    p.setFont( mfont );
 
41
    p.setSelected( sel );
 
42
    imp.draw( p );
 
43
  }
 
44
}
 
45
 
 
46
bool ObjectDrawer::contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv ) const
 
47
{
 
48
  bool shownornv = mshown || nv;
 
49
  return shownornv && imp.contains( pt, mwidth, w );
 
50
}
 
51
 
 
52
bool ObjectDrawer::shown( ) const
 
53
{
 
54
  return mshown;
 
55
}
 
56
 
 
57
QColor ObjectDrawer::color() const
 
58
{
 
59
  return mcolor;
 
60
}
 
61
 
 
62
ObjectDrawer* ObjectDrawer::getCopyShown( bool s ) const
 
63
{
 
64
  ObjectDrawer* ret = new ObjectDrawer;
 
65
  ret->mcolor = mcolor;
 
66
  ret->mshown = s;
 
67
  ret->mwidth = mwidth;
 
68
  ret->mstyle = mstyle;
 
69
  ret->mpointstyle = mpointstyle;
 
70
  ret->mfont = mfont;
 
71
  return ret;
 
72
}
 
73
 
 
74
ObjectDrawer* ObjectDrawer::getCopyColor( const QColor& c ) const
 
75
{
 
76
  ObjectDrawer* ret = new ObjectDrawer;
 
77
  ret->mcolor = c;
 
78
  ret->mshown = mshown;
 
79
  ret->mwidth = mwidth;
 
80
  ret->mstyle = mstyle;
 
81
  ret->mpointstyle = mpointstyle;
 
82
  ret->mfont = mfont;
 
83
  return ret;
 
84
}
 
85
 
 
86
ObjectDrawer* ObjectDrawer::getCopyWidth( int w ) const
 
87
{
 
88
  ObjectDrawer* ret = new ObjectDrawer;
 
89
  ret->mcolor = mcolor;
 
90
  ret->mshown = mshown;
 
91
  ret->mwidth = w;
 
92
  ret->mstyle = mstyle;
 
93
  ret->mpointstyle = mpointstyle;
 
94
  ret->mfont = mfont;
 
95
  return ret;
 
96
}
 
97
 
 
98
ObjectDrawer* ObjectDrawer::getCopyStyle( Qt::PenStyle s ) const
 
99
{
 
100
  ObjectDrawer* ret = new ObjectDrawer;
 
101
  ret->mcolor = mcolor;
 
102
  ret->mshown = mshown;
 
103
  ret->mwidth = mwidth;
 
104
  ret->mstyle = s;
 
105
  ret->mpointstyle = mpointstyle;
 
106
  ret->mfont = mfont;
 
107
  return ret;
 
108
}
 
109
 
 
110
ObjectDrawer* ObjectDrawer::getCopyPointStyle( int p ) const
 
111
{
 
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;
 
118
  ret->mfont = mfont;
 
119
  return ret;
 
120
}
 
121
 
 
122
ObjectDrawer* ObjectDrawer::getCopyFont( const QFont& f ) const
 
123
{
 
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;
 
130
  ret->mfont = f;
 
131
  return ret;
 
132
}
 
133
 
 
134
int ObjectDrawer::width() const
 
135
{
 
136
  return mwidth;
 
137
}
 
138
 
 
139
Qt::PenStyle ObjectDrawer::style() const
 
140
{
 
141
  return mstyle;
 
142
}
 
143
 
 
144
int ObjectDrawer::pointStyle() const
 
145
{
 
146
  return mpointstyle;
 
147
}
 
148
 
 
149
QFont ObjectDrawer::font() const
 
150
{
 
151
  return mfont;
 
152
}
 
153
 
 
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 )
 
156
{
 
157
}
 
158
 
 
159
ObjectDrawer::ObjectDrawer()
 
160
  : mcolor( Qt::blue ), mshown( true ), mwidth( -1 ), mstyle( Qt::SolidLine ), mpointstyle( 0 ), mfont( QFont() )
 
161
{
 
162
}
 
163
 
 
164
bool ObjectDrawer::inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const
 
165
{
 
166
  return mshown && imp.inRect( r, mwidth, w );
 
167
}
 
168
 
 
169
int ObjectDrawer::pointStyleFromString( const QString& style )
 
170
{
 
171
  if ( style == "Round" )
 
172
    return 0;
 
173
  else if ( style == "RoundEmpty" )
 
174
    return 1;
 
175
  else if ( style == "Rectangular" )
 
176
    return 2;
 
177
  else if ( style == "RectangularEmpty" )
 
178
    return 3;
 
179
  else if ( style == "Cross" )
 
180
    return 4;
 
181
  return 0;
 
182
}
 
183
 
 
184
QString ObjectDrawer::pointStyleToString() const
 
185
{
 
186
  if ( mpointstyle == 0 )
 
187
    return "Round";
 
188
  else if ( mpointstyle == 1 )
 
189
    return "RoundEmpty";
 
190
  else if ( mpointstyle == 2 )
 
191
    return "Rectangular";
 
192
  else if ( mpointstyle == 3 )
 
193
    return "RectangularEmpty";
 
194
  else if ( mpointstyle == 4 )
 
195
    return "Cross";
 
196
  assert( false );
 
197
  return QString();
 
198
}
 
199
 
 
200
Qt::PenStyle ObjectDrawer::styleFromString( const QString& style )
 
201
{
 
202
  if ( style == "SolidLine" )
 
203
    return Qt::SolidLine;
 
204
  else if ( style == "DashLine" )
 
205
    return Qt::DashLine;
 
206
  else if ( style == "DotLine" )
 
207
    return Qt::DotLine;
 
208
  else if ( style == "DashDotLine" )
 
209
    return Qt::DashDotLine;
 
210
  else if ( style == "DashDotDotLine" )
 
211
    return Qt::DashDotDotLine;
 
212
  else return Qt::SolidLine;
 
213
}
 
214
 
 
215
QString ObjectDrawer::styleToString() const
 
216
{
 
217
  if ( mstyle == Qt::SolidLine )
 
218
    return "SolidLine";
 
219
  else if ( mstyle == Qt::DashLine )
 
220
    return "DashLine";
 
221
  else if ( mstyle == Qt::DotLine )
 
222
    return "DotLine";
 
223
  else if ( mstyle == Qt::DashDotLine )
 
224
    return "DashDotLine";
 
225
  else if ( mstyle == Qt::DashDotDotLine )
 
226
    return "DashDotDotLine";
 
227
  return "SolidLine";
 
228
}