kchart

KDFrame.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 __KDFRAME_H__
30#define __KDFRAME_H__
31
32#include <tqapplication.h>
33#include <tqfont.h>
34#include <tqcolor.h>
35#include <tqpixmap.h>
36#include <tqpen.h>
37#include <tqmap.h>
38#include <tqobject.h>
39#include <tqtextstream.h>
40#include <tqdom.h>
41
42#include <KDFrameProfileSection.h>
43
44
87class KDCHART_EXPORT KDFrame : public TQObject
88{
89 TQ_OBJECT
90
91 TQ_ENUMS( BackPixmapMode )
92 TQ_ENUMS( SimpleFrame )
93 TQ_ENUMS( ProfileName )
94 TQ_ENUMS( CornerName )
95 TQ_ENUMS( CornerStyle )
96 TQ_ENUMS( KDFramePaintSteps )
97
98public:
100
101
109 enum BackPixmapMode { PixCentered, PixScaled, PixStretched };
110
111public slots:
112
120 static TQString backPixmapModeToString( BackPixmapMode type ) {
121 switch( type ) {
122 case PixCentered:
123 return "Centered";
124 case PixScaled:
125 return "Scaled";
126 case PixStretched:
127 return "Stretched";
128 }
129
130 return "Stretched";
131 }
132
133
140 static BackPixmapMode stringToBackPixmapMode( const TQString& string ) {
141 if( string == "Centered" )
142 return PixCentered;
143 else if( string == "Scaled" )
144 return PixScaled;
145 else if( string == "Stretched" )
146 return PixStretched;
147
148 return PixStretched;
149 }
150
151
152public:
153
154
177 enum SimpleFrame { FrameFlat, FrameElegance,
178 FrameBoxRaized, FrameBoxSunken,
179 FramePanelRaized, FramePanelSunken,
180 FrameSemicircular };
181
182public slots:
183
218 void setSimpleFrame( SimpleFrame frame,
219 int lineWidth,
220 int midLineWidth,
221 TQPen pen,
222 TQBrush background = TQBrush(),
223 const TQPixmap* backPixmap = 0,
224 BackPixmapMode backPixmapMode = PixStretched );
225
226public:
241 enum ProfileName { ProfileTop, ProfileRight,
242 ProfileBottom, ProfileLeft };
243
244public slots:
259 void clearProfile( ProfileName name );
260
277 void addProfileSection( ProfileName name,
278 int wid,
279 TQPen pen,
280 KDFrameProfileSection::Direction dir = KDFrameProfileSection::DirPlain, // PENDING(blackie) possible enum problem
281 KDFrameProfileSection::Curvature curv = KDFrameProfileSection::CvtPlain );
282
320 void setProfile( ProfileName name, const KDFrameProfile& profile );
321
331 const KDFrameProfile& profile( ProfileName name ) const;
332
333public:
334
349 enum CornerName { CornerTopLeft,
350 CornerTopRight,
351 CornerBottomLeft,
352 CornerBottomRight,
353 CornerUNKNOWN };
354
355public slots:
366 static TQString cornerNameToString( CornerName type ) {
367 switch( type ) {
368 case CornerTopLeft:
369 return "TopLeft";
370 case CornerTopRight:
371 return "TopRight";
372 case CornerBottomLeft:
373 return "BottomLeft";
374 case CornerBottomRight:
375 return "BottomRight";
376 case CornerUNKNOWN:
377 return "UNKNOWN";
378 }
379
380 return "UNKNOWN";
381 }
382
383
394 static CornerName stringToCornerName( const TQString& string ) {
395 if( string == "TopLeft" )
396 return CornerTopLeft;
397 else if( string == "TopRight" )
398 return CornerTopRight;
399 else if( string == "BottomLeft" )
400 return CornerBottomLeft;
401 else if( string == "BottomRight" )
402 return CornerBottomRight;
403 else if( string == "UNKNOWN" )
404 return CornerUNKNOWN;
405
406 return CornerUNKNOWN;
407 }
408
409public:
410
411
425 enum CornerStyle { CornerNormal,
426 CornerRound,
427 CornerOblique };
428
429public slots:
440 static TQString cornerStyleToString( CornerStyle type ) {
441 switch( type ) {
442 case CornerNormal:
443 return "Normal";
444 case CornerRound:
445 return "Round";
446 case CornerOblique:
447 return "Oblique";
448 }
449
450 return "Normal";
451 }
452
453
464 static CornerStyle stringToCornerStyle( const TQString& string ) {
465 if( string == "Normal" )
466 return CornerNormal;
467 else if( string == "Round" )
468 return CornerRound;
469 else if( string == "Oblique" )
470 return CornerOblique;
471
472 return CornerNormal;
473 }
474
475
476public:
477
478// MOC_SKIP_BEGIN
491 class KDCHART_EXPORT KDFrameCorner
492 {
493 friend class KDFrame;
494 public:
495 KDFrameCorner( CornerStyle style = CornerNormal,
496 int width = 0,
497 KDFrameProfile* const profile = 0 )
498 : _style( style ),
499 _width( width )
500 {
501 if( profile )
502 _profile = *profile;
503 else
504 _profile.clear();
505 }
509 virtual ~KDFrameCorner();
510
524 static void createFrameCornerNode( TQDomDocument& document,
525 TQDomNode& parent,
526 const TQString& elementName,
527 const KDFrameCorner& corner );
528
540 static bool readFrameCornerNode( const TQDomElement& element,
541 KDFrameCorner& corner );
542
543 protected:
544 void setAll( CornerStyle style,
545 int width,
546 KDFrameProfile* const profile = 0 )
547 {
548 _style = style;
549 _width = width;
550 if( profile )
551 _profile = *profile;
552 else
553 _profile.clear();
554 }
555 CornerStyle style() const
556 {
557 return _style;
558 }
559 int width() const
560 {
561 return _width;
562 }
563 const KDFrameProfile& profile() const
564 {
565 return _profile;
566 }
567 private:
568 CornerStyle _style;
569 int _width;
570 KDFrameProfile _profile;
571 };
572
573// MOC_SKIP_END
574
575public slots:
587 CornerStyle style,
588 int width,
589 KDFrameProfile* const profile = 0 )
590 {
591 switch( name ) {
592 case CornerTopLeft: _cornerTL.setAll( style, width, profile );
593 break;
594 case CornerTopRight: _cornerTR.setAll( style, width, profile );
595 break;
596 case CornerBottomLeft: _cornerBL.setAll( style, width, profile );
597 break;
598 case CornerBottomRight: _cornerBR.setAll( style, width, profile );
599 break;
600 case CornerUNKNOWN:
601 break;
602 }
603 }
604
616 int width,
617 KDFrameProfile* const profile = 0 )
618 {
619 _cornerTL.setAll( style, width, profile );
620 _cornerTR.setAll( style, width, profile );
621 _cornerBL.setAll( style, width, profile );
622 _cornerBR.setAll( style, width, profile );
623 }
624
625
636 {
637 switch( name ) {
638 case CornerTopLeft: return _cornerTL.style();
639 case CornerTopRight: return _cornerTR.style();
640 case CornerBottomLeft: return _cornerBL.style();
641 case CornerBottomRight: return _cornerBR.style();
642 case CornerUNKNOWN:
643 default: return CornerNormal;
644 }
645 }
646
656 int cornerWidth( CornerName name ) const
657 {
658 switch( name ) {
659 case CornerTopLeft: return _cornerTL.width();
660 case CornerTopRight: return _cornerTR.width();
661 case CornerBottomLeft: return _cornerBL.width();
662 case CornerBottomRight: return _cornerBR.width();
663 case CornerUNKNOWN:
664 default: return 0;
665 }
666 }
667
677 const KDFrameProfile& cornerProfile( CornerName name ) const
678 {
679 switch( name ) {
680 case CornerUNKNOWN:
681 case CornerTopLeft: return _cornerTL.profile();
682 case CornerTopRight: return _cornerTR.profile();
683 case CornerBottomLeft: return _cornerBL.profile();
684 case CornerBottomRight: return _cornerBR.profile();
685 default: return _cornerTL.profile();
686 }
687 }
688
689
699 void setSunPos( CornerName sunPos )
700 {
701 _sunPos = sunPos;
702 }
703
714 {
715 return _sunPos;
716 }
717
718
730 void setBackground( TQBrush background = TQBrush( TQt::NoBrush ) )
731 {
732 _background = background;
733 }
734
744 void setBackPixmap( const TQPixmap* backPixmap = 0,
745 BackPixmapMode backPixmapMode = PixStretched )
746 {
747 _backPixmap = backPixmap ? *backPixmap : TQPixmap();
748 _backPixmapMode = backPixmapMode;
749 }
750
763 const TQBrush& background( const TQPixmap*& backPixmap,
764 BackPixmapMode& backPixmapMode ) const
765 {
766 backPixmap = &_backPixmap;
767 backPixmapMode = _backPixmapMode;
768 return _background;
769 }
770
771
782 void setInnerRect( TQRect innerRect )
783 {
784 _innerRect = innerRect;
785 }
786
797 TQRect innerRect() const
798 {
799 return _innerRect;
800 }
801
802
810 virtual void paintBackground( TQPainter& painter, const TQRect& innerRect ) const;
818 virtual void paintEdges( TQPainter& painter, const TQRect& innerRect ) const;
826 virtual void paintCorners( TQPainter& painter, const TQRect& innerRect ) const;
827
828
829public:
843 enum KDFramePaintSteps { PaintBackground, PaintEdges, PaintCorners, PaintBorder, PaintAll };
844
845public slots:
846
871 virtual void paint( TQPainter* painter,
872 KDFramePaintSteps steps = PaintAll,
873 TQRect innerRect = TQRect(0,0,0,0) ) const;
874
875
879 void clearAll()
880 {
881 _background = TQBrush();
882 _backPixmap = TQPixmap();
883 _backPixmapMode = PixStretched;
884 _shadowWidth = 0;
885 _sunPos = CornerTopLeft;
886 _innerRect = TQRect( 0,0, 0,0 );
887 _topProfile.clear();
888 _rightProfile.clear();
889 _bottomProfile.clear();
890 _leftProfile.clear();
891 _cornerTL.setAll( CornerNormal, 0, 0 );
892 _cornerTR.setAll( CornerNormal, 0, 0 );
893 _cornerBL.setAll( CornerNormal, 0, 0 );
894 _cornerBR.setAll( CornerNormal, 0, 0 );
895 }
896
897public:
898
917 KDFrame( TQRect innerRect = TQRect(0,0,0,0),
918 SimpleFrame frame = FrameFlat,
919 int lineWidth = 1,
920 int midLineWidth = 0,
921 TQPen pen = TQPen(), // solid black line with 0 width
922 TQBrush background = TQBrush(), // no brush
923 const TQPixmap* backPixmap = 0, // no pixmap
924 BackPixmapMode backPixmapMode = PixStretched,
925 int shadowWidth = 0,
926 CornerName sunPos = CornerTopLeft )
927 {
928 _profileSections.setAutoDelete( true );
929 _innerRect = innerRect;
930 setSimpleFrame( frame,
931 lineWidth,
932 midLineWidth,
933 pen,
934 background,
935 backPixmap,
936 backPixmapMode );
937 _shadowWidth = shadowWidth;
938 _sunPos = sunPos;
939 }
940
941
942/*
943 Constructor. Set up a frame by copying settings of another frame.
944
945 The constructor does *not* have a \c parent parameter since drawing
946 of the frame is not done transparently but by (one or more) explicit
947 calls of the frames paint() methode. See explanation given there
948 to learn about the why and how of this...
949
950 \note The rectangle applies to the <b>inner</b> area of the frame.
951 The Frame is drawn around this area: touching it but not covering it.
952 The outer size of the frame and the position of its outer left corner
953 depends from the frame profile width.
954
955 \sa rect, setInnerRect, setProfile
956
957 KDFrame( TQRect innerRect,
958 const KDFrame& R,
959 CornerName sunPos = CornerUNKNOWN )
960 {
961 deepCopy( *this, R );
962 if( innerRect.isValid() )
963 _innerRect = innerRect;
964 if( CornerUNKNOWN != sunPos )
965 _sunPos = sunPos;
966
967 _profileSections.setAutoDelete( true );
968 }
969*/
970private:
971 KDFrame( const KDFrame& ) : TQObject(0) {}
972 KDFrame& operator=( const KDFrame& ){return *this;}
973
974
975
976public:
980 virtual ~KDFrame();
981
982 /*
983 Kopierroutine, aufgerufen im Copy-C'tor und im Zuweisungs-Operator
984 */
985 static void deepCopy( KDFrame& D, const KDFrame& R )
986 {
987 D._shadowWidth = R._shadowWidth;
988 D._sunPos = R._sunPos;
989 D._background = R._background;
990 D._backPixmap = R._backPixmap;
991 D._backPixmapMode = R._backPixmapMode;
992 D._innerRect = R._innerRect;
993 D._topProfile = R._topProfile;
994 D._rightProfile = R._rightProfile;
995 D._bottomProfile = R._bottomProfile;
996 D._leftProfile = R._leftProfile;
997 D._cornerTL = R._cornerTL;
998 D._cornerTR = R._cornerTR;
999 D._cornerBL = R._cornerBL;
1000 D._cornerBR = R._cornerBR;
1001 D._profileSections= R._profileSections;
1002 D._profileSections.setAutoDelete( true );
1003 R.setProfileSectionsAutoDelete( false );
1004 }
1005
1006 friend TQTextStream& operator<<( TQTextStream& s, const KDFrame& p );
1007 friend TQTextStream& operator>>( TQTextStream& s, KDFrame& p );
1008
1018 static void createFrameNode( TQDomDocument& document, TQDomNode& parent,
1019 const TQString& elementName,
1020 const KDFrame& frame );
1021
1031 static void createFrameProfileNode( TQDomDocument& document,
1032 TQDomNode& parent,
1033 const TQString& elementName,
1034 KDFrameProfile profile );
1035
1043 static bool readFrameNode( const TQDomElement& element,
1044 KDFrame& frame );
1045
1053 static bool readFrameProfileNode( const TQDomElement& element,
1054 KDFrameProfile& profile );
1055
1056signals:
1060 void changed();
1061
1062private:
1063 void setProfileSectionsAutoDelete( bool on ) const
1064 {
1065 ((KDFrame*)this)->_profileSections.setAutoDelete( on );
1066 }
1067
1071 int _shadowWidth;
1072
1076 CornerName _sunPos;
1077
1081 TQBrush _background;
1082
1086 TQPixmap _backPixmap;
1087
1092 BackPixmapMode _backPixmapMode;
1093
1097 TQRect _innerRect;
1098
1109 KDFrameProfile _profileSections;
1110
1114 KDFrameProfile _topProfile;
1118 KDFrameProfile _rightProfile;
1122 KDFrameProfile _bottomProfile;
1126 KDFrameProfile _leftProfile;
1127
1131 KDFrameCorner _cornerTL;
1135 KDFrameCorner _cornerTR;
1139 KDFrameCorner _cornerBL;
1143 KDFrameCorner _cornerBR;
1144};
1145
1146
1154TQTextStream& operator<<( TQTextStream& s, const KDFrame& p );
1155
1156
1165TQTextStream& operator>>( TQTextStream& s, KDFrame& p );
1166
1167
1168#endif
TQTextStream & operator>>(TQTextStream &s, KDFrame &p)
Reads the an XML document from the text stream s into the KDFrame object p.
TQTextStream & operator<<(TQTextStream &s, const KDFrame &p)
Writes the KDFrame object p as an XML document to the text stream s.
Curvature
Profile Curvature Mode: specifying the shape of a frame profile section.
Direction
Profile Direction Mode: specifying whether a part of a profile looks embossed or engraved in comparis...
The main class of KDFrame.
Definition KDFrame.h:88
static BackPixmapMode stringToBackPixmapMode(const TQString &string)
Converts the specified string to a background pixmap mode enum value.
Definition KDFrame.h:140
void setBackPixmap(const TQPixmap *backPixmap=0, BackPixmapMode backPixmapMode=PixStretched)
Specifies a pixmap to be used to fill the inner area of this frame, calling this methode without pass...
Definition KDFrame.h:744
BackPixmapMode
These are ways how to display a pixmap that might be painted into the inner area.
Definition KDFrame.h:109
friend TQTextStream & operator>>(TQTextStream &s, KDFrame &p)
Reads the an XML document from the text stream s into the KDFrame object p.
const KDFrameProfile & cornerProfile(CornerName name) const
Definition KDFrame.h:677
KDFramePaintSteps
The different steps taken to paint the frame: first paint the background then the edges then the corn...
Definition KDFrame.h:843
TQRect innerRect() const
Returns the position and the size of the frame.
Definition KDFrame.h:797
KDFrame(TQRect innerRect=TQRect(0, 0, 0, 0), SimpleFrame frame=FrameFlat, int lineWidth=1, int midLineWidth=0, TQPen pen=TQPen(), TQBrush background=TQBrush(), const TQPixmap *backPixmap=0, BackPixmapMode backPixmapMode=PixStretched, int shadowWidth=0, CornerName sunPos=CornerTopLeft)
Default Constructor.
Definition KDFrame.h:917
void setBackground(TQBrush background=TQBrush(TQt::NoBrush))
Specifies the brush to be used to fill the inner area of this frame, calling this methode without pas...
Definition KDFrame.h:730
CornerName sunPos() const
Definition KDFrame.h:713
SimpleFrame
These simple frames are pre-defined for your convenience.
Definition KDFrame.h:177
static CornerName stringToCornerName(const TQString &string)
Definition KDFrame.h:394
static TQString cornerStyleToString(CornerStyle type)
Definition KDFrame.h:440
int cornerWidth(CornerName name) const
Definition KDFrame.h:656
void changed()
This signal is emitted when any of the frame parameters has changed.
void setInnerRect(TQRect innerRect)
Specifies the position and the size of area that is surrounded by the frame.
Definition KDFrame.h:782
void clearAll()
Remove all settings and specify no border, no edges, no background.
Definition KDFrame.h:879
void setCorner(CornerName name, CornerStyle style, int width, KDFrameProfile *const profile=0)
Definition KDFrame.h:586
static TQString cornerNameToString(CornerName type)
Definition KDFrame.h:366
CornerStyle cornerStyle(CornerName name) const
Definition KDFrame.h:635
void setSunPos(CornerName sunPos)
Definition KDFrame.h:699
static TQString backPixmapModeToString(BackPixmapMode type)
Converts the specified background pixmap mode enum to a string representation.
Definition KDFrame.h:120
ProfileName
Definition KDFrame.h:241
void setCorners(CornerStyle style, int width, KDFrameProfile *const profile=0)
Definition KDFrame.h:615
static CornerStyle stringToCornerStyle(const TQString &string)
Definition KDFrame.h:464
CornerStyle
Definition KDFrame.h:425
friend TQTextStream & operator<<(TQTextStream &s, const KDFrame &p)
Writes the KDFrame object p as an XML document to the text stream s.
const TQBrush & background(const TQPixmap *&backPixmap, BackPixmapMode &backPixmapMode) const
Returns the brush that is used to fill the inner area of this frame, or a TQBrush( \cNoBrush ) if no ...
Definition KDFrame.h:763