Warning, file /office/calligra/libs/odf/KoOdfLineNumberingConfiguration.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 0003 Copyright (C) 2010 KO GmbH <boud@kogmbh.com> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License version 2 as published by the Free Software Foundation. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 #include "KoOdfLineNumberingConfiguration.h" 0020 0021 #include <OdfDebug.h> 0022 #include "KoXmlNS.h" 0023 #include "KoUnit.h" 0024 #include "KoXmlWriter.h" 0025 #include "KoOdfNumberDefinition.h" 0026 0027 class Q_DECL_HIDDEN KoOdfLineNumberingConfiguration::Private 0028 { 0029 public: 0030 bool lineNumberingEnabled; 0031 KoOdfNumberDefinition numberFormat; 0032 QString textStyle; 0033 int increment; 0034 Position position; 0035 int offset; 0036 bool countEmptyLines; 0037 bool countLinesInTextBoxes; 0038 bool restartNumberingOnEveryPage; 0039 QString separator; 0040 int separatorIncrement; 0041 }; 0042 0043 KoOdfLineNumberingConfiguration::KoOdfLineNumberingConfiguration() 0044 : d(new Private()) 0045 { 0046 d->lineNumberingEnabled = false; 0047 d->increment = 1; 0048 d->position = Left; 0049 d->offset = 10; 0050 d->countEmptyLines = false; 0051 d->countLinesInTextBoxes = false; 0052 d->separatorIncrement = 5; 0053 } 0054 0055 KoOdfLineNumberingConfiguration::~KoOdfLineNumberingConfiguration() 0056 { 0057 delete d; 0058 } 0059 0060 KoOdfLineNumberingConfiguration::KoOdfLineNumberingConfiguration(const KoOdfLineNumberingConfiguration &other) 0061 : QObject(), d(new Private()) 0062 { 0063 d->lineNumberingEnabled = other.d->lineNumberingEnabled; 0064 d->numberFormat = other.d->numberFormat; 0065 d->textStyle = other.d->textStyle; 0066 d->increment = other.d->increment; 0067 d->position = other.d->position; 0068 d->offset = other.d->offset; 0069 d->countEmptyLines = other.d->countEmptyLines; 0070 d->countLinesInTextBoxes = other.d->countLinesInTextBoxes; 0071 d->restartNumberingOnEveryPage = other.d->restartNumberingOnEveryPage; 0072 d->separator = other.d->separator; 0073 d->separatorIncrement = other.d->separatorIncrement; 0074 } 0075 0076 KoOdfLineNumberingConfiguration &KoOdfLineNumberingConfiguration::operator=(const KoOdfLineNumberingConfiguration &other) 0077 { 0078 d->lineNumberingEnabled = other.d->lineNumberingEnabled; 0079 d->numberFormat = other.d->numberFormat; 0080 d->textStyle = other.d->textStyle; 0081 d->increment = other.d->increment; 0082 d->position = other.d->position; 0083 d->offset = other.d->offset; 0084 d->countEmptyLines = other.d->countEmptyLines; 0085 d->countLinesInTextBoxes = other.d->countLinesInTextBoxes; 0086 d->restartNumberingOnEveryPage = other.d->restartNumberingOnEveryPage; 0087 d->separator = other.d->separator; 0088 d->separatorIncrement = other.d->separatorIncrement; 0089 0090 return *this; 0091 } 0092 0093 0094 void KoOdfLineNumberingConfiguration::loadOdf(const KoXmlElement &element) 0095 { 0096 d->lineNumberingEnabled = element.attributeNS(KoXmlNS::text, "number-lines", "true") == "true"; 0097 d->numberFormat.loadOdf(element); 0098 d->textStyle = element.attributeNS(KoXmlNS::text, "style-name", QString()); 0099 d->increment = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "increment", "1")); 0100 0101 QString position = element.attributeNS(KoXmlNS::text, "position", "left"); 0102 if (position == "left") { 0103 d->position = Left; 0104 } 0105 else if (position == "right") { 0106 d->position = Right; 0107 } 0108 else if (position == "inner") { 0109 d->position = Inner; 0110 } 0111 else if (position == "outer") { 0112 d->position = Outer; 0113 } 0114 0115 d->offset = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "offset", "10")); 0116 d->countEmptyLines = element.attributeNS(KoXmlNS::text, "count-empty-lines", "false") == "true"; 0117 d->countLinesInTextBoxes = element.attributeNS(KoXmlNS::text, "count-in-text-boxes", "false") == "true"; 0118 d->restartNumberingOnEveryPage = element.attributeNS(KoXmlNS::text, "restart-on-page", "false") == "true"; 0119 0120 if(element.hasChildNodes()) { 0121 KoXmlNode node = element.firstChild(); 0122 while(!node.isNull()) { 0123 if(node.isElement()) { 0124 KoXmlElement nodeElement = node.toElement(); 0125 if(nodeElement.localName() == "linenumber-separator") { 0126 d->separator = nodeElement.text(); 0127 d->separatorIncrement = KoUnit::parseValue(element.attributeNS(KoXmlNS::text, "increment", "10")); 0128 break; 0129 } 0130 } 0131 node = node.nextSibling(); 0132 } 0133 } 0134 0135 0136 } 0137 0138 void KoOdfLineNumberingConfiguration::saveOdf(KoXmlWriter *writer) const 0139 { 0140 writer->addAttribute("text:number-lines", "true"); 0141 d->numberFormat.saveOdf(writer); 0142 if (!d->textStyle.isEmpty()) { 0143 writer->addAttribute("text:style-name", d->textStyle); 0144 } 0145 writer->addAttribute("text:increment", d->increment); 0146 switch(d->position) { 0147 case Left: 0148 break; // this is default, don't save 0149 case Right: 0150 writer->addAttribute("text:position", "right"); 0151 break; 0152 case Inner: 0153 writer->addAttribute("text:position", "inner"); 0154 break; 0155 case Outer: 0156 writer->addAttribute("text:position", "outer"); 0157 break; 0158 } 0159 if (d->offset != 10) { writer->addAttribute("text:offset", d->offset); } 0160 if (d->countEmptyLines) { writer->addAttribute("text:count-empty-lines", d->countEmptyLines); } 0161 if (d->countLinesInTextBoxes) { writer->addAttribute("text:count-in-text-boxes", d->countLinesInTextBoxes); } 0162 if (d->restartNumberingOnEveryPage) { writer->addAttribute("text:restart-on-page", d->restartNumberingOnEveryPage); } 0163 if (!d->separator.isNull()) { 0164 writer->startElement("txt:linenumber-separator"); 0165 if (d->separatorIncrement != 10) { writer->addAttribute("text:increment", d->separatorIncrement); } 0166 writer->addTextNode(d->separator); 0167 writer->endElement(); 0168 } 0169 } 0170 0171 bool KoOdfLineNumberingConfiguration::enabled() const 0172 { 0173 return d->lineNumberingEnabled; 0174 } 0175 0176 void KoOdfLineNumberingConfiguration::setEnabled(bool enabled) 0177 { 0178 d->lineNumberingEnabled = enabled; 0179 } 0180 0181 KoOdfNumberDefinition KoOdfLineNumberingConfiguration::numberFormat() const 0182 { 0183 return d->numberFormat; 0184 } 0185 0186 void KoOdfLineNumberingConfiguration::setNumberFormat(const KoOdfNumberDefinition &numberFormat) 0187 { 0188 d->numberFormat = numberFormat; 0189 } 0190 0191 QString KoOdfLineNumberingConfiguration::textStyle() const 0192 { 0193 return d->textStyle; 0194 } 0195 0196 void KoOdfLineNumberingConfiguration::setTextStyle(const QString &textStyle) 0197 { 0198 d->textStyle = textStyle; 0199 } 0200 0201 int KoOdfLineNumberingConfiguration::increment() const 0202 { 0203 return d->increment; 0204 } 0205 0206 void KoOdfLineNumberingConfiguration::setIncrement(int increment) 0207 { 0208 d->increment = increment; 0209 } 0210 0211 KoOdfLineNumberingConfiguration::Position KoOdfLineNumberingConfiguration::position() const 0212 { 0213 return d->position; 0214 } 0215 0216 void KoOdfLineNumberingConfiguration::setPosition(KoOdfLineNumberingConfiguration::Position position) 0217 { 0218 d->position = position; 0219 } 0220 0221 int KoOdfLineNumberingConfiguration::offset() const 0222 { 0223 return d->offset; 0224 } 0225 0226 void KoOdfLineNumberingConfiguration::setOffset(int offset) 0227 { 0228 d->offset = offset; 0229 } 0230 0231 bool KoOdfLineNumberingConfiguration::countEmptyLines() const 0232 { 0233 return d->countEmptyLines; 0234 } 0235 0236 void KoOdfLineNumberingConfiguration::setCountEmptyLines(bool countEmptyLines) 0237 { 0238 d->countEmptyLines = countEmptyLines; 0239 } 0240 0241 bool KoOdfLineNumberingConfiguration::countLinesInTextBoxes() const 0242 { 0243 return d->countLinesInTextBoxes; 0244 } 0245 0246 void KoOdfLineNumberingConfiguration::setCountLinesInTextBoxes(bool countLinesInTextBoxes) 0247 { 0248 d->countLinesInTextBoxes = countLinesInTextBoxes; 0249 } 0250 0251 bool KoOdfLineNumberingConfiguration::restartNumberingOnEveryPage() const 0252 { 0253 return d->restartNumberingOnEveryPage; 0254 } 0255 0256 void KoOdfLineNumberingConfiguration::setRestartNumberingOnEveryPage(bool restartNumberingOnEveryPage) 0257 { 0258 d->restartNumberingOnEveryPage = restartNumberingOnEveryPage; 0259 } 0260 0261 QString KoOdfLineNumberingConfiguration::separator() const 0262 { 0263 return d->separator; 0264 } 0265 0266 void KoOdfLineNumberingConfiguration::setSeparator(const QString &separator) 0267 { 0268 d->separator = separator; 0269 } 0270 0271 int KoOdfLineNumberingConfiguration::separatorIncrement() const 0272 { 0273 return d->separatorIncrement; 0274 } 0275 0276 void KoOdfLineNumberingConfiguration::setSeparatorIncrement(int separatorIncrement) 0277 { 0278 d->separatorIncrement = separatorIncrement; 0279 } 0280