File indexing completed on 2024-05-12 16:37:12

0001 /* This file is part of the Calligra project
0002  * Copyright (C) 2005-2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2008 Pierre Ducroquet <pinaraf@pinaraf.info>
0004  * Copyright (C) 2008,2011 Sebastian Sauer <mail@dipe.org>
0005  *
0006  * This library is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU Library General Public
0008  * License as published by the Free Software Foundation; either
0009  * version 2 of the License, or (at your option) any later version.
0010  *
0011  * This library is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  * Library General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Library General Public License
0017  * along with this library; see the file COPYING.LIB.  If not, write to
0018  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020  */
0021 #ifndef KW_PAGEMANAGER_H
0022 #define KW_PAGEMANAGER_H
0023 
0024 #include "words_export.h"
0025 #include "KWPageStyle.h"
0026 
0027 #include <KoPageLayout.h>
0028 #include <KoInsets.h>
0029 
0030 #include <QList>
0031 #include <QPointF>
0032 
0033 class KWPage;
0034 class KoShape;
0035 class KWPageManagerPrivate;
0036 
0037 
0038 /**
0039  * The Page Manager manages all the pages a document contains and separates all the frames
0040  * the document contains into actual printed pages.
0041  */
0042 class WORDS_EXPORT KWPageManager
0043 {
0044 public:
0045     explicit KWPageManager();
0046     ~KWPageManager();
0047 
0048     /**
0049      * return pageNumber of @p point, pagenumbers for a normal document start at 0.
0050      */
0051     int pageNumber(const QPointF &point) const;
0052 
0053     /**
0054      * return pageNumber of the argument shape, pagenumbers for a normal document start at 0.
0055      */
0056     int pageNumber(const KoShape *shape) const;
0057 
0058     /**
0059      * return pageNumber of page with document-offset (in the Y direction) of @p ptY,
0060      * pagenumbers for a normal document start at 0.
0061      */
0062     int pageNumber(qreal ptY) const;
0063 
0064     /**
0065      * return total number of pages in this document.
0066      */
0067     int pageCount() const;
0068 
0069     /**
0070      * return the KWPage of a specific page number. Returns 0 if page does not exist.
0071      */
0072     KWPage page(int pageNumber) const;
0073 
0074     /**
0075      * return the KWPage instance where the shape is on. Returns 0 if page does not exist.
0076      */
0077     KWPage page(const KoShape *shape) const;
0078 
0079     /**
0080      * return the KWPage instance where the point is on. Returns 0 if page does not exist.
0081      */
0082     KWPage page(const QPointF &point) const;
0083 
0084     /**
0085      * return the KWPage instance of the y-coordinate in the document. Returns 0 if
0086      * page does not exist.
0087      */
0088     KWPage page(qreal ptY) const;
0089 
0090     /**
0091      * Return the y-offset in this document of the top of page with @p pageNumber
0092      * Note that pageNumber is NOT an offset in the document, but the real number
0093      * of the page.
0094      * @see setStartPage(int)
0095      */
0096     qreal topOfPage(int pageNumber) const; // in pt
0097 
0098     /**
0099      * Return the y-offset in this document of the bottom of page with @p pageNumber
0100      * Note that pageNumber is NOT an offset in the document, but the real number
0101      * of the page.
0102      * @see setStartPage(int)
0103      */
0104     qreal bottomOfPage(int pageNumber) const; // in pt
0105 
0106     /**
0107      * Inserts a new page at the specified position in the document.
0108      * Shifts the page currently at that position (if any) and any subsequent pages after.
0109      * @param pageNumber page number of the new page, or -1 to append
0110      * @param pageStyle the page style to use for the new page
0111      */
0112     KWPage insertPage(int pageNumber, const KWPageStyle &pageStyle = KWPageStyle());
0113 
0114     /**
0115      * Append a new page at the end of the document
0116      * @param pageStyle the page style to use for the new page
0117      */
0118     KWPage appendPage(const KWPageStyle &pageStyle = KWPageStyle());
0119 
0120     /// Remove the page with @p pageNumber renumbering all pages after pages already added
0121     void removePage(int pageNumber);
0122 
0123     /// Remove @p page renumbering all pages after pages already added
0124     void removePage(const KWPage &page);
0125 
0126     /**
0127      * Return an ordered list of all pages.
0128      * @param pageStyle if non empty return only the pages that follow the page style.
0129      */
0130     QVector<KWPage> pages(const QString &pageStyle = QString()) const;
0131 
0132     /**
0133      * Return the padding used for this document. This is used to have some space around each
0134      * page outside of the printable area for page bleed.
0135      */
0136     KoInsets padding() const;
0137 
0138     /**
0139      * Set a new padding used for this document. This is used to have some space around each
0140      * page outside of the printable area for page bleed.
0141      */
0142     void setPadding(const KoInsets &padding);
0143 
0144     /**
0145      * This property can be set to register that new pages created should be made to be a pageSpread when appropriate.
0146      * Note that the pageManager itself will not use this variable since it doesn't have a factory method for pages.
0147      */
0148     bool preferPageSpread() const;
0149 
0150     /**
0151      * Set the property to register that new pages created should be made to be a pageSpread when appropriate.
0152      * Note that the pageManager itself will not use this variable since it doesn't have a factory method for pages.
0153      * @param on If true, it is requested that new, even numbered pages are set to be page spreads.
0154      */
0155     void setPreferPageSpread(bool on);
0156 
0157     /**
0158      * Add a new \a KWPageStyle instance to this document.
0159      *
0160      * \note that you need to make sure that you only add pageStyle with a
0161      * masterpage-name that are NOT already registered cause those names need
0162      * to be unique.
0163      *
0164      * \param pageStyle The \a KWPageStyle instance that should be added.
0165      */
0166     void addPageStyle(const KWPageStyle &pageStyle);
0167 
0168     /**
0169      * Remove the page-style from the page-manager.
0170      */
0171     void removePageStyle(const KWPageStyle &pageStyle);
0172 
0173     /**
0174      * Returns all pagestyles.
0175      * // TODO only return a qlist of styles, they have a their name in them alraedy
0176      */
0177     QHash<QString, KWPageStyle> pageStyles() const;
0178 
0179     /**
0180      * Returns the \a KWPageStyle known under the name \p name or nullptr if the
0181      * document has no such page style.
0182      */
0183     KWPageStyle pageStyle(const QString &name) const;
0184 
0185     /**
0186      * Return the default page style. This equals to pageStyle("Standard").
0187      */
0188     KWPageStyle defaultPageStyle() const;
0189 
0190     /**
0191      * Remove all page style and clears the default one.
0192      */
0193     void clearPageStyles();
0194 
0195     /**
0196      * Return the first page in the page managers list of pages.
0197      * Will return 0 if there are no pages.
0198      */
0199     const KWPage begin() const;
0200 
0201     /**
0202      * Return the last page in the page managers list of pages.
0203      * Will return 0 if there are no pages.
0204      */
0205     const KWPage last() const;
0206 
0207     /**
0208      * Return the first page in the page managers list of pages.
0209      * Will return 0 if there are no pages.
0210      */
0211     KWPage begin();
0212 
0213     /**
0214      * Return the last page in the page managers list of pages.
0215      * Will return 0 if there are no pages.
0216      */
0217     KWPage last();
0218 
0219     KWPageManagerPrivate *priv() { return d; }
0220 
0221 private:
0222     /// disable copy constructor and assignment operator
0223     Q_DISABLE_COPY(KWPageManager)
0224 
0225     KWPageManagerPrivate * const d;
0226 };
0227 
0228 #endif