kchart

KDChartPainter.h

00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KDChart library.
00009  **
00010  ** This file may be distributed and/or modified under the terms of the
00011  ** GNU General Public License version 2 as published by the Free Software
00012  ** Foundation and appearing in the file LICENSE.GPL included in the
00013  ** packaging of this file.
00014  **
00015  ** Licensees holding valid commercial KDChart licenses may use this file in
00016  ** accordance with the KDChart Commercial License Agreement provided with
00017  ** the Software.
00018  **
00019  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021  **
00022  ** See http://www.klaralvdalens-datakonsult.se/?page=products for
00023  **   information about KDChart Commercial License Agreements.
00024  **
00025  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00026  ** licensing are not clear to you.
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         // Note: dataRow, dataCol (and data3rd, resp.)
00123         //       must only be set if area == KDChartEnums::AreaChartDataRegion
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; /* The Outermost rect covers the complete
00187                                  area of the painter. */
00188 
00189         QRect _innermostRect; /* The Innermost rect covers the area of
00190                                  the painter MINUS the the global
00191                                  left/top/right/bottom leading.
00192                                  ALL following ones are INSIDE the Innermost.
00193                                  */
00194 
00195         QRect _dataRect;
00196 
00197         QRect _axesRect; /* The Axes rect contains the Data rect. Up to 4
00198                             axes might be at the left and bottom as well
00199                             as at the right and/or at the to top of the
00200                             chart.
00201                             */
00202 
00203         QRect _legendRect; /* The legend position depends on the parameter
00204                               settings. If it is not directly to the left or
00205                               to the right of the data display, it will be
00206                               below the headers and on top of the footers.
00207                               */
00208         int _legendEMSpace; // an em space in the legend font
00209         int _legendSpacing; // the line spacing in the legend font
00210         int _legendHeight; // the font height in the legend font
00211         int _legendLeading; // the font leading in the legend font
00212         //     int _legendTitleSpacing; // the line spacing in the legend title font
00213         //     int _legendTitleLeading; // the font leading in the legend title font
00214         KDChartTextPiece* _legendTitle;
00215 
00216         int _numLegendTexts; // the number of legend items to show
00217 
00218         int _logicalWidth;
00219         int _logicalHeight;
00220         double _areaWidthP1000;
00221         double _areaHeightP1000;
00222 
00223         QMap < int, QString > _legendTexts; // precomputed legend texts
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         // disallow copy-construction and assignment
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 trueLegendTitleFont() const;
00275         QFont trueLegendFont() const;
00276         void calculateHorizontalLegendSize( QPainter* painter,
00277                                             QSize& size,
00278                                             bool& legendNewLinesStartAtLeft ) const;
00279         bool mustDrawVerticalLegend() const;
00280         void findLegendTexts( KDChartTableDataBase* );
00281         int calculateHdFtRects( QPainter* painter,
00282                                 double averageValueP1000,
00283                                 int  xposLeft,
00284                                 int  xposRight,
00285                                 bool bHeader,
00286                                 int& yposTop,
00287                                 int& yposBottom );
00288         bool _legendNewLinesStartAtLeft;
00289         int _legendTitleHeight;
00290         int _legendTitleWidth;
00291         int _legendTitleMetricsHeight; // the font height in the legend title font
00292         int _hdLeading;
00293         int _ftLeading;
00294 };
00295 
00296 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys