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

« back to all changes in this revision

Viewing changes to plugins/textshape/TextShape.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:
1
1
/* This file is part of the KDE project
2
 
 * Copyright (C) 2006-2007 Thomas Zander <zander@kde.org>
3
 
 * Copyright (C) 2008 Thorsten Zachmann <zachmann@kde.org>
 
2
 * Copyright (C) 2006-2010 Thomas Zander <zander@kde.org>
 
3
 * Copyright (C) 2008-2010 Thorsten Zachmann <zachmann@kde.org>
4
4
 * Copyright (C) 2008 Pierre Stirnweiss \pierre.stirnweiss_koffice@gadz.org>
5
5
 *
6
6
 * This library is free software; you can redistribute it and/or
19
19
 * Boston, MA 02110-1301, USA.
20
20
 */
21
21
#include "TextShape.h"
 
22
#include <KoTextSharedLoadingData.h>
22
23
 
23
24
#define synchronized(T) QMutex T; \
24
25
    for(Finalizer finalizer(T); finalizer.loop(); finalizer.inc())
41
42
};
42
43
 
43
44
#include "Layout.h"
 
45
//#include "TextLayerShape.h"
44
46
 
45
47
#include <KoCanvasBase.h>
46
48
#include <KoResourceManager.h>
132
134
    Q_ASSERT(doc);
133
135
    KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(doc->documentLayout());
134
136
 
135
 
    //lay->state()->setImageCollection(m_imageCollection);
136
 
 
137
137
    if (m_textShapeData->endPosition() < 0) { // not layouted yet.
138
138
        if (lay == 0) {
139
139
            kWarning(32500) << "Painting shape that doesn't have a kotext doc-layout, which can't work";
152
152
        KoTextPage *page = m_pageProvider->page(this);
153
153
        if (page) {
154
154
            // this is used to not trigger repaints if layout during the painting is done
155
 
            // this enbales to use the same shapes on different pages showing different page numbers
 
155
            // this enables to use the same shapes on different pages showing different page numbers
156
156
            m_paintRegion = painter.clipRegion();
157
157
            if (!m_textShapeData->page() || page->pageNumber() != m_textShapeData->page()->pageNumber()) {
158
158
                m_textShapeData->setPage(page);
193
193
 
194
194
QPointF TextShape::convertScreenPos(const QPointF &point)
195
195
{
196
 
    QPointF p = matrix().inverted().map(point);
 
196
    QPointF p = absoluteTransformation(0).inverted().map(point);
197
197
    return p + QPointF(0.0, m_textShapeData->documentOffset());
198
198
}
199
199
 
325
325
    }
326
326
    const bool saveMyText = index == 0 && !m_demoText; // only save the text once.
327
327
 
328
 
    m_textShapeData->saveOdf(context, 0, saveMyText ? -1 : 0);
 
328
    m_textShapeData->saveOdf(context, 0, 0, saveMyText ? -1 : 0);
329
329
    writer.endElement(); // draw:text-box
330
330
    saveOdfCommonChildElements(context);
331
331
    writer.endElement(); // draw:frame
332
332
}
333
333
 
 
334
QString TextShape::saveStyle(KoGenStyle &style, KoShapeSavingContext &context) const
 
335
{
 
336
    Qt::Alignment vAlign(m_textShapeData->verticalAlignment());
 
337
    QString verticalAlign = "top";
 
338
    if (vAlign == Qt::AlignBottom) {
 
339
        verticalAlign = "bottom";
 
340
    }
 
341
    else if ( vAlign == Qt::AlignVCenter ) {
 
342
        verticalAlign = "middle";
 
343
    }
 
344
    style.addProperty("draw:textarea-vertical-align", verticalAlign);
 
345
 
 
346
    return KoShape::saveStyle(style, context);
 
347
}
 
348
 
 
349
void TextShape::loadStyle(const KoXmlElement &element, KoShapeLoadingContext &context)
 
350
{
 
351
    KoShape::loadStyle(element, context);
 
352
    KoStyleStack &styleStack = context.odfLoadingContext().styleStack();
 
353
    styleStack.setTypeProperties("graphic");
 
354
    QString verticalAlign(styleStack.property(KoXmlNS::draw, "textarea-vertical-align"));
 
355
    Qt::Alignment alignment(Qt::AlignTop);
 
356
    if (verticalAlign == "bottom") {
 
357
        alignment = Qt::AlignBottom;
 
358
    }
 
359
    else if (verticalAlign == "justify") {
 
360
        // not yet supported
 
361
        alignment = Qt::AlignVCenter;
 
362
    }
 
363
    else if (verticalAlign == "middle") {
 
364
        alignment = Qt::AlignVCenter;
 
365
    }
 
366
 
 
367
    m_textShapeData->setVerticalAlignment(alignment);
 
368
}
 
369
 
334
370
bool TextShape::loadOdf(const KoXmlElement &element, KoShapeLoadingContext &context)
335
371
{
336
372
    m_textShapeData->document()->setUndoRedoEnabled(false);
357
393
 
358
394
    if (style) {
359
395
        KoParagraphStyle paragraphStyle;
360
 
        paragraphStyle.loadOdf(style, context.odfLoadingContext());
 
396
        paragraphStyle.loadOdf(style, context);
361
397
 
362
398
        QTextDocument *document = m_textShapeData->document();
363
399
        QTextCursor cursor(document);
364
400
        QTextBlock block = cursor.block();
365
401
        paragraphStyle.applyStyle(block, false);
 
402
 
366
403
    }
367
404
 
368
405
    bool answer = loadOdfFrame(element, context);
370
407
    return answer;
371
408
}
372
409
 
 
410
bool TextShape::loadOdfFrame(const KoXmlElement &element, KoShapeLoadingContext &context)
 
411
{
 
412
    // if the loadOdfFrame from the base class for draw:text-box failes check for table:table
 
413
    if (!KoFrameShape::loadOdfFrame(element, context)) {
 
414
        const KoXmlElement & frameElement(KoXml::namedItemNS(element, KoXmlNS::table, "table"));
 
415
        if (frameElement.isNull()) {
 
416
            return false;
 
417
        }
 
418
        else {
 
419
            return loadOdfFrameElement(frameElement, context);
 
420
        }
 
421
    }
 
422
    return true;
 
423
}
 
424
 
373
425
bool TextShape::loadOdfFrameElement(const KoXmlElement &element, KoShapeLoadingContext &context)
374
426
{
375
 
    return m_textShapeData->loadOdf(element, context);
 
427
    return m_textShapeData->loadOdf(element, context, 0, this);
376
428
}
377
429
 
378
430
QTextDocument *TextShape::footnoteDocument()
409
461
 
410
462
void TextShape::waitUntilReady(const KoViewConverter &, bool asynchronous) const
411
463
{
 
464
    KoTextDocumentLayout *lay = qobject_cast<KoTextDocumentLayout*>(m_textShapeData->document()->documentLayout());
 
465
    Q_ASSERT(lay);
 
466
    if (!lay->hasLayouter()) {
 
467
        lay->setLayout(new Layout(lay));
 
468
    }
 
469
 
412
470
    if (asynchronous) {
413
471
        synchronized(m_mutex) {
414
472
            if (m_textShapeData->isDirty()) {