~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to libs/flake/KoPathShape.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include "KoShapeBackground.h"
33
33
#include "KoShapeContainer.h"
34
34
#include "KoFilterEffectStack.h"
 
35
#include "KoTextOnShapeContainer.h"
35
36
 
36
37
#include <KoXmlReader.h>
37
38
#include <KoXmlWriter.h>
44
45
#include <KDebug>
45
46
#include <QtGui/QPainter>
46
47
 
 
48
#ifndef QT_NO_DEBUG
47
49
#include <qnumeric.h> // for qIsNaN
48
50
static bool qIsNaNPoint(const QPointF &p) {
49
51
    return qIsNaN(p.x()) || qIsNaN(p.y());
50
52
}
 
53
#endif
51
54
 
52
55
KoPathShapePrivate::KoPathShapePrivate(KoPathShape *q)
53
56
    : KoShapePrivate(q),
77
80
        pos.setY(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "y", QString())));
78
81
 
79
82
        // create matrix to transform original path data into desired size and position
80
 
        QMatrix viewMatrix;
 
83
        QTransform viewMatrix;
81
84
        viewMatrix.translate(-viewBox.left(), -viewBox.top());
82
85
        viewMatrix.scale(size.width() / viewBox.width(), size.height() / viewBox.height());
83
86
        viewMatrix.translate(pos.x(), pos.y());
114
117
    context.xmlWriter().addAttribute("koffice:nodeTypes", d->nodeTypes());
115
118
 
116
119
    saveOdfCommonChildElements(context);
 
120
    if (parent())
 
121
        parent()->saveOdfChildElements(context);
117
122
    context.xmlWriter().endElement();
118
123
}
119
124
 
162
167
 
163
168
    d->applyViewboxTransformation(element);
164
169
    QPointF pos = normalize();
165
 
    setTransformation(QMatrix());
 
170
    setTransformation(QTransform());
166
171
 
167
172
    if (element.hasAttributeNS(KoXmlNS::svg, "x") || element.hasAttributeNS(KoXmlNS::svg, "y")) {
168
173
        pos.setX(KoUnit::parseValue(element.attributeNS(KoXmlNS::svg, "x", QString())));
172
177
    setPosition(pos);
173
178
 
174
179
    loadOdfAttributes(element, context, OdfTransformation);
 
180
    KoTextOnShapeContainer::tryWrapShape(this, element, context);
175
181
 
176
182
    return true;
177
183
}
190
196
    KoShape::loadStyle(element, context);
191
197
 
192
198
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
193
 
    styleStack.save();
194
 
 
195
 
    // fill the style stack with the shapes style
196
 
    if (element.hasAttributeNS(KoXmlNS::draw, "style-name")) {
197
 
        context.odfLoadingContext().fillStyleStack(element, KoXmlNS::draw, "style-name", "graphic");
198
 
    } else if (element.hasAttributeNS(KoXmlNS::presentation, "style-name")) {
199
 
        context.odfLoadingContext().fillStyleStack(element, KoXmlNS::presentation, "style-name", "presentation");
200
 
    }
201
199
    styleStack.setTypeProperties("graphic");
202
200
 
203
201
    if (styleStack.hasProperty(KoXmlNS::svg, "fill-rule")) {
204
202
        QString rule = styleStack.property(KoXmlNS::svg, "fill-rule");
205
203
        d->fillRule = rule == "nonzero" ?  Qt::WindingFill : Qt::OddEvenFill;
206
204
    }
207
 
    styleStack.restore();
208
205
}
209
206
 
210
207
QRectF KoPathShape::loadOdfViewbox(const KoXmlElement & element) const
243
240
 
244
241
    if (background())
245
242
        background()->paint(painter, path);
246
 
    //paintDebug( painter );
 
243
    //paintDebug(painter);
247
244
}
248
245
 
249
246
#ifndef NDEBUG
335
332
                    lastPoint->controlPoint2(),
336
333
                    currPoint->controlPoint1(),
337
334
                    currPoint->point());
338
 
            } else if( activeCP || currPoint->activeControlPoint1()) {
 
335
            } else if (activeCP || currPoint->activeControlPoint1()) {
339
336
                Q_ASSERT(!qIsNaNPoint(lastPoint->controlPoint2()));
340
337
                Q_ASSERT(!qIsNaNPoint(currPoint->controlPoint1()));
341
338
                path.quadTo(
355
352
                        firstPoint->controlPoint1(),
356
353
                        firstPoint->point());
357
354
                }
