1 /* This file is part of the KDE project
2  * Copyright (C) 2006, 2008-2009 Thomas Zander <zander@kde.org>
3  * Copyright (C) 2008 Pierre Ducroquet <pinaraf@pinaraf.info>
4  * Copyright (C) 2008 Sebastian Sauer <mail@dipe.org>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef KWPAGESTYLE_H
23 #define KWPAGESTYLE_H
24 
25 #include "Words.h"
26 #include "words_export.h"
27 
28 #include <KoPageLayout.h>
29 #include <KoText.h>
30 
31 #include <QSharedDataPointer>
32 
33 class KWPageStylePrivate;
34 class KoShapeBackground;
35 class KoOdfLoadingContext;
36 class KoDocumentResourceManager;
37 struct KoColumns;
38 
39 /**
40  * A page style represents a set of all the properties that change the layout and size
41  * of a page and the text area on it.
42  *
43  * For documents that have a main text auto generated we have a lot of little options
44  * to do that. This class wraps all these options.
45  *
46  * Words has one KWPageManager per document, the manager collects all page styles by
47  * name and allows pages to follow this named style. This means that changing a page
48  * style will update all pages that are using that page style with the new properties.
49  *
50  * The KWPageStyle object is a value class, you can pass it by reference and create it
51  * on the stack. You should never use 'new' on the KWPageStyle.
52  * The KWPageStyle is a so called QExplicitlySharedDataPointer, which is best explained
53  * with a code example;
54  * @code
55  * KWPageStyle style1("mystyle");
56  * KWPageStyle style2 = style1;
57  * style1.setHeaderPolicy(Words::HFTypeEvenOdd); // set it on one
58  * Q_ASSERT(style2.headerPolicy() == Words::HFTypeEvenOdd); // the other changes too
59  * @endcode
60  */
61 class WORDS_EXPORT KWPageStyle
62 {
63 public:
64     /**
65      * Creates an empty, invalid page style.
66      */
67     KWPageStyle();
68     /**
69      * constructor, initializing the data to some default values.
70      *
71      * \param mastername the master page name for this page style.
72      * \param displayname the display name for this page style. If not
73      * defined then the \p mastername will be used as display name.
74      */
75     explicit KWPageStyle(const QString &mastername, const QString &displayname = QString());
76     /**
77      * copy constructor
78      *
79      * \p ps the original that will be copied
80      */
81     KWPageStyle(const KWPageStyle &ps);
82     KWPageStyle &operator=(const KWPageStyle &ps);
83     /// destructor
84     ~KWPageStyle();
85 
86     /// returns true if the KWPageStyle is valid
87     bool isValid() const;
88 
89     /// Specifies the type of pages that a page master should generate.
90     enum PageUsageType {
91         AllPages, ///< if there are no style:header-left or style:footer-left elements, the header and footer content is the same for left and right pages.
92         LeftPages, ///< style:header-left or style:footer-left elements are ignored.
93         MirroredPages, ///< if there are no style:header-left or style:footer-left elements, the header and footer content is the same for left and right pages.
94         RightPages ///< style:header-left or style:footer-left elements are ignored.
95     };
96 
97     /**
98      * Returns the type of pages that should be generated.
99      */
100     PageUsageType pageUsage() const;
101 
102     /**
103      * Sets the type of pages that should be generated.
104      */
105     void setPageUsage(PageUsageType pageusage) const;
106 
107     /**
108      * Return the current columns settings.
109      */
110     KoColumns columns() const;
111     /**
112      * Set the new columns settings
113      */
114     void setColumns(const KoColumns &columns);
115 
116     /// Return the type of header the pages will get.
117     Words::HeaderFooterType headerPolicy() const;
118     /// set the type of header the pages will get.
119     void setHeaderPolicy(Words::HeaderFooterType p);
120 
121     /// Return the type of footers the pages will get.
122     Words::HeaderFooterType footerPolicy() const;
123     /// Set the type of footers the pages will get.
124     void setFooterPolicy(Words::HeaderFooterType p);
125 
126     /// return the distance between the main text and the header
127     qreal headerDistance() const;
128     /**
129      * Set the distance between the main text and the header
130      * @param distance the distance
131      */
132     void setHeaderDistance(qreal distance);
133 
134     /// return if a growing header eats the distance first.
135     bool headerDynamicSpacing() const;
136 
137     /// set if a growing header eats the distance first.
138     void setHeaderDynamicSpacing(bool dynamic);
139 
140     /// return the minimum header height.
141     qreal headerMinimumHeight() const;
142     /**
143      * Set the minimum header height.
144      * @param height the height
145      */
146     void setHeaderMinimumHeight(qreal height);
147 
148     /// return the minimum footer height.
149     qreal footerMinimumHeight() const;
150     /**
151      * Set the minimum footer height.
152      * @param height the height
153      */
154     void setFooterMinimumHeight(qreal height);
155 
156     /// return the distance between the footer and the frame directly above that (footnote or main)
157     qreal footerDistance() const;
158     /**
159      * Set the distance between the footer and the frame directly above that (footnote or main)
160      * @param distance the distance
161      */
162     void setFooterDistance(qreal distance);
163 
164     /// return if a growing footer eats the distance first.
165     bool footerDynamicSpacing() const;
166 
167     /// set if a growing footer eats the distance first.
168     void setFooterDynamicSpacing(bool dynamic);
169 
170     /// initialize to default settings
171     void clear();
172 
173     /// return the pageLayout applied for these pages
174     KoPageLayout pageLayout() const;
175 
176     /// return true if pages of this style can turn into page-spreads
177     bool isPageSpread() const;
178 
179     /// set the pageLayout applied for these pages
180     void setPageLayout(const KoPageLayout &layout);
181 
182     /// get the master page name for this page style.
183     QString name() const;
184     /// get the display name for this page style.
185     QString displayName() const;
186 
187     KoText::Direction direction() const;
188     void setDirection(KoText::Direction direction);
189 
190     /// Get the background.
191     QSharedPointer<KoShapeBackground> background() const;
192 
193     /// set the background/
194     void setBackground(QSharedPointer<KoShapeBackground> background);
195 
196     /// get the next page master style/
197     QString nextStyleName() const;
198 
199     /// set the next page master style/
200     void setNextStyleName(const QString &nextStyleName);
201 
202     /**
203      * Save this page style to ODF.
204      */
205     KoGenStyle saveOdf() const;
206 
207     /**
208      * Load this page style from ODF
209      */
210     void loadOdf(KoOdfLoadingContext &context, const KoXmlElement &masterNode, const KoXmlElement &style, KoDocumentResourceManager *documentResources);
211 
212     bool operator==(const KWPageStyle &other) const;
213     inline bool operator!=(const KWPageStyle &other) const { return ! operator==(other); }
214     uint hash() const;
215 
216     /// internal
217     const KWPageStylePrivate *priv() const;
218     /// internal
219     KWPageStylePrivate *priv();
220 
221     /**
222      * Detach from shared data and set a new name for this one.
223      *
224      * Note that the detached style is not known by the page-manager yet. Use
225      * KWPageManager::addPageStyle to make the detached page-style permanent.
226      */
227     void detach(const QString &name, const QString &displayName = QString());
228 
229 private:
230     QExplicitlySharedDataPointer<KWPageStylePrivate> d;
231 };
232 
233 WORDS_TEST_EXPORT uint qHash(const KWPageStyle &style);
234 
235 #endif
236