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

« back to all changes in this revision

Viewing changes to objects/point_imp.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)  2002  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 "point_imp.h"
 
19
 
 
20
#include "bogus_imp.h"
 
21
#include "../misc/kigtransform.h"
 
22
#include "../misc/kigpainter.h"
 
23
#include "../misc/coordinate_system.h"
 
24
#include "../kig/kig_document.h"
 
25
#include "../kig/kig_view.h"
 
26
 
 
27
#include <klocale.h>
 
28
 
 
29
PointImp::PointImp( const Coordinate& c )
 
30
  : mc( c )
 
31
{
 
32
}
 
33
 
 
34
Coordinate PointImp::attachPoint() const
 
35
{
 
36
  return mc;
 
37
//  return Coordinate::invalidCoord();
 
38
}
 
39
 
 
40
void PointImp::draw( KigPainter& p ) const
 
41
{
 
42
  p.drawFatPoint( mc );
 
43
}
 
44
 
 
45
bool PointImp::contains( const Coordinate& p, int width, const KigWidget& w ) const
 
46
{
 
47
  int twidth = width == -1 ? 5 : width;
 
48
  return (p - mc).length() - twidth*w.screenInfo().pixelWidth() < 0;
 
49
}
 
50
 
 
51
bool PointImp::inRect( const Rect& r, int width, const KigWidget& w ) const
 
52
{
 
53
  double am = w.screenInfo().normalMiss( width );
 
54
  return r.contains( mc, am );
 
55
}
 
56
 
 
57
int PointImp::numberOfProperties() const
 
58
{
 
59
  return Parent::numberOfProperties() + 3;
 
60
}
 
61
 
 
62
const QByteArrayList PointImp::propertiesInternalNames() const
 
63
{
 
64
  QByteArrayList l = Parent::propertiesInternalNames();
 
65
  l << "coordinate";
 
66
  l << "coordinate-x";
 
67
  l << "coordinate-y";
 
68
  assert( l.size() == PointImp::numberOfProperties() );
 
69
  return l;
 
70
}
 
71
 
 
72
const QByteArrayList PointImp::properties() const
 
73
{
 
74
  QByteArrayList l = Parent::properties();
 
75
  l << I18N_NOOP( "Coordinate" );
 
76
  l << I18N_NOOP( "X coordinate" );
 
77
  l << I18N_NOOP( "Y coordinate" );
 
78
  assert( l.size() == PointImp::numberOfProperties() );
 
79
  return l;
 
80
}
 
81
 
 
82
const ObjectImpType* PointImp::impRequirementForProperty( int which ) const
 
83
{
 
84
  if ( which < Parent::numberOfProperties() )
 
85
    return Parent::impRequirementForProperty( which );
 
86
  else return PointImp::stype();
 
87
}
 
88
 
 
89
const char* PointImp::iconForProperty( int which ) const
 
90
{
 
91
  if ( which < Parent::numberOfProperties() )
 
92
    return Parent::iconForProperty( which );
 
93
  if ( which == Parent::numberOfProperties() )
 
94
    return "pointxy"; // coordinate
 
95
  if ( which == Parent::numberOfProperties() + 1 )
 
96
    return "pointxy"; // coordinate-x
 
97
  if ( which == Parent::numberOfProperties() + 2 )
 
98
    return "pointxy"; // coordinate-y
 
99
  else assert( false );
 
100
  return "";
 
101
}
 
102
 
 
103
ObjectImp* PointImp::property( int which, const KigDocument& d ) const
 
104
{
 
105
  if ( which < Parent::numberOfProperties() )
 
106
    return Parent::property( which, d );
 
107
  if ( which == Parent::numberOfProperties() )
 
108
    return new PointImp( mc );
 
109
  if ( which == Parent::numberOfProperties() + 1 )
 
110
    return new DoubleImp( mc.x );
 
111
  if ( which == Parent::numberOfProperties() + 2 )
 
112
    return new DoubleImp( mc.y );
 
113
//  else assert( false );
 
114
  return new InvalidImp;
 
115
}
 
