KoShape.cpp 17.2 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 3
   Copyright (C) 2006 Casper Boemann Rasmussen <cbr@boemann.dk>
   Copyright (C) 2006 Thomas Zander <zander@kde.org>
4
   Copyright (C) 2006-2007 Thorsten Zachmann <zachmann@kde.org>
Thomas Zander's avatar
Thomas Zander committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

   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"
#include "KoShapeContainer.h"
#include "KoSelection.h"
25
#include "KoPointerEvent.h"
Thomas Zander's avatar
Thomas Zander committed
26 27
#include "KoInsets.h"
#include "KoShapeBorderModel.h"
28
#include "KoShapeManager.h"
29
#include "KoShapeUserData.h"
30
#include "KoShapeApplicationData.h"
31
#include "KoShapeSavingContext.h"
32
#include "KoViewConverter.h"
Thomas Zander's avatar
Thomas Zander committed
33

34 35 36 37
#include <KoXmlWriter.h>
#include <KoGenStyles.h>
#include <KoGenStyle.h>

Thomas Zander's avatar
Thomas Zander committed
38
#include <QPainter>
39
#include <QVariant>
Thomas Zander's avatar
Thomas Zander committed
40
#include <QPainterPath>
41
#include <QList>
Thomas Zander's avatar
Thomas Zander committed
42

43 44
#include <kdebug.h>

Thomas Zander's avatar
Thomas Zander committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
class KoShapePrivate {
public:
    KoShapePrivate()
        : scaleX( 1 ),
        scaleY( 1 ),
        angle( 0 ),
        shearX( 0 ),
        shearY( 0 ),
        size( 50, 50 ),
        pos( 0, 0 ),
        zIndex( 0 ),
        parent( 0 ),
        visible( true ),
        locked( false ),
        keepAspect( false ),
        selectable( true ),
        detectCollision( false ),
        userData(0),
63 64 65
        appData(0),
        backgroundBrush(Qt::NoBrush),
        border(0)
Thomas Zander's avatar
Thomas Zander committed
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
    {
    }

    ~KoShapePrivate() {
        delete userData;
        delete appData;
    }

    double scaleX;
    double scaleY;
    double angle; // degrees
    double shearX;
    double shearY;

    QSizeF size; // size in pt
    QPointF pos; // position (top left) in pt
    QString shapeId;

    QMatrix matrix;

    QVector<QPointF> connectors; // in pt

    int zIndex;
    KoShapeContainer *parent;

    bool visible;
    bool locked;
    bool keepAspect;
    bool selectable;
    bool detectCollision;

    QSet<KoShapeManager *> shapeManagers;
    KoShapeUserData *userData;
    KoShapeApplicationData *appData;
100 101
    QBrush backgroundBrush; ///< Stands for the background color / fill etc.
    KoShapeBorderModel *border; ///< points to a border, or 0 if there is no border
102
    QList<KoShapeConnection*> connections;
Thomas Zander's avatar
Thomas Zander committed
103 104
};

Thomas Zander's avatar
Thomas Zander committed
105
KoShape::KoShape()
Thomas Zander's avatar
Thomas Zander committed
106
    : d(new KoShapePrivate())
Thomas Zander's avatar
Thomas Zander committed
107 108 109 110 111 112
{
    recalcMatrix();
}

KoShape::~KoShape()
{
Thomas Zander's avatar
Thomas Zander committed
113
    delete d;
Thomas Zander's avatar
Thomas Zander committed
114 115
}

