KoShape.cpp 38.7 KB
Newer Older
Thomas Zander's avatar
Thomas Zander committed
1
/* This file is part of the KDE project
Thomas Zander's avatar
Thomas Zander committed
2
   Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
3
   Copyright (C) 2006-2009 Thomas Zander <zander@kde.org>
4
   Copyright (C) 2006-2008 Thorsten Zachmann <zachmann@kde.org>
5
   Copyright (C) 2007-2009 Jan Hambrecht <jaham@gmx.net>
Thomas Zander's avatar
Thomas Zander committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "KoShape.h"
24
#include "KoShape_p.h"
Thomas Zander's avatar
Thomas Zander committed
25
#include "KoShapeContainer.h"
26
#include "KoShapeLayer.h"
27
#include "KoShapeContainerModel.h"
Thomas Zander's avatar
Thomas Zander committed
28
#include "KoSelection.h"
29
#include "KoPointerEvent.h"
Thomas Zander's avatar
Thomas Zander committed
30 31
#include "KoInsets.h"
#include "KoShapeBorderModel.h"
32 33 34 35
#include "KoShapeBackground.h"
#include "KoColorBackground.h"
#include "KoGradientBackground.h"
#include "KoPatternBackground.h"
36
#include "KoShapeManager.h"
37
#include "KoShapeUserData.h"
38
#include "KoShapeApplicationData.h"
39
#include "KoShapeSavingContext.h"
40
#include "KoShapeLoadingContext.h"
41
#include "KoViewConverter.h"
42
#include "KoLineBorder.h"
43
#include "ShapeDeleter_p.h"
44
#include "KoShapeShadow.h"
Thorsten Zachmann's avatar
Thorsten Zachmann committed
45 46
#include "KoEventAction.h"
#include "KoEventActionRegistry.h"
47
#include "KoOdfWorkaround.h"
Thomas Zander's avatar
Thomas Zander committed
48

49
#include <KoXmlReader.h>
50
#include <KoXmlWriter.h>
51
#include <KoXmlNS.h>
52
#include <KoGenStyle.h>
53
#include <KoGenStyles.h>
54
#include <KoUnit.h>
55
#include <KoOdfStylesReader.h>
56
#include <KoOdfGraphicStyles.h>
57
#include <KoOdfLoadingContext.h>
58

Thomas Zander's avatar
Thomas Zander committed
59
#include <QPainter>
60
#include <QVariant>
Thomas Zander's avatar
Thomas Zander committed
61
#include <QPainterPath>
62
#include <QList>
63
#include <QMap>
64
#include <QByteArray>
Thomas Zander's avatar
Thomas Zander committed
65

66 67
#include <kdebug.h>

68 69
#include <limits>

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
KoShapePrivate::KoShapePrivate(KoShape *shape)
    : size(50, 50),
    parent(0),
    userData(0),
    appData(0),
    fill(0),
    border(0),
    me(shape),
    shadow(0),
    zIndex(0),
    visible(true),
    printable(true),
    geometryProtected(false),
    keepAspect(false),
    selectable(true),
    detectCollision(false),
    protectContent(false)
87
    {
Thomas Zander's avatar
Thomas Zander committed
88 89
    }

90 91 92 93 94 95 96
KoShapePrivate::~KoShapePrivate()
{
    if (parent)
        parent->removeChild(me);
    foreach(KoShapeManager *manager, shapeManagers) {
        manager->remove(me);
        manager->removeAdditional(me);
Thomas Zander's avatar
Thomas Zander committed
97
    }
98 99 100 101 102 103 104 105 106 107
    delete userData;
    delete appData;
    if (border && ! border->removeUser())
        delete border;
    if (shadow && ! shadow->removeUser())
        delete shadow;
    if (fill && ! fill->removeUser())
        delete fill;
    qDeleteAll(eventActions);
}
Thomas Zander's avatar
Thomas Zander committed
108

109 110 111 112 113 114 115 116
void KoShapePrivate::shapeChanged(KoShape::ChangeType type)
{
    if (parent)
        parent->model()->childChanged(me, type);
    me->shapeChanged(type);
    foreach(KoShape * shape, dependees)
        shape->shapeChanged(type, me);
}
117

Thomas Zander's avatar
Thomas Zander committed
118

119
// ======== KoShape
Thomas Zander's avatar
Thomas Zander committed
120
KoShape::KoShape()
121
        : d_ptr(new KoShapePrivate(this))
Thomas Zander's avatar
Thomas Zander committed
122
{
123
    Q_D(KoShape);
124 125 126 127
    d->connectors.append(QPointF(0.5, 0.0));
    d->connectors.append(QPointF(1.0, 0.5));
    d->connectors.append(QPointF(0.5, 1.0));
    d->connectors.append(QPointF(0.0, 0.5));
128

129
    notifyChanged();
Thomas Zander's avatar
Thomas Zander committed
130 131
}

132 133 134 135 136
KoShape::KoShape(KoShapePrivate &dd)
    : d_ptr(&dd)
{
}

Thomas Zander's avatar
Thomas Zander committed
137 138
KoShape::~KoShape()
{
139
    Q_D(KoShape);
140
    d->shapeChanged(Deleted);
141
    delete d_ptr;
Thomas Zander's avatar
Thomas Zander committed
142 143
}

144 145
void KoShape::paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas)
{
Thomas Zander's avatar
Thomas Zander committed
146 147 148
    Q_UNUSED(painter);
    Q_UNUSED(converter);
    Q_UNUSED(canvas);
149 150
    /* Since this code is not actually used (kivio is going to be the main user) lets disable instead of fix.
        if ( selected )
Thomas Zander's avatar
Thomas Zander committed
151
        {
152 153 154 155 156 157 158 159 160 161 162 163
            // draw connectors
            QPen pen( Qt::blue );
            pen.setWidth( 0 );
            painter.setPen( pen );
            painter.setBrush( Qt::NoBrush );
            for ( int i = 0; i < d->connectors.size(); ++i )
            {
                QPointF p = converter.documentToView(d->connectors[ i ]);
                painter.drawLine( QPointF( p.x() - 2, p.y() + 2 ), QPointF( p.x() + 2, p.y() - 2 ) );
                painter.drawLine( QPointF( p.x() + 2, p.y() + 2 ), QPointF( p.x() - 2, p.y() - 2 ) );
            }
        }*/
