1 /* This file is part of the KDE project
2  * Copyright (C) 2011-2015 C. Boemann <cbo@boemann.dk>
3  * Copyright (C) 2011 Sebastian Sauer <sebastian.sauer@kdab.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KWROOTAREAPROVIDER_H
22 #define KWROOTAREAPROVIDER_H
23 
24 #include "KWPage.h"
25 #include <KWRootAreaProviderBase.h>
26 
27 #include <QMap>
28 #include <QPair>
29 
30 class KoShape;
31 class KoTextShapeData;
32 class KWTextFrameSet;
33 class KWPage;
34 
35 class KWRootAreaPage
36 {
37 public:
KWRootAreaPage()38     KWRootAreaPage() {};
~KWRootAreaPage()39     ~KWRootAreaPage() {};
40     KWPage page;
41     QList<KoTextLayoutRootArea *> rootAreas;
KWRootAreaPage(const KWPage & p)42     explicit KWRootAreaPage(const KWPage &p) : page(p) {}
43 };
44 
45 class KWRootAreaProvider : public KWRootAreaProviderBase
46 {
47 public:
48     //KWRootAreaProvider(KWTextFrameSet *textFrameSet, KoShape *shape, KoTextShapeData *data);
49     explicit KWRootAreaProvider(KWTextFrameSet *textFrameSet);
50     ~KWRootAreaProvider() override;
51 
52     void addDependentProvider(KWRootAreaProviderBase *provider, int pageNumber);
53 
54     void clearPages(int pageNumber) override;
55     void setPageDirty(int pageNumber) override;
56 
57     /// reimplemented
58     KoTextLayoutRootArea *provide(KoTextDocumentLayout *documentLayout, const RootAreaConstraint &constraints, int requestedPosition, bool *isNewArea) override;
59     void releaseAllAfter(KoTextLayoutRootArea *afterThis) override;
60     void doPostLayout(KoTextLayoutRootArea *rootArea, bool isNewRootArea) override;
61 
62 private:
63     QList<KWRootAreaPage *> m_pages;
64     QHash<KoTextLayoutRootArea*, KWRootAreaPage *> m_pageHash;
65     QList<KoTextLayoutRootArea*> m_rootAreaCache;
66     QList<QPair<KWRootAreaProviderBase *, int> > m_dependentProviders;
67 
pages()68     QList<KWRootAreaPage *> pages() const { return m_pages; }
69     KoTextLayoutRootArea* provideNext(KoTextDocumentLayout *documentLayout, const RootAreaConstraint &constraints);
70     void handleDependentProviders(int pageNumber);
71 };
72 
73 #endif
74