File indexing completed on 2024-12-08 12:56:11
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 "KoRowStyle.h" 0020 #include <QActionEvent> 0021 0022 namespace { 0023 class BreakStyleMap : public QMap<KoRowStyle::BreakType, QString> 0024 { 0025 public: 0026 BreakStyleMap() 0027 { 0028 insert(KoRowStyle::NoBreak, QString()); 0029 insert(KoRowStyle::AutoBreak, "auto"); 0030 insert(KoRowStyle::ColumnBreak, "column"); 0031 insert(KoRowStyle::PageBreak, "page"); 0032 } 0033 } breakStyleMap; 0034 0035 class KeepTogetherMap : public QMap<KoRowStyle::KeepTogetherType, QString> 0036 { 0037 public: 0038 KeepTogetherMap() 0039 { 0040 insert(KoRowStyle::DontKeepTogether, QString()); 0041 insert(KoRowStyle::AutoKeepTogether, "auto"); 0042 insert(KoRowStyle::AlwaysKeeptogether, "always"); 0043 } 0044 } keepTogetherMap; 0045 0046 0047 const QString prefix = "row"; 0048 const char familyName[] = "table-row"; 0049 } 0050 0051 KOSTYLE_DECLARE_SHARED_POINTER_IMPL(KoRowStyle) 0052 0053 KoRowStyle::KoRowStyle() 0054 : KoStyle() 0055 , m_backgroundColor() 0056 , m_height(10) 0057 , m_heightType(ExactHeight) 0058 , m_breakAfter(NoBreak) 0059 , m_breakBefore(NoBreak) 0060 , m_keepTogether(DontKeepTogether) 0061 { 0062 } 0063 0064 KoRowStyle::~KoRowStyle() 0065 { 0066 } 0067 0068 void KoRowStyle::setBackgroundColor(const QColor& color) 0069 { 0070 m_backgroundColor = color; 0071 } 0072 0073 QColor KoRowStyle::backgroundColor() const 0074 { 0075 return m_backgroundColor; 0076 } 0077 0078 void KoRowStyle::setBreakAfter(KoRowStyle::BreakType breakAfter) 0079 { 0080 m_breakAfter = breakAfter; 0081 } 0082 0083 KoRowStyle::BreakType KoRowStyle::breakAfter() const 0084 { 0085 return m_breakAfter; 0086 } 0087 0088 void KoRowStyle::setBreakBefore(KoRowStyle::BreakType breakBefore) 0089 { 0090 m_breakBefore = breakBefore; 0091 } 0092 0093 KoRowStyle::BreakType KoRowStyle::breakBefore() const 0094 { 0095 return m_breakBefore; 0096 } 0097 0098 void KoRowStyle::setHeightType(KoRowStyle::HeightType type) 0099 { 0100 m_heightType = type; 0101 } 0102 0103 void KoRowStyle::setHeight(qreal height) 0104 { 0105 m_height = height; 0106 } 0107 0108 qreal KoRowStyle::height() const 0109 { 0110 return m_height; 0111 } 0112 0113 void KoRowStyle::setKeepTogether(KoRowStyle::KeepTogetherType keepTogether) 0114 { 0115 m_keepTogether = keepTogether; 0116 } 0117 0118 KoRowStyle::KeepTogetherType KoRowStyle::keepTogether() const 0119 { 0120 return m_keepTogether; 0121 } 0122 0123 KoGenStyle::Type KoRowStyle::automaticstyleType() const 0124 { 0125 return KoGenStyle::TableRowAutoStyle; 0126 } 0127 0128 KoGenStyle::Type KoRowStyle::styleType() const 0129 { 0130 return KoGenStyle::TableRowStyle; 0131 } 0132 0133 QString KoRowStyle::defaultPrefix() const 0134 { 0135 return prefix; 0136 } 0137 0138 const char* KoRowStyle::styleFamilyName() const 0139 { 0140 return familyName; 0141 } 0142 0143 void KoRowStyle::prepareStyle(KoGenStyle& style) const 0144 { 0145 if(m_breakAfter != NoBreak) { 0146 style.addProperty("fo:break-after", breakStyleMap.value(m_breakAfter)); 0147 } 0148 if(m_breakBefore != NoBreak) { 0149 style.addProperty("fo:break-before", breakStyleMap.value(m_breakBefore)); 0150 } 0151 0152 if(m_keepTogether != DontKeepTogether) { 0153 style.addProperty("fo:keep-together", keepTogetherMap.value(m_keepTogether)); 0154 } 0155 0156 switch(m_heightType) { 0157 case MinimumHeight: 0158 style.addPropertyPt("style:min-row-height", m_height); 0159 break; 0160 case ExactHeight: 0161 style.addPropertyPt("style:row-height", m_height); 0162 break; 0163 case OptimalHeight: 0164 style.addProperty("style:use-optimal-row-height", "true"); 0165 break; 0166 } 0167 }