Thomas Zander's avatar
Thomas Zander committed
164 165
}

166
void KoShape::setScale(qreal sx, qreal sy)
Thomas Zander's avatar
Thomas Zander committed
167
{
168
    Q_D(KoShape);
169 170
    QPointF pos = position();
    QMatrix scaleMatrix;
171 172 173
    scaleMatrix.translate(pos.x(), pos.y());
    scaleMatrix.scale(sx, sy);
    scaleMatrix.translate(-pos.x(), -pos.y());
174
    d->localMatrix = d->localMatrix * scaleMatrix;
175

176
    notifyChanged();
177
    d->shapeChanged(ScaleChanged);
Thomas Zander's avatar
Thomas Zander committed
178 179
}

180
void KoShape::rotate(qreal angle)
Thomas Zander's avatar
Thomas Zander committed
181
{
182
    Q_D(KoShape);
183
    QPointF center = d->localMatrix.map(QPointF(0.5 * size().width(), 0.5 * size().height()));
184
    QMatrix rotateMatrix;
185 186 187
    rotateMatrix.translate(center.x(), center.y());
    rotateMatrix.rotate(angle);
    rotateMatrix.translate(-center.x(), -center.y());
188
    d->localMatrix = d->localMatrix * rotateMatrix;
189

190
    notifyChanged();
191
    d->shapeChanged(RotationChanged);
Thomas Zander's avatar
Thomas Zander committed
192 193
}

194
void KoShape::setShear(qreal sx, qreal sy)
Thomas Zander's avatar
Thomas Zander committed
195
{
196
    Q_D(KoShape);
197 198
    QPointF pos = position();
    QMatrix shearMatrix;
199 200 201
    shearMatrix.translate(pos.x(), pos.y());
    shearMatrix.shear(sx, sy);
    shearMatrix.translate(-pos.x(), -pos.y());
202
    d->localMatrix = d->localMatrix * shearMatrix;
203

204
    notifyChanged();
205
    d->shapeChanged(ShearChanged);
Thomas Zander's avatar
Thomas Zander committed
206 207
}

