kchart

KDFrame.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 __KDFRAME_H__
00030 #define __KDFRAME_H__
00031 
00032 #include <qapplication.h>
00033 #include <qfont.h>
00034 #include <qcolor.h>
00035 #include <qpixmap.h>
00036 #include <qpen.h>
00037 #include <qmap.h>
00038 #include <qobject.h>
00039 #include <qtextstream.h>
00040 #include <qdom.h>
00041 
00042 #include <KDFrameProfileSection.h>
00043 
00044 
00087 class KDCHART_EXPORT KDFrame : public QObject
00088 {
00089     Q_OBJECT
00090     Q_ENUMS( BackPixmapMode )
00091     Q_ENUMS( SimpleFrame )
00092     Q_ENUMS( ProfileName )
00093     Q_ENUMS( CornerName )
00094     Q_ENUMS( CornerStyle )
00095     Q_ENUMS( KDFramePaintSteps )
00096 
00097 public:
00099 
00100 
00108     enum BackPixmapMode { PixCentered, PixScaled, PixStretched };
00109 
00110 public slots:
00111 
00119     static QString backPixmapModeToString( BackPixmapMode type ) {
00120         switch( type ) {
00121             case PixCentered:
00122                 return "Centered";
00123             case PixScaled:
00124                 return "Scaled";
00125             case PixStretched:
00126                 return "Stretched";
00127         }
00128 
00129         return "Stretched";
00130     }
00131 
00132 
00139     static BackPixmapMode stringToBackPixmapMode( const QString& string ) {
00140         if( string == "Centered" )
00141             return PixCentered;
00142         else if( string == "Scaled" )
00143             return PixScaled;
00144         else if( string == "Stretched" )
00145             return PixStretched;
00146 
00147         return PixStretched;
00148     }
00149 
00150 
00151 public:
00152 
00153 
00176     enum SimpleFrame { FrameFlat,        FrameElegance,
00177         FrameBoxRaized,   FrameBoxSunken,
00178         FramePanelRaized, FramePanelSunken,
00179         FrameSemicircular };
00180 
00181 public slots:
00182 
00217     void setSimpleFrame( SimpleFrame    frame,
00218             int            lineWidth,
00219             int            midLineWidth,
00220             QPen           pen,
00221             QBrush         background     = QBrush(),
00222             const QPixmap* backPixmap     = 0,
00223             BackPixmapMode backPixmapMode = PixStretched );
00224 
00225 public:
00240     enum ProfileName { ProfileTop,    ProfileRight,
00241         ProfileBottom, ProfileLeft };
00242 
00243 public slots:
00258     void clearProfile( ProfileName name );
00259 
00276     void addProfileSection( ProfileName      name,
00277             int              wid,
00278             QPen             pen,
00279             KDFrameProfileSection::Direction dir  = KDFrameProfileSection::DirPlain, // PENDING(blackie) possible enum problem
00280             KDFrameProfileSection::Curvature curv = KDFrameProfileSection::CvtPlain );
00281 
00319     void setProfile( ProfileName name, const KDFrameProfile& profile );
00320 
00330     const KDFrameProfile& profile( ProfileName name ) const;
00331 
00332 public:
00333 
00348     enum CornerName { CornerTopLeft,
00349         CornerTopRight,
00350         CornerBottomLeft,
00351         CornerBottomRight,
00352         CornerUNKNOWN };
00353 
00354 public slots:
00365     static QString cornerNameToString( CornerName type ) {
00366         switch( type ) {
00367             case CornerTopLeft:
00368                 return "TopLeft";
00369             case CornerTopRight:
00370                 return "TopRight";
00371             case CornerBottomLeft:
00372                 return "BottomLeft";
00373             case CornerBottomRight:
00374                 return "BottomRight";
00375             case CornerUNKNOWN:
00376                 return "UNKNOWN";
00377         }
00378 
00379         return "UNKNOWN";
00380     }
00381 
00382 
00393     static CornerName stringToCornerName( const QString& string ) {
00394         if( string == "TopLeft" )
00395             return CornerTopLeft;
00396         else if( string == "TopRight" )
00397             return CornerTopRight;
00398         else if( string == "BottomLeft" )
00399             return CornerBottomLeft;
00400         else if( string == "BottomRight" )
00401             return CornerBottomRight;
00402         else if( string == "UNKNOWN" )
00403             return CornerUNKNOWN;
00404 
00405         return CornerUNKNOWN;
00406     }
00407 
00408 public:
00409 
00410 
00424     enum CornerStyle { CornerNormal,
00425         CornerRound,
00426         CornerOblique };
00427 
00428 public slots:
00439         static QString cornerStyleToString( CornerStyle type ) {
00440             switch( type ) {
00441                 case CornerNormal:
00442                     return "Normal";
00443                 case CornerRound:
00444                     return "Round";
00445                 case CornerOblique:
00446                     return "Oblique";
00447             }
00448 
00449             return "Normal";
00450         }
00451 
00452 
00463         static CornerStyle stringToCornerStyle( const QString& string ) {
00464             if( string == "Normal" )
00465                 return CornerNormal;
00466             else if( string == "Round" )
00467                 return CornerRound;
00468             else if( string == "Oblique" )
00469                 return CornerOblique;
00470 
00471             return CornerNormal;
00472         }
00473 
00474 
00475 public:
00476 
00477 // MOC_SKIP_BEGIN
00490     class KDCHART_EXPORT KDFrameCorner
00491         {
00492             friend class KDFrame;
00493             public:
00494             KDFrameCorner( CornerStyle           style   = CornerNormal,
00495                     int                   width   = 0,
00496                     KDFrameProfile* const profile = 0 )
00497                 : _style( style ),
00498             _width( width )
00499             {
00500                 if( profile )
00501                     _profile = *profile;
00502                 else
00503                     _profile.clear();
00504             }
00508             virtual ~KDFrameCorner();
00509 
00523             static void createFrameCornerNode( QDomDocument& document,
00524                     QDomNode& parent,
00525                     const QString& elementName,
00526                     const KDFrameCorner& corner );
00527 
00539             static bool readFrameCornerNode( const QDomElement& element,
00540                     KDFrameCorner& corner );
00541 
00542             protected:
00543             void setAll( CornerStyle           style,
00544                     int                   width,
00545                     KDFrameProfile* const profile = 0 )
00546             {
00547                 _style = style;
00548                 _width = width;
00549                 if( profile )
00550                     _profile = *profile;
00551                 else
00552                     _profile.clear();
00553             }
00554             CornerStyle style() const
00555             {
00556                 return _style;
00557             }
00558             int width() const
00559             {
00560                 return _width;
00561             }
00562             const KDFrameProfile& profile() const
00563             {
00564                 return _profile;
00565             }
00566             private:
00567             CornerStyle  _style;
00568             int          _width;
00569             KDFrameProfile _profile;
00570         };
00571 
00572 // MOC_SKIP_END
00573 
00574 public slots:
00585         void setCorner( CornerName name,
00586                 CornerStyle style,
00587                 int width,
00588                 KDFrameProfile* const profile = 0 )
00589         {
00590             switch( name ) {
00591                 case CornerTopLeft:     _cornerTL.setAll( style, width, profile );
00592                                         break;
00593                 case CornerTopRight:    _cornerTR.setAll( style, width, profile );
00594                                         break;
00595                 case CornerBottomLeft:  _cornerBL.setAll( style, width, profile );
00596                                         break;
00597                 case CornerBottomRight: _cornerBR.setAll( style, width, profile );
00598                                         break;
00599                 case CornerUNKNOWN:
00600                                         break;
00601             }
00602         }
00603 
00614         void setCorners( CornerStyle style,
00615                 int width,
00616                 KDFrameProfile* const profile = 0 )
00617         {
00618             _cornerTL.setAll( style, width, profile );
00619             _cornerTR.setAll( style, width, profile );
00620             _cornerBL.setAll( style, width, profile );
00621             _cornerBR.setAll( style, width, profile );
00622         }
00623 
00624 
00634         CornerStyle cornerStyle( CornerName name ) const
00635         {
00636             switch( name ) {
00637                 case CornerTopLeft:     return _cornerTL.style();
00638                 case CornerTopRight:    return _cornerTR.style();
00639                 case CornerBottomLeft:  return _cornerBL.style();
00640                 case CornerBottomRight: return _cornerBR.style();
00641                 case CornerUNKNOWN:
00642                 default:                return CornerNormal;
00643             }
00644         }
00645 
00655         int cornerWidth( CornerName name ) const
00656         {
00657             switch( name ) {
00658                 case CornerTopLeft:     return _cornerTL.width();
00659                 case CornerTopRight:    return _cornerTR.width();
00660                 case CornerBottomLeft:  return _cornerBL.width();
00661                 case CornerBottomRight: return _cornerBR.width();
00662                 case CornerUNKNOWN:
00663                 default:                return 0;
00664             }
00665         }
00666 
00676         const KDFrameProfile& cornerProfile( CornerName name ) const
00677         {
00678             switch( name ) {
00679                 case CornerUNKNOWN:
00680                 case CornerTopLeft:     return _cornerTL.profile();
00681                 case CornerTopRight:    return _cornerTR.profile();
00682                 case CornerBottomLeft:  return _cornerBL.profile();
00683                 case CornerBottomRight: return _cornerBR.profile();
00684                 default: return _cornerTL.profile();
00685             }
00686         }
00687 
00688 
00698         void setSunPos( CornerName sunPos )
00699         {
00700             _sunPos = sunPos;
00701         }
00702 
00712         CornerName sunPos() const
00713         {
00714             return _sunPos;
00715         }
00716 
00717 
00729         void setBackground( QBrush background = QBrush( Qt::NoBrush ) )
00730         {
00731             _background = background;
00732         }
00733 
00743         void setBackPixmap( const QPixmap* backPixmap     = 0,
00744                 BackPixmapMode backPixmapMode = PixStretched )
00745         {
00746             _backPixmap     = backPixmap ? *backPixmap : QPixmap();
00747             _backPixmapMode = backPixmapMode;
00748         }
00749 
00762         const QBrush& background( const QPixmap*& backPixmap,
00763                 BackPixmapMode& backPixmapMode ) const
00764         {
00765             backPixmap     = &_backPixmap;
00766             backPixmapMode =  _backPixmapMode;
00767             return _background;
00768         }
00769 
00770 
00781         void setInnerRect( QRect innerRect )
00782         {
00783             _innerRect = innerRect;
00784         }
00785 
00796         QRect innerRect() const
00797         {
00798             return _innerRect;
00799         }
00800 
00801 
00809         virtual void paintBackground( QPainter& painter, const QRect& innerRect ) const;
00817         virtual void paintEdges( QPainter& painter, const QRect& innerRect ) const;
00825         virtual void paintCorners( QPainter& painter, const QRect& innerRect ) const;
00826 
00827 
00828 public:
00842         enum KDFramePaintSteps { PaintBackground, PaintEdges, PaintCorners, PaintBorder, PaintAll };
00843 
00844 public slots:
00845 
00870         virtual void paint( QPainter* painter,
00871                 KDFramePaintSteps steps = PaintAll,
00872                 QRect innerRect         = QRect(0,0,0,0) ) const;
00873 
00874 
00878         void clearAll()
00879         {
00880             _background     = QBrush();
00881             _backPixmap     = QPixmap();
00882             _backPixmapMode = PixStretched;
00883             _shadowWidth    = 0;
00884             _sunPos         = CornerTopLeft;
00885             _innerRect      = QRect( 0,0, 0,0 );
00886             _topProfile.clear();
00887             _rightProfile.clear();
00888             _bottomProfile.clear();
00889             _leftProfile.clear();
00890             _cornerTL.setAll( CornerNormal, 0, 0 );
00891             _cornerTR.setAll( CornerNormal, 0, 0 );
00892             _cornerBL.setAll( CornerNormal, 0, 0 );
00893             _cornerBR.setAll( CornerNormal, 0, 0 );
00894         }
00895 
00896 public:
00897 
00916     KDFrame( QRect          innerRect      = QRect(0,0,0,0),
00917             SimpleFrame    frame          = FrameFlat,
00918             int            lineWidth      = 1,
00919             int            midLineWidth   = 0,
00920             QPen           pen            = QPen(),   // solid black line with 0 width
00921             QBrush         background     = QBrush(), // no brush
00922             const QPixmap* backPixmap     = 0,        // no pixmap
00923             BackPixmapMode backPixmapMode = PixStretched,
00924             int            shadowWidth    = 0,
00925             CornerName     sunPos         = CornerTopLeft )
00926     {
00927         _profileSections.setAutoDelete( true );
00928         _innerRect = innerRect;
00929         setSimpleFrame( frame,
00930                         lineWidth,
00931                         midLineWidth,
00932                         pen,
00933                         background,
00934                         backPixmap,
00935                         backPixmapMode );
00936         _shadowWidth = shadowWidth;
00937         _sunPos      = sunPos;
00938     }
00939 
00940 
00941 /*
00942     Constructor. Set up a frame by copying settings of another frame.
00943 
00944     The constructor does *not* have a \c parent parameter since drawing
00945     of the frame is not done transparently but by (one or more) explicit
00946     calls of the frames paint() methode.  See explanation given there
00947     to learn about the why and how of this...
00948 
00949     \note The rectangle applies to the <b>inner</b> area of the frame.
00950     The Frame is drawn around this area: touching it but not covering it.
00951     The outer size of the frame and the position of its outer left corner
00952     depends from the frame profile width.
00953 
00954     \sa rect, setInnerRect, setProfile
00955 
00956     KDFrame( QRect innerRect,
00957             const KDFrame& R,
00958             CornerName sunPos = CornerUNKNOWN )
00959     {
00960         deepCopy( *this, R );
00961         if( innerRect.isValid() )
00962             _innerRect = innerRect;
00963         if( CornerUNKNOWN != sunPos )
00964             _sunPos = sunPos;
00965 
00966         _profileSections.setAutoDelete( true );
00967     }
00968 */
00969 private:
00970     KDFrame( const KDFrame& ) : QObject(0) {}
00971     KDFrame& operator=( const KDFrame& ){return *this;}
00972 
00973 
00974 
00975 public:
00979     virtual ~KDFrame();
00980 
00981     /*
00982     Kopierroutine, aufgerufen im Copy-C'tor und im Zuweisungs-Operator
00983     */
00984     static void deepCopy( KDFrame& D, const KDFrame& R )
00985     {
00986         D._shadowWidth    = R._shadowWidth;
00987         D._sunPos         = R._sunPos;
00988         D._background     = R._background;
00989         D._backPixmap     = R._backPixmap;
00990         D._backPixmapMode = R._backPixmapMode;
00991         D._innerRect      = R._innerRect;
00992         D._topProfile     = R._topProfile;
00993         D._rightProfile   = R._rightProfile;
00994         D._bottomProfile  = R._bottomProfile;
00995         D._leftProfile    = R._leftProfile;
00996         D._cornerTL       = R._cornerTL;
00997         D._cornerTR       = R._cornerTR;
00998         D._cornerBL       = R._cornerBL;
00999         D._cornerBR       = R._cornerBR;
01000         D._profileSections= R._profileSections;
01001         D._profileSections.setAutoDelete( true );
01002         R.setProfileSectionsAutoDelete( false );
01003     }
01004 
01005     friend QTextStream& operator<<( QTextStream& s, const KDFrame& p );
01006     friend QTextStream& operator>>( QTextStream& s, KDFrame& p );
01007 
01017     static void createFrameNode( QDomDocument& document, QDomNode& parent,
01018             const QString& elementName,
01019             const KDFrame& frame );
01020 
01030     static void createFrameProfileNode( QDomDocument& document,
01031             QDomNode& parent,
01032             const QString& elementName,
01033             KDFrameProfile profile );
01034 
01042     static bool readFrameNode( const QDomElement& element,
01043             KDFrame& frame );
01044 
01052     static bool readFrameProfileNode( const QDomElement& element,
01053             KDFrameProfile& profile );
01054 
01055 signals:
01059     void changed();
01060 
01061 private:
01062     void setProfileSectionsAutoDelete( bool on ) const
01063     {
01064         ((KDFrame*)this)->_profileSections.setAutoDelete( on );
01065     }
01066 
01070     int _shadowWidth;
01071 
01075     CornerName _sunPos;
01076 
01080     QBrush _background;
01081 
01085     QPixmap _backPixmap;
01086 
01091     BackPixmapMode _backPixmapMode;
01092 
01096     QRect _innerRect;
01097 
01108     KDFrameProfile _profileSections;
01109 
01113     KDFrameProfile _topProfile;
01117     KDFrameProfile _rightProfile;
01121     KDFrameProfile _bottomProfile;
01125     KDFrameProfile _leftProfile;
01126 
01130     KDFrameCorner _cornerTL;
01134     KDFrameCorner _cornerTR;
01138     KDFrameCorner _cornerBL;
01142     KDFrameCorner _cornerBR;
01143 };
01144 
01145 
01153 QTextStream& operator<<( QTextStream& s, const KDFrame& p );
01154 
01155 
01164 QTextStream& operator>>( QTextStream& s, KDFrame& p );
01165 
01166 
01167 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys