File indexing completed on 2025-01-12 13:05:33

0001 /*
0002  *  Copyright (c) 2010 Sebastian Sauer <sebsauer@kdab.com>
0003  *  Copyright (c) 2010 Carlos Licea <carlos@kdab.com>
0004  *  Copyright (c) 2014-2015 Inge Wallin <inge@lysator.liu.se>
0005  *
0006  *  This library is free software; you can redistribute it and/or modify
0007  *  it under the terms of the GNU Lesser General Public License as published
0008  *  by the Free Software Foundation; either version 2.1 of the License, or
0009  *  (at your option) any later version.
0010  *
0011  *  This library is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  *  GNU Lesser General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU Lesser General Public License
0017  *  along with this program; if not, write to the Free Software
0018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef KOODFCHARTWRITER_H
0022 #define KOODFCHARTWRITER_H
0023 
0024 #include <Charting.h>
0025 
0026 #include "koodf2_export.h"
0027 
0028 class KoStore;
0029 class KoXmlWriter;
0030 class KoGenStyles;
0031 class KoGenStyle;
0032 
0033 
0034 class KOODF2_EXPORT KoOdfChartWriter
0035 {
0036 public:
0037     explicit KoOdfChartWriter(KoChart::Chart* chart);
0038     virtual ~KoOdfChartWriter();
0039 
0040     KoChart::Chart* chart() const { return m_chart; }
0041 
0042     void setSheetReplacement(bool val);
0043 
0044     void set2003ColorPalette(QList< QColor > palette);
0045     QString markerType(KoChart::MarkerType type, int currentSeriesNumber);
0046 
0047     bool m_drawLayer;
0048     QString m_href;
0049     QString m_cellRangeAddress;
0050     QString m_endCellAddress;
0051     QString m_notifyOnUpdateOfRanges;
0052 #if 0
0053     /// anchored to sheet
0054     QString m_sheetName;
0055     /// anchored to cell
0056     //unsigned long m_colL, m_rwT;
0057 #endif
0058     qreal m_x, m_y, m_width, m_height; //in pt
0059     qreal m_end_x, m_end_y; //in pt
0060 
0061     // Saving of content
0062             bool saveIndex(KoXmlWriter* xmlWriter);
0063     virtual bool saveContent(KoStore* store, KoXmlWriter* manifestWriter);
0064     virtual bool saveSeries(KoGenStyles &styles, KoGenStyles &mainStyles, KoXmlWriter* bodyWriter,
0065                 int maxExplode);
0066 
0067     // helper functions
0068     qreal calculateFade(int index, int maxIndex);
0069     QColor shadeColor(const QColor& col, qreal factor);
0070 
0071 protected:
0072     KoChart::Chart* m_chart;
0073 
0074     QString normalizeCellRange(QString range);
0075     QString toPtString(int number);
0076     enum Orientation {
0077         vertical,
0078         horizontal
0079     };
0080     float sprcToPt(int sprc, Orientation orientation);
0081     QColor tintColor(const QColor & color, qreal tintfactor);
0082     QString replaceSheet(const QString &originalString, const QString &replacementSheet);
0083     bool sheetReplacement;
0084 
0085     // Style generation
0086             QString genChartAreaStyle(KoGenStyles& styles, KoGenStyles& mainStyles);
0087     virtual QString genChartAreaStyle(KoGenStyle& style, KoGenStyles& styles,
0088                       KoGenStyles& mainStyles);
0089             QString genPlotAreaStyle(KoGenStyles& styles, KoGenStyles& mainStyles);
0090     virtual QString genPlotAreaStyle(KoGenStyle& style, KoGenStyles& styles,
0091                      KoGenStyles& mainStyles);
0092             void addShapePropertyStyle(/*const*/ KoChart::Series* series,
0093                        KoGenStyle& style, KoGenStyles& mainStyles);
0094     virtual void addDataThemeToStyle(KoGenStyle& style,
0095                      int dataNumber, int maxNumData = 1, bool strokes = true);
0096 
0097     QString generateGradientStyle(KoGenStyles& mainStyles, const KoChart::Gradient* grad);
0098 
0099     // Color functions
0100     virtual QColor calculateColorFromGradientStop(const KoChart::Gradient::GradientStop& grad);
0101     virtual QColor labelFontColor() const;
0102     void writeInternalTable(KoXmlWriter* bodyWriter);
0103 
0104     // MS Office related stuff
0105     QList<QColor> m_palette;
0106     // tells if a 2003 color palette has been set
0107     bool paletteIsSet;
0108 };
0109 
0110 #endif  // KOODFCHARTWRITER_H