Warning, file /office/calligra/libs/odf/KoOdfNotesConfiguration.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 Boudewijn Rempt 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 "KoOdfNotesConfiguration.h" 0020 0021 #include <OdfDebug.h> 0022 #include "KoXmlNS.h" 0023 #include "KoXmlWriter.h" 0024 #include "KoOdfNumberDefinition.h" 0025 0026 class Q_DECL_HIDDEN KoOdfNotesConfiguration::Private 0027 { 0028 public: 0029 KoOdfNotesConfiguration::NoteClass noteClass; 0030 QString citationTextStyleName; 0031 QString citationBodyTextStyleName; 0032 QString defaultNoteParagraphStyleName; 0033 void *citationTextStyle; 0034 void *citationBodyTextStyle; 0035 void *defaultNoteParagraphStyle; 0036 QString masterPageName; 0037 int startValue; 0038 KoOdfNumberDefinition numberFormat; 0039 KoOdfNotesConfiguration::NumberingScheme numberingScheme; 0040 KoOdfNotesConfiguration::FootnotesPosition footnotesPosition; 0041 QString footnotesContinuationForward; 0042 QString footnotesContinuationBackward; 0043 0044 }; 0045 0046 KoOdfNotesConfiguration::KoOdfNotesConfiguration(NoteClass noteClass) 0047 : d(new Private()) 0048 { 0049 d->noteClass = noteClass; 0050 d->startValue = 1; 0051 d->numberingScheme = BeginAtDocument; 0052 d->footnotesPosition = Page; 0053 0054 d->defaultNoteParagraphStyle = 0; 0055 d->citationTextStyle = 0; 0056 d->citationBodyTextStyle = 0; 0057 0058 if (noteClass == KoOdfNotesConfiguration::Footnote) { 0059 d->numberFormat.setFormatSpecification(KoOdfNumberDefinition::Numeric); 0060 d->defaultNoteParagraphStyleName = "Footnote"; 0061 d->citationTextStyleName = "Footnote_20_Symbol"; 0062 d->citationBodyTextStyleName = "Footnote_20_anchor"; 0063 } else { 0064 d->numberFormat.setFormatSpecification(KoOdfNumberDefinition::RomanLowerCase); 0065 d->defaultNoteParagraphStyleName = "Endnote"; 0066 d->citationTextStyleName = "Endnote_20_Symbol"; 0067 d->citationBodyTextStyleName = "Endnote_20_anchor"; 0068 } 0069 } 0070 0071 KoOdfNotesConfiguration::~KoOdfNotesConfiguration() 0072 { 0073 delete d; 0074 } 0075 0076 KoOdfNotesConfiguration::KoOdfNotesConfiguration(const KoOdfNotesConfiguration &other) 0077 : QObject(), d(new Private()) 0078 { 0079 d->noteClass = other.d->noteClass; 0080 d->citationTextStyleName = other.d->citationTextStyleName; 0081 d->citationBodyTextStyleName = other.d->citationBodyTextStyleName; 0082 d->defaultNoteParagraphStyleName = other.d->defaultNoteParagraphStyleName; 0083 d->citationTextStyle = other.d->citationTextStyle; 0084 d->citationBodyTextStyle = other.d->citationBodyTextStyle; 0085 d->defaultNoteParagraphStyle = other.d->defaultNoteParagraphStyle; 0086 d->masterPageName = other.d->masterPageName; 0087 d->startValue = other.d->startValue; 0088 d->numberFormat = other.d->numberFormat; 0089 d->numberingScheme = other.d->numberingScheme; 0090 d->footnotesPosition = other.d->footnotesPosition; 0091 d->footnotesContinuationForward = other.d->footnotesContinuationForward; 0092 d->footnotesContinuationBackward = other.d->footnotesContinuationBackward; 0093 0094 } 0095 0096 KoOdfNotesConfiguration &KoOdfNotesConfiguration::operator=(const KoOdfNotesConfiguration &other) 0097 { 0098 d->noteClass = other.d->noteClass; 0099 d->citationTextStyleName = other.d->citationTextStyleName; 0100 d->citationBodyTextStyleName = other.d->citationBodyTextStyleName; 0101 d->defaultNoteParagraphStyleName = other.d->defaultNoteParagraphStyleName; 0102 d->citationTextStyle = other.d->citationTextStyle; 0103 d->citationBodyTextStyle = other.d->citationBodyTextStyle; 0104 d->defaultNoteParagraphStyle = other.d->defaultNoteParagraphStyle; 0105 d->masterPageName = other.d->masterPageName; 0106 d->startValue = other.d->startValue; 0107 d->numberFormat = other.d->numberFormat; 0108 d->numberingScheme = other.d->numberingScheme; 0109 d->footnotesPosition = other.d->footnotesPosition; 0110 d->footnotesContinuationForward = other.d->footnotesContinuationForward; 0111 d->footnotesContinuationBackward = other.d->footnotesContinuationBackward; 0112 0113 return *this; 0114 } 0115 0116 0117 void KoOdfNotesConfiguration::loadOdf(const KoXmlElement &element) 0118 { 0119 d->citationTextStyleName = element.attributeNS(KoXmlNS::text, "citation-style-name", d->citationTextStyleName); 0120 d->citationBodyTextStyleName = element.attributeNS(KoXmlNS::text, "citation-body-style-name", d->citationBodyTextStyleName); 0121 d->defaultNoteParagraphStyleName = element.attributeNS(KoXmlNS::text, "default-style-name", d->defaultNoteParagraphStyleName); 0122 d->masterPageName = element.attributeNS(KoXmlNS::text, "master-page-name", d->masterPageName); 0123 d->startValue = qMax(1, element.attributeNS(KoXmlNS::text, "start-value", QString::number(d->startValue)).toInt()); 0124 0125 d->numberFormat.loadOdf(element); 0126 0127 QString numberingScheme = element.attributeNS(KoXmlNS::text, "start-numbering-at", "document"); 0128 if (numberingScheme == "document") { 0129 d->numberingScheme = BeginAtDocument; 0130 } 0131 else if (numberingScheme == "chapter") { 0132 d->numberingScheme = BeginAtChapter; 0133 } 0134 else if (numberingScheme == "page") { 0135 d->numberingScheme = BeginAtPage; 0136 } 0137 0138 QString footnotesPosition = element.attributeNS(KoXmlNS::text, "footnotes-position", "page"); 0139 if (footnotesPosition == "text") { 0140 d->footnotesPosition = Text; 0141 } 0142 else if (footnotesPosition == "page") { 0143 d->footnotesPosition = Page; 0144 } 0145 else if (footnotesPosition == "section") { 0146 d->footnotesPosition = Section; 0147 } 0148 else if (footnotesPosition == "document") { 0149 d->footnotesPosition = Document; 0150 } 0151 0152 for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) { 0153 KoXmlElement child = node.toElement(); 0154 if (child.namespaceURI() == KoXmlNS::text) { 0155 if (child.localName() == "note-continuation-notice-forward") { 0156 d->footnotesContinuationForward = child.text(); 0157 } else if (child.localName() == "note-continuation-notice-backward") { 0158 d->footnotesContinuationBackward = child.text(); 0159 } 0160 } 0161 } 0162 } 0163 0164 void KoOdfNotesConfiguration::saveOdf(KoXmlWriter *writer) const 0165 { 0166 writer->startElement("text:notes-configuration"); 0167 0168 if (d->noteClass == Footnote) { 0169 writer->addAttribute("text:note-class", "footnote"); 0170 } 0171 else if (d->noteClass == Endnote) { 0172 writer->addAttribute("text:note-class", "endnote"); 0173 } 0174 if (!d->citationTextStyleName.isNull()) {writer->addAttribute("text:citation-style-name", d->citationTextStyleName); } 0175 if (!d->citationBodyTextStyleName.isNull()) {writer->addAttribute("text:citation-body-style-name", d->citationBodyTextStyleName); } 0176 if (!d->defaultNoteParagraphStyleName.isNull()) {writer->addAttribute("text:default-style-name", d->defaultNoteParagraphStyleName); } 0177 if (!d->masterPageName.isNull()) {writer->addAttribute("text:master-page-name", d->masterPageName); } 0178 if (d->startValue != 0) { writer->addAttribute("text:start-value", d->startValue); } 0179 0180 d->numberFormat.saveOdf(writer); 0181 switch(d->numberingScheme) { 0182 case BeginAtDocument: 0183 writer->addAttribute("text:start-numbering-at", "document"); 0184 break; 0185 case BeginAtChapter: 0186 writer->addAttribute("text:start-numbering-at", "chapter"); 0187 break; 0188 case BeginAtPage: 0189 writer->addAttribute("text:start-numbering-at", "page"); 0190 break; 0191 } 0192 switch(d->footnotesPosition) { 0193 case Text: 0194 writer->addAttribute("text:footnotes-position", "text"); 0195 break; 0196 case Page: 0197 writer->addAttribute("text:footnotes-position", "page"); 0198 break; 0199 case Section: 0200 writer->addAttribute("text:footnotes-position", "section"); 0201 break; 0202 case Document: 0203 writer->addAttribute("text:footnotes-position", "document"); 0204 break; 0205 } 0206 if (!d->footnotesContinuationForward.isNull()) { 0207 writer->startElement("text:note-continuation-notice-forward", false); 0208 writer->addTextNode(d->footnotesContinuationForward); 0209 writer->endElement(); 0210 } 0211 if (!d->footnotesContinuationBackward.isNull()) { 0212 writer->startElement("text:note-continuation-notice-backward", false); 0213 writer->addTextNode(d->footnotesContinuationBackward); 0214 writer->endElement(); 0215 } 0216 0217 writer->endElement(); //text:notes-configuration 0218 } 0219 0220 0221 KoOdfNotesConfiguration::NoteClass KoOdfNotesConfiguration::noteClass() const 0222 { 0223 return d->noteClass; 0224 } 0225 0226 0227 void *KoOdfNotesConfiguration::citationTextStyle() const 0228 { 0229 return d->citationTextStyle; 0230 } 0231 0232 QString KoOdfNotesConfiguration::citationTextStyleName() const 0233 { 0234 return d->citationTextStyleName; 0235 } 0236 0237 void KoOdfNotesConfiguration::setCitationTextStyle(void *citationTextStyle) 0238 { 0239 d->citationTextStyle = citationTextStyle; 0240 } 0241 0242 void *KoOdfNotesConfiguration::citationBodyTextStyle() const 0243 { 0244 return d->citationBodyTextStyle; 0245 } 0246 0247 QString KoOdfNotesConfiguration::citationBodyTextStyleName() const 0248 { 0249 return d->citationBodyTextStyleName; 0250 } 0251 0252 void KoOdfNotesConfiguration::setCitationBodyTextStyle(void *citationBodyTextStyle) 0253 { 0254 d->citationBodyTextStyle = citationBodyTextStyle; 0255 } 0256 0257 void *KoOdfNotesConfiguration::defaultNoteParagraphStyle() const 0258 { 0259 return d->defaultNoteParagraphStyle; 0260 } 0261 0262 QString KoOdfNotesConfiguration::defaultNoteParagraphStyleName() const 0263 { 0264 return d->defaultNoteParagraphStyleName; 0265 } 0266 0267 void KoOdfNotesConfiguration::setDefaultNoteParagraphStyle(void *defaultNoteParagraphStyle) 0268 { 0269 d->defaultNoteParagraphStyle = defaultNoteParagraphStyle; 0270 } 0271 0272 QString KoOdfNotesConfiguration::masterPage() const 0273 { 0274 return d->masterPageName; 0275 } 0276 0277 void KoOdfNotesConfiguration::setMasterPage(const QString &masterPage) 0278 { 0279 d->masterPageName = masterPage; 0280 } 0281 0282 int KoOdfNotesConfiguration::startValue() const 0283 { 0284 return d->startValue; 0285 } 0286 0287 void KoOdfNotesConfiguration::setStartValue(int startValue) 0288 { 0289 d->startValue = qMax(1, startValue); 0290 } 0291 0292 0293 KoOdfNumberDefinition KoOdfNotesConfiguration::numberFormat() const 0294 { 0295 return d->numberFormat; 0296 } 0297 0298 void KoOdfNotesConfiguration::setNumberFormat(const KoOdfNumberDefinition &numberFormat) 0299 { 0300 d->numberFormat = numberFormat; 0301 } 0302 0303 KoOdfNotesConfiguration::NumberingScheme KoOdfNotesConfiguration::numberingScheme() const 0304 { 0305 return d->numberingScheme; 0306 } 0307 0308 void KoOdfNotesConfiguration::setNumberingScheme(NumberingScheme numberingScheme) 0309 { 0310 d->numberingScheme = numberingScheme; 0311 } 0312 0313 KoOdfNotesConfiguration::FootnotesPosition KoOdfNotesConfiguration::footnotesPosition() const 0314 { 0315 return d->footnotesPosition; 0316 } 0317 0318 void KoOdfNotesConfiguration::setFootnotesPosition(FootnotesPosition footnotesPosition) 0319 { 0320 d->footnotesPosition = footnotesPosition; 0321 } 0322 0323 QString KoOdfNotesConfiguration::footnoteContinuationForward() const 0324 { 0325 return d->footnotesContinuationForward; 0326 } 0327 0328 void KoOdfNotesConfiguration::setFootnoteContinuationForward(const QString &footnoteContinuationForward) 0329 { 0330 d->footnotesContinuationForward = footnoteContinuationForward; 0331 } 0332 0333 QString KoOdfNotesConfiguration::footnoteContinuationBackward() const 0334 { 0335 return d->footnotesContinuationBackward; 0336 } 0337 0338 void KoOdfNotesConfiguration::setFootnoteContinuationBackward(const QString &footnoteContinuationBackward) 0339 { 0340 d->footnotesContinuationBackward = footnoteContinuationBackward; 0341 }