File indexing completed on 2024-05-12 16:29:16

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 "KoCellStyle.h"
0020 #include <KoGenStyle.h>
0021 #include <KoGenStyles.h>
0022 
0023 namespace {
0024     QString prefix = "cell";
0025     const char familyName[] = "table-cell";
0026 }
0027 
0028 KOSTYLE_DECLARE_SHARED_POINTER_IMPL(KoCellStyle)
0029 
0030 KoCellStyle::KoCellStyle()
0031 : KoStyle()
0032 , m_borders(new KoBorder)
0033 , m_backgroundColor()
0034 , m_backgroundOpacity(0.0)
0035 , m_leftPadding(0.0)
0036 , m_topPadding(0.0)
0037 , m_rightPadding(0.0)
0038 , m_bottomPadding(0.0)
0039 , m_verticalAlign("")
0040 , m_glyphOrientation(true)
0041 {
0042 }
0043 
0044 KoCellStyle::~KoCellStyle()
0045 {
0046     delete m_borders;
0047 }
0048 
0049 KoBorder* KoCellStyle::borders()
0050 {
0051     return m_borders;
0052 }
0053 
0054 QString KoCellStyle::defaultPrefix() const
0055 {
0056     return prefix;
0057 }
0058 
0059 KoGenStyle::Type KoCellStyle::styleType() const
0060 {
0061     return KoGenStyle::TableCellStyle;
0062 }
0063 
0064 KoGenStyle::Type KoCellStyle::automaticstyleType() const
0065 {
0066     return KoGenStyle::TableCellAutoStyle;
0067 }
0068 
0069 const char* KoCellStyle::styleFamilyName() const
0070 {
0071     return familyName;
0072 }
0073 
0074 QColor KoCellStyle::backgroundColor() const
0075 {
0076     return m_backgroundColor;
0077 }
0078 
0079 void KoCellStyle::setBackgroundColor(const QColor& color)
0080 {
0081     m_backgroundColor = color;
0082 }
0083 
0084 void KoCellStyle::setBackgroundOpacity(qreal opacity)
0085 {
0086     m_backgroundOpacity = opacity;
0087 }
0088 
0089 qreal KoCellStyle::backgroundOpacity() const
0090 {
0091     return m_backgroundOpacity;
0092 }
0093 
0094 qreal KoCellStyle::topPadding() const
0095 {
0096     return m_topPadding;
0097 }
0098 
0099 void KoCellStyle::setTopPadding(qreal padding)
0100 {
0101     m_topPadding = padding;
0102 }
0103 
0104 qreal KoCellStyle::bottomPadding() const
0105 {
0106     return m_bottomPadding;
0107 }
0108 
0109 void KoCellStyle::setBottomPadding(qreal padding)
0110 {
0111     m_bottomPadding = padding;
0112 }
0113 
0114 qreal KoCellStyle::leftPadding() const
0115 {
0116     return m_leftPadding;
0117 }
0118 
0119 void KoCellStyle::setLeftPadding(qreal padding)
0120 {
0121     m_leftPadding = padding;
0122 }
0123 
0124 qreal KoCellStyle::rightPadding() const
0125 {
0126     return m_rightPadding;
0127 }
0128 
0129 void KoCellStyle::setRightPadding(qreal padding)
0130 {
0131     m_rightPadding = padding;
0132 }
0133 
0134 QString KoCellStyle::verticalAlign() const
0135 {
0136     return m_verticalAlign;
0137 }
0138 
0139 void KoCellStyle::setVerticalAlign(const QString& align)
0140 {
0141     m_verticalAlign = align;
0142 }
0143 
0144 bool KoCellStyle::glyphOrientation() const
0145 {
0146     return m_glyphOrientation;
0147 }
0148 
0149 void KoCellStyle::setGlyphOrientation(bool orientation)
0150 {
0151     m_glyphOrientation = orientation;
0152 }
0153 
0154 KoGenStyle KoCellStyle::styleProperties() const
0155 {
0156     return m_styleProperties;
0157 }
0158 
0159 void KoCellStyle::setTextStyle(const KoGenStyle& style)
0160 {
0161     KoGenStyle::copyPropertiesFromStyle(style, m_styleProperties, KoGenStyle::TextType);
0162 }
0163 
0164 void KoCellStyle::setParagraphStyle(const KoGenStyle& style)
0165 {
0166     KoGenStyle::copyPropertiesFromStyle(style, m_styleProperties, KoGenStyle::ParagraphType);
0167 }
0168 
0169 void KoCellStyle::prepareStyle( KoGenStyle& style ) const
0170 {
0171     m_borders->saveOdf(style);
0172     if (m_backgroundColor.isValid()) {
0173         style.addProperty("fo:background-color", m_backgroundColor.name());
0174     }
0175     if (m_backgroundOpacity != 0.0) {
0176         style.addProperty("draw:opacity", QString("%1%").arg(m_backgroundOpacity), KoGenStyle::GraphicType);
0177     }
0178     if(m_leftPadding != 0) {
0179         style.addPropertyPt("fo:padding-left", m_leftPadding);
0180     }
0181     if(m_topPadding != 0) {
0182         style.addPropertyPt("fo:padding-top", m_topPadding);
0183     }
0184     if(m_rightPadding != 0) {
0185         style.addPropertyPt("fo:padding-right", m_rightPadding);
0186     }
0187     if(m_bottomPadding != 0) {
0188         style.addPropertyPt("fo:padding-bottom", m_bottomPadding);
0189     }
0190     if (!m_verticalAlign.isEmpty()) {
0191         style.addProperty("style:vertical-align", m_verticalAlign);
0192     }
0193     if (!m_glyphOrientation) {
0194         style.addProperty("style:glyph-orientation-vertical", "0");
0195     }
0196     KoGenStyle::copyPropertiesFromStyle(m_styleProperties, style, KoGenStyle::ParagraphType);
0197     KoGenStyle::copyPropertiesFromStyle(m_styleProperties, style, KoGenStyle::TextType);
0198 }