208
void KoShape::setSize(const QSizeF &newSize)
Thomas Zander's avatar
Thomas Zander committed
209
{
210
    Q_D(KoShape);
211 212
    QSizeF oldSize(size());
    if (oldSize == newSize)
Thomas Zander's avatar
Thomas Zander committed
213
        return;
214

215
    QMatrix matrix;
216 217
    oldSize.setHeight(qMax((qreal) 1E-4, oldSize.height())); // avoids devision by zero below
    oldSize.setWidth(qMax((qreal) 1E-4, oldSize.width()));
218
    matrix.scale(newSize.width()/oldSize.width(), newSize.height()/oldSize.height());
219 220

    KoGradientBackground * g = dynamic_cast<KoGradientBackground*>(d->fill);
221
    if (g) {
222
        g->setMatrix(g->matrix() * matrix);
223
    }
224
    KoLineBorder *l = dynamic_cast<KoLineBorder*>(d->border);
225 226
    if (l && l->lineBrush().gradient()) {
        QBrush brush = l->lineBrush();
227 228
        brush.setMatrix(brush.matrix() * matrix);
        l->setLineBrush(brush);
229
    }
230

Thomas Zander's avatar
Thomas Zander committed
231
    d->size = newSize;
232

233
    notifyChanged();
234
    d->shapeChanged(SizeChanged);
Thomas Zander's avatar
Thomas Zander committed
235 236
}

237
void KoShape::setPosition(const QPointF &newPosition)
Thomas Zander's avatar
Thomas Zander committed
238
{
239
    Q_D(KoShape);
240
    QPointF currentPos = position();
241
    if (newPosition == currentPos)
Thomas Zander's avatar
Thomas Zander committed
242
        return;
243
    QMatrix translateMatrix;
244
    translateMatrix.translate(newPosition.x() - currentPos.x(), newPosition.y() - currentPos.y());
245 246 247
    d->localMatrix = d->localMatrix * translateMatrix;

    notifyChanged();
248
    d->shapeChanged(PositionChanged);
Thomas Zander's avatar
Thomas Zander committed
249 250
}

251
bool KoShape::hitTest(const QPointF &position) const
Thomas Zander's avatar
Thomas Zander committed
252
{
253
    Q_D(const KoShape);
254
    if (d->parent && d->parent->childClipped(this) && !d->parent->hitTest(position))
Thomas Zander's avatar
Thomas Zander committed
255 256
        return false;

257
    QPointF point = absoluteTransformation(0).inverted().map(position);
258
    QRectF bb(QPointF(), size());
259
    if (d->border) {
260
        KoInsets insets;
261
        d->border->borderInsets(this, insets);
262
        bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
263
    }
264 265 266
    if (bb.contains(point))
        return true;

267
    // if there is no shadow we can as well just leave
268
    if (! d->shadow)
269
        return false;
Thomas Zander's avatar
Thomas Zander committed
270

271 272
    // the shadow has an offset to the shape, so we simply
    // check if the position minus the shadow offset hits the shape
273
    point = absoluteTransformation(0).inverted().map(position - d->shadow->offset());
274

275
    return bb.contains(point);
Thomas Zander's avatar
Thomas Zander committed
276 277
}

278
QRectF KoShape::boundingRect() const
Thomas Zander's avatar
Thomas Zander committed
279
{
280
    Q_D(const KoShape);
281
    QRectF bb(QPointF(0, 0), size());
282
    if (d->border) {
283 284 285 286
        KoInsets insets;
        d->border->borderInsets(this, insets);
        bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
    }
287 288
    bb = absoluteTransformation(0).mapRect(bb);
    if (d->shadow) {
289
        KoInsets insets;
290
        d->shadow->insets(this, insets);
291 292 293
        bb.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
    }
    return bb;
Thomas Zander's avatar
Thomas Zander committed
294 295
}

