File indexing completed on 2024-05-12 16:37:12
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2006, 2008-2009 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2008 Pierre Ducroquet <pinaraf@pinaraf.info> 0004 * Copyright (C) 2008 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 0022 #ifndef KWPAGESTYLE_H 0023 #define KWPAGESTYLE_H 0024 0025 #include "Words.h" 0026 #include "words_export.h" 0027 0028 #include <KoPageLayout.h> 0029 #include <KoText.h> 0030 0031 #include <QSharedDataPointer> 0032 0033 class KWPageStylePrivate; 0034 class KoShapeBackground; 0035 class KoOdfLoadingContext; 0036 class KoDocumentResourceManager; 0037 struct KoColumns; 0038 0039 /** 0040 * A page style represents a set of all the properties that change the layout and size 0041 * of a page and the text area on it. 0042 * 0043 * For documents that have a main text auto generated we have a lot of little options 0044 * to do that. This class wraps all these options. 0045 * 0046 * Words has one KWPageManager per document, the manager collects all page styles by 0047 * name and allows pages to follow this named style. This means that changing a page 0048 * style will update all pages that are using that page style with the new properties. 0049 * 0050 * The KWPageStyle object is a value class, you can pass it by reference and create it 0051 * on the stack. You should never use 'new' on the KWPageStyle. 0052 * The KWPageStyle is a so called QExplicitlySharedDataPointer, which is best explained 0053 * with a code example; 0054 * @code 0055 * KWPageStyle style1("mystyle"); 0056 * KWPageStyle style2 = style1; 0057 * style1.setHeaderPolicy(Words::HFTypeEvenOdd); // set it on one 0058 * Q_ASSERT(style2.headerPolicy() == Words::HFTypeEvenOdd); // the other changes too 0059 * @endcode 0060 */ 0061 class WORDS_EXPORT KWPageStyle 0062 { 0063 public: 0064 /** 0065 * Creates an empty, invalid page style. 0066 */ 0067 KWPageStyle(); 0068 /** 0069 * constructor, initializing the data to some default values. 0070 * 0071 * \param mastername the master page name for this page style. 0072 * \param displayname the display name for this page style. If not 0073 * defined then the \p mastername will be used as display name. 0074 */ 0075 explicit KWPageStyle(const QString &mastername, const QString &displayname = QString()); 0076 /** 0077 * copy constructor 0078 * 0079 * \p ps the original that will be copied 0080 */ 0081 KWPageStyle(const KWPageStyle &ps); 0082 KWPageStyle &operator=(const KWPageStyle &ps); 0083 /// destructor 0084 ~KWPageStyle(); 0085 0086 /// returns true if the KWPageStyle is valid 0087 bool isValid() const; 0088 0089 /// Specifies the type of pages that a page master should generate. 0090 enum PageUsageType { 0091 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. 0092 LeftPages, ///< style:header-left or style:footer-left elements are ignored. 0093 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. 0094 RightPages ///< style:header-left or style:footer-left elements are ignored. 0095 }; 0096 0097 /** 0098 * Returns the type of pages that should be generated. 0099 */ 0100 PageUsageType pageUsage() const; 0101 0102 /** 0103 * Sets the type of pages that should be generated. 0104 */ 0105 void setPageUsage(PageUsageType pageusage) const; 0106 0107 /** 0108 * Return the current columns settings. 0109 */ 0110 KoColumns columns() const; 0111 /** 0112 * Set the new columns settings 0113 */ 0114 void setColumns(const KoColumns &columns); 0115 0116 /// Return the type of header the pages will get. 0117 Words::HeaderFooterType headerPolicy() const; 0118 /// set the type of header the pages will get. 0119 void setHeaderPolicy(Words::HeaderFooterType p); 0120 0121 /// Return the type of footers the pages will get. 0122 Words::HeaderFooterType footerPolicy() const; 0123 /// Set the type of footers the pages will get. 0124 void setFooterPolicy(Words::HeaderFooterType p); 0125 0126 /// return the distance between the main text and the header 0127 qreal headerDistance() const; 0128 /** 0129 * Set the distance between the main text and the header 0130 * @param distance the distance 0131 */ 0132 void setHeaderDistance(qreal distance); 0133 0134 /// return if a growing header eats the distance first. 0135 bool headerDynamicSpacing() const; 0136 0137 /// set if a growing header eats the distance first. 0138 void setHeaderDynamicSpacing(bool dynamic); 0139 0140 /// return the minimum header height. 0141 qreal headerMinimumHeight() const; 0142 /** 0143 * Set the minimum header height. 0144 * @param height the height 0145 */ 0146 void setHeaderMinimumHeight(qreal height); 0147 0148 /// return the minimum footer height. 0149 qreal footerMinimumHeight() const; 0150 /** 0151 * Set the minimum footer height. 0152 * @param height the height 0153 */ 0154 void setFooterMinimumHeight(qreal height); 0155 0156 /// return the distance between the footer and the frame directly above that (footnote or main) 0157 qreal footerDistance() const; 0158 /** 0159 * Set the distance between the footer and the frame directly above that (footnote or main) 0160 * @param distance the distance 0161 */ 0162 void setFooterDistance(qreal distance); 0163 0164 /// return if a growing footer eats the distance first. 0165 bool footerDynamicSpacing() const; 0166 0167 /// set if a growing footer eats the distance first. 0168 void setFooterDynamicSpacing(bool dynamic); 0169 0170 /// initialize to default settings 0171 void clear(); 0172 0173 /// return the pageLayout applied for these pages 0174 KoPageLayout pageLayout() const; 0175 0176 /// return true if pages of this style can turn into page-spreads 0177 bool isPageSpread() const; 0178 0179 /// set the pageLayout applied for these pages 0180 void setPageLayout(const KoPageLayout &layout); 0181 0182 /// get the master page name for this page style. 0183 QString name() const; 0184 /// get the display name for this page style. 0185 QString displayName() const; 0186 0187 KoText::Direction direction() const; 0188 void setDirection(KoText::Direction direction); 0189 0190 /// Get the background. 0191 QSharedPointer<KoShapeBackground> background() const; 0192 0193 /// set the background/ 0194 void setBackground(QSharedPointer<KoShapeBackground> background); 0195 0196 /// get the next page master style/ 0197 QString nextStyleName() const; 0198 0199 /// set the next page master style/ 0200 void setNextStyleName(const QString &nextStyleName); 0201 0202 /** 0203 * Save this page style to ODF. 0204 */ 0205 KoGenStyle saveOdf() const; 0206 0207 /** 0208 * Load this page style from ODF 0209 */ 0210 void loadOdf(KoOdfLoadingContext &context, const KoXmlElement &masterNode, const KoXmlElement &style, KoDocumentResourceManager *documentResources); 0211 0212 bool operator==(const KWPageStyle &other) const; 0213 inline bool operator!=(const KWPageStyle &other) const { return ! operator==(other); } 0214 uint hash() const; 0215 0216 /// internal 0217 const KWPageStylePrivate *priv() const; 0218 /// internal 0219 KWPageStylePrivate *priv(); 0220 0221 /** 0222 * Detach from shared data and set a new name for this one. 0223 * 0224 * Note that the detached style is not known by the page-manager yet. Use 0225 * KWPageManager::addPageStyle to make the detached page-style permanent. 0226 */ 0227 void detach(const QString &name, const QString &displayName = QString()); 0228 0229 private: 0230 QExplicitlySharedDataPointer<KWPageStylePrivate> d; 0231 }; 0232 0233 WORDS_TEST_EXPORT uint qHash(const KWPageStyle &style); 0234 0235 #endif