116
void KoShape::paintDecorations(QPainter &painter, const KoViewConverter &converter, const KoCanvasBase *canvas) {
Thomas Zander's avatar
Thomas Zander committed
117 118 119
    Q_UNUSED(painter);
    Q_UNUSED(converter);
    Q_UNUSED(canvas);
120
/* Since this code is not actually used (kivio is going to be the main user) lets disable instead of fix.
Thomas Zander's avatar
Thomas Zander committed
121 122 123 124 125 126 127
    if ( selected )
    {
        // draw connectors
        QPen pen( Qt::blue );
        pen.setWidth( 0 );
        painter.setPen( pen );
        painter.setBrush( Qt::NoBrush );
Thomas Zander's avatar
Thomas Zander committed
128
        for ( int i = 0; i < d->connectors.size(); ++i )
Thomas Zander's avatar
Thomas Zander committed
129
        {
Thomas Zander's avatar
Thomas Zander committed
130
            QPointF p = converter.documentToView(d->connectors[ i ]);
Thomas Zander's avatar
Thomas Zander committed
131 132 133
            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 ) );
        }
134
    }*/
Thomas Zander's avatar
Thomas Zander committed
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
bool KoShape::saveOdf( KoShapeSavingContext & context )
{
    const char * tag = odfTagName();
    if ( tag[0] == '\0' )
    {
        kWarning(30006) << "No support for shape yet. Not saving!" << endl;
    }
    else
    {
        context.xmlWriter().startElement( tag );
        context.xmlWriter().addAttribute( context.isSet( KoShapeSavingContext::PresentationShape ) ? 
                                          "presentation:style-name": "draw:style-name", 
                                          getStyle( context ) );

        if ( context.isSet( KoShapeSavingContext::DrawId ) )
        {
            context.xmlWriter().addAttribute( "draw:id", context.drawId( this ) );
        }

        saveOdfData( context );
        context.xmlWriter().endElement();
    }
    return true;
}

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
void KoShape::saveOdfSizeAndPosition( KoShapeSavingContext &context ) const
{
    QSizeF s( size() );
    context.xmlWriter().addAttributePt( "svg:width", s.width() );
    context.xmlWriter().addAttributePt( "svg:height", s.height() );

    if ( d->scaleX == 1 and d->scaleY == 1 && d->angle == 0 && d->shearX == 0 && d->shearY == 0 )
    {
        QPointF pos( position() );
        context.xmlWriter().addAttributePt( "svg:x", pos.x() );
        context.xmlWriter().addAttributePt( "svg:y", pos.y() );
    }
    else
    {
        // looks like position is not needed it would be svg:x="0" and svg:y="0"
        // looks like OO 2.0 can not load the translation in the matrix 
        QString m = QString( "matrix(%1 %2 %3 %4 %5 %6)" ).arg( d->matrix.m11() ).arg( d->matrix.m12() )
                                                          .arg( d->matrix.m21() ).arg( d->matrix.m22() )
                                                          .arg( d->matrix.dx() ) .arg( d->matrix.dy() );
        context.xmlWriter().addAttribute( "draw:transform", m );
    }
}

185 186 187
QString KoShape::getStyle( KoShapeSavingContext &context )
{
    KoGenStyle style;
188
    if ( context.isSet( KoShapeSavingContext::PresentationShape ) ) {
189
        style = KoGenStyle( KoGenStyle::STYLE_PRESENTATIONAUTO, "presentation" );
190 191
    }
    else {
192
        style = KoGenStyle( KoGenStyle::STYLE_GRAPHICAUTO, "graphic" );
193
    }
194 195 196

    fillStyle( style, context );
    
197
    if ( context.isSet( KoShapeSavingContext::AutoStyleInStyleXml ) ) {
198
        style.setAutoStyleInStylesDotXml( true );
199
    }
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

    return context.mainStyles().lookup( style, context.isSet( KoShapeSavingContext::PresentationShape ) ? "pr" : "gr" );
}

void KoShape::fillStyle( KoGenStyle &style, KoShapeSavingContext &context )
{
    KoShapeBorderModel * b = border();
    if ( b )
    {
        b->fillStyle( style, context );
    }
    QBrush bg( background() );
    switch ( bg.style() )
    {
        case Qt::NoBrush:
            style.addProperty( "draw:fill","none" );
            break;
        default:    
            //KoOasisStyles::saveOasisFillStyle( style, context.mainStyles(), bg );
            break;
    }
}

Thomas Zander's avatar
Thomas Zander committed
223 224
void KoShape::scale( double sx, double sy )
{
Thomas Zander's avatar
Thomas Zander committed
225
    if(d->scaleX == sx && d->scaleY == sy)
Thomas Zander's avatar
Thomas Zander committed
226
        return;
Thomas Zander's avatar
Thomas Zander committed
227 228
    d->scaleX = sx;
    d->scaleY = sy;
Thomas Zander's avatar
Thomas Zander committed
229
    recalcMatrix();
230
    shapeChanged(ScaleChanged);
Thomas Zander's avatar
Thomas Zander committed
231 232 233 234
}

void KoShape::rotate( double angle )
{
Thomas Zander's avatar
Thomas Zander committed
235
    if(d->angle == angle)
Thomas Zander's avatar
Thomas Zander committed
236
        return;
Thomas Zander's avatar
Thomas Zander committed
237 238 239
    d->angle = angle;
    while(d->angle >= 360) d->angle -= 360;
    while(d->angle <= -360) d->angle += 360;
Thomas Zander's avatar
Thomas Zander committed
240
    recalcMatrix();
241
    shapeChanged(RotationChanged);
Thomas Zander's avatar
Thomas Zander committed
242 243 244 245
}

void KoShape::shear( double sx, double sy )
{
Thomas Zander's avatar
Thomas Zander committed
246
    if(d->shearX == sx && d->shearY == sy)
Thomas Zander's avatar
Thomas Zander committed
247
        return;
Thomas Zander's avatar
Thomas Zander committed
248 249
    d->shearX = sx;
    d->shearY = sy;
Thomas Zander's avatar
Thomas Zander committed
250
    recalcMatrix();
251
    shapeChanged(ShearChanged);
Thomas Zander's avatar
Thomas Zander committed
252 253
}

254
void KoShape::resize( const QSizeF &newSize )
Thomas Zander's avatar
Thomas Zander committed
255
{
256 257
    QSizeF s( size() );
    if(s == newSize)
Thomas Zander's avatar
Thomas Zander committed
258
        return;
259

260 261
    double fx = newSize.width() / s.width();
    double fy = newSize.height() / s.height();
262

Thomas Zander's avatar
Thomas Zander committed
263
    d->size = newSize;
264

Thomas Zander's avatar
Thomas Zander committed
265
    for ( int i = 0; i < d->connectors.size(); ++i )
266
    {
Thomas Zander's avatar
Thomas Zander committed
267
        QPointF &point = d->connectors[i];
268 269 270
        point.setX(point.x() * fx);
        point.setY(point.y() * fy);
    }
271 272
    recalcMatrix();
    shapeChanged(SizeChanged);
Thomas Zander's avatar
Thomas Zander committed
273 274 275 276
}

void KoShape::setPosition( const QPointF &position )
{
Thomas Zander's avatar
Thomas Zander committed
277
    if(d->pos == position)
Thomas Zander's avatar
Thomas Zander committed
278
        return;
Thomas Zander's avatar
Thomas Zander committed
279
    d->pos = position;
Thomas Zander's avatar
Thomas Zander committed
280
    recalcMatrix();
281
    shapeChanged(PositionChanged);
Thomas Zander's avatar
Thomas Zander committed
282 283 284 285
}

bool KoShape::hitTest( const QPointF &position ) const
{
Thomas Zander's avatar
Thomas Zander committed
286
    if(d->parent && d->parent->childClipped(this) && !d->parent->hitTest(position))
Thomas Zander's avatar
Thomas Zander committed
287 288
        return false;

289
    QPointF point( position * d->matrix.inverted() );
290
    KoInsets insets(0, 0, 0, 0);
291 292
    if(d->border)
        d->border->borderInsets(this, insets);
Thomas Zander's avatar
Thomas Zander committed
293

294 295 296
    QSizeF s( size() );
    return point.x() >= -insets.left && point.x() <= s.width() + insets.right &&
             point.y() >= -insets.top && point.y() <= s.height() + insets.bottom;
Thomas Zander's avatar
Thomas Zander committed
297 298
}

299
QRectF KoShape::boundingRect() const
Thomas Zander's avatar
Thomas Zander committed
300
{
301
    QRectF bb( QPointF(0, 0), size() );
Thomas Zander's avatar
Thomas Zander committed
302
    return d->matrix.mapRect( bb );
Thomas Zander's avatar
Thomas Zander committed
303 304 305 306
}

void KoShape::recalcMatrix()
{
Thomas Zander's avatar
Thomas Zander committed
307
    d->matrix = transformationMatrix(0);
Thomas Zander's avatar
Thomas Zander committed
308
    notifyChanged();
Thomas Zander's avatar
Thomas Zander committed
309 310
}

311
QMatrix KoShape::transformationMatrix(const KoViewConverter *converter) const {
Thomas Zander's avatar
Thomas Zander committed
312 313 314
    QMatrix matrix;
    QRectF zoomedRect = QRectF(position(), size());
    if(converter)
315
        zoomedRect = converter->documentToView(zoomedRect);
Thomas Zander's avatar
Thomas Zander committed
316 317 318
    matrix.translate( zoomedRect.x(), zoomedRect.y() );

    // apply parents matrix to inherit any transformations done there.
Thomas Zander's avatar
Thomas Zander committed
319
    KoShapeContainer *container = d->parent;
Thomas Zander's avatar
Thomas Zander committed
320 321 322 323 324 325 326
    KoShape const *child = this;
    while(container) {
        if(container->childClipped(child))
            matrix *= container->transformationMatrix(0);
        else {
            QPointF containerPos =container->position();
            if(converter)
327
                containerPos = converter->documentToView(containerPos);
Thomas Zander's avatar
Thomas Zander committed
328 329 330 331 332 333
            matrix.translate(containerPos.x(), containerPos.y());
        }
        container = dynamic_cast<KoShapeContainer*>(container->parent());
        child = child->parent();
    }

Thomas Zander's avatar
Thomas Zander committed
334
    if ( d->angle != 0 )
Thomas Zander's avatar
Thomas Zander committed
335
    {
Thomas Zander's avatar
Thomas Zander committed
336 337 338 339 340
        matrix.translate( zoomedRect.width() / 2.0 * d->scaleX, zoomedRect.height() / 2.0 * d->scaleY );
        matrix.translate( zoomedRect.height() / 2.0 * d->shearX, zoomedRect.width() / 2.0 * d->shearY );
        matrix.rotate( d->angle );
        matrix.translate( -zoomedRect.width() / 2.0 * d->scaleX, -zoomedRect.height() / 2.0 * d->scaleY );
        matrix.translate( -zoomedRect.height() / 2.0 * d->shearX, -zoomedRect.width() / 2.0 * d->shearY );
Thomas Zander's avatar
Thomas Zander committed
341
    }
Thomas Zander's avatar
Thomas Zander committed
342 343
    matrix.shear( d->shearX, d->shearY );
    matrix.scale( d->scaleX, d->scaleY );
Thomas Zander's avatar
Thomas Zander committed
344 345 346 347
    return matrix;
}


348 349
bool KoShape::compareShapeZIndex(KoShape *s1, KoShape *s2) {
    return s1->zIndex() < s2->zIndex();
Thomas Zander's avatar
Thomas Zander committed
350 351 352 353
}

void KoShape::setParent(KoShapeContainer *parent) {
    if(dynamic_cast<KoShape*>(parent) != this)
Thomas Zander's avatar
Thomas Zander committed
354
        d->parent = parent;
Thomas Zander's avatar
Thomas Zander committed
355
    else
Thomas Zander's avatar
Thomas Zander committed
356
        d->parent = 0;
Thomas Zander's avatar
Thomas Zander committed
357
    recalcMatrix();
358
    shapeChanged(ParentChanged);
Thomas Zander's avatar
Thomas Zander committed
359 360 361 362
}

int KoShape::zIndex() const {
    if(parent()) // we can't be under our parent...
Thomas Zander's avatar
Thomas Zander committed
363 364
        return qMax(d->zIndex, parent()->zIndex());
    return d->zIndex;
Thomas Zander's avatar
Thomas Zander committed
365 366 367
}

void KoShape::repaint() const {
Thomas Zander's avatar
Thomas Zander committed
368
    if ( !d->shapeManagers.empty() )
369
    {
370 371 372 373 374 375 376
        QRectF rect(QPointF(0, 0), size() );
        if(d->border) {
            KoInsets insets(0, 0, 0, 0);
            d->border->borderInsets(this, insets);
            rect.adjust(-insets.left, -insets.top, insets.right, insets.bottom);
        }
        rect = d->matrix.mapRect(rect);
Thomas Zander's avatar
Thomas Zander committed
377
        foreach( KoShapeManager * manager, d->shapeManagers )
378
            manager->repaint( rect, this, true );
Thomas Zander's avatar
Thomas Zander committed
379 380 381
    }
}

382
void KoShape::repaint(const QRectF &shape) const {
Thomas Zander's avatar
Thomas Zander committed
383
    if ( !d->shapeManagers.empty() && isVisible() )
384
    {
Thomas Zander's avatar
Thomas Zander committed
385 386
        QRectF rect(d->matrix.mapRect(shape));
        foreach( KoShapeManager * manager, d->shapeManagers )
387 388 389 390
        {
            manager->repaint(rect);
        }
    }
Thomas Zander's avatar
Thomas Zander committed
391 392 393 394
}

const QPainterPath KoShape::outline() const {
    QPainterPath path;
395
    path.addRect(QRectF( QPointF(0, 0), size() ));
Thomas Zander's avatar
Thomas Zander committed
396 397 398 399
    return path;
}

QPointF KoShape::absolutePosition() const {
Thomas Zander's avatar
Thomas Zander committed
400
    return d->matrix.map(QPointF(size().width() / 2.0 , size().height() / 2.0));
Thomas Zander's avatar
Thomas Zander committed
401 402 403 404 405 406
}

void KoShape::setAbsolutePosition(QPointF newPosition) {
    QPointF zero(0, 0);
    QMatrix matrix;
    // apply parents matrix to inherit any transformations done there.
Thomas Zander's avatar
Thomas Zander committed
407
    KoShapeContainer *container = d->parent;
Thomas Zander's avatar
Thomas Zander committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
    KoShape const *child = this;
    while(container) {
        if(container->childClipped(child)) {
            matrix *= container->transformationMatrix(0);
            break;
        }
        else {
            QPointF containerPos =container->position();
            matrix.translate(containerPos.x(), containerPos.y());
        }
        container = dynamic_cast<KoShapeContainer*>(container->parent());
        child = child->parent();
    }
    QPointF vector1 = matrix.inverted().map(zero);

    matrix = QMatrix();
Thomas Zander's avatar
Thomas Zander committed
424
    if ( d->angle != 0 )
425
    {
Thomas Zander's avatar
Thomas Zander committed
426 427 428 429 430
        matrix.translate( size().width() / 2.0 * d->scaleX, size().height() / 2.0 * d->scaleY );
        matrix.translate( size().height() / 2.0 * d->shearX, size().width() / 2.0 * d->shearY );
        matrix.rotate( d->angle );
        matrix.translate( -size().width() / 2.0 * d->scaleX, -size().height() / 2.0 * d->scaleY );
        matrix.translate( -size().height() / 2.0 * d->shearX, -size().width() / 2.0 * d->shearY );
431
    }
Thomas Zander's avatar
Thomas Zander committed
432 433
    matrix.shear( d->shearX, d->shearY );
    matrix.scale( d->scaleX, d->scaleY );
Thomas Zander's avatar
Thomas Zander committed
434 435

    QPointF vector2 = matrix.map( QPointF(size().width() / 2.0, size().height() / 2.0) );
Thomas Zander's avatar
Thomas Zander committed
436
    //kDebug(30006) << "vector1: " << vector1 << ", vector2: " << vector2 << endl;
Thomas Zander's avatar
Thomas Zander committed
437 438 439 440

    setPosition(newPosition + vector1 - vector2);
}

Thomas Zander's avatar
Thomas Zander committed
441
void KoShape::copySettings(const KoShape *shape) {
Thomas Zander's avatar
Thomas Zander committed
442 443 444 445 446 447 448 449
    d->pos = shape->position();
    d->scaleX = shape->scaleX();
    d->scaleY = shape->scaleY();
    d->angle = shape->rotation();
    d->shearX = shape->shearX();
    d->shearY = shape->shearY();
    d->size = shape->size();
    d->connectors.clear();
Thomas Zander's avatar
Thomas Zander committed
450 451
    foreach(QPointF point, shape->connectors())
        addConnectionPoint(point);
Thomas Zander's avatar
Thomas Zander committed
452 453 454 455
    d->zIndex = shape->zIndex();
    d->visible = shape->isVisible();
    d->locked = shape->isLocked();
    d->keepAspect = shape->keepAspectRatio();
Thomas Zander's avatar
Thomas Zander committed
456 457
}

Thomas Zander's avatar
Thomas Zander committed
458 459 460
void KoShape::moveBy(double distanceX, double distanceY) {
    QPointF p = absolutePosition();
    setAbsolutePosition(QPointF(p.x() + distanceX, p.y() + distanceY));
Thomas Zander's avatar
Thomas Zander committed
461 462
}

Thomas Zander's avatar
Thomas Zander committed
463
void KoShape::notifyChanged()
464
{
Thomas Zander's avatar
Thomas Zander committed
465
    foreach( KoShapeManager * manager, d->shapeManagers )
466
    {
Thomas Zander's avatar
Thomas Zander committed
467
        manager->notifyShapeChanged( this );
468 469 470
    }
}

471
void KoShape::setUserData(KoShapeUserData *userData) {
Thomas Zander's avatar
Thomas Zander committed
472 473 474
    if(d->userData)
        delete d->userData;
    d->userData = userData;
475 476 477
}

KoShapeUserData *KoShape::userData() const {
Thomas Zander's avatar
Thomas Zander committed
478
    return d->userData;
479 480
}

481
void KoShape::setApplicationData(KoShapeApplicationData *appData) {
Thomas Zander's avatar
Thomas Zander committed
482 483
    delete d->appData;
    d->appData = appData;
484 485 486
}

KoShapeApplicationData *KoShape::applicationData() const {
Thomas Zander's avatar
Thomas Zander committed
487
    return d->appData;
488 489
}

490
bool KoShape::hasTransparency() {
491
    if(d->backgroundBrush.style() == Qt::NoBrush)
Thomas Zander's avatar
Thomas Zander committed
492
        return true;
493
    return !d->backgroundBrush.isOpaque();
Thomas Zander's avatar
Thomas Zander committed
494 495
}

496 497
KoInsets KoShape::borderInsets() const {
    KoInsets answer;
498 499
    if(d->border)
        d->border->borderInsets(this, answer);
500 501 502
    return answer;
}

Thomas Zander's avatar
Thomas Zander committed
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
double KoShape::scaleX() const {
    return d->scaleX;
}
double KoShape::scaleY() const {
    return d->scaleY;
}

double KoShape::rotation() const {
    return d->angle;
}

double KoShape::shearX() const {
    return d->shearX;
}

double KoShape::shearY() const {
    return d->shearY;
}

QSizeF KoShape::size () const {
    return d->size;
}

QPointF KoShape::position() const {
    return d->pos;
}

void KoShape::addConnectionPoint( const QPointF &point ) {
    d->connectors.append( point );
}

QList<QPointF> KoShape::connectors() const {
    return d->connectors.toList();
}

void KoShape::setBackground ( const QBrush & brush ) {
539
    d->backgroundBrush = brush;
Thomas Zander's avatar
Thomas Zander committed
540 541 542
}

const QBrush& KoShape::background () {
543
    return d->backgroundBrush;
Thomas Zander's avatar
Thomas Zander committed
544 545 546
}

void KoShape::setZIndex(int zIndex) {
547
    notifyChanged();
Thomas Zander's avatar
Thomas Zander committed
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
    d->zIndex = zIndex;
}

void KoShape::setVisible(bool on) {
    d->visible = on;
}

bool KoShape::isVisible() const {
    return d->visible;
}

void KoShape::setSelectable(bool selectable) {
    d->selectable = selectable;
}

bool KoShape::isSelectable() const {
    return d->selectable;
}

void KoShape::setLocked(bool locked) {
    d->locked = locked;
}

bool KoShape::isLocked() const {
    return d->locked;
}

KoShapeContainer *KoShape::parent() const {
    return d->parent;
}

void KoShape::setKeepAspectRatio(bool keepAspect) {
    d->keepAspect = keepAspect;
}

bool KoShape::keepAspectRatio() const {
    return d->keepAspect;
}

const QString &KoShape::shapeId() const {
    return d->shapeId;
}

void KoShape::setShapeId(const QString &id) {
    d->shapeId = id;
}

void KoShape::setCollisionDetection(bool detect) {
    d->detectCollision = detect;
}

bool KoShape::collisionDetection() {
    return d->detectCollision;
}

void KoShape::addShapeManager( KoShapeManager * manager ) {
    d->shapeManagers.insert( manager );
}

void KoShape::removeShapeManager( KoShapeManager * manager ) {
    d->shapeManagers.remove( manager );
}

611 612 613 614 615 616 617 618 619 620 621 622
KoShapeBorderModel *KoShape::border() const {
    return d->border;
}

void KoShape::setBorder(KoShapeBorderModel *border) {
    d->border = border;
}

const QMatrix& KoShape::matrix() const {
    return d->matrix;
}

623 624 625 626 627 628 629 630 631 632 633 634 635
void KoShape::addConnection(KoShapeConnection *connection) {
    d->connections.append(connection);
    foreach(KoShapeManager *sm, d->shapeManagers)
        sm->addShapeConnection( connection );
}

void KoShape::removeConnection(KoShapeConnection *connection) {
    d->connections.removeAll(connection);
}

QList<KoShapeConnection*> KoShape::connections() const {
    return d->connections;
}
636

Thomas Zander's avatar
Thomas Zander committed
637 638 639 640 641 642
// static
void KoShape::applyConversion(QPainter &painter, const KoViewConverter &converter) {
    double zoomX, zoomY;
    converter.zoom(&zoomX, &zoomY);
    painter.scale(zoomX, zoomY);
}
643