296 297
QMatrix KoShape::absoluteTransformation(const KoViewConverter *converter) const
{
298
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
299 300
    QMatrix matrix;
    // apply parents matrix to inherit any transformations done there.
301
    KoShapeContainer * container = d->parent;
302 303
    if (container) {
        if (container->childClipped(this))
Johannes Simon's avatar
Johannes Simon committed
304
            matrix = container->absoluteTransformation(0);
Thomas Zander's avatar
Thomas Zander committed
305
        else {
306 307 308 309
            QSizeF containerSize = container->size();
            QPointF containerPos = container->absolutePosition() - QPointF(0.5 * containerSize.width(), 0.5 * containerSize.height());
            if (converter)
                containerPos = converter->documentToView(containerPos);
310
            matrix.translate(containerPos.x(), containerPos.y());
Thomas Zander's avatar
Thomas Zander committed
311 312 313
        }
    }

314
    if (converter) {
315 316 317
        QPointF pos = d->localMatrix.map(QPointF());
        QPointF trans = converter->documentToView(pos) - pos;
        matrix.translate(trans.x(), trans.y());
Thomas Zander's avatar
Thomas Zander committed
318
    }
319 320

    return d->localMatrix * matrix;
Thomas Zander's avatar
Thomas Zander committed
321 322
}

323
void KoShape::applyAbsoluteTransformation(const QMatrix &matrix)
324
{
325
    QMatrix globalMatrix = absoluteTransformation(0);
326 327
    // the transformation is relative to the global coordinate system
    // but we want to change the local matrix, so convert the matrix
Thomas Zander's avatar
Thomas Zander committed
328
    // to be relative to the local coordinate system
329
    QMatrix transformMatrix = globalMatrix * matrix * globalMatrix.inverted();
330
    applyTransformation(transformMatrix);
331 332
}

333
void KoShape::applyTransformation(const QMatrix &matrix)
334
{
335
    Q_D(KoShape);
336
    d->localMatrix = matrix * d->localMatrix;
337
    notifyChanged();
338
    d->shapeChanged(GenericMatrixChange);
339 340
}

341
void KoShape::setTransformation(const QMatrix &matrix)
342
{
343
    Q_D(KoShape);
344 345
    d->localMatrix = matrix;
    notifyChanged();
346
    d->shapeChanged(GenericMatrixChange);
347
}
Thomas Zander's avatar
Thomas Zander committed
348

349
QMatrix KoShape::transformation() const
350
{
351
    Q_D(const KoShape);
352 353 354
    return d->localMatrix;
}

355 356
bool KoShape::compareShapeZIndex(KoShape *s1, KoShape *s2)
{
357
    int diff = s1->zIndex() - s2->zIndex();
358
    if (diff == 0) {
359
        KoShape *s = s1->parent();
360
        while (s) {
361
            if (s == s2) // s1 is a child of s2
362 363 364 365
                return false; // children are always on top of their parents.
            s = s->parent();
        }
        s = s2->parent();
366
        while (s) {
367
            if (s == s1) // s2 is a child of s1
368 369 370 371 372
                return true;
            s = s->parent();
        }
    }
    return diff < 0;
Thomas Zander's avatar
Thomas Zander committed
373 374
}

375 376
void KoShape::setParent(KoShapeContainer *parent)
{
377
    Q_D(KoShape);
378
    if (d->parent == parent)
379
        return;
380 381 382 383
    KoShapeContainer *oldParent = d->parent;
    d->parent = 0; // avoids recursive removing
    if (oldParent)
        oldParent->removeChild(this);
Thomas Zander's avatar
Thomas Zander committed
384
    if (parent && parent != this) {
Thomas Zander's avatar
Thomas Zander committed
385
        d->parent = parent;
386
        parent->addChild(this);
387
    }
388
    notifyChanged();
389
    d->shapeChanged(ParentChanged);
Thomas Zander's avatar
Thomas Zander committed
390 391
}

392 393
int KoShape::zIndex() const
{
394
    Q_D(const KoShape);
395
    if (parent()) // we can't be under our parent...
396
        return qMax((int) d->zIndex, parent()->zIndex());
Thomas Zander's avatar
Thomas Zander committed
397
    return d->zIndex;
Thomas Zander's avatar
Thomas Zander committed
398 399
}

