andre@1: /**************************************************************************** andre@1: ** Copyright (c) 2013-2014 Debao Zhang andre@1: ** All right reserved. andre@1: ** andre@1: ** Permission is hereby granted, free of charge, to any person obtaining andre@1: ** a copy of this software and associated documentation files (the andre@1: ** "Software"), to deal in the Software without restriction, including andre@1: ** without limitation the rights to use, copy, modify, merge, publish, andre@1: ** distribute, sublicense, and/or sell copies of the Software, and to andre@1: ** permit persons to whom the Software is furnished to do so, subject to andre@1: ** the following conditions: andre@1: ** andre@1: ** The above copyright notice and this permission notice shall be andre@1: ** included in all copies or substantial portions of the Software. andre@1: ** andre@1: ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, andre@1: ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF andre@1: ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND andre@1: ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE andre@1: ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION andre@1: ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION andre@1: ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. andre@1: ** andre@1: ****************************************************************************/ andre@1: #include "xlsxformat.h" andre@1: #include "xlsxformat_p.h" andre@1: #include "xlsxcolor_p.h" andre@1: #include "xlsxnumformatparser_p.h" andre@1: #include andre@1: #include andre@1: andre@1: QT_BEGIN_NAMESPACE_XLSX andre@1: andre@1: FormatPrivate::FormatPrivate() andre@1: : dirty(true) andre@1: , font_dirty(true), font_index_valid(false), font_index(0) andre@1: , fill_dirty(true), fill_index_valid(false), fill_index(0) andre@1: , border_dirty(true), border_index_valid(false), border_index(0) andre@1: , xf_index(-1), xf_indexValid(false) andre@1: , is_dxf_fomat(false), dxf_index(-1), dxf_indexValid(false) andre@1: , theme(0) andre@1: { andre@1: } andre@1: andre@1: FormatPrivate::FormatPrivate(const FormatPrivate &other) andre@1: : QSharedData(other) andre@1: , dirty(other.dirty), formatKey(other.formatKey) andre@1: , font_dirty(other.font_dirty), font_index_valid(other.font_index_valid), font_key(other.font_key), font_index(other.font_index) andre@1: , fill_dirty(other.fill_dirty), fill_index_valid(other.fill_index_valid), fill_key(other.fill_key), fill_index(other.fill_index) andre@1: , border_dirty(other.border_dirty), border_index_valid(other.border_index_valid), border_key(other.border_key), border_index(other.border_index) andre@1: , xf_index(other.xf_index), xf_indexValid(other.xf_indexValid) andre@1: , is_dxf_fomat(other.is_dxf_fomat), dxf_index(other.dxf_index), dxf_indexValid(other.dxf_indexValid) andre@1: , theme(other.theme) andre@1: , properties(other.properties) andre@1: { andre@1: andre@1: } andre@1: andre@1: FormatPrivate::~FormatPrivate() andre@1: { andre@1: andre@1: } andre@1: andre@1: /*! andre@1: * \class Format andre@1: * \inmodule QtXlsx andre@1: * \brief Providing the methods and properties that are available for formatting cells in Excel. andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::FontScript andre@1: * andre@1: * The enum type defines the type of font script. andre@1: * andre@1: * \value FontScriptNormal normal andre@1: * \value FontScriptSuper super script andre@1: * \value FontScriptSub sub script andre@1: */ andre@1: andre@1: andre@1: /*! andre@1: * \enum Format::FontUnderline andre@1: * andre@1: * The enum type defines the type of font underline. andre@1: * andre@1: * \value FontUnderlineNone andre@1: * \value FontUnderlineSingle andre@1: * \value FontUnderlineDouble andre@1: * \value FontUnderlineSingleAccounting andre@1: * \value FontUnderlineDoubleAccounting andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::HorizontalAlignment andre@1: * andre@1: * The enum type defines the type of horizontal alignment. andre@1: * andre@1: * \value AlignHGeneral andre@1: * \value AlignLeft andre@1: * \value AlignHCenter andre@1: * \value AlignRight andre@1: * \value AlignHFill andre@1: * \value AlignHJustify andre@1: * \value AlignHMerge andre@1: * \value AlignHDistributed andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::VerticalAlignment andre@1: * andre@1: * The enum type defines the type of vertical alignment. andre@1: * andre@1: * \value AlignTop, andre@1: * \value AlignVCenter, andre@1: * \value AlignBottom, andre@1: * \value AlignVJustify, andre@1: * \value AlignVDistributed andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::BorderStyle andre@1: * andre@1: * The enum type defines the type of font underline. andre@1: * andre@1: * \value BorderNone andre@1: * \value BorderThin andre@1: * \value BorderMedium andre@1: * \value BorderDashed andre@1: * \value BorderDotted andre@1: * \value BorderThick andre@1: * \value BorderDouble andre@1: * \value BorderHair andre@1: * \value BorderMediumDashed andre@1: * \value BorderDashDot andre@1: * \value BorderMediumDashDot andre@1: * \value BorderDashDotDot andre@1: * \value BorderMediumDashDotDot andre@1: * \value BorderSlantDashDot andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::DiagonalBorderType andre@1: * andre@1: * The enum type defines the type of diagonal border. andre@1: * andre@1: * \value DiagonalBorderNone andre@1: * \value DiagonalBorderDown andre@1: * \value DiagonalBorderUp andre@1: * \value DiagnoalBorderBoth andre@1: */ andre@1: andre@1: /*! andre@1: * \enum Format::FillPattern andre@1: * andre@1: * The enum type defines the type of fill. andre@1: * andre@1: * \value PatternNone andre@1: * \value PatternSolid andre@1: * \value PatternMediumGray andre@1: * \value PatternDarkGray andre@1: * \value PatternLightGray andre@1: * \value PatternDarkHorizontal andre@1: * \value PatternDarkVertical andre@1: * \value PatternDarkDown andre@1: * \value PatternDarkUp andre@1: * \value PatternDarkGrid andre@1: * \value PatternDarkTrellis andre@1: * \value PatternLightHorizontal andre@1: * \value PatternLightVertical andre@1: * \value PatternLightDown andre@1: * \value PatternLightUp andre@1: * \value PatternLightTrellis andre@1: * \value PatternGray125 andre@1: * \value PatternGray0625 andre@1: * \value PatternLightGrid andre@1: */ andre@1: andre@1: /*! andre@1: * Creates a new invalid format. andre@1: */ andre@1: Format::Format() andre@1: { andre@1: //The d pointer is initialized with a null pointer andre@1: } andre@1: andre@1: /*! andre@1: Creates a new format with the same attributes as the \a other format. andre@1: */ andre@1: Format::Format(const Format &other) andre@1: :d(other.d) andre@1: { andre@1: andre@1: } andre@1: andre@1: /*! andre@1: Assigns the \a other format to this format, and returns a andre@1: reference to this format. andre@1: */ andre@1: Format &Format::operator =(const Format &other) andre@1: { andre@1: d = other.d; andre@1: return *this; andre@1: } andre@1: andre@1: /*! andre@1: * Destroys this format. andre@1: */ andre@1: Format::~Format() andre@1: { andre@1: } andre@1: andre@1: /*! andre@1: * Returns the number format identifier. andre@1: */ andre@1: int Format::numberFormatIndex() const andre@1: { andre@1: return intProperty(FormatPrivate::P_NumFmt_Id, 0); andre@1: } andre@1: andre@1: /*! andre@1: * Set the number format identifier. The \a format andre@1: * must be a valid built-in number format identifier andre@1: * or the identifier of a custom number format. andre@1: */ andre@1: void Format::setNumberFormatIndex(int format) andre@1: { andre@1: setProperty(FormatPrivate::P_NumFmt_Id, format); andre@1: clearProperty(FormatPrivate::P_NumFmt_FormatCode); andre@1: } andre@1: andre@1: /*! andre@1: * Returns the number format string. andre@1: * \note for built-in number formats, this may andre@1: * return an empty string. andre@1: */ andre@1: QString Format::numberFormat() const andre@1: { andre@1: return stringProperty(FormatPrivate::P_NumFmt_FormatCode); andre@1: } andre@1: andre@1: /*! andre@1: * Set number \a format. andre@1: * http://office.microsoft.com/en-001/excel-help/create-a-custom-number-format-HP010342372.aspx andre@1: */ andre@1: void Format::setNumberFormat(const QString &format) andre@1: { andre@1: if (format.isEmpty()) andre@1: return; andre@1: setProperty(FormatPrivate::P_NumFmt_FormatCode, format); andre@1: clearProperty(FormatPrivate::P_NumFmt_Id); //numFmt id must be re-generated. andre@1: } andre@1: andre@1: /*! andre@1: * Returns whether the number format is probably a dateTime or not andre@1: */ andre@1: bool Format::isDateTimeFormat() const andre@1: { andre@1: if (hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { andre@1: //Custom numFmt, so andre@1: //Gauss from the number string andre@1: return NumFormatParser::isDateTime(numberFormat()); andre@1: } else if (hasProperty(FormatPrivate::P_NumFmt_Id)){ andre@1: //Non-custom numFmt andre@1: int idx = numberFormatIndex(); andre@1: andre@1: //Is built-in date time number id? andre@1: if ((idx >= 14 && idx <= 22) || (idx >= 45 && idx <= 47)) andre@1: return true; andre@1: andre@1: if ((idx >= 27 && idx <= 36) || (idx >= 50 && idx <= 58)) //Used in CHS\CHT\JPN\KOR andre@1: return true; andre@1: } andre@1: andre@1: return false; andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Set a custom num \a format with the given \a id. andre@1: */ andre@1: void Format::setNumberFormat(int id, const QString &format) andre@1: { andre@1: setProperty(FormatPrivate::P_NumFmt_Id, id); andre@1: setProperty(FormatPrivate::P_NumFmt_FormatCode, format); andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Called by styles to fix the numFmt andre@1: */ andre@1: void Format::fixNumberFormat(int id, const QString &format) andre@1: { andre@1: setProperty(FormatPrivate::P_NumFmt_Id, id, 0, false); andre@1: setProperty(FormatPrivate::P_NumFmt_FormatCode, format, QString(), false); andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Return true if the format has number format. andre@1: */ andre@1: bool Format::hasNumFmtData() const andre@1: { andre@1: if (!d) andre@1: return false; andre@1: andre@1: if (hasProperty(FormatPrivate::P_NumFmt_Id) andre@1: || hasProperty(FormatPrivate::P_NumFmt_FormatCode)) { andre@1: return true; andre@1: } andre@1: return false; andre@1: } andre@1: andre@1: /*! andre@1: * Return the size of the font in points. andre@1: */ andre@1: int Format::fontSize() const andre@1: { andre@1: return intProperty(FormatPrivate::P_Font_Size); andre@1: } andre@1: andre@1: /*! andre@1: * Set the \a size of the font in points. andre@1: */ andre@1: void Format::setFontSize(int size) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Size, size, 0); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the font is italic. andre@1: */ andre@1: bool Format::fontItalic() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Font_Italic); andre@1: } andre@1: andre@1: /*! andre@1: * Turn on/off the italic font based on \a italic. andre@1: */ andre@1: void Format::setFontItalic(bool italic) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Italic, italic, false); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the font is strikeout. andre@1: */ andre@1: bool Format::fontStrikeOut() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Font_StrikeOut); andre@1: } andre@1: andre@1: /*! andre@1: * Turn on/off the strikeOut font based on \a strikeOut. andre@1: */ andre@1: void Format::setFontStrikeOut(bool strikeOut) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_StrikeOut, strikeOut, false); andre@1: } andre@1: andre@1: /*! andre@1: * Return the color of the font. andre@1: */ andre@1: QColor Format::fontColor() const andre@1: { andre@1: if (hasProperty(FormatPrivate::P_Font_Color)) andre@1: return colorProperty(FormatPrivate::P_Font_Color); andre@1: return QColor(); andre@1: } andre@1: andre@1: /*! andre@1: * Set the \a color of the font. andre@1: */ andre@1: void Format::setFontColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Color, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the font is bold. andre@1: */ andre@1: bool Format::fontBold() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Font_Bold); andre@1: } andre@1: andre@1: /*! andre@1: * Turn on/off the bold font based on the given \a bold. andre@1: */ andre@1: void Format::setFontBold(bool bold) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Bold, bold, false); andre@1: } andre@1: andre@1: /*! andre@1: * Return the script style of the font. andre@1: */ andre@1: Format::FontScript Format::fontScript() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Font_Script)); andre@1: } andre@1: andre@1: /*! andre@1: * Set the script style of the font to \a script. andre@1: */ andre@1: void Format::setFontScript(FontScript script) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Script, script, FontScriptNormal); andre@1: } andre@1: andre@1: /*! andre@1: * Return the underline style of the font. andre@1: */ andre@1: Format::FontUnderline Format::fontUnderline() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Font_Underline)); andre@1: } andre@1: andre@1: /*! andre@1: * Set the underline style of the font to \a underline. andre@1: */ andre@1: void Format::setFontUnderline(FontUnderline underline) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Underline, underline, FontUnderlineNone); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the font is outline. andre@1: */ andre@1: bool Format::fontOutline() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Font_Outline); andre@1: } andre@1: andre@1: /*! andre@1: * Turn on/off the outline font based on \a outline. andre@1: */ andre@1: void Format::setFontOutline(bool outline) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Outline, outline, false); andre@1: } andre@1: andre@1: /*! andre@1: * Return the name of the font. andre@1: */ andre@1: QString Format::fontName() const andre@1: { andre@1: return stringProperty(FormatPrivate::P_Font_Name, QStringLiteral("Calibri")); andre@1: } andre@1: andre@1: /*! andre@1: * Set the name of the font to \a name. andre@1: */ andre@1: void Format::setFontName(const QString &name) andre@1: { andre@1: setProperty(FormatPrivate::P_Font_Name, name, QStringLiteral("Calibri")); andre@1: } andre@1: andre@1: /*! andre@1: * Returns a QFont object based on font data contained in the format. andre@1: */ andre@1: QFont Format::font() const andre@1: { andre@1: QFont font; andre@1: font.setFamily(fontName()); andre@1: if (fontSize() > 0) andre@1: font.setPointSize(fontSize()); andre@1: font.setBold(fontBold()); andre@1: font.setItalic(fontItalic()); andre@1: font.setUnderline(fontUnderline()!=FontUnderlineNone); andre@1: font.setStrikeOut(fontStrikeOut()); andre@1: return font; andre@1: } andre@1: andre@1: /*! andre@1: * Set the format properties from the given \a font. andre@1: */ andre@1: void Format::setFont(const QFont &font) andre@1: { andre@1: setFontName(font.family()); andre@1: if (font.pointSize() > 0) andre@1: setFontSize(font.pointSize()); andre@1: setFontBold(font.bold()); andre@1: setFontItalic(font.italic()); andre@1: setFontUnderline(font.underline() ? FontUnderlineSingle : FontUnderlineNone); andre@1: setFontStrikeOut(font.strikeOut()); andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: * When the format has font data, when need to assign a valid index for it. andre@1: * The index value is depend on the order in styles.xml andre@1: */ andre@1: bool Format::fontIndexValid() const andre@1: { andre@1: if (!hasFontData()) andre@1: return false; andre@1: return d->font_index_valid; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: int Format::fontIndex() const andre@1: { andre@1: if (fontIndexValid()) andre@1: return d->font_index; andre@1: andre@1: return 0; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: void Format::setFontIndex(int index) andre@1: { andre@1: d->font_index = index; andre@1: d->font_index_valid = true; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: QByteArray Format::fontKey() const andre@1: { andre@1: if (isEmpty()) andre@1: return QByteArray(); andre@1: andre@1: if (d->font_dirty) { andre@1: QByteArray key; andre@1: QDataStream stream(&key, QIODevice::WriteOnly); andre@1: for (int i=FormatPrivate::P_Font_STARTID; iproperties.contains(i)) andre@1: stream << i << d->properties[i]; andre@1: }; andre@1: andre@1: const_cast(this)->d->font_key = key; andre@1: const_cast(this)->d->font_dirty = false; andre@1: } andre@1: andre@1: return d->font_key; andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Return true if the format has font format, otherwise return false. andre@1: */ andre@1: bool Format::hasFontData() const andre@1: { andre@1: if (!d) andre@1: return false; andre@1: andre@1: for (int i=FormatPrivate::P_Font_STARTID; i(intProperty(FormatPrivate::P_Alignment_AlignH, AlignHGeneral)); andre@1: } andre@1: andre@1: /*! andre@1: * Set the horizontal alignment with the given \a align. andre@1: */ andre@1: void Format::setHorizontalAlignment(HorizontalAlignment align) andre@1: { andre@1: if (hasProperty(FormatPrivate::P_Alignment_Indent) andre@1: &&(align != AlignHGeneral && align != AlignLeft && align != AlignRight && align != AlignHDistributed)) { andre@1: clearProperty(FormatPrivate::P_Alignment_Indent); andre@1: } andre@1: andre@1: if (hasProperty(FormatPrivate::P_Alignment_ShinkToFit) andre@1: && (align == AlignHFill || align == AlignHJustify || align == AlignHDistributed)) { andre@1: clearProperty(FormatPrivate::P_Alignment_ShinkToFit); andre@1: } andre@1: andre@1: setProperty(FormatPrivate::P_Alignment_AlignH, align, AlignHGeneral); andre@1: } andre@1: andre@1: /*! andre@1: * Return the vertical alignment. andre@1: */ andre@1: Format::VerticalAlignment Format::verticalAlignment() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Alignment_AlignV, AlignBottom)); andre@1: } andre@1: andre@1: /*! andre@1: * Set the vertical alignment with the given \a align. andre@1: */ andre@1: void Format::setVerticalAlignment(VerticalAlignment align) andre@1: { andre@1: setProperty(FormatPrivate::P_Alignment_AlignV, align, AlignBottom); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the cell text is wrapped. andre@1: */ andre@1: bool Format::textWrap() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Alignment_Wrap); andre@1: } andre@1: andre@1: /*! andre@1: * Enable the text wrap if \a wrap is true. andre@1: */ andre@1: void Format::setTextWarp(bool wrap) andre@1: { andre@1: if (wrap && hasProperty(FormatPrivate::P_Alignment_ShinkToFit)) andre@1: clearProperty(FormatPrivate::P_Alignment_ShinkToFit); andre@1: andre@1: setProperty(FormatPrivate::P_Alignment_Wrap, wrap, false); andre@1: } andre@1: andre@1: /*! andre@1: * Return the text rotation. andre@1: */ andre@1: int Format::rotation() const andre@1: { andre@1: return intProperty(FormatPrivate::P_Alignment_Rotation); andre@1: } andre@1: andre@1: /*! andre@1: * Set the text roation with the given \a rotation. Must be in the range [0, 180] or 255. andre@1: */ andre@1: void Format::setRotation(int rotation) andre@1: { andre@1: setProperty(FormatPrivate::P_Alignment_Rotation, rotation, 0); andre@1: } andre@1: andre@1: /*! andre@1: * Return the text indentation level. andre@1: */ andre@1: int Format::indent() const andre@1: { andre@1: return intProperty(FormatPrivate::P_Alignment_Indent); andre@1: } andre@1: andre@1: /*! andre@1: * Set the text indentation level with the given \a indent. Must be less than or equal to 15. andre@1: */ andre@1: void Format::setIndent(int indent) andre@1: { andre@1: if (indent && hasProperty(FormatPrivate::P_Alignment_AlignH)) { andre@1: HorizontalAlignment hl = horizontalAlignment(); andre@1: andre@1: if (hl != AlignHGeneral && hl != AlignLeft && hl!= AlignRight && hl!= AlignHJustify) { andre@1: setHorizontalAlignment(AlignLeft); andre@1: } andre@1: } andre@1: andre@1: setProperty(FormatPrivate::P_Alignment_Indent, indent, 0); andre@1: } andre@1: andre@1: /*! andre@1: * Return whether the cell is shrink to fit. andre@1: */ andre@1: bool Format::shrinkToFit() const andre@1: { andre@1: return boolProperty(FormatPrivate::P_Alignment_ShinkToFit); andre@1: } andre@1: andre@1: /*! andre@1: * Turn on/off shrink to fit base on \a shink. andre@1: */ andre@1: void Format::setShrinkToFit(bool shink) andre@1: { andre@1: if (shink && hasProperty(FormatPrivate::P_Alignment_Wrap)) andre@1: clearProperty(FormatPrivate::P_Alignment_Wrap); andre@1: andre@1: if (shink && hasProperty(FormatPrivate::P_Alignment_AlignH)) { andre@1: HorizontalAlignment hl = horizontalAlignment(); andre@1: if (hl == AlignHFill || hl == AlignHJustify || hl == AlignHDistributed) andre@1: setHorizontalAlignment(AlignLeft); andre@1: } andre@1: andre@1: setProperty(FormatPrivate::P_Alignment_ShinkToFit, shink, false); andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: bool Format::hasAlignmentData() const andre@1: { andre@1: if (!d) andre@1: return false; andre@1: andre@1: for (int i=FormatPrivate::P_Alignment_STARTID; i(intProperty(FormatPrivate::P_Border_LeftStyle)); andre@1: } andre@1: andre@1: /*! andre@1: * Sets the left border style to \a style andre@1: */ andre@1: void Format::setLeftBorderStyle(BorderStyle style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_LeftStyle, style, BorderNone); andre@1: } andre@1: andre@1: /*! andre@1: * Returns the left border color andre@1: */ andre@1: QColor Format::leftBorderColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Border_LeftColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the left border color to the given \a color andre@1: */ andre@1: void Format::setLeftBorderColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_LeftColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: Returns the right border style. andre@1: */ andre@1: Format::BorderStyle Format::rightBorderStyle() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Border_RightStyle)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the right border style to the given \a style. andre@1: */ andre@1: void Format::setRightBorderStyle(BorderStyle style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_RightStyle, style, BorderNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the right border color. andre@1: */ andre@1: QColor Format::rightBorderColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Border_RightColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the right border color to the given \a color andre@1: */ andre@1: void Format::setRightBorderColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_RightColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: Returns the top border style. andre@1: */ andre@1: Format::BorderStyle Format::topBorderStyle() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Border_TopStyle)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the top border style to the given \a style. andre@1: */ andre@1: void Format::setTopBorderStyle(BorderStyle style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_TopStyle, style, BorderNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the top border color. andre@1: */ andre@1: QColor Format::topBorderColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Border_TopColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the top border color to the given \a color. andre@1: */ andre@1: void Format::setTopBorderColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_TopColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: Returns the bottom border style. andre@1: */ andre@1: Format::BorderStyle Format::bottomBorderStyle() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Border_BottomStyle)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the bottom border style to the given \a style. andre@1: */ andre@1: void Format::setBottomBorderStyle(BorderStyle style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_BottomStyle, style, BorderNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the bottom border color. andre@1: */ andre@1: QColor Format::bottomBorderColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Border_BottomColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the bottom border color to the given \a color. andre@1: */ andre@1: void Format::setBottomBorderColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_BottomColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: Return the diagonla border style. andre@1: */ andre@1: Format::BorderStyle Format::diagonalBorderStyle() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Border_DiagonalStyle)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the diagonal border style to the given \a style. andre@1: */ andre@1: void Format::setDiagonalBorderStyle(BorderStyle style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_DiagonalStyle, style, BorderNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the diagonal border type. andre@1: */ andre@1: Format::DiagonalBorderType Format::diagonalBorderType() const andre@1: { andre@1: return static_cast(intProperty(FormatPrivate::P_Border_DiagonalType)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the diagonal border type to the given \a style andre@1: */ andre@1: void Format::setDiagonalBorderType(DiagonalBorderType style) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_DiagonalType, style, DiagonalBorderNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the diagonal border color. andre@1: */ andre@1: QColor Format::diagonalBorderColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Border_DiagonalColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the diagonal border color to the given \a color andre@1: */ andre@1: void Format::setDiagonalBorderColor(const QColor &color) andre@1: { andre@1: setProperty(FormatPrivate::P_Border_DiagonalColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Returns whether this format has been set valid border index. andre@1: */ andre@1: bool Format::borderIndexValid() const andre@1: { andre@1: if (!hasBorderData()) andre@1: return false; andre@1: return d->border_index_valid; andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Returns the border index. andre@1: */ andre@1: int Format::borderIndex() const andre@1: { andre@1: if (borderIndexValid()) andre@1: return d->border_index; andre@1: return 0; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: void Format::setBorderIndex(int index) andre@1: { andre@1: d->border_index = index; andre@1: d->border_index_valid = true; andre@1: } andre@1: andre@1: /*! \internal andre@1: */ andre@1: QByteArray Format::borderKey() const andre@1: { andre@1: if (isEmpty()) andre@1: return QByteArray(); andre@1: andre@1: if (d->border_dirty) { andre@1: QByteArray key; andre@1: QDataStream stream(&key, QIODevice::WriteOnly); andre@1: for (int i=FormatPrivate::P_Border_STARTID; iproperties.contains(i)) andre@1: stream << i << d->properties[i]; andre@1: }; andre@1: andre@1: const_cast(this)->d->border_key = key; andre@1: const_cast(this)->d->border_dirty = false; andre@1: } andre@1: andre@1: return d->border_key; andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Return true if the format has border format, otherwise return false. andre@1: */ andre@1: bool Format::hasBorderData() const andre@1: { andre@1: if (!d) andre@1: return false; andre@1: andre@1: for (int i=FormatPrivate::P_Border_STARTID; i(intProperty(FormatPrivate::P_Fill_Pattern, PatternNone)); andre@1: } andre@1: andre@1: /*! andre@1: Sets the fill pattern to the given \a pattern. andre@1: */ andre@1: void Format::setFillPattern(FillPattern pattern) andre@1: { andre@1: setProperty(FormatPrivate::P_Fill_Pattern, pattern, PatternNone); andre@1: } andre@1: andre@1: /*! andre@1: Returns the foreground color of the pattern. andre@1: */ andre@1: QColor Format::patternForegroundColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Fill_FgColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the foreground color of the pattern with the given \a color. andre@1: */ andre@1: void Format::setPatternForegroundColor(const QColor &color) andre@1: { andre@1: if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) andre@1: setFillPattern(PatternSolid); andre@1: setProperty(FormatPrivate::P_Fill_FgColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: Returns the background color of the pattern. andre@1: */ andre@1: QColor Format::patternBackgroundColor() const andre@1: { andre@1: return colorProperty(FormatPrivate::P_Fill_BgColor); andre@1: } andre@1: andre@1: /*! andre@1: Sets the background color of the pattern with the given \a color. andre@1: */ andre@1: void Format::setPatternBackgroundColor(const QColor &color) andre@1: { andre@1: if (color.isValid() && !hasProperty(FormatPrivate::P_Fill_Pattern)) andre@1: setFillPattern(PatternSolid); andre@1: setProperty(FormatPrivate::P_Fill_BgColor, XlsxColor(color), XlsxColor()); andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: bool Format::fillIndexValid() const andre@1: { andre@1: if (!hasFillData()) andre@1: return false; andre@1: return d->fill_index_valid; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: int Format::fillIndex() const andre@1: { andre@1: if (fillIndexValid()) andre@1: return d->fill_index; andre@1: return 0; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: void Format::setFillIndex(int index) andre@1: { andre@1: d->fill_index = index; andre@1: d->fill_index_valid = true; andre@1: } andre@1: andre@1: /*! andre@1: * \internal andre@1: */ andre@1: QByteArray Format::fillKey() const andre@1: { andre@1: if (isEmpty()) andre@1: return QByteArray(); andre@1: andre@1: if (d->fill_dirty) { andre@1: QByteArray key; andre@1: QDataStream stream(&key, QIODevice::WriteOnly); andre@1: for (int i=FormatPrivate::P_Fill_STARTID; iproperties.contains(i)) andre@1: stream << i << d->properties[i]; andre@1: }; andre@1: andre@1: const_cast(this)->d->fill_key = key; andre@1: const_cast(this)->d->fill_dirty = false; andre@1: } andre@1: andre@1: return d->fill_key; andre@1: } andre@1: andre@1: /*! andre@1: \internal andre@1: Return true if the format has fill format, otherwise return false. andre@1: */ andre@1: bool Format::hasFillData() const andre@1: { andre@1: if (!d) andre@1: return false; andre@1: andre@1: for (int i=FormatPrivate::P_Fill_STARTID; i