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

« back to all changes in this revision

Viewing changes to libs/flake/KoShapeSavingContext.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:
2
2
   Copyright (C) 2004-2006 David Faure <faure@kde.org>
3
3
   Copyright (C) 2007-2008 Thorsten Zachmann <zachmann@kde.org>
4
4
   Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net>
 
5
   Copyright (C) 2010 Benjamin Port <port.benjamin@gmail.com>
5
6
 
6
7
   This library is free software; you can redistribute it and/or
7
8
   modify it under the terms of the GNU Library General Public
40
41
    KoXmlWriter *xmlWriter;
41
42
    KoShapeSavingContext::ShapeSavingOptions savingOptions;
42
43
    QMap<const KoShape *, QString> drawIds;
 
44
    QMap<const QTextBlockUserData*, QString> subIds;
43
45
    QList<const KoShapeLayer*> layers;
44
46
    QSet<KoDataCenterBase *> dataCenter;
45
47
    int drawId;
 
48
    int subId;
46
49
    QMap<QString, KoSharedSavingData*> sharedData;
47
50
    QMap<qint64, QString> imageNames;
48
51
    int imageId;
49
52
    QMap<QString, QImage> images;
50
 
    QHash<const KoShape *, QMatrix> shapeOffsets;
 
53
    QHash<const KoShape *, QTransform> shapeOffsets;
51
54
 
52
55
    KoGenStyles& mainStyles;
53
56
    KoEmbeddedDocumentSaver& embeddedSaver;
58
61
        : xmlWriter(&w),
59
62
        savingOptions(0),
60
63
        drawId(0),
 
64
        subId(0),
61
65
        imageId(0),
62
66
        mainStyles(s),
63
67
        embeddedSaver(e)
141
145
    d->drawId = 0;
142
146
}
143
147
 
144
 
void KoShapeSavingContext::addLayerForSaving(const KoShapeLayer * layer)
 
148
QString KoShapeSavingContext::subId(const QTextBlockUserData *subItem, bool insert)
 
149
{
 
150
    QMap<const QTextBlockUserData*, QString>::iterator it(d->subIds.find(subItem));
 
151
    if (it == d->subIds.end()) {
 
152
        if (insert == true) {
 
153
            it = d->subIds.insert(subItem, QString("subitem%1").arg(++d->subId));
 
154
        } else {
 
155
            return QString();
 
156
        }
 
157
    }
 
158
    return it.value();
 
159
}
 
160
 
 
161
void KoShapeSavingContext::addLayerForSaving(const KoShapeLayer *layer)
145
162
{
146
163
    if (layer && ! d->layers.contains(layer))
147
164
        d->layers.append(layer);
148
165
}
149
166
 
150
 
void KoShapeSavingContext::saveLayerSet(KoXmlWriter & xmlWriter) const
 
167
void KoShapeSavingContext::saveLayerSet(KoXmlWriter &xmlWriter) const
151
168
{
152
169
    xmlWriter.startElement("draw:layer-set");
153
170
    foreach(const KoShapeLayer * layer, d->layers) {
172
189
    QMap<qint64, QString>::iterator it(d->imageNames.find(image->key()));
173
190
    if (it == d->imageNames.end()) {
174
191
        QString suffix = image->suffix();
175
 
        if ( suffix.isEmpty() ) {
 
192
        if (suffix.isEmpty()) {
176
193
            it = d->imageNames.insert(image->key(), QString("Pictures/image%1").arg(++d->imageId));
177
194
        }
178
195
        else {
182
199
    return it.value();
183
200
}
184
201
 
185
 
QString KoShapeSavingContext::imageHref(QImage & image)
 
202
QString KoShapeSavingContext::imageHref(QImage &image)
186
203
{
187
204
    // TODO this can be optimized to recocnice images which have the same content
188
205
    // Also this can use quite a lot of memeory as the qimage are all kept until
209
226
        ok = ok && dataCenter->completeSaving(store, manifestWriter, this);
210
227
        //kDebug() << "ok" << ok;
211
228
    }
212
 
    for ( QMap<QString, QImage>::iterator it(d->images.begin()); it != d->images.end(); ++it ) {
 
229
    for (QMap<QString, QImage>::iterator it(d->images.begin()); it != d->images.end(); ++it) {
213
230
        if (store->open(it.key())) {
214
231
            KoStoreDevice device(store);
215
232
            ok = ok && it.value().save(&device, "PNG");
231
248
    return ok;
232
249
}
233
250
 
234
 
void KoShapeSavingContext::addSharedData(const QString & id, KoSharedSavingData * data)
 
251
void KoShapeSavingContext::addSharedData(const QString &id, KoSharedSavingData * data)
235
252
{
236
253
    QMap<QString, KoSharedSavingData*>::iterator it(d->sharedData.find(id));
237
254
    // data will not be overwritten
243
260
    }
244
261
}
245
262
 
246
 
KoSharedSavingData * KoShapeSavingContext::sharedData(const QString & id) const
 
263
KoSharedSavingData * KoShapeSavingContext::sharedData(const QString &id) const
247
264
{
248
265
    KoSharedSavingData * data = 0;
249
266
    QMap<QString, KoSharedSavingData*>::const_iterator it(d->sharedData.constFind(id));
253
270
    return data;
254
271
}
255
272
 
256
 
void KoShapeSavingContext::addShapeOffset(const KoShape * shape, const QMatrix & m)
 
273
void KoShapeSavingContext::addShapeOffset(const KoShape *shape, const QTransform &m)
257
274
{
258
275
    d->shapeOffsets.insert(shape, m);
259
276
}
260
277
 
261
 
void KoShapeSavingContext::removeShapeOffset(const KoShape * shape)
 
278
void KoShapeSavingContext::removeShapeOffset(const KoShape *shape)
262
279
{
263
280
    d->shapeOffsets.remove(shape);
264
281
}
265
282
 
266
 
QMatrix KoShapeSavingContext::shapeOffset(const KoShape * shape) const
 
283
QTransform KoShapeSavingContext::shapeOffset(const KoShape *shape) const
267
284
{
268
 
    return d->shapeOffsets.value(shape, QMatrix());
 
285
    return d->shapeOffsets.value(shape, QTransform());
269
286
}