400 401
void KoShape::update() const
{
402
    Q_D(const KoShape);
403 404 405
    if (!d->shapeManagers.empty()) {
        QRectF rect(boundingRect());
        foreach(KoShapeManager * manager, d->shapeManagers)
Jan Hambrecht's avatar
Jan Hambrecht committed
406
            manager->update(rect, this, true);
Thomas Zander's avatar
Thomas Zander committed
407 408 409
    }
}

410 411
void KoShape::update(const QRectF &shape) const
{
412
    Q_D(const KoShape);
413
    if (!d->shapeManagers.empty() && isVisible()) {
414
        QRectF rect(absoluteTransformation(0).mapRect(shape));
415
        foreach(KoShapeManager * manager, d->shapeManagers) {
416
            manager->update(rect);
417 418
        }
    }
Thomas Zander's avatar
Thomas Zander committed
419 420
}

421 422
const QPainterPath KoShape::outline() const
{
423
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
424
    QPainterPath path;
425
    path.addRect(QRectF(QPointF(0, 0), QSizeF(qMax(d->size.width(), qreal(0.0001)), qMax(d->size.height(), qreal(0.0001)))));
Thomas Zander's avatar
Thomas Zander committed
426 427 428
    return path;
}

429 430
QPointF KoShape::absolutePosition(KoFlake::Position anchor) const
{
431
    QPointF point;
432 433 434 435 436 437
    switch (anchor) {
    case KoFlake::TopLeftCorner: break;
    case KoFlake::TopRightCorner: point = QPointF(size().width(), 0.0); break;
    case KoFlake::BottomLeftCorner: point = QPointF(0.0, size().height()); break;
    case KoFlake::BottomRightCorner: point = QPointF(size().width(), size().height()); break;
    case KoFlake::CenteredPosition: point = QPointF(size().width() / 2.0, size().height() / 2.0); break;
438
    }
439
    return absoluteTransformation(0).map(point);
Thomas Zander's avatar
Thomas Zander committed
440 441
}

442 443
void KoShape::setAbsolutePosition(QPointF newPosition, KoFlake::Position anchor)
{
444
    Q_D(KoShape);
445
    QPointF currentAbsPosition = absolutePosition(anchor);
446
    QPointF translate = newPosition - currentAbsPosition;
Jan Hambrecht's avatar
Jan Hambrecht committed
447
    QMatrix translateMatrix;
448 449
    translateMatrix.translate(translate.x(), translate.y());
    applyAbsoluteTransformation(translateMatrix);
450
    notifyChanged();
451
    d->shapeChanged(PositionChanged);
Thomas Zander's avatar
Thomas Zander committed
452 453
}

454 455
void KoShape::copySettings(const KoShape *shape)
{
456
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
457 458
    d->size = shape->size();
    d->connectors.clear();
Jan Hambrecht's avatar
Jan Hambrecht committed
459 460
    foreach(const QPointF & point, shape->connectionPoints())
        addConnectionPoint(point);
Thomas Zander's avatar
Thomas Zander committed
461 462
    d->zIndex = shape->zIndex();
    d->visible = shape->isVisible();
463

464 465 466 467 468
    // Ensure printable is true by default
    if (!d->visible)
        d->printable = true;
    else
        d->printable = shape->isPrintable();
469

470
    d->geometryProtected = shape->isGeometryProtected();
Thomas Zander's avatar
Thomas Zander committed
471
    d->keepAspect = shape->keepAspectRatio();
472
    d->localMatrix = shape->d_ptr->localMatrix;
Thomas Zander's avatar
Thomas Zander committed
473 474
}

Thomas Zander's avatar
Thomas Zander committed
475
void KoShape::notifyChanged()
476
{
477
    Q_D(KoShape);
478 479
    foreach(KoShapeManager * manager, d->shapeManagers) {
        manager->notifyShapeChanged(this);
480 481 482
    }
}

483 484
void KoShape::setUserData(KoShapeUserData *userData)
{
485
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
486
    delete d->userData;
Thomas Zander's avatar
Thomas Zander committed
487
    d->userData = userData;
488 489
}

490 491
KoShapeUserData *KoShape::userData() const
{
492
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
493
    return d->userData;
494 495
}

