~ubuntu-branches/ubuntu/oneiric/koffice/oneiric-updates

« back to all changes in this revision

Viewing changes to plugins/paragraphtool/ParagraphBase.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
2
 * Copyright (C) 2008 Florian Merz <florianmerz@gmx.de>
 
3
 * Copyright (C) 2010 Thomas Zander <zander@kde.org>
3
4
 *
4
5
 * This library is free software; you can redistribute it and/or
5
6
 * modify it under the terms of the GNU Library General Public
24
25
#include <KoShapeManager.h>
25
26
#include <KoTextDocumentLayout.h>
26
27
#include <KoTextShapeData.h>
27
 
 
28
 
#include <KDebug>
29
 
#include <KLocalizedString>
30
 
 
31
 
#include <QAbstractTextDocumentLayout>
32
 
#include <QTextDocument>
33
 
 
34
 
#include <assert.h>
 
28
#include <KoParagraphStyle.h>
 
29
 
 
30
#include <KLocale>
35
31
 
36
32
ParagraphBase::ParagraphBase(QObject *parent, KoCanvasBase *canvas)
37
33
        : QObject(parent),
54
50
 
55
51
void ParagraphBase::activateTextBlockAt(const QPointF &point)
56
52
{
57
 
    KoShape *shape = dynamic_cast<KoShape*>(m_canvas->shapeManager()->shapeAt(point));
58
 
    if (shape == NULL) {
 
53
 
 
54
    KoShape *shape = 0;
 
55
    KoTextShapeData *textShapeData = 0;
 
56
    foreach (KoShape *s, m_canvas->shapeManager()->shapesAt(QRectF(point, QSizeF(4, 4)))) {
 
57
        textShapeData = qobject_cast<KoTextShapeData*>(s->userData());
 
58
        if (textShapeData) { // found it!
 
59
            shape = s;
 
60
            break;
 
61
        }
 
62
    }
 
63
    if (shape == 0 || textShapeData == 0) {
59
64
        // there is no shape below the mouse position
60
65
        deactivateTextBlock();
61
66
        return;
62
67
    }
63
68
 
64
 
    KoTextShapeData *textShapeData = qobject_cast<KoTextShapeData*>(shape->userData());
65
 
    if (textShapeData == NULL) {
66
 
        // the shape below the mouse position is not a text shape
67
 
        deactivateTextBlock();
68
 
        return;
69
 
    }
70
 
 
71
69
    QTextDocument *document = textShapeData->document();
72
70
 
73
 
    QPointF p = shape->transformation().inverted().map(point);
 
71
    QPointF p = shape->absoluteTransformation(0).inverted().map(point);
74
72
    p += QPointF(0.0, textShapeData->documentOffset());
75
73
 
76
74
    int position = document->documentLayout()->hitTest(p, Qt::ExactHit);
81
79
    }
82
80
 
83
81
    QTextBlock newBlock(document->findBlock(position));
84
 
    assert(newBlock.isValid());
 
82
    Q_ASSERT(newBlock.isValid());
85
83
 
86
84
    activateTextBlock(newBlock, document);
87
85
}
122
120
        // easy way to get from the cursor to a non-const document pointer
123
121
        // but it doesn't make any sense to pass in a document pointer which is
124
122
        // different to the document the text block belongs to
125
 
        assert(newBlock.document() == document);
 
123
        Q_ASSERT(newBlock.document() == document);
126
124
        m_document = document;
127
125
    }
128
126
 
153
151
    m_fragments.clear();
154
152
 
155
153
    KoTextDocumentLayout *layout = qobject_cast<KoTextDocumentLayout*>(textBlock().document()->documentLayout());
156
 
    assert(layout != NULL);
 
154
    Q_ASSERT(layout);
157
155
 
158
156
    QList<KoShape*> shapes = layout->shapes();
159
157
    foreach(KoShape *shape, shapes) {
177
175
qreal ParagraphBase::shapeTop(const KoShape *shape) const
178
176
{
179
177
    KoTextShapeData *textShapeData = qobject_cast<KoTextShapeData*>(shape->userData());
180
 
    assert(textShapeData != NULL);
 
178
    Q_ASSERT(textShapeData);
181
179
 
182
180
    return textShapeData->documentOffset();
183
181
}