358
 
                else if(currPoint->activeControlPoint2() || firstPoint->activeControlPoint1()) {
 
355
                else if (currPoint->activeControlPoint2() || firstPoint->activeControlPoint1()) {
359
356
                    Q_ASSERT(!qIsNaNPoint(currPoint->point()));
360
357
                    Q_ASSERT(!qIsNaNPoint(currPoint->controlPoint1()));
361
358
                    path.quadTo(
378
375
 
379
376
QRectF KoPathShape::boundingRect() const
380
377
{
381
 
    QMatrix transform = absoluteTransformation(0);
 
378
    QTransform transform = absoluteTransformation(0);
382
379
    // calculate the bounding rect of the transformed outline
383
380
    QRectF bb(transform.map(outline()).boundingRect());
384
381
    if (border()) {
417
414
void KoPathShape::setSize(const QSizeF &newSize)
418
415
{
419
416
    Q_D(KoPathShape);
420
 
    QMatrix matrix(resizeMatrix(newSize));
 
417
    QTransform matrix(resizeMatrix(newSize));
421
418
 
422
419
    KoShape::setSize(newSize);
423
420
    d->map(matrix);
424
421
}
425
422
 
426
 
QMatrix KoPathShape::resizeMatrix( const QSizeF & newSize ) const
 
423
QTransform KoPathShape::resizeMatrix(const QSizeF & newSize) const
427
424
{
428
425
    QSizeF oldSize = size();
429
426
    if (oldSize.width() == 0.0) {
441
438
        sizeNew.setHeight(0.000001);
442
439
    }
443
440
 
444
 
    return QMatrix(sizeNew.width() / oldSize.width(), 0, 0, sizeNew.height() / oldSize.height(), 0, 0);
 
441
    return QTransform(sizeNew.width() / oldSize.width(), 0, 0, sizeNew.height() / oldSize.height(), 0, 0);
445
442
}
446
443
 
447
444
KoPathPoint * KoPathShape::moveTo(const QPointF &p)
600
597
{
601
598
    Q_D(KoPathShape);
602
599
    QPointF tl(outline().boundingRect().topLeft());
603
 
    QMatrix matrix;
 
600
    QTransform matrix;
604
601
    matrix.translate(-tl.x(), -tl.y());
605
602
    d->map(matrix);
606
603
 
610
607
    return tl;
611
608
}
612
609
 
613
 
void KoPathShapePrivate::map(const QMatrix &matrix)
 
610
void KoPathShapePrivate::map(const QTransform &matrix)
614
611
{
615
612
    Q_Q(KoPathShape);
616
613
    KoSubpathList::const_iterator pathIt(q->m_subpaths.constBegin());
1052
1049
    if (! path)
1053
1050
        return false;
1054
1051
 
1055
 
    QMatrix pathMatrix = path->absoluteTransformation(0);
1056
 
    QMatrix myMatrix = absoluteTransformation(0).inverted();
 
1052
    QTransform pathMatrix = path->absoluteTransformation(0);
 
1053
    QTransform myMatrix = absoluteTransformation(0).inverted();
1057
1054
 
1058
1055
    foreach(KoSubpath* subpath, path->m_subpaths) {
1059
1056
        KoSubpath *newSubpath = new KoSubpath();
1076
1073
    if (! m_subpaths.size())
1077
1074
        return false;
1078
1075
 
1079
 
    QMatrix myMatrix = absoluteTransformation(0);
 
1076
    QTransform myMatrix = absoluteTransformation(0);
1080
1077
 
1081
1078
    foreach(KoSubpath* subpath, m_subpaths) {
1082
1079
        KoPathShape *shape = new KoPathShape();
1149
1146
    return KoPathShapeId;
1150
1147
}
1151
1148
 
1152
 
QString KoPathShape::toString(const QMatrix &matrix) const
 
1149
QString KoPathShape::toString(const QTransform &matrix) const
1153
1150
{
1154
1151
    QString d;
1155
1152
 
1207
1204
    return d;
1208
1205
}
1209
1206
 
1210
 
char nodeType( const KoPathPoint * point )
 
1207
char nodeType(const KoPathPoint * point)
1211
1208
{
1212
1209
    if (point->properties() & KoPathPoint::IsSmooth) {
1213
1210
        return 's';
1229
1226
        KoSubpath::const_iterator it((*pathIt)->constBegin());
1230
1227
        for (; it != (*pathIt)->constEnd(); ++it) {
1231
1228
            if (it == (*pathIt)->constBegin()) {
1232
 
                types.append( 'c' );
 
1229
                types.append('c');
1233
1230
            }
1234
1231
            else {
1235
 
                types.append( nodeType( *it ) );
 
1232
                types.append(nodeType(*it));
1236
1233
            }
1237
1234
 
1238
1235
            if ((*it)->properties() & KoPathPoint::StopSubpath
1239
1236
                && (*it)->properties() & KoPathPoint::CloseSubpath) {
1240
1237
                KoPathPoint * firstPoint = (*pathIt)->first();
1241
 
                types.append( nodeType( firstPoint ) );
 
1238
                types.append(nodeType(firstPoint));
1242
1239
            }
1243
1240
        }
1244
1241
    }
1245
1242
    return types;
1246
1243
}
1247
1244
 
1248
 
void updateNodeType( KoPathPoint * point, const QChar & nodeType )
 
1245
void updateNodeType(KoPathPoint * point, const QChar & nodeType)
1249
1246
{
1250
1247
    if (nodeType == 's') {
1251
1248
        point->setProperty(KoPathPoint::IsSmooth);
1327
1324
 
1328
1325
bool KoPathShape::hitTest(const QPointF &position) const
1329
1326
{
1330
 
    if (parent() && parent()->childClipped(this) && ! parent()->hitTest(position))
 
1327
    if (parent() && parent()->isClipped(this) && ! parent()->hitTest(position))
1331
1328
        return false;
1332
1329
 
1333
1330
    QPointF point = absoluteTransformation(0).inverted().map(position);
1335
1332
    if (border()) {
1336
1333
        KoInsets insets;
1337
1334
        border()->borderInsets(this, insets);
1338
 
        QRectF roi( QPointF(-insets.left, -insets.top), QPointF(insets.right, insets.bottom) );
1339
 
        roi.moveCenter( point );
1340
 
        if( outlinePath.intersects( roi ) || outlinePath.contains( roi ) )
 
1335
        QRectF roi(QPointF(-insets.left, -insets.top), QPointF(insets.right, insets.bottom));
 
1336
        roi.moveCenter(point);
 
1337
        if (outlinePath.intersects(roi) || outlinePath.contains(roi))
1341
1338
            return true;
1342
1339
    } else {
1343
 
        if( outlinePath.contains( point ) )
 
1340
        if (outlinePath.contains(point))
1344
1341
            return true;
1345
1342
    }
1346
1343