496 497
void KoShape::setApplicationData(KoShapeApplicationData *appData)
{
498
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
499
    // appdata is deleted by the application.
Thomas Zander's avatar
Thomas Zander committed
500
    d->appData = appData;
501 502
}

503 504
KoShapeApplicationData *KoShape::applicationData() const
{
505
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
506
    return d->appData;
507 508
}

509 510
bool KoShape::hasTransparency()
{
511
    Q_D(KoShape);
512
    if (! d->fill)
Thomas Zander's avatar
Thomas Zander committed
513
        return true;
514 515
    else
        return d->fill->hasTransparency();
Thomas Zander's avatar
Thomas Zander committed
516 517
}

518 519
KoInsets KoShape::borderInsets() const
{
520
    Q_D(const KoShape);
521
    KoInsets answer;
522
    if (d->border)
523
        d->border->borderInsets(this, answer);
524 525 526
    return answer;
}

527 528
qreal KoShape::rotation() const
{
529
    Q_D(const KoShape);
530
    // try to extract the rotation angle out of the local matrix
531 532 533
    // if it is a pure rotation matrix

    // check if the matrix has shearing mixed in
534
    if (fabs(fabs(d->localMatrix.m12()) - fabs(d->localMatrix.m21())) > 1e-10)
535
        return std::numeric_limits<qreal>::quiet_NaN();
536
    // check if the matrix has scaling mixed in
537
    if (fabs(d->localMatrix.m11() - d->localMatrix.m22()) > 1e-10)
538
        return std::numeric_limits<qreal>::quiet_NaN();
539 540

    // calculate the angle from the matrix elements
541 542
    qreal angle = atan2(-d->localMatrix.m21(), d->localMatrix.m11()) * 180.0 / M_PI;
    if (angle < 0.0)
543 544 545
        angle += 360.0;

    return angle;
Thomas Zander's avatar
Thomas Zander committed
546 547
}

548
QSizeF KoShape::size() const
549
{
550
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
551 552 553
    return d->size;
}

554 555
QPointF KoShape::position() const
{
556
    Q_D(const KoShape);
557 558
    QPointF center(0.5*size().width(), 0.5*size().height());
    return d->localMatrix.map(center) - center;
559
    //return d->localMatrix.map( QPointF(0,0) );
Thomas Zander's avatar
Thomas Zander committed
560 561
}

562
void KoShape::addConnectionPoint(const QPointF &point)
563
{
564
    Q_D(KoShape);
565 566
    QSizeF s = size();
    // convert glue point from shape coordinates to factors of size
567
    d->connectors.append(QPointF(point.x() / s.width(), point.y() / s.height()));
Thomas Zander's avatar
Thomas Zander committed
568 569
}

570 571
QList<QPointF> KoShape::connectionPoints() const
{
572
    Q_D(const KoShape);
573 574 575
    QList<QPointF> points;
    QSizeF s = size();
    // convert glue points to shape coordinates
Jan Hambrecht's avatar
Jan Hambrecht committed
576 577
    foreach(const QPointF & cp, d->connectors)
        points.append(QPointF(s.width() * cp.x(), s.height() * cp.y()));
578 579

    return points;
580 581
}

582
void KoShape::addEventAction(KoEventAction * action)
583
{
584
    Q_D(KoShape);
585 586
    if (! d->eventActions.contains(action)) {
        d->eventActions.append(action);
587 588 589
    }
}

590
void KoShape::removeEventAction(KoEventAction * action)
591
{
592
    Q_D(KoShape);
593 594
    if (d->eventActions.contains(action)) {
        d->eventActions.removeAll(action);
595 596 597 598 599
    }
}

QList<KoEventAction *> KoShape::eventActions() const
{
600
    Q_D(const KoShape);
601 602 603
    return d->eventActions;
}

604
void KoShape::setBackground(KoShapeBackground * fill)
605
{
606
    Q_D(KoShape);
607
    if (d->fill)
608 609
        d->fill->removeUser();
    d->fill = fill;
610
    if (d->fill)
611
        d->fill->addUser();
612 613
    d->shapeChanged(BackgroundChanged);
    notifyChanged();
Thomas Zander's avatar
Thomas Zander committed
614 615
}

