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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
// SPDX-FileCopyrightText: 2003 Dominique Devriese <devriese@kde.org>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "text_imp.h"
#include "../misc/kigpainter.h"
#include "bogus_imp.h"
TextImp::TextImp(const QString &text, const Coordinate &loc, bool frame)
: mtext(text)
, mloc(loc)
, mframe(frame)
, mboundrect(Rect::invalidRect())
{
}
TextImp *TextImp::copy() const
{
return new TextImp(mtext, mloc);
}
TextImp::~TextImp()
{
}
Coordinate TextImp::attachPoint() const
{
return Coordinate::invalidCoord();
}
ObjectImp *TextImp::transform(const Transformation &t) const
{
Coordinate nloc = t.apply(mloc);
return new TextImp(mtext, nloc, mframe);
}
void TextImp::draw(KigPainter &p) const
{
mboundrect = p.simpleBoundingRect(mloc, mtext);
p.drawTextFrame(mboundrect, mtext, mframe);
}
bool TextImp::contains(const Coordinate &p, int, const KigWidget &) const
{
return mboundrect.contains(p);
}
bool TextImp::inRect(const Rect &r, int, const KigWidget &) const
{
return mboundrect.intersects(r);
}
bool TextImp::valid() const
{
return true;
}
int TextImp::numberOfProperties() const
{
return Parent::numberOfProperties() + 1;
}
const QByteArrayList TextImp::propertiesInternalNames() const
{
QByteArrayList ret = Parent::propertiesInternalNames();
ret << "kig_text";
return ret;
}
const QList<KLazyLocalizedString> TextImp::properties() const
{
QList<KLazyLocalizedString> ret = Parent::properties();
ret << kli18n("Text");
return ret;
}
const ObjectImpType *TextImp::impRequirementForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::impRequirementForProperty(which);
return TextImp::stype();
}
const char *TextImp::iconForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::iconForProperty(which);
else if (which == Parent::numberOfProperties())
return "draw-text"; // text
else
assert(false);
return "";
}
ObjectImp *TextImp::property(int which, const KigDocument &w) const
{
if (which < Parent::numberOfProperties())
return Parent::property(which, w);
else if (which == Parent::numberOfProperties())
return new StringImp(text());
else
assert(false);
return new InvalidImp;
}
QString TextImp::text() const
{
return mtext;
}
void TextImp::visit(ObjectImpVisitor *vtor) const
{
vtor->visit(this);
}
const Coordinate TextImp::coordinate() const
{
return mloc;
}
bool TextImp::equals(const ObjectImp &rhs) const
{
return rhs.inherits(TextImp::stype()) && static_cast<const TextImp &>(rhs).coordinate() == coordinate()
&& static_cast<const TextImp &>(rhs).text() == text() && static_cast<const TextImp &>(rhs).hasFrame() == hasFrame();
}
bool TextImp::hasFrame() const
{
return mframe;
}
const ObjectImpType *TextImp::stype()
{
static const ObjectImpType t(Parent::stype(),
"label",
kli18n("label"),
kli18n("Select this label"),
kli18n("Select label %1"),
kli18n("Remove a Label"),
kli18n("Add a Label"),
kli18n("Move a Label"),
kli18n("Attach to this label"),
kli18n("Show a Label"),
kli18n("Hide a Label"));
return &t;
}
const ObjectImpType *TextImp::type() const
{
return TextImp::stype();
}
bool TextImp::isPropertyDefinedOnOrThroughThisImp(int which) const
{
return Parent::isPropertyDefinedOnOrThroughThisImp(which);
}
Rect TextImp::surroundingRect() const
{
return mboundrect;
}
/*
* NumericTextImp
*/
NumericTextImp::NumericTextImp(const QString &text, const Coordinate &loc, bool frame, double value)
: TextImp(text, loc, frame)
, mvalue(value)
{
}
NumericTextImp *NumericTextImp::copy() const
{
return new NumericTextImp(text(), coordinate(), hasFrame(), mvalue);
}
const ObjectImpType *NumericTextImp::stype()
{
static const ObjectImpType t(Parent::stype(),
"numeric-label",
kli18n("numeric label"),
kli18n("Select this numeric label"),
kli18n("Select numeric label %1"),
kli18n("Remove a Numeric Label"),
kli18n("Add a Numeric Label"),
kli18n("Move a Numeric Label"),
kli18n("Attach to this numeric label"),
kli18n("Show a Numeric Label"),
kli18n("Hide a Numeric Label"));
return &t;
}
const ObjectImpType *NumericTextImp::type() const
{
return NumericTextImp::stype();
}
double NumericTextImp::getValue(void) const
{
return mvalue;
}
int NumericTextImp::numberOfProperties() const
{
return Parent::numberOfProperties() + 1;
}
const QByteArrayList NumericTextImp::propertiesInternalNames() const
{
QByteArrayList ret = Parent::propertiesInternalNames();
ret << "kig_value";
return ret;
}
const QList<KLazyLocalizedString> NumericTextImp::properties() const
{
QList<KLazyLocalizedString> ret = Parent::properties();
ret << kli18n("Numeric value");
return ret;
}
const ObjectImpType *NumericTextImp::impRequirementForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::impRequirementForProperty(which);
return NumericTextImp::stype();
}
const char *NumericTextImp::iconForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::iconForProperty(which);
else if (which == Parent::numberOfProperties())
return "value"; // text
else
assert(false);
return "";
}
ObjectImp *NumericTextImp::property(int which, const KigDocument &w) const
{
if (which < Parent::numberOfProperties())
return Parent::property(which, w);
else if (which == Parent::numberOfProperties())
return new DoubleImp(getValue());
else
assert(false);
return new InvalidImp;
}
bool NumericTextImp::isPropertyDefinedOnOrThroughThisImp(int which) const
{
return Parent::isPropertyDefinedOnOrThroughThisImp(which);
}
/*
* BoolTextImp
*/
BoolTextImp::BoolTextImp(const QString &text, const Coordinate &loc, bool frame, bool value)
: TextImp(text, loc, frame)
, mvalue(value)
{
}
BoolTextImp *BoolTextImp::copy() const
{
return new BoolTextImp(text(), coordinate(), hasFrame(), mvalue);
}
const ObjectImpType *BoolTextImp::stype()
{
static const ObjectImpType t(Parent::stype(),
"boolean-label",
kli18n("boolean label"),
kli18n("Select this boolean label"),
kli18n("Select boolean label %1"),
kli18n("Remove a Boolean Label"),
kli18n("Add a Boolean Label"),
kli18n("Move a Boolean Label"),
kli18n("Attach to this boolean label"),
kli18n("Show a Boolean Label"),
kli18n("Hide a Boolean Label"));
return &t;
}
const ObjectImpType *BoolTextImp::type() const
{
return BoolTextImp::stype();
}
bool BoolTextImp::getValue(void) const
{
return mvalue;
}
int BoolTextImp::numberOfProperties() const
{
return Parent::numberOfProperties() + 1;
}
const QByteArrayList BoolTextImp::propertiesInternalNames() const
{
QByteArrayList ret = Parent::propertiesInternalNames();
ret << "kig_value";
return ret;
}
const QList<KLazyLocalizedString> BoolTextImp::properties() const
{
QList<KLazyLocalizedString> ret = Parent::properties();
ret << kli18n("Numeric value");
return ret;
}
const ObjectImpType *BoolTextImp::impRequirementForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::impRequirementForProperty(which);
return NumericTextImp::stype();
}
const char *BoolTextImp::iconForProperty(int which) const
{
if (which < Parent::numberOfProperties())
return Parent::iconForProperty(which);
else if (which == Parent::numberOfProperties())
return "value"; // text
else
assert(false);
return "";
}
ObjectImp *BoolTextImp::property(int which, const KigDocument &w) const
{
if (which < Parent::numberOfProperties())
return Parent::property(which, w);
else if (which == Parent::numberOfProperties())
return new DoubleImp(getValue());
else
assert(false);
return new InvalidImp;
}
bool BoolTextImp::isPropertyDefinedOnOrThroughThisImp(int which) const
{
return Parent::isPropertyDefinedOnOrThroughThisImp(which);
}
|