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 205 206 207 208 209 210 211
|
// SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "point_imp.h"
#include "../kig/kig_document.h"
#include "../kig/kig_view.h"
#include "../misc/coordinate_system.h"
#include "../misc/kigpainter.h"
#include "../misc/kigtransform.h"
#include "bogus_imp.h"
#include <KLazyLocalizedString>
PointImp::PointImp(const Coordinate &c)
: mc(c)
{
}
Coordinate PointImp::attachPoint() const
{
return mc;
// return Coordinate::invalidCoord();
}
void PointImp::draw(KigPainter &p) const
{
p.drawFatPoint(mc);
}
bool PointImp::contains(const Coordinate &p, int width, const KigWidget &w) const
{
int twidth = width == -1 ? 5 : width;
return (p - mc).length() - twidth * w.screenInfo().pixelWidth() < 0;
}
bool PointImp::inRect(const Rect &r, int width, const KigWidget &w) const
{
double am = w.screenInfo().normalMiss(width);
return r.contains(mc, am);
}
int PointImp::numberOfProperties() const
{
return Parent::numberOfProperties() + 3;
}
const QByteArrayList PointImp::propertiesInternalNames() const
{
QByteArrayList l = Parent::propertiesInternalNames();
l << "coordinate";
l << "coordinate-x";
l << "coordinate-y";
assert(l.size() == PointImp::numberOfProperties());
return l;
}
const QList<KLazyLocalizedString> PointImp::properties() const
{
QList<KLazyLocalizedString> l = Parent::properties();
l << kli18n("Coordinate");
l << kli18n("X coordinate");
l << kli18n("Y coordinate");
assert(l.size() == PointImp::numberOfProperties());
return l;
}
const ObjectImpType *PointImp::impRequirementForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::impRequirementForProperty(which);
else
return PointImp::stype();
}
const char *PointImp::iconForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::iconForProperty(which);
if (which == Parent::numberOfProperties())
return "pointxy"; // coordinate
if (which == Parent::numberOfProperties() + 1)
return "pointxy"; // coordinate-x
if (which == Parent::numberOfProperties() + 2)
return "pointxy"; // coordinate-y
else
assert(false);
return "";
}
ObjectImp *PointImp::property(int which, const KigDocument &d) const
{
if (which < Parent::numberOfProperties())
return Parent::property(which, d);
if (which == Parent::numberOfProperties())
return new PointImp(mc);
if (which == Parent::numberOfProperties() + 1)
return new DoubleImp(mc.x);
if (which == Parent::numberOfProperties() + 2)
return new DoubleImp(mc.y);
// else assert( false );
return new InvalidImp;
}
PointImp::~PointImp()
{
}
PointImp *PointImp::copy() const
{
return new PointImp(mc);
}
ObjectImp *PointImp::transform(const Transformation &t) const
{
Coordinate nc = t.apply(mc);
if (nc.valid())
return new PointImp(nc);
else
return new InvalidImp();
}
void PointImp::setCoordinate(const Coordinate &c)
{
mc = c;
}
void PointImp::fillInNextEscape(QString &s, const KigDocument &doc) const
{
s = s.arg(doc.coordinateSystem().fromScreen(mc, doc));
}
void PointImp::visit(ObjectImpVisitor *vtor) const
{
vtor->visit(this);
}
bool PointImp::equals(const ObjectImp &rhs) const
{
return rhs.inherits(PointImp::stype()) && static_cast<const PointImp &>(rhs).coordinate() == coordinate();
}
bool PointImp::canFillInNextEscape() const
{
return true;
}
const ObjectImpType *PointImp::stype()
{
static const ObjectImpType t(Parent::stype(),
"point",
kli18n("point"),
kli18n("Select this point"),
kli18n("Select point %1"),
kli18n("Remove a Point"),
kli18n("Add a Point"),
kli18n("Move a Point"),
kli18n("Attach to this point"),
kli18n("Show a Point"),
kli18n("Hide a Point"));
return &t;
}
const ObjectImpType *PointImp::type() const
{
return PointImp::stype();
}
bool PointImp::isPropertyDefinedOnOrThroughThisImp(int which) const
{
return Parent::isPropertyDefinedOnOrThroughThisImp(which);
}
Rect PointImp::surroundingRect() const
{
return Rect(mc, 0., 0.);
}
/*
*/
BogusPointImp::BogusPointImp(const Coordinate &c)
: PointImp(c)
{
}
BogusPointImp::~BogusPointImp()
{
}
const ObjectImpType *BogusPointImp::stype()
{
static const ObjectImpType t(nullptr,
"boguspoint",
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString(),
KLazyLocalizedString());
return &t;
}
const ObjectImpType *BogusPointImp::type() const
{
return BogusPointImp::stype();
}
|