Warning, file /office/calligra/libs/textlayout/KoTextLayoutRootArea.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2011 C. Boemann <cbo@kogmbh.com>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "KoTextLayoutRootArea.h"
0021 
0022 #include "FrameIterator.h"
0023 
0024 #include <KoShapeContainer.h>
0025 #include <KoTextShapeData.h>
0026 #include <KoTextPage.h>
0027 
0028 class Q_DECL_HIDDEN KoTextLayoutRootArea::Private
0029 {
0030 public:
0031     Private()
0032         : shape(0)
0033         , dirty(true)
0034         , textpage(0)
0035         , nextStartOfArea(0)
0036     {
0037     }
0038     KoShape *shape;
0039     bool dirty;
0040     KoTextPage *textpage;
0041     FrameIterator *nextStartOfArea;
0042 };
0043 
0044 KoTextLayoutRootArea::KoTextLayoutRootArea(KoTextDocumentLayout *documentLayout)
0045   : KoTextLayoutArea(0, documentLayout)
0046   , d(new Private)
0047 {
0048 }
0049 
0050 KoTextLayoutRootArea::~KoTextLayoutRootArea()
0051 {
0052     if (d->shape)
0053     {
0054         KoTextShapeData *data = qobject_cast<KoTextShapeData*>(d->shape->userData());
0055         if (data)
0056             data->setRootArea(0);
0057     }
0058     delete d->nextStartOfArea;
0059     delete d->textpage;
0060     delete d;
0061 }
0062 
0063 bool KoTextLayoutRootArea::layoutRoot(FrameIterator *cursor)
0064 {
0065     d->dirty = false;
0066 
0067     setVirginPage(true);
0068 
0069     bool retval = KoTextLayoutArea::layout(cursor);
0070 
0071     delete d->nextStartOfArea;
0072     d->nextStartOfArea = new FrameIterator(cursor);
0073     return retval;
0074 }
0075 
0076 void KoTextLayoutRootArea::setAssociatedShape(KoShape *shape)
0077 {
0078     d->shape = shape;
0079 }
0080 
0081 KoShape *KoTextLayoutRootArea::associatedShape() const
0082 {
0083     return d->shape;
0084 }
0085 
0086 void KoTextLayoutRootArea::setPage(KoTextPage *textpage)
0087 {
0088     delete d->textpage;
0089     d->textpage = textpage;
0090 }
0091 
0092 KoTextPage* KoTextLayoutRootArea::page() const
0093 {
0094     if (d->textpage) {
0095         return d->textpage;
0096     }
0097     // If this root area has no KoTextPage then walk up the shape-hierarchy and look if we
0098     // have a textshape-parent that has a valid KoTextPage. This handles the in Words valid
0099     // case that the associatedShape is nested in another shape.
0100     KoTextPage *p = 0;
0101     for(KoShape *shape = associatedShape() ? associatedShape()->parent() : 0; shape; shape = shape->parent()) {
0102         if (KoTextShapeData *data = qobject_cast<KoTextShapeData*>(shape->userData())) {
0103             if (KoTextLayoutRootArea *r = data->rootArea())
0104                 p = r->page();
0105             break;
0106         }
0107     }
0108     return p;
0109 }
0110 
0111 void KoTextLayoutRootArea::setDirty()
0112 {
0113     d->dirty = true;
0114     documentLayout()->emitLayoutIsDirty();
0115 }
0116 
0117 bool KoTextLayoutRootArea::isDirty() const
0118 {
0119     return d->dirty;
0120 }
0121 
0122 FrameIterator *KoTextLayoutRootArea::nextStartOfArea() const
0123 {
0124     return d->nextStartOfArea;
0125 }
0126 
0127 
0128 KoText::Direction KoTextLayoutRootArea::parentTextDirection() const
0129 {
0130     return KoText::LeftRightTopBottom;
0131 }
0132 
0133 void KoTextLayoutRootArea::setBottom(qreal b)
0134 {
0135     KoTextLayoutArea::setBottom(b);
0136 }