kchart

KDChartCustomBox.h
Go to the documentation of this file.
1/*
2 KDChart - a multi-platform charting engine
3 */
4
5/****************************************************************************
6 ** Copyright (C) 2001-2003 Klarälvdalens Datakonsult AB. All rights reserved.
7 **
8 ** This file is part of the KDChart library.
9 **
10 ** This file may be distributed and/or modified under the terms of the
11 ** GNU General Public License version 2 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.GPL included in the
13 ** packaging of this file.
14 **
15 ** Licensees holding valid commercial KDChart licenses may use this file in
16 ** accordance with the KDChart Commercial License Agreement provided with
17 ** the Software.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ** See http://www.klaralvdalens-datakonsult.se/?page=products for
23 ** information about KDChart Commercial License Agreements.
24 **
25 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
26 ** licensing are not clear to you.
27 **
28 **********************************************************************/
29#ifndef __KDCHARTCUSTOMBOX_H__
30#define __KDCHARTCUSTOMBOX_H__
31
32#include <tqobject.h>
33#include <tqtextstream.h>
34#include <tqfont.h>
35#include <tqdom.h>
36#include "KDChartGlobal.h"
37#include "KDChartEnums.h"
38#include "KDChartTextPiece.h"
39
40
41class KDFrame;
42
43// needed because there was no AlignAuto before TQt 3.0
44#define KDCHART_AlignAuto 0
45
46
54class KDCHART_EXPORT KDChartCustomBox :public TQObject
55{
56 TQ_OBJECT
57
58 friend class KDChartPainter;
59 friend class KDChartParams;
60
61public:
62
68 _rotation( 0 ),
69 _fontSize( -10 ),
70 _fontScaleGlobal( true ),
71 _deltaX( 0 ),
72 _deltaY( 0 ),
73 _width( 0 ),
74 _height( 0 ),
75 _color( TQt::black ),
76 _paper( TQt::NoBrush ),
77 _anchorArea( KDChartEnums::AreaInnermost ),
78 _anchorPos( KDChartEnums::PosTopLeft ),
79 _anchorAlign( TQt::AlignTop + TQt::AlignLeft ),
80 _dataRow( 0 ),
81 _dataCol( 0 ),
82 _data3rd( 0 ),
83 _deltaAlign( KDCHART_AlignAuto ),
84 _deltaScaleGlobal( true ),
85 _anchorBeingCalculated( false ),
86 _parentAxisArea( -1 )
87 {
88 const KDChartTextPiece piece( 0, "", TQFont( "helvetica", 8, TQFont::Normal, false ) );
89 _content.deepCopy( &piece );
90 }
91
109 KDChartCustomBox( const KDChartTextPiece & content,
110 int fontSize,
111 bool fontScaleGlobal = true ) :
112 _rotation( 0 ),
113 _fontSize( fontSize ),
114 _fontScaleGlobal( fontScaleGlobal ),
115 _deltaX( 0 ),
116 _deltaY( 0 ),
117 _width( 0 ),
118 _height( 0 ),
119 _color( TQt::black ),
120 _paper( TQt::NoBrush ),
121 _anchorArea( KDChartEnums::AreaInnermost ),
122 _anchorPos( KDChartEnums::PosTopLeft ),
123 _anchorAlign( TQt::AlignTop + TQt::AlignLeft ),
124 _dataRow( 0 ),
125 _dataCol( 0 ),
126 _data3rd( 0 ),
127 _deltaAlign( KDCHART_AlignAuto ),
128 _deltaScaleGlobal( true ),
129 _anchorBeingCalculated( false ),
130 _parentAxisArea( -1 )
131 {
132 _content.deepCopy( &content );
133 }
134
135
202 KDChartCustomBox( const KDChartTextPiece & content,
203 int fontSize,
204 bool fontScaleGlobal,
205 int deltaX,
206 int deltaY,
207 int width,
208 int height,
209 const TQColor & color = TQColor( TQt::black ),
210 const TQBrush & paper = TQBrush( TQt::NoBrush ),
211 uint area = KDChartEnums::AreaInnermost,
212 KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
213 uint align = TQt::AlignTop + TQt::AlignLeft,
214 uint dataRow = 0,
215 uint dataCol = 0,
216 uint data3rd = 0,
217 uint deltaAlign = KDCHART_AlignAuto,
218 bool deltaScaleGlobal = true,
219 int parentAxis = -1 )
220 : _rotation( 0 ),
221 _fontSize( fontSize ),
222 _fontScaleGlobal( fontScaleGlobal ),
223 _deltaX( deltaX ),
224 _deltaY( deltaY ),
225 _width( width ),
226 _height( height ),
227 _color( color ),
228 _paper( paper ),
229 _anchorArea( area ),
230 _anchorPos( position ),
231 _anchorAlign( align ),
232 _dataRow( dataRow ),
233 _dataCol( dataCol ),
234 _data3rd( data3rd ),
235 _deltaAlign( deltaAlign ),
236 _deltaScaleGlobal( deltaScaleGlobal ),
237 _anchorBeingCalculated( false ),
238 _parentAxisArea( parentAxis )
239 {
240 _content.deepCopy( &content );
241 }
242
243
323 KDChartCustomBox( int rotation,
324 const KDChartTextPiece & content,
325 int fontSize,
326 bool fontScaleGlobal,
327 int deltaX,
328 int deltaY,
329 int width,
330 int height,
331 const TQColor & color = TQColor( TQt::black ),
332 const TQBrush & paper = TQBrush( TQt::NoBrush ),
333 uint area = KDChartEnums::AreaInnermost,
334 KDChartEnums::PositionFlag position = KDChartEnums::PosTopLeft,
335 uint align = TQt::AlignTop + TQt::AlignLeft,
336 uint dataRow = 0,
337 uint dataCol = 0,
338 uint data3rd = 0,
339 uint deltaAlign = KDCHART_AlignAuto,
340 bool deltaScaleGlobal = true,
341 int parentAxis = -1 )
342 : _rotation( rotation ),
343 _fontSize( fontSize ),
344 _fontScaleGlobal( fontScaleGlobal ),
345 _deltaX( deltaX ),
346 _deltaY( deltaY ),
347 _width( width ),
348 _height( height ),
349 _color( color ),
350 _paper( paper ),
351 _anchorArea( area ),
352 _anchorPos( position ),
353 _anchorAlign( align ),
354 _dataRow( dataRow ),
355 _dataCol( dataCol ),
356 _data3rd( data3rd ),
357 _deltaAlign( deltaAlign ),
358 _deltaScaleGlobal( deltaScaleGlobal ),
359 _anchorBeingCalculated( false ),
360 _parentAxisArea( parentAxis )
361 {
362 _content.deepCopy( &content );
363 }
364
365
375 static void createCustomBoxNode( TQDomDocument& document,
376 TQDomNode& parent,
377 const TQString& elementName,
378 const KDChartCustomBox* custombox );
379
387 static bool readCustomBoxNode( const TQDomElement& element,
388 KDChartCustomBox& custombox );
389
390public slots: // PENDING(blackie) merge slots sections.
391
392 float trueFontSize( double areaWidthP1000,
393 double areaHeightP1000,
394 int rectHeight ) const;
395 int trueFontLineSpacing( double areaWidthP1000,
396 double areaHeightP1000,
397 int rectHeight ) const;
398 int trueRectAlignX(const TQRect& rect) const;
399 int trueRectAlignY(const TQRect& rect) const;
400 void getTrueShift( double areaWidthP1000,
401 double areaHeightP1000,
402 int rectHeight,
403 int& dX,
404 int& dY )const;
405
406
423 TQRect trueRect( TQPainter * painter,
424 TQPoint anchor, double areaWidthP1000, double areaHeightP1000 ) const ;
425
438 virtual TQRect trueRect( TQPoint anchor,
439 double areaWidthP1000,
440 double areaHeightP1000 ) const ;
441
459 virtual void paint( TQPainter* painter,
460 TQPoint anchor,
461 double areaWidthP1000,
462 double areaHeightP1000,
463 const KDFrame* frame = 0,
464 const TQRect& frameRect = TQRect(),
465 const TQColor * color = 0,
466 const TQBrush * paper = 0 ) const ;
467
471 void setRotation( int rotation )
472 {
473 _rotation = rotation;
474 }
475
479 void setContent( const KDChartTextPiece & content )
480 {
481 _content.deepCopy( &content );
482 }
483
505 void setFontSize( int fontSize, bool fontScaleGlobal )
506 {
507 _fontSize = fontSize;
508 _fontScaleGlobal = fontScaleGlobal;
509 }
510
514 void setAnchorArea( uint area )
515 {
516 _anchorArea = area;
517 }
518
525 {
526 // Note if you change the parameters here, then you must also change them in wrappers/KDChartCustomBoxWrapper.h
527 _anchorPos = position;
528 }
529
533 void setAnchorAlign( uint align )
534 {
535 _anchorAlign = align;
536 }
537
542 void setDataRow( uint dataRow )
543 {
544 _dataRow = dataRow;
545 }
546
551 void setDataCol( uint dataCol )
552 {
553 _dataCol = dataCol;
554 }
555
561 void setData3rd( uint data3rd )
562 {
563 _data3rd = data3rd;
564 }
565
588 void setDistanceAndSize( int deltaX,
589 int deltaY,
590 int width,
591 int height,
592 uint deltaAlign = KDCHART_AlignAuto,
593 bool deltaScaleGlobal = true )
594 {
595 _deltaX = deltaX;
596 _deltaY = deltaY;
597 _width = width;
598 _height = height;
599 _deltaAlign = deltaAlign;
600 _deltaScaleGlobal = deltaScaleGlobal;
601 }
602
629 void setDistance( int deltaX,
630 int deltaY,
631 uint align = KDCHART_AlignAuto,
632 bool deltaScaleGlobal = true )
633 {
634 _deltaX = deltaX;
635 _deltaY = deltaY;
636 _deltaAlign = align;
637 _deltaScaleGlobal = deltaScaleGlobal;
638 }
639
669 void setDeltaAlign( uint align,
670 bool deltaScaleGlobal = true )
671 {
672 _deltaAlign = align;
673 _deltaScaleGlobal = deltaScaleGlobal;
674 }
675
687 void setDeltaScale( bool deltaScaleGlobal )
688 {
689 _deltaScaleGlobal = deltaScaleGlobal;
690 }
691
711 void setSize( int width, int height )
712 {
713 _width = width;
714 _height = height;
715 }
716
722 void setColor( TQColor color )
723 {
724 _color = color;
725 }
726
732 void setPaper( const TQBrush & paper )
733 {
734 _paper = paper;
735 }
736
740 int rotation() const
741 {
742 return _rotation;
743 }
744
748 const KDChartTextPiece & content() const
749 {
750 return _content;
751 }
752
763 int fontSize() const
764 {
765 return _fontSize;
766 }
767
774 bool fontScaleGlobal() const
775 {
776 return _fontScaleGlobal;
777 }
778
782 uint anchorArea() const
783 {
784 return _anchorArea;
785 }
786
793 {
794 return _anchorPos;
795 }
796
800 uint anchorAlign() const
801 {
802 return _anchorAlign;
803 }
804
810 uint dataRow() const
811 {
812 return _dataRow;
813 }
814
820 uint dataCol() const
821 {
822 return _dataCol;
823 }
824
831 uint data3rd() const
832 {
833 return _data3rd;
834 }
835
846 int deltaX() const
847 {
848 return _deltaX;
849 }
850
861 int deltaY() const
862 {
863 return _deltaY;
864 }
865
872 uint deltaAlign() const
873 {
874 return _deltaAlign;
875 }
876
883 bool deltaScaleGlobal() const
884 {
885 return _deltaScaleGlobal;
886 }
887
895 int width() const
896 {
897 return _width;
898 }
899
907 int height() const
908 {
909 return _height;
910 }
911
915 TQColor color() const
916 {
917 return _color;
918 }
919
923 const TQBrush & paper() const
924 {
925 return _paper;
926 }
927
928public:
932 virtual ~KDChartCustomBox();
933
941 void deepCopy( const KDChartCustomBox* source );
942
943
953 const KDChartCustomBox* clone() const;
954
955private:
956 KDChartCustomBox( const KDChartCustomBox& ) : TQObject(0) {}
957
958protected:
965 {
966 KDChartCustomBox* that = const_cast<KDChartCustomBox*>(this);
967 that->_anchorBeingCalculated = flag;
968 }
973 {
974 return _anchorBeingCalculated;
975 }
976
977 void setParentAxisArea( int parentAxis ) const
978 {
979 KDChartCustomBox* that = const_cast<KDChartCustomBox*>(this);
980 that->_parentAxisArea = parentAxis;
981 }
982
983 int parentAxisArea() const
984 {
985 return _parentAxisArea;
986 }
987
988private:
989 int _rotation;
990 KDChartTextPiece _content;
991 int _fontSize;
992 bool _fontScaleGlobal;
993 // Values to be transformed into a real rect at painting time.
994 // If greater 0, values are exact, if less than 0, values are in per-mille
995 // of the size of the drawing area.
996 int _deltaX;
997 int _deltaY;
998 int _width;
999 int _height;
1000
1001 TQColor _color;
1002 TQBrush _paper;
1003
1004 uint _anchorArea;
1005 KDChartEnums::PositionFlag _anchorPos;
1006 uint _anchorAlign;
1007 uint _dataRow;
1008 uint _dataCol;
1009 uint _data3rd;
1010 uint _deltaAlign;
1011 bool _deltaScaleGlobal;
1012 //
1013 // The following flag is NOT to be saved/restored in a file.
1014 //
1015 // Being a TEMPORARY flag preventing circular recursion
1016 // it must be set to f a l s e
1017 // after loading a KDChartCustomBox from a file.
1018 bool _anchorBeingCalculated;
1019 int _parentAxisArea;
1020};
1021
1022
1030//TQTextStream& operator<<( TQTextStream& s, const KDChartCustomBox& p );
1031
1032
1041//TQTextStream& operator>>( TQTextStream& s, KDChartCustomBox& p );
1042
1043
1044#endif
Definition of global enums.
Class for specifying and drawing custom boxes.
void setDataRow(uint dataRow)
Specifies the row number of the KDChart data region that is to be used as anchor area.
bool deltaScaleGlobal() const
Returns the way how the distance between the box and its anchor is calculated.
const TQBrush & paper() const
Returns the background brush.
void setData3rd(uint data3rd)
Specifies the third dimensions number of the KDChart data region that is to be used as anchor area.
void setDistanceAndSize(int deltaX, int deltaY, int width, int height, uint deltaAlign=KDCHART_AlignAuto, bool deltaScaleGlobal=true)
Specifies the distance between the box and the anchor point and specifies the size of the box.
int fontSize() const
Returns the font size to be used.
KDChartEnums::PositionFlag anchorPosition() const
Returns the anchor position.
uint deltaAlign() const
Returns the way how the values specified for deltaX and/or deltaY affect the position of the box.
void setPaper(const TQBrush &paper)
Specifies the brush to be used for the background.
uint dataCol() const
Returns the column number of the KDChart data region that is to be used as anchor area.
const KDChartTextPiece & content() const
Returns the text piece content that is to be drawn.
bool fontScaleGlobal() const
Returns the way how the font size is calculated if fontSize() is negative.
int width() const
Returns the width of the region where to draw the box.
int height() const
Returns the height of the region where to draw the box.
void setAnchorPosition(KDChartEnums::PositionFlag position)
Specifies the anchor position.
void setInternalFlagAnchorBeingCalculated(bool flag) const
Internal routine for recursion handling.
KDChartCustomBox(const KDChartTextPiece &content, int fontSize, bool fontScaleGlobal=true)
Constructor.
uint dataRow() const
Returns the row number of the KDChart data region that is to be used as anchor area.
void setSize(int width, int height)
Specifies the size of the box.
void setRotation(int rotation)
Specifies the rotation angle of the box in degrees (0..360).
void setFontSize(int fontSize, bool fontScaleGlobal)
Specifies the font size to be used.
KDChartCustomBox(const KDChartTextPiece &content, int fontSize, bool fontScaleGlobal, int deltaX, int deltaY, int width, int height, const TQColor &color=TQColor(TQt::black), const TQBrush &paper=TQBrush(TQt::NoBrush), uint area=KDChartEnums::AreaInnermost, KDChartEnums::PositionFlag position=KDChartEnums::PosTopLeft, uint align=TQt::AlignTop+TQt::AlignLeft, uint dataRow=0, uint dataCol=0, uint data3rd=0, uint deltaAlign=KDCHART_AlignAuto, bool deltaScaleGlobal=true, int parentAxis=-1)
Constructor.
void setDistance(int deltaX, int deltaY, uint align=KDCHART_AlignAuto, bool deltaScaleGlobal=true)
Specifies the distance between the box and the anchor point.
uint data3rd() const
Returns the third dimensions number of the KDChart data region that is to be used as anchor area.
int deltaY() const
Returns the Y distance between the box and its anchor.
void setAnchorAlign(uint align)
Specifies the way how the box is to be aligned to its anchor.
uint anchorArea() const
Returns the area to which the box is to be aligned.
int rotation() const
Returns the rotation angle of the box in degrees (0..360).
TQColor color() const
Returns the text color.
void setDataCol(uint dataCol)
Specifies the column number of the KDChart data region that is to be used as anchor area.
void setColor(TQColor color)
Specifies the text color to be used.
void setContent(const KDChartTextPiece &content)
Specifies the text piece content to be drawn.
KDChartCustomBox(int rotation, const KDChartTextPiece &content, int fontSize, bool fontScaleGlobal, int deltaX, int deltaY, int width, int height, const TQColor &color=TQColor(TQt::black), const TQBrush &paper=TQBrush(TQt::NoBrush), uint area=KDChartEnums::AreaInnermost, KDChartEnums::PositionFlag position=KDChartEnums::PosTopLeft, uint align=TQt::AlignTop+TQt::AlignLeft, uint dataRow=0, uint dataCol=0, uint data3rd=0, uint deltaAlign=KDCHART_AlignAuto, bool deltaScaleGlobal=true, int parentAxis=-1)
Constructor.
bool anchorBeingCalculated() const
Internal routine for recursion handling.
void setDeltaScale(bool deltaScaleGlobal)
Specifies the way how the distance between the box and its anchor will be calculated.
void setDeltaAlign(uint align, bool deltaScaleGlobal=true)
Specifies the way how the values specified for deltaX and/or deltaY affect the position of the box.
int deltaX() const
Returns the X distance between the box and its anchor.
KDChartCustomBox()
Constructor.
void setAnchorArea(uint area)
Specifies the area to which the box is to be aligned.
uint anchorAlign() const
Returns the way how the box is to be aligned to its anchor.
Project global class providing some enums needed both by KDChartParams and by KDChartCustomBox.
PositionFlag
The general position flag to specify a point of an area, for example this could be the anchor point w...
An abstract base class that defines an interface for classes that implement chart drawing.
Bundles the display parameters of a chart.
The main class of KDFrame.
Definition KDFrame.h:88