File indexing completed on 2024-12-01 13:11:43
0001 /* 0002 * Copyright (c) 2010 Carlos Licea <carlos@kdab.com> 0003 * 0004 * This library is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU Lesser General Public License as published 0006 * by the Free Software Foundation; either version 2.1 of the License, or 0007 * (at your option) any later version. 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 0012 * GNU Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "KoColumnStyle.h" 0020 #include <KoGenStyle.h> 0021 0022 namespace { 0023 class BreakStyleMap : public QMap<KoColumnStyle::BreakType, QString> 0024 { 0025 public: 0026 BreakStyleMap() 0027 { 0028 insert(KoColumnStyle::NoBreak, QString()); 0029 insert(KoColumnStyle::AutoBreak, "auto"); 0030 insert(KoColumnStyle::ColumnBreak, "column"); 0031 insert(KoColumnStyle::PageBreak, "page"); 0032 } 0033 } breakStyleMap; 0034 0035 const QString prefix = "col"; 0036 const char familyName[] = "table-column"; 0037 } 0038 0039 KOSTYLE_DECLARE_SHARED_POINTER_IMPL(KoColumnStyle) 0040 0041 KoColumnStyle::KoColumnStyle() 0042 : KoStyle() 0043 , m_breakAfter(NoBreak) 0044 , m_breakBefore(NoBreak) 0045 , m_width(15) 0046 , m_widthType(ExactWidth) 0047 { 0048 } 0049 0050 KoColumnStyle::~KoColumnStyle() 0051 { 0052 } 0053 0054 qreal KoColumnStyle::width() const 0055 { 0056 return m_width; 0057 } 0058 0059 void KoColumnStyle::setWidth(qreal width) 0060 { 0061 m_width = width; 0062 } 0063 0064 KoColumnStyle::BreakType KoColumnStyle::breakAfter() const 0065 { 0066 return m_breakAfter; 0067 } 0068 0069 void KoColumnStyle::setBreakAfter(KoColumnStyle::BreakType breakAfter) 0070 { 0071 m_breakAfter = breakAfter; 0072 } 0073 0074 KoColumnStyle::BreakType KoColumnStyle::breakBefore() const 0075 { 0076 return m_breakBefore; 0077 } 0078 0079 void KoColumnStyle::setBreakBefore(KoColumnStyle::BreakType breakBefore) 0080 { 0081 m_breakBefore = breakBefore; 0082 } 0083 0084 void KoColumnStyle::setWidthType(KoColumnStyle::WidthType type) 0085 { 0086 m_widthType = type; 0087 } 0088 0089 KoColumnStyle::WidthType KoColumnStyle::widthType() const 0090 { 0091 return m_widthType; 0092 } 0093 0094 QString KoColumnStyle::defaultPrefix() const 0095 { 0096 return prefix; 0097 } 0098 0099 KoGenStyle::Type KoColumnStyle::styleType() const 0100 { 0101 return KoGenStyle::TableColumnStyle; 0102 } 0103 0104 KoGenStyle::Type KoColumnStyle::automaticstyleType() const 0105 { 0106 return KoGenStyle::TableColumnAutoStyle; 0107 } 0108 0109 const char* KoColumnStyle::styleFamilyName() const 0110 { 0111 return familyName; 0112 } 0113 0114 void KoColumnStyle::prepareStyle(KoGenStyle& style) const 0115 { 0116 if(m_breakAfter != NoBreak) { 0117 style.addProperty("fo:break-after", breakStyleMap.value(m_breakAfter)); 0118 } 0119 if(m_breakBefore != NoBreak) { 0120 style.addProperty("fo:break-before", breakStyleMap.value(m_breakBefore)); 0121 } 0122 0123 switch(m_widthType) { 0124 case MinimumWidth: 0125 style.addPropertyPt("style:min-column-width", m_width); 0126 break; 0127 case ExactWidth: 0128 style.addPropertyPt("style:column-width", m_width); 0129 break; 0130 case OptimalWidth: 0131 style.addProperty("style:use-optimal-column-width", "true"); 0132 break; 0133 } 0134 }