616 617
KoShapeBackground * KoShape::background() const
{
618
    Q_D(const KoShape);
619
    return d->fill;
Thomas Zander's avatar
Thomas Zander committed
620 621
}

622 623
void KoShape::setZIndex(int zIndex)
{
624
    Q_D(KoShape);
625
    notifyChanged();
Thomas Zander's avatar
Thomas Zander committed
626 627 628
    d->zIndex = zIndex;
}

629 630
void KoShape::setVisible(bool on)
{
631
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
632 633 634
    d->visible = on;
}

635
bool KoShape::isVisible(bool recursive) const
636
{
637
    Q_D(const KoShape);
638
    if (! recursive)
639
        return d->visible;
640
    if (recursive && ! d->visible)
Jan Hambrecht's avatar
Jan Hambrecht committed
641 642
        return false;

643
    KoShapeContainer * parentShape = parent();
644 645
    while (parentShape) {
        if (! parentShape->isVisible())
646 647 648 649
            return false;
        parentShape = parentShape->parent();
    }
    return true;
Thomas Zander's avatar
Thomas Zander committed
650 651
}

652 653
void KoShape::setPrintable(bool on)
{
654
    Q_D(KoShape);
655 656
    d->printable = on;
}
657

658 659
bool KoShape::isPrintable() const
{
660
    Q_D(const KoShape);
661 662 663 664
    if (d->visible)
        return d->printable;
    else
        return false;
665 666
}

667 668
void KoShape::setSelectable(bool selectable)
{
669
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
670 671 672
    d->selectable = selectable;
}

673 674
bool KoShape::isSelectable() const
{
675
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
676 677 678
    return d->selectable;
}

679
void KoShape::setGeometryProtected(bool on)
680
{
681
    Q_D(KoShape);
682
    d->geometryProtected = on;
Thomas Zander's avatar
Thomas Zander committed
683 684
}

685
bool KoShape::isGeometryProtected() const
686
{
687
    Q_D(const KoShape);
688
    return d->geometryProtected;
Thomas Zander's avatar
Thomas Zander committed
689 690
}

691 692
void KoShape::setContentProtected(bool protect)
{
693
    Q_D(KoShape);
694 695 696 697 698
    d->protectContent = protect;
}

bool KoShape::isContentProtected() const
{
699
    Q_D(const KoShape);
700 701 702
    return d->protectContent;
}

703 704
KoShapeContainer *KoShape::parent() const
{
705
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
706 707 708
    return d->parent;
}

709 710
void KoShape::setKeepAspectRatio(bool keepAspect)
{
711
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
712 713 714
    d->keepAspect = keepAspect;
}

715 716
bool KoShape::keepAspectRatio() const
{
717
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
718 719 720
    return d->keepAspect;
}

721 722
const QString &KoShape::shapeId() const
{
723
    Q_D(const KoShape);
Thomas Zander's avatar
Thomas Zander committed
724 725 726
    return d->shapeId;
}

727 728
void KoShape::setShapeId(const QString &id)
{
729
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
730 731 732
    d->shapeId = id;
}

733 734
void KoShape::setCollisionDetection(bool detect)
{
735
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
736 737 738
    d->detectCollision = detect;
}

739 740
bool KoShape::collisionDetection()
{
741
    Q_D(KoShape);
Thomas Zander's avatar
Thomas Zander committed
742 743 744
    return d->detectCollision;
}

745
void KoShape::addShapeManager(KoShapeManager * manager)
746
{
747
    Q_D(KoShape);
748
    d->shapeManagers.insert(manager);
Thomas Zander's avatar
Thomas Zander committed
749 750
}

751
void KoShape::removeShapeManager(KoShapeManager * manager)
752
{
753
    Q_D(KoShape);
754
    d->shapeManagers.remove(manager);
Thomas Zander's avatar
Thomas Zander committed
755 756
}

757 758
KoShapeBorderModel *KoShape::border() const
{
759
    Q_D(const KoShape);
760 761 762
    return d->border;
}

763 764
void KoShape::setBorder(KoShapeBorderModel *border)
{
765
    Q_D(KoShape);