kchart

KDChartCustomBox.h

Go to the documentation of this file.
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 __KDCHARTCUSTOMBOX_H__
00030 #define __KDCHARTCUSTOMBOX_H__
00031 
00032 #include <qobject.h>
00033 #include <qtextstream.h>
00034 #include <qfont.h>
00035 #include <qdom.h>
00036 #include "KDChartGlobal.h"
00037 #include "KDChartEnums.h"
00038 #include "KDChartTextPiece.h"
00039 
00040 
00041 class KDFrame;
00042 
00043 // needed because there was no AlignAuto before Qt 3.0
00044 #define KDCHART_AlignAuto 0
00045 
00046 
00054 class KDCHART_EXPORT KDChartCustomBox :public QObject
00055 {
00056     Q_OBJECT
00057     friend class KDChartPainter;
00058 
00059 public:
00060 
00065     KDChartCustomBox() :
00066         _rotation( 0 ),
00067         _fontSize( -10 ),
00068         _fontScaleGlobal( true ),
00069         _deltaX( 0 ),
00070         _deltaY( 0 ),
00071         _width(  0 ),
00072         _height( 0 ),
00073         _color( Qt::black ),
00074         _paper( Qt::NoBrush ),
00075         _anchorArea(  KDChartEnums::AreaInnermost ),
00076         _anchorPos(   KDChartEnums::PosTopLeft ),
00077         _anchorAlign( Qt::AlignTop + Qt::AlignLeft ),
00078         _dataRow( 0 ),
00079         _dataCol( 0 ),
00080         _data3rd( 0 ),
00081         _deltaAlign( KDCHART_AlignAuto ),
00082         _deltaScaleGlobal( true ),
00083         _anchorBeingCalculated( false )
00084     {
00085         const KDChartTextPiece piece( 0, "", QFont( "helvetica", 8, QFont::Normal, false ) );
00086         _content.deepCopy( &piece );
00087     }
00088 
00106     KDChartCustomBox( const KDChartTextPiece & content,
00107                       int fontSize,
00108                       bool fontScaleGlobal = true ) :
00109         _rotation( 0 ),
00110         _fontSize( fontSize ),
00111         _fontScaleGlobal( fontScaleGlobal ),
00112         _deltaX( 0 ),
00113         _deltaY( 0 ),
00114         _width(  0 ),
00115         _height( 0 ),
00116         _color( Qt::black ),
00117         _paper( Qt::NoBrush ),
00118         _anchorArea(  KDChartEnums::AreaInnermost ),
00119         _anchorPos(   KDChartEnums::PosTopLeft ),
00120         _anchorAlign( Qt::AlignTop + Qt::AlignLeft ),
00121         _dataRow( 0 ),
00122         _dataCol( 0 ),
00123         _data3rd( 0 ),
00124         _deltaAlign( KDCHART_AlignAuto ),
00125         _deltaScaleGlobal( true ),
00126         _anchorBeingCalculated( false )
00127     {
00128         _content.deepCopy( &content );
00129     }
00130 
00131 
00198     KDChartCustomBox( const KDChartTextPiece & content,
00199                       int fontSize,
00200                       bool fontScaleGlobal,
00201                       int deltaX,
00202                       int deltaY,
00203                       int width,
00204                       int height,
00205                       const QColor & color = QColor( Qt::black   ),
00206                       const QBrush & paper = QBrush( Qt::NoBrush ),
00207                       uint area                           = KDChartEnums::AreaInnermost,
00208                       KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
00209                       uint align                          = Qt::AlignTop + Qt::AlignLeft,
00210                       uint dataRow = 0,
00211                       uint dataCol = 0,
00212                       uint data3rd = 0,
00213                       uint deltaAlign = KDCHART_AlignAuto,
00214                       bool deltaScaleGlobal = true )
00215         : _rotation( 0 ),
00216           _fontSize( fontSize ),
00217           _fontScaleGlobal( fontScaleGlobal ),
00218           _deltaX( deltaX ),
00219           _deltaY( deltaY ),
00220           _width( width ),
00221           _height( height ),
00222           _color( color ),
00223           _paper( paper ),
00224           _anchorArea( area ),
00225           _anchorPos( position ),
00226           _anchorAlign( align ),
00227           _dataRow( dataRow ),
00228           _dataCol( dataCol ),
00229           _data3rd( data3rd ),
00230           _deltaAlign( deltaAlign ),
00231           _deltaScaleGlobal( deltaScaleGlobal ),
00232           _anchorBeingCalculated( false )
00233     {
00234         _content.deepCopy( &content );
00235     }
00236 
00237 
00317     KDChartCustomBox( int rotation,
00318                       const KDChartTextPiece & content,
00319                       int fontSize,
00320                       bool fontScaleGlobal,
00321                       int deltaX,
00322                       int deltaY,
00323                       int width,
00324                       int height,
00325                       const QColor & color = QColor( Qt::black   ),
00326                       const QBrush & paper = QBrush( Qt::NoBrush ),
00327                       uint area                           = KDChartEnums::AreaInnermost,
00328                       KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
00329                       uint align                          = Qt::AlignTop + Qt::AlignLeft,
00330                       uint dataRow = 0,
00331                       uint dataCol = 0,
00332                       uint data3rd = 0,
00333                       uint deltaAlign = KDCHART_AlignAuto,
00334                       bool deltaScaleGlobal = true )
00335         : _rotation( rotation ),
00336           _fontSize( fontSize ),
00337           _fontScaleGlobal( fontScaleGlobal ),
00338           _deltaX( deltaX ),
00339           _deltaY( deltaY ),
00340           _width( width ),
00341           _height( height ),
00342           _color( color ),
00343           _paper( paper ),
00344           _anchorArea( area ),
00345           _anchorPos( position ),
00346           _anchorAlign( align ),
00347           _dataRow( dataRow ),
00348           _dataCol( dataCol ),
00349           _data3rd( data3rd ),
00350           _deltaAlign( deltaAlign ),
00351           _deltaScaleGlobal( deltaScaleGlobal ),
00352           _anchorBeingCalculated( false )
00353     {
00354         _content.deepCopy( &content );
00355     }
00356 
00357 
00367     static void createCustomBoxNode( QDomDocument& document,
00368                                      QDomNode& parent,
00369                                      const QString& elementName,
00370                                      const KDChartCustomBox* custombox );
00371 
00379     static bool readCustomBoxNode( const QDomElement& element,
00380                                    KDChartCustomBox& custombox );
00381 
00382 public slots: // PENDING(blackie) merge slots sections.
00383 
00384     float trueFontSize( double areaWidthP1000,
00385                         double areaHeightP1000,
00386                         int rectHeight ) const;
00387     int trueFontLineSpacing( double areaWidthP1000,
00388                              double areaHeightP1000,
00389                              int rectHeight ) const;
00390     int trueRectAlignX(const QRect& rect) const;
00391     int trueRectAlignY(const QRect& rect) const;
00392     void getTrueShift( double areaWidthP1000,
00393                        double areaHeightP1000,
00394                        int rectHeight,
00395                        int& dX,
00396                        int& dY )const;
00397 
00398 
00412     virtual QRect trueRect( QPoint anchor,
00413                             double areaWidthP1000,
00414                             double areaHeightP1000 ) const ;
00415 
00433     virtual void paint( QPainter* painter,
00434                         QPoint anchor,
00435                         double areaWidthP1000,
00436                         double areaHeightP1000,
00437                         const KDFrame* frame     = 0,
00438                         const QRect&   frameRect = QRect(),
00439                         const QColor * color = 0,
00440                         const QBrush * paper = 0 ) const ;
00441 
00445     void setRotation( int rotation )
00446     {
00447         _rotation = rotation;
00448     }
00449 
00453     void setContent( const KDChartTextPiece & content )
00454     {
00455         _content.deepCopy( &content );
00456     }
00457 
00479     void setFontSize( int fontSize, bool fontScaleGlobal )
00480     {
00481         _fontSize        = fontSize;
00482         _fontScaleGlobal = fontScaleGlobal;
00483     }
00484 
00488     void setAnchorArea( uint area )
00489     {
00490         _anchorArea = area;
00491     }
00492 
00498     void setAnchorPosition( KDChartEnums::PositionFlag position )
00499     {
00500         // Note if you change the parameters here, then you must also change them in wrappers/KDChartCustomBoxWrapper.h
00501         _anchorPos = position;
00502     }
00503 
00507     void setAnchorAlign( uint align )
00508     {
00509         _anchorAlign = align;
00510     }
00511 
00516     void setDataRow( uint dataRow )
00517     {
00518         _dataRow = dataRow;
00519     }
00520 
00525     void setDataCol( uint dataCol )
00526     {
00527         _dataCol = dataCol;
00528     }
00529 
00535     void setData3rd( uint data3rd )
00536     {
00537         _data3rd = data3rd;
00538     }
00539 
00562     void setDistanceAndSize( int deltaX,
00563                              int deltaY,
00564                              int width,
00565                              int height,
00566                              uint deltaAlign = KDCHART_AlignAuto,
00567                              bool deltaScaleGlobal = true )
00568     {
00569         _deltaX = deltaX;
00570         _deltaY = deltaY;
00571         _width = width;
00572         _height = height;
00573         _deltaAlign = deltaAlign;
00574         _deltaScaleGlobal = deltaScaleGlobal;
00575     }
00576 
00603     void setDistance( int deltaX,
00604                       int deltaY,
00605                       uint align = KDCHART_AlignAuto,
00606                       bool deltaScaleGlobal = true )
00607     {
00608         _deltaX = deltaX;
00609         _deltaY = deltaY;
00610         _deltaAlign = align;
00611         _deltaScaleGlobal = deltaScaleGlobal;
00612     }
00613 
00643     void setDeltaAlign( uint align,
00644                         bool deltaScaleGlobal = true )
00645     {
00646         _deltaAlign = align;
00647         _deltaScaleGlobal = deltaScaleGlobal;
00648     }
00649 
00661     void setDeltaScale( bool deltaScaleGlobal )
00662     {
00663         _deltaScaleGlobal = deltaScaleGlobal;
00664     }
00665 
00685     void setSize( int width, int height )
00686     {
00687         _width = width;
00688         _height = height;
00689     }
00690 
00696     void setColor( QColor color )
00697     {
00698         _color = color;
00699     }
00700 
00706     void setPaper( const QBrush & paper )
00707     {
00708         _paper = paper;
00709     }
00710 
00714     int rotation() const
00715     {
00716         return _rotation;
00717     }
00718 
00722     const KDChartTextPiece & content() const
00723     {
00724         return _content;
00725     }
00726 
00737     int fontSize() const
00738     {
00739         return _fontSize;
00740     }
00741 
00748     bool fontScaleGlobal() const
00749     {
00750         return _fontScaleGlobal;
00751     }
00752 
00756     uint anchorArea() const
00757     {
00758         return _anchorArea;
00759     }
00760 
00766     KDChartEnums::PositionFlag anchorPosition() const
00767     {
00768         return _anchorPos;
00769     }
00770 
00774     uint anchorAlign() const
00775     {
00776         return _anchorAlign;
00777     }
00778 
00784     uint dataRow() const
00785     {
00786         return _dataRow;
00787     }
00788 
00794     uint dataCol() const
00795     {
00796         return _dataCol;
00797     }
00798 
00805     uint data3rd() const
00806     {
00807         return _data3rd;
00808     }
00809 
00820     int deltaX() const
00821     {
00822         return _deltaX;
00823     }
00824 
00835     int deltaY() const
00836     {
00837         return _deltaY;
00838     }
00839 
00846     uint deltaAlign() const
00847     {
00848         return _deltaAlign;
00849     }
00850 
00857     bool deltaScaleGlobal() const
00858     {
00859         return _deltaScaleGlobal;
00860     }
00861 
00869     int width() const
00870     {
00871         return _width;
00872     }
00873 
00881     int height() const
00882     {
00883         return _height;
00884     }
00885 
00889     QColor color() const
00890     {
00891         return _color;
00892     }
00893 
00897     const QBrush & paper() const
00898     {
00899         return _paper;
00900     }
00901 
00902 public:
00906     virtual ~KDChartCustomBox();
00907 
00915     void deepCopy( const KDChartCustomBox* source );
00916 
00917 
00927     const KDChartCustomBox* clone() const;
00928 
00929 private:
00930     KDChartCustomBox( const KDChartCustomBox& ) : QObject(0) {}
00931 
00932 protected:
00938     void setInternalFlagAnchorBeingCalculated( bool flag ) const
00939     {
00940         KDChartCustomBox* that = const_cast<KDChartCustomBox*>(this);
00941         that->_anchorBeingCalculated = flag;
00942     }
00946     bool anchorBeingCalculated() const
00947     {
00948         return _anchorBeingCalculated;
00949     }
00950 
00951 private:
00952     int              _rotation;
00953     KDChartTextPiece _content;
00954     int              _fontSize;
00955     bool             _fontScaleGlobal;
00956     // Values to be transformed into a real rect at painting time.
00957     // If greater 0, values are exact, if less than 0, values are in per-mille
00958     // of the size of the drawing area.
00959     int _deltaX;
00960     int _deltaY;
00961     int _width;
00962     int _height;
00963 
00964     QColor _color;
00965     QBrush _paper;
00966 
00967     uint                       _anchorArea;
00968     KDChartEnums::PositionFlag _anchorPos;
00969     uint                       _anchorAlign;
00970     uint _dataRow;
00971     uint _dataCol;
00972     uint _data3rd;
00973     uint                       _deltaAlign;
00974     bool                       _deltaScaleGlobal;
00975     //
00976     // The following flag is NOT to be saved/restored in a file.
00977     //
00978     // Being a TEMPORARY flag preventing circular recursion
00979     // it must be set to   f a l s e
00980     // after loading a KDChartCustomBox from a file.
00981     bool _anchorBeingCalculated;
00982 };
00983 
00984 
00992 //QTextStream& operator<<( QTextStream& s, const KDChartCustomBox& p );
00993 
00994 
01003 //QTextStream& operator>>( QTextStream& s, KDChartCustomBox& p );
01004 
01005 
01006 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys