1
// Copyright (C) 2002 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 "point_imp.h"
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"
29
PointImp::PointImp( const Coordinate& c )
34
Coordinate PointImp::attachPoint() const
37
// return Coordinate::invalidCoord();
40
void PointImp::draw( KigPainter& p ) const
45
bool PointImp::contains( const Coordinate& p, int width, const KigWidget& w ) const
47
int twidth = width == -1 ? 5 : width;
48
return (p - mc).length() - twidth*w.screenInfo().pixelWidth() < 0;
51
bool PointImp::inRect( const Rect& r, int width, const KigWidget& w ) const
53
double am = w.screenInfo().normalMiss( width );
54
return r.contains( mc, am );
57
int PointImp::numberOfProperties() const
59
return Parent::numberOfProperties() + 3;
62
const QByteArrayList PointImp::propertiesInternalNames() const
64
QByteArrayList l = Parent::propertiesInternalNames();
68
assert( l.size() == PointImp::numberOfProperties() );
72
const QByteArrayList PointImp::properties() const
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() );
82
const ObjectImpType* PointImp::impRequirementForProperty( int which ) const
84
if ( which < Parent::numberOfProperties() )
85
return Parent::impRequirementForProperty( which );
86
else return PointImp::stype();
89
const char* PointImp::iconForProperty( int which ) const
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
103
ObjectImp* PointImp::property( int which, const KigDocument& d ) const
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;
117
PointImp::~PointImp()
121
PointImp* PointImp::copy() const
123
return new PointImp( mc );
126
ObjectImp* PointImp::transform( const Transformation& t ) const
128
Coordinate nc = t.apply( mc );
129
if ( nc.valid() ) return new PointImp( nc );
130
else return new InvalidImp();
133
void PointImp::setCoordinate( const Coordinate& c )
138
void PointImp::fillInNextEscape( QString& s, const KigDocument& doc ) const
140
s = s.arg( doc.coordinateSystem().fromScreen( mc, doc ) );
143
void PointImp::visit( ObjectImpVisitor* vtor ) const
148
bool PointImp::equals( const ObjectImp& rhs ) const
150
return rhs.inherits( PointImp::stype() ) &&
151
static_cast<const PointImp&>( rhs ).coordinate() == coordinate();
154
bool PointImp::canFillInNextEscape() const
159
const ObjectImpType* PointImp::stype()
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" )
176
const ObjectImpType* PointImp::type() const
178
return PointImp::stype();
181
bool PointImp::isPropertyDefinedOnOrThroughThisImp( int which ) const
183
return Parent::isPropertyDefinedOnOrThroughThisImp( which );
186
Rect PointImp::surroundingRect() const
188
return Rect( mc, 0., 0. );
194
BogusPointImp::BogusPointImp( const Coordinate& c )
199
BogusPointImp::~BogusPointImp()
203
const ObjectImpType* BogusPointImp::stype()
205
static const ObjectImpType t(
220
const ObjectImpType* BogusPointImp::type() const
222
return BogusPointImp::stype();