116
 
 
117
PointImp::~PointImp()
 
118
{
 
119
}
 
120
 
 
121
PointImp* PointImp::copy() const
 
122
{
 
123
  return new PointImp( mc );
 
124
}
 
125
 
 
126
ObjectImp* PointImp::transform( const Transformation& t ) const
 
127
{
 
128
  Coordinate nc = t.apply( mc );
 
129
  if ( nc.valid() ) return new PointImp( nc );
 
130
  else return new InvalidImp();
 
131
}
 
132
 
 
133
void PointImp::setCoordinate( const Coordinate& c )
 
134
{
 
135
  mc = c;
 
136
}
 
137
 
 
138
void PointImp::fillInNextEscape( QString& s, const KigDocument& doc ) const
 
139
{
 
140
  s = s.arg( doc.coordinateSystem().fromScreen( mc, doc ) );
 
141
}
 
142
 
 
143
void PointImp::visit( ObjectImpVisitor* vtor ) const
 
144
{
 
145
  vtor->visit( this );
 
146
}
 
147
 
 
148
bool PointImp::equals( const ObjectImp& rhs ) const
 
149
{
 
150
  return rhs.inherits( PointImp::stype() ) &&
 
151
    static_cast<const PointImp&>( rhs ).coordinate() == coordinate();
 
152
}
 
153
 
 
154
bool PointImp::canFillInNextEscape() const
 
155
{
 
156
  return true;
 
157
}
 
158
 
 
159
const ObjectImpType* PointImp::stype()
 
160
{
 
161
  static const ObjectImpType t(
 
162
    Parent::stype(), "point",
 
163
    I18N_NOOP( "point" ),
 
164
    I18N_NOOP( "Select this point" ),
 
165
    I18N_NOOP( "Select point %1" ),
 
166
    I18N_NOOP( "Remove a Point" ),
 
167
    I18N_NOOP( "Add a Point" ),
 
168
    I18N_NOOP( "Move a Point" ),
 
169
    I18N_NOOP( "Attach to this point" ),
 
170
    I18N_NOOP( "Show a Point" ),
 
171
    I18N_NOOP( "Hide a Point" )
 
172
    );
 
173
  return &t;
 
174
}
 
175
 
 
176
const ObjectImpType* PointImp::type() const
 
177
{
 
178
  return PointImp::stype();
 
179
}
 
180
 
 
181
bool PointImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
 
182
{
 
183
  return Parent::isPropertyDefinedOnOrThroughThisImp( which );
 
184
}
 
185
 
 
186
Rect PointImp::surroundingRect() const
 
187
{
 
188
  return Rect( mc, 0., 0. );
 
189
}
 
190
 
 
191
/*
 
192
 */
 
193
 
 
194
BogusPointImp::BogusPointImp( const Coordinate& c )
 
195
  : PointImp( c )
 
196
{
 
197
}
 
198
 
 
199
BogusPointImp::~BogusPointImp()
 
200
{
 
201
}
 
202
 
 
203
const ObjectImpType* BogusPointImp::stype()
 
204
{
 
205
  static const ObjectImpType t(
 
206
    0, "boguspoint",
 
207
    "SHOULDNOTBESEEN",
 
208
    "SHOULDNOTBESEEN",
 
209
    "SHOULDNOTBESEEN",
 
210
    "SHOULDNOTBESEEN",
 
211
    "SHOULDNOTBESEEN",
 
212
    "SHOULDNOTBESEEN",
 
213
    "SHOULDNOTBESEEN",
 
214
    "SHOULDNOTBESEEN",
 
215
    "SHOULDNOTBESEEN"
 
216
    );
 
217
  return &t;
 
218
}
 
219
 
 
220
const ObjectImpType* BogusPointImp::type() const
 
221
{
 
222
  return BogusPointImp::stype();
 
223
}