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

0001 /* This file is part of the Calligra project
0002  * Copyright (C) 2005, 2007-2008, 2010 Thomas Zander <zander@kde.org>
0003  * Copyright (C) 2008 Pierre Ducroquet <pinaraf@pinaraf.info>
0004  * Copyright (C) 2005, 2007-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 KWPAGE_H
0022 #define KWPAGE_H
0023 
0024 #include "KWPageManager.h"
0025 #include "KWPageStyle.h"
0026 #include "words_export.h"
0027 
0028 #include <KoText.h>
0029 #include <KoTextPage.h>
0030 #include <QRectF>
0031 #include <QObject>
0032 
0033 class KWPageManagerPrivate;
0034 class KoShapeManager;
0035 
0036 /**
0037  * This class represents a printed page of the document.  Each page is either left, right or
0038  * a pageSpread. See the PageSide for details.
0039  * The KWPage is created and maintained by the KWPageManager so you won't find a constructor
0040  * on this class.
0041  * Each KWPage is attached to a KWPageStyle representing the page master.
0042  */
0043 class WORDS_EXPORT KWPage : public KoTextPage
0044 {
0045 public:
0046     inline KWPage() : priv(0), n(0) {}
0047     inline KWPage(KWPageManagerPrivate *manager, int index) : priv(manager), n(index) {}
0048     inline KWPage(const KWPage &o) : priv(o.priv), n(o.n) {}
0049     inline KWPage &operator=(const KWPage &o) { priv = o.priv; n = o.n; return *this; }
0050 
0051     /// An enum to define if this is a page that is printed to be a left or a right page
0052     enum PageSide {
0053         Left,       ///< A left page. Used for even-numbered pages
0054         Right       ///< A right page. Used for odd numbered pages
0055     };
0056 
0057     /// return the width of this page (in pt)
0058     qreal width() const;
0059     /// return the height of this page (in pt)
0060     qreal height() const;
0061     /// return the height of the margin at top (in pt);
0062     qreal topMargin() const;
0063     /// return the height of the margin at bottom (in pt);
0064     qreal bottomMargin() const;
0065     /// return the width of the margin at left (in pt);
0066     qreal leftMargin() const;
0067     /// return the width of the margin at right (in pt);
0068     qreal rightMargin() const;
0069     /// return the height of the padding at top (in pt);
0070     qreal topPadding() const;
0071     /// return the height of the padding at bottom (in pt);
0072     qreal bottomPadding() const;
0073     /// return the width of the padding at left (in pt);
0074     qreal leftPadding() const;
0075     /// return the width of the padding at right (in pt);
0076     qreal rightPadding() const;
0077     /// return width of the margin that is the closest to the page edge, i.e. left for even pages
0078     qreal pageEdgeMargin() const;
0079     /// return width of the margin that is the closest to the binding, i.e. right for even pages
0080     qreal marginClosestBinding() const;
0081 
0082     /**
0083      * return a rectangle outlining this page, using the offset in the document.
0084      */
0085     QRectF rect() const override;
0086 
0087     /**
0088      * return a rectangle outlining the main text on this page, using the offset in the document.
0089      */
0090     QRectF contentRect() const override;
0091 
0092     /* set the content rect valid on this page
0093      */
0094     void setContentRect(const QRectF &rect);
0095 
0096     // the y coordinate
0097     /**
0098      * All Pages are in a document-wide coordinate system that simply puts every page under
0099      * the next page and keeps the Y coordinate counting throughout the doc.  The X coordinate
0100      * off each page in the document is zero, i.e. aligned to the left.
0101      * This method returns the offset of this page in the whole document which means it will
0102      * add the height of all the pages that come before this one.
0103      */
0104     qreal offsetInDocument() const;
0105     /**
0106      * Set the offset of the page.
0107      */
0108     void setOffsetInDocument(qreal offset);
0109 
0110     /// Return the pageSide of this page, see the PageSide
0111     PageSide pageSide() const;
0112     /// set the pageSide of this page, see the PageSide
0113     void setPageSide(PageSide ps);
0114 
0115     /// reimplemented from KoTextPage
0116     int visiblePageNumber(PageSelection select = CurrentPage, int adjustment = 0) const override;
0117 
0118     /// reimplemented from KoTextPage
0119     int pageNumber() const override;
0120 
0121     /**
0122      * Adjusts the visible page number of this page.
0123      *
0124      * This implements hard-coded page numbers like those defined via @a KoParagraphStyle::PageNumber . If
0125      * the page number equals zero then the page has an auto page number. That means previous page number
0126      * plus one.
0127      *
0128      * @param pageNumber The visible page-number for this page.
0129      */
0130     void setVisiblePageNumber(int pageNumber);
0131 
0132     /// reimplemented from KoTextPage
0133     QString masterPageName() const override;
0134 
0135     /// returns the page style applied on this page
0136     KWPageStyle pageStyle() const;
0137     /// set the page style to apply on this page
0138     void setPageStyle(const KWPageStyle style);
0139 
0140     /**
0141      * Return the orientation property of the page.
0142      * Note that the orientation has no influence on the actual page or its size in any way. Its
0143      * just a property. There are dialogs that will be better at showing page sizes and at offering features
0144      * when this property is set properly, though.
0145      */
0146     KoPageFormat::Orientation orientationHint() const;
0147     void setOrientationHint(KoPageFormat::Orientation);
0148 
0149     /**
0150      * Set the text-direction that text on this page should be initialized with.
0151      * New text that is written on this page can use this to set the text direction for
0152      * the paragraph.
0153      * @param direction the direction.
0154      */
0155     void setDirectionHint(KoText::Direction direction);
0156 
0157     /**
0158      * return the text-direction that text on this page should be initialized with.
0159      * New text that is written on this page can use this to set the text direction for
0160      * the paragraph.
0161      */
0162     KoText::Direction directionHint() const;
0163 
0164     void setAutoGenerated(bool on);
0165     bool isAutoGenerated() const;
0166 
0167     /// returns the previous page.
0168     const KWPage previous() const;
0169     /// returns the next page.
0170     const KWPage next() const;
0171 
0172     bool isValid() const;
0173 
0174     /**
0175      * Create a thumbnail image for this page.
0176      * Note: if the page has not been laid out yet, the result may be empty!
0177      *
0178      * @param size: the size in pixels of the thumbnail
0179      * @param shapeManager the shape manager containing the page's shapes
0180      * @param asPrint set to @c true if the rendering should be done like for print,
0181      *                or @c false if with the current view settings
0182      * @returns the thumbnail
0183      */
0184     QImage thumbnail(const QSize &size, KoShapeManager *shapeManager, bool asPrint = false) const;
0185 
0186     bool operator==(const KWPage &other) const;
0187     inline bool operator!=(const KWPage &other) const { return ! operator==(other); }
0188     inline bool operator<(const KWPage &other) const { return n < other.n; }
0189     inline bool operator>(const KWPage &other) const { return n > other.n; }
0190     uint hash() const;
0191 
0192 private:
0193     friend class KWPageTextInfo;
0194     KWPageManagerPrivate *priv;
0195     int n;
0196 };
0197 
0198 Q_DECLARE_TYPEINFO(KWPage, Q_MOVABLE_TYPE);
0199 
0200 inline uint qHash(const KWPage &page)
0201 {
0202     return page.hash();
0203 }
0204 
0205 #endif