1 /*
2 * Copyright (c) 2010 Carlos Licea <carlos@kdab.com>
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #include "KoCellStyle.h"
20 #include <KoGenStyle.h>
21 #include <KoGenStyles.h>
22
23 namespace {
24 QString prefix = "cell";
25 const char familyName[] = "table-cell";
26 }
27
KOSTYLE_DECLARE_SHARED_POINTER_IMPL(KoCellStyle)28 KOSTYLE_DECLARE_SHARED_POINTER_IMPL(KoCellStyle)
29
30 KoCellStyle::KoCellStyle()
31 : KoStyle()
32 , m_borders(new KoBorder)
33 , m_backgroundColor()
34 , m_backgroundOpacity(0.0)
35 , m_leftPadding(0.0)
36 , m_topPadding(0.0)
37 , m_rightPadding(0.0)
38 , m_bottomPadding(0.0)
39 , m_verticalAlign("")
40 , m_glyphOrientation(true)
41 {
42 }
43
~KoCellStyle()44 KoCellStyle::~KoCellStyle()
45 {
46 delete m_borders;
47 }
48
borders()49 KoBorder* KoCellStyle::borders()
50 {
51 return m_borders;
52 }
53
defaultPrefix() const54 QString KoCellStyle::defaultPrefix() const
55 {
56 return prefix;
57 }
58
styleType() const59 KoGenStyle::Type KoCellStyle::styleType() const
60 {
61 return KoGenStyle::TableCellStyle;
62 }
63
automaticstyleType() const64 KoGenStyle::Type KoCellStyle::automaticstyleType() const
65 {
66 return KoGenStyle::TableCellAutoStyle;
67 }
68
styleFamilyName() const69 const char* KoCellStyle::styleFamilyName() const
70 {
71 return familyName;
72 }
73
backgroundColor() const74 QColor KoCellStyle::backgroundColor() const
75 {
76 return m_backgroundColor;
77 }
78
setBackgroundColor(const QColor & color)79 void KoCellStyle::setBackgroundColor(const QColor& color)
80 {
81 m_backgroundColor = color;
82 }
83
setBackgroundOpacity(qreal opacity)84 void KoCellStyle::setBackgroundOpacity(qreal opacity)
85 {
86 m_backgroundOpacity = opacity;
87 }
88
backgroundOpacity() const89 qreal KoCellStyle::backgroundOpacity() const
90 {
91 return m_backgroundOpacity;
92 }
93
topPadding() const94 qreal KoCellStyle::topPadding() const
95 {
96 return m_topPadding;
97 }
98
setTopPadding(qreal padding)99 void KoCellStyle::setTopPadding(qreal padding)
100 {
101 m_topPadding = padding;
102 }
103
bottomPadding() const104 qreal KoCellStyle::bottomPadding() const
105 {
106 return m_bottomPadding;
107 }
108
setBottomPadding(qreal padding)109 void KoCellStyle::setBottomPadding(qreal padding)
110 {
111 m_bottomPadding = padding;
112 }
113
leftPadding() const114 qreal KoCellStyle::leftPadding() const
115 {
116 return m_leftPadding;
117 }
118
setLeftPadding(qreal padding)119 void KoCellStyle::setLeftPadding(qreal padding)
120 {
121 m_leftPadding = padding;
122 }
123
rightPadding() const124 qreal KoCellStyle::rightPadding() const
125 {
126 return m_rightPadding;
127 }
128
setRightPadding(qreal padding)129 void KoCellStyle::setRightPadding(qreal padding)
130 {
131 m_rightPadding = padding;
132 }
133
verticalAlign() const134 QString KoCellStyle::verticalAlign() const
135 {
136 return m_verticalAlign;
137 }
138
setVerticalAlign(const QString & align)139 void KoCellStyle::setVerticalAlign(const QString& align)
140 {
141 m_verticalAlign = align;
142 }
143
glyphOrientation() const144 bool KoCellStyle::glyphOrientation() const
145 {
146 return m_glyphOrientation;
147 }
148
setGlyphOrientation(bool orientation)149 void KoCellStyle::setGlyphOrientation(bool orientation)
150 {
151 m_glyphOrientation = orientation;
152 }
153
styleProperties() const154 KoGenStyle KoCellStyle::styleProperties() const
155 {
156 return m_styleProperties;
157 }
158
setTextStyle(const KoGenStyle & style)159 void KoCellStyle::setTextStyle(const KoGenStyle& style)
160 {
161 KoGenStyle::copyPropertiesFromStyle(style, m_styleProperties, KoGenStyle::TextType);
162 }
163
setParagraphStyle(const KoGenStyle & style)164 void KoCellStyle::setParagraphStyle(const KoGenStyle& style)
165 {
166 KoGenStyle::copyPropertiesFromStyle(style, m_styleProperties, KoGenStyle::ParagraphType);
167 }
168
prepareStyle(KoGenStyle & style) const169 void KoCellStyle::prepareStyle( KoGenStyle& style ) const
170 {
171 m_borders->saveOdf(style);
172 if (m_backgroundColor.isValid()) {
173 style.addProperty("fo:background-color", m_backgroundColor.name());
174 }
175 if (m_backgroundOpacity != 0.0) {
176 style.addProperty("draw:opacity", QString("%1%").arg(m_backgroundOpacity), KoGenStyle::GraphicType);
177 }
178 if(m_leftPadding != 0) {
179 style.addPropertyPt("fo:padding-left", m_leftPadding);
180 }
181 if(m_topPadding != 0) {
182 style.addPropertyPt("fo:padding-top", m_topPadding);
183 }
184 if(m_rightPadding != 0) {
185 style.addPropertyPt("fo:padding-right", m_rightPadding);
186 }
187 if(m_bottomPadding != 0) {
188 style.addPropertyPt("fo:padding-bottom", m_bottomPadding);
189 }
190 if (!m_verticalAlign.isEmpty()) {
191 style.addProperty("style:vertical-align", m_verticalAlign);
192 }
193 if (!m_glyphOrientation) {
194 style.addProperty("style:glyph-orientation-vertical", "0");
195 }
196 KoGenStyle::copyPropertiesFromStyle(m_styleProperties, style, KoGenStyle::ParagraphType);
197 KoGenStyle::copyPropertiesFromStyle(m_styleProperties, style, KoGenStyle::TextType);
198 }
199