1 /*
2  *  Copyright (c) 2010 Sebastian Sauer <sebsauer@kdab.com>
3  *  Copyright (c) 2010 Carlos Licea <carlos@kdab.com>
4  *  Copyright (c) 2014-2015 Inge Wallin <inge@lysator.liu.se>
5  *
6  *  This library is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU Lesser General Public License as published
8  *  by the Free Software Foundation; either version 2.1 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KOODFCHARTWRITER_H
22 #define KOODFCHARTWRITER_H
23 
24 #include <Charting.h>
25 
26 #include "koodf2_export.h"
27 
28 class KoStore;
29 class KoXmlWriter;
30 class KoGenStyles;
31 class KoGenStyle;
32 
33 
34 class KOODF2_EXPORT KoOdfChartWriter
35 {
36 public:
37     explicit KoOdfChartWriter(KoChart::Chart* chart);
38     virtual ~KoOdfChartWriter();
39 
chart()40     KoChart::Chart* chart() const { return m_chart; }
41 
42     void setSheetReplacement(bool val);
43 
44     void set2003ColorPalette(QList< QColor > palette);
45     QString markerType(KoChart::MarkerType type, int currentSeriesNumber);
46 
47     bool m_drawLayer;
48     QString m_href;
49     QString m_cellRangeAddress;
50     QString m_endCellAddress;
51     QString m_notifyOnUpdateOfRanges;
52 #if 0
53     /// anchored to sheet
54     QString m_sheetName;
55     /// anchored to cell
56     //unsigned long m_colL, m_rwT;
57 #endif
58     qreal m_x, m_y, m_width, m_height; //in pt
59     qreal m_end_x, m_end_y; //in pt
60 
61     // Saving of content
62             bool saveIndex(KoXmlWriter* xmlWriter);
63     virtual bool saveContent(KoStore* store, KoXmlWriter* manifestWriter);
64     virtual bool saveSeries(KoGenStyles &styles, KoGenStyles &mainStyles, KoXmlWriter* bodyWriter,
65 			    int maxExplode);
66 
67     // helper functions
68     qreal calculateFade(int index, int maxIndex);
69     QColor shadeColor(const QColor& col, qreal factor);
70 
71 protected:
72     KoChart::Chart* m_chart;
73 
74     QString normalizeCellRange(QString range);
75     QString toPtString(int number);
76     enum Orientation {
77         vertical,
78         horizontal
79     };
80     float sprcToPt(int sprc, Orientation orientation);
81     QColor tintColor(const QColor & color, qreal tintfactor);
82     QString replaceSheet(const QString &originalString, const QString &replacementSheet);
83     bool sheetReplacement;
84 
85     // Style generation
86             QString genChartAreaStyle(KoGenStyles& styles, KoGenStyles& mainStyles);
87     virtual QString genChartAreaStyle(KoGenStyle& style, KoGenStyles& styles,
88 				      KoGenStyles& mainStyles);
89             QString genPlotAreaStyle(KoGenStyles& styles, KoGenStyles& mainStyles);
90     virtual QString genPlotAreaStyle(KoGenStyle& style, KoGenStyles& styles,
91 				     KoGenStyles& mainStyles);
92             void addShapePropertyStyle(/*const*/ KoChart::Series* series,
93 				       KoGenStyle& style, KoGenStyles& mainStyles);
94     virtual void addDataThemeToStyle(KoGenStyle& style,
95 				     int dataNumber, int maxNumData = 1, bool strokes = true);
96 
97     QString generateGradientStyle(KoGenStyles& mainStyles, const KoChart::Gradient* grad);
98 
99     // Color functions
100     virtual QColor calculateColorFromGradientStop(const KoChart::Gradient::GradientStop& grad);
101     virtual QColor labelFontColor() const;
102     void writeInternalTable(KoXmlWriter* bodyWriter);
103 
104     // MS Office related stuff
105     QList<QColor> m_palette;
106     // tells if a 2003 color palette has been set
107     bool paletteIsSet;
108 };
109 
110 #endif  // KOODFCHARTWRITER_H
111