00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __KDCHARTPAINTER_H__
00030 #define __KDCHARTPAINTER_H__
00031
00032 #include <qmap.h>
00033 #include <qrect.h>
00034 #include <qdatetime.h>
00035 #include <qregion.h>
00036 #include <qstring.h>
00037
00038 #include "KDChartGlobal.h"
00039 #include "KDChartUnknownTypeException.h"
00040 #include "KDChartNotEnoughSpaceException.h"
00041 #include "KDChartTable.h"
00042 #include "KDChartDataRegion.h"
00043 #include "KDChartParams.h"
00044
00045 class KDChartTableDataBase;
00046 class KDChartCustomBox;
00047 class KDChartTextPiece;
00048 class KDChartPropertySet;
00049 class KDChartAxisParams;
00050 class QPainter;
00051
00052
00053 struct internal__KDChart__CalcValues {
00054 bool processThisAxis;
00055 bool bSteadyCalc;
00056 bool bLogarithmic;
00057 bool bDecreasing;
00058 KDChartAxisParams::AxisPos basicPos;
00059 QPoint orig;
00060 QPoint dest;
00061 double pXDeltaFactor;
00062 double pYDeltaFactor;
00063 double pXDelimDeltaFaktor;
00064 double pYDelimDeltaFaktor;
00065 double nSubDelimFactor;
00066 double pDelimDelta;
00067 double nTxtHeight;
00068 double pTextsX;
00069 double pTextsY;
00070 double pTextsW;
00071 double pTextsH;
00072 int textAlign;
00073 bool isDateTime;
00074 bool autoDtLabels;
00075 QDateTime dtLow;
00076 QDateTime dtHigh;
00077 KDChartAxisParams::ValueScale dtDeltaScale;
00078 double nLow;
00079 double nHigh;
00080 double nDelta;
00081 double nDeltaPix;
00082 double pLastX;
00083 double pLastY;
00084 };
00085
00086
00087 class KDCHART_EXPORT KDChartPainter
00088 {
00089 public:
00090 static KDChartPainter* create( KDChartParams* params,
00091 bool make2nd = false );
00092
00093 virtual ~KDChartPainter();
00094
00095 static void registerPainter( const QString& painterName,
00096 KDChartPainter* painter );
00097 static void unregisterPainter( const QString& painterName );
00098
00099 virtual void setupGeometry ( QPainter* painter,
00100 KDChartTableDataBase* data,
00101 const QRect& rect );
00102
00103 virtual void paint( QPainter* painter, KDChartTableDataBase* data,
00104 bool paintFirst,
00105 bool paintLast,
00106 KDChartDataRegionList* regions = 0,
00107 const QRect* rect = 0,
00108 bool mustCalculateGeometry = true );
00109
00110 virtual QRect outermostRect() const { return _outermostRect; }
00111
00112 static void drawMarker( QPainter* painter,
00113 int style,
00114 const QColor& color,
00115 const QPoint& p,
00116 const QSize& size,
00117 uint align = Qt::AlignCenter );
00118
00119 protected:
00120 KDChartPainter( KDChartParams* );
00121
00122
00123
00124 virtual void paintArea( QPainter* painter,
00125 uint area,
00126 KDChartDataRegionList* regions = 0,
00127 uint dataRow = 0,
00128 uint dataCol = 0,
00129 uint data3rd = 0 );
00130
00131 virtual void paintDataRegionAreas( QPainter* painter,
00132 KDChartDataRegionList* regions );
00133
00134 virtual void paintAreaWithGap( QPainter* painter,
00135 QRect rect,
00136 const KDChartParams::KDChartFrameSettings& settings );
00137 virtual void paintCustomBoxes( QPainter* painter,
00138 KDChartDataRegionList* regions );
00139
00140 virtual void paintData( QPainter* painter, KDChartTableDataBase* data,
00141 bool paint2nd,
00142 KDChartDataRegionList* regions = 0 ) = 0;
00143 virtual void paintDataValues( QPainter* painter,
00144 KDChartTableDataBase* data,
00145 KDChartDataRegionList* regions );
00146 virtual void paintAxes( QPainter* painter,
00147 KDChartTableDataBase* data );
00148 virtual void paintLegend( QPainter* painter,
00149 KDChartTableDataBase* data );
00150 virtual void paintHeaderFooter( QPainter* painter,
00151 KDChartTableDataBase* data );
00152 virtual bool axesOverlapping( int axis1, int axis2 );
00153
00154 virtual void findChartDatasets( KDChartTableDataBase* data,
00155 bool paint2nd,
00156 uint chart,
00157 uint& chartDatasetStart,
00158 uint& chartDatasetEnd );
00159
00160 virtual void calculateAllAxesRects( QPainter* painter,
00161 bool finalPrecision,
00162 KDChartTableDataBase* data );
00163
00164 virtual QPoint calculateAnchor( const KDChartCustomBox & box,
00165 KDChartDataRegionList* regions = 0 ) const;
00166 virtual QRect calculateAreaRect( bool & allCustomBoxes,
00167 uint area,
00168 uint dataRow,
00169 uint dataCol,
00170 uint data3rd,
00171 KDChartDataRegionList* regions ) const;
00172
00173 virtual QString fallbackLegendText( uint dataset ) const;
00174 virtual uint numLegendFallbackTexts( KDChartTableDataBase* data ) const;
00175
00176 static QPoint pointOnCircle( const QRect& rect, double angle );
00177 static void makeArc( QPointArray& points,
00178 const QRect& rect,
00179 double startAngle, double angles );
00180
00181 const KDChartParams* params() const
00182 {
00183 return _params;
00184 }
00185
00186 QRect _outermostRect;
00187
00188
00189 QRect _innermostRect;
00190
00191
00192
00193
00194
00195 QRect _dataRect;
00196
00197 QRect _axesRect;
00198
00199
00200
00201
00202
00203 QRect _legendRect;
00204
00205
00206
00207
00208 int _legendEMSpace;
00209 int _legendSpacing;
00210 int _legendHeight;
00211 int _legendLeading;
00212
00213
00214 KDChartTextPiece* _legendTitle;
00215
00216 int _numLegendTexts;
00217
00218 int _logicalWidth;
00219 int _logicalHeight;
00220 double _areaWidthP1000;
00221 double _areaHeightP1000;
00222
00223 QMap < int, QString > _legendTexts;
00224
00225 internal__KDChart__CalcValues calcVal[ KDCHART_MAX_AXES ];
00226 virtual bool calculateAllAxesLabelTextsAndCalcValues(
00227 QPainter* painter,
00228 KDChartTableDataBase* data,
00229 double areaWidthP1000,
00230 double areaHeightP1000,
00231 double& delimLen );
00232
00233 virtual void drawExtraLinesAndMarkers(
00234 KDChartPropertySet& propSet,
00235 const QPen& defaultPen,
00236 const KDChartParams::LineMarkerStyle& defaultMarkerStyle,
00237 int myPointX,
00238 int myPointY,
00239 QPainter* painter,
00240 const KDChartAxisParams* abscissaPara,
00241 const KDChartAxisParams* ordinatePara,
00242 const double areaWidthP1000,
00243 const double areaHeightP1000,
00244 bool bDrawInFront = FALSE );
00245
00246 static KDChartDataRegion* drawMarker( QPainter* painter,
00247 const KDChartParams* params,
00248 double areaWidthP1000,
00249 double areaHeightP1000,
00250 int deltaX,
00251 int deltaY,
00252 int style,
00253 const QColor& color,
00254 const QPoint& p,
00255 uint dataset, uint value, uint chart,
00256 KDChartDataRegionList* regions = 0,
00257 int* width = 0,
00258 int* height = 0,
00259 uint align = Qt::AlignCenter );
00260
00261 private:
00262
00263 KDChartPainter( const KDChartPainter& );
00264 KDChartPainter& operator=( const KDChartPainter& );
00265
00266
00267 QMap < QString, KDChartPainter* > _customPainters;
00268 KDChartParams* _params;
00269
00270 QRect trueFrameRect( const QRect& orgRect,
00271 const KDChartParams::KDChartFrameSettings* settings ) const;
00272
00273 int legendTitleVertGap() const;
00274 QFont trueLegendFont() const;
00275 void calculateHorizontalLegendSize( QPainter* painter,
00276 QSize& size,
00277 bool& legendNewLinesStartAtLeft ) const;
00278 bool mustDrawVerticalLegend() const;
00279 void findLegendTexts( KDChartTableDataBase* );
00280 int calculateHdFtRects( QPainter* painter,
00281 double averageValueP1000,
00282 int xposLeft,
00283 int xposRight,
00284 bool bHeader,
00285 int& yposTop,
00286 int& yposBottom );
00287 bool _legendNewLinesStartAtLeft;
00288 int _legendTitleHeight;
00289 int _legendTitleWidth;
00290 int _legendTitleMetricsHeight;
00291 int _hdLeading;
00292 int _ftLeading;
00293 };
00294
00295 #endif