KD Chart 2: KDChartLayoutItems.h Source File

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# KDChartLayoutItems.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002  ** Copyright (C) 2006 Klarälvdalens Datakonsult AB.  All rights reserved.
    00003  **
    00004  ** This file is part of the KD Chart library.
    00005  **
    00006  ** This file may be distributed and/or modified under the terms of the
    00007  ** GNU General Public License version 2 as published by the Free Software
    00008  ** Foundation and appearing in the file LICENSE.GPL included in the
    00009  ** packaging of this file.
    00010  **
    00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
    00012  ** accordance with the KD Chart Commercial License Agreement provided with
    00013  ** the Software.
    00014  **
    00015  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00016  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00017  **
    00018  ** See http://www.kdab.net/kdchart for
    00019  **   information about KDChart Commercial License Agreements.
    00020  **
    00021  ** Contact info@kdab.net if any conditions of this
    00022  ** licensing are not clear to you.
    00023  **
    00024  **********************************************************************/
    00025
    00026 #ifndef KDCHARTLAYOUTITEMS_H
    00027 #define KDCHARTLAYOUTITEMS_H
    00028
    00029 #include <QBrush>
    00030 #include <QFont>
    00031 #include <QFontMetricsF>
    00032 #include <QLayout>
    00033 #include <QLayoutItem>
    00034 #include <QPen>
    00035
    00036 #include "KDChartTextAttributes.h"
    00037 #include "KDChartMarkerAttributes.h"
    00038
    00039 class QPainter;
    00040 class KDTextDocument;
    00041
    00042 namespace KDChart {
    00043     class AbstractDiagram;
    00044     class PaintContext;
    00045
    00048     class KDCHART_EXPORT AbstractLayoutItem : public QLayoutItem
    00049     {
    00050     public:
    00051         AbstractLayoutItem( Qt::Alignment itemAlignment = 0 ) :
    00052             QLayoutItem( itemAlignment ),
    00053             mParent( 0 ),
    00054             mParentLayout( 0 ) {}
    00055
    00062         virtual void paintAll( QPainter& painter );
    00063
    00064         virtual void paint( QPainter* ) = 0;
    00065
    00066         virtual void paintCtx( PaintContext* context );
    00067         virtual void setParentWidget( QWidget* widget );
    00068         virtual void sizeHintChanged()const;
    00069
    00070         void setParentLayout( QLayout* lay )
    00071         {
    00072             mParentLayout = lay;
    00073         }
    00074         QLayout* parentLayout()
    00075         {
    00076             return mParentLayout;
    00077         }
    00078         void removeFromParentLayout()
    00079         {
    00080             if( mParentLayout ){
    00081                 if( widget() )
    00082                     mParentLayout->removeWidget( widget() );
    00083                 else
    00084                     mParentLayout->removeItem( this );
    00085             }
    00086         }
    00087     protected:
    00088         QWidget* mParent;
    00089         QLayout* mParentLayout;
    00090     };
    00091
    00094     class KDCHART_EXPORT TextLayoutItem : public AbstractLayoutItem
    00095     {
    00096     public:
    00097         TextLayoutItem();
    00098         TextLayoutItem( const QString& text,
    00099                         const TextAttributes& attributes,
    00100                         const QObject* autoReferenceArea,
    00101                         KDChartEnums::MeasureOrientation autoReferenceOrientation,
    00102                         Qt::Alignment alignment = 0 );
    00103
    00104         void setAutoReferenceArea( const QObject* area );
    00105         const QObject* autoReferenceArea() const;
    00106
    00107         void setText(const QString & text);
    00108         QString text() const;
    00109
    00110         void setTextAttributes( const TextAttributes& a );
    00111         TextAttributes textAttributes() const;
    00112
    00114         virtual bool isEmpty() const;
    00116         virtual Qt::Orientations expandingDirections() const;
    00118         virtual QSize maximumSize() const;
    00120         virtual QSize minimumSize() const;
    00122         virtual QSize sizeHint() const;
    00124         virtual void setGeometry( const QRect& r );
    00126         virtual QRect geometry() const;
    00127
    00128         virtual bool intersects( const TextLayoutItem& other, const QPointF& myPos, const QPointF& otherPos ) const;
    00129         virtual bool intersects( const TextLayoutItem& other, const QPoint& myPos, const QPoint& otherPos ) const;
    00130
    00131         virtual qreal realFontSize() const;
    00132         virtual QFont realFont() const;
    00133
    00134         virtual void paint( QPainter* );
    00135
    00136     private:
    00137         QPolygon rotatedCorners() const;
    00138         bool realFontWasRecalculated() const;
    00139         QSize unrotatedSizeHint( QFont fnt = QFont() ) const;
    00140         QSize calcSizeHint( QFont fnt ) const;
    00141
    00142         QRect mRect;
    00143         QString mText;
    00144         TextAttributes mAttributes;
    00145         const QObject* mAutoReferenceArea;
    00146         KDChartEnums::MeasureOrientation mAutoReferenceOrientation;
    00147         mutable QSize cachedSizeHint;
    00148         mutable qreal cachedFontSize;
    00149         mutable QFont cachedFont;
    00150     };
    00151
    00154     class KDCHART_EXPORT MarkerLayoutItem : public AbstractLayoutItem
    00155     {
    00156         public:
    00157             MarkerLayoutItem( AbstractDiagram* diagram,
    00158                               const MarkerAttributes& marker,
    00159                               const QBrush& brush,
    00160                               const QPen& pen,
    00161                               Qt::Alignment alignment = 0 );
    00162
    00163             virtual Qt::Orientations expandingDirections() const;
    00164             virtual QRect geometry() const;
    00165             virtual bool isEmpty() const;
    00166             virtual QSize maximumSize() const;
    00167             virtual QSize minimumSize() const;
    00168             virtual void setGeometry( const QRect& r );
    00169             virtual QSize sizeHint() const;
    00170
    00171             virtual void paint( QPainter* );
    00172
    00173             static void paintIntoRect(
    00174                     QPainter* painter,
    00175                     const QRect& rect,
    00176                     AbstractDiagram* diagram,
    00177                     const MarkerAttributes& marker,
    00178                     const QBrush& brush,
    00179                     const QPen& pen );
    00180
    00181         private:
    00182             AbstractDiagram* mDiagram;
    00183             QRect mRect;
    00184             MarkerAttributes mMarker;
    00185             QBrush mBrush;
    00186             QPen mPen;
    00187     };
    00188
    00191     class KDCHART_EXPORT LineLayoutItem : public AbstractLayoutItem
    00192     {
    00193         public:
    00194             LineLayoutItem( AbstractDiagram* diagram,
    00195                             int length,
    00196                             const QPen& pen,
    00197                             Qt::Alignment alignment = 0 );
    00198
    00199             virtual Qt::Orientations expandingDirections() const;
    00200             virtual QRect geometry() const;
    00201             virtual bool isEmpty() const;
    00202             virtual QSize maximumSize() const;
    00203             virtual QSize minimumSize() const;
    00204             virtual void setGeometry( const QRect& r );
    00205             virtual QSize sizeHint() const;
    00206
    00207             virtual void paint( QPainter* );
    00208
    00209             static void paintIntoRect(
    00210                     QPainter* painter,
    00211                     const QRect& rect,
    00212                     const QPen& pen );
    00213
    00214         private:
    00215             AbstractDiagram* mDiagram;
    00216             int mLength;
    00217             QPen mPen;
    00218             QRect mRect;
    00219     };
    00220
    00223     class KDCHART_EXPORT LineWithMarkerLayoutItem : public AbstractLayoutItem
    00224     {
    00225         public:
    00226             LineWithMarkerLayoutItem( AbstractDiagram* diagram,
    00227                                       int lineLength,
    00228                                       const QPen& linePen,
    00229                                       int markerOffs,
    00230                                       const MarkerAttributes& marker,
    00231                                       const QBrush& markerBrush,
    00232                                       const QPen& markerPen,
    00233                                       Qt::Alignment alignment = 0 );
    00234
    00235             virtual Qt::Orientations expandingDirections() const;
    00236             virtual QRect geometry() const;
    00237             virtual bool isEmpty() const;
    00238             virtual QSize maximumSize() const;
    00239             virtual QSize minimumSize() const;
    00240             virtual void setGeometry( const QRect& r );
    00241             virtual QSize sizeHint() const;
    00242
    00243             virtual void paint( QPainter* );
    00244
    00245         private:
    00246             AbstractDiagram* mDiagram;
    00247             QRect mRect;
    00248             int mLineLength;
    00249             QPen mLinePen;
    00250             int mMarkerOffs;
    00251             MarkerAttributes mMarker;
    00252             QBrush mMarkerBrush;
    00253             QPen mMarkerPen;
    00254     };
    00255
    00256
    00259     class KDCHART_EXPORT HorizontalLineLayoutItem : public AbstractLayoutItem
    00260     {
    00261     public:
    00262         HorizontalLineLayoutItem();
    00263
    00264         virtual Qt::Orientations expandingDirections() const;
    00265         virtual QRect geometry() const;
    00266         virtual bool isEmpty() const;
    00267         virtual QSize maximumSize() const;
    00268         virtual QSize minimumSize() const;
    00269         virtual void setGeometry( const QRect& r );
    00270         virtual QSize sizeHint() const;
    00271
    00272         virtual void paint( QPainter* );
    00273
    00274     private:
    00275         QRect mRect;
    00276     };
    00277
    00280     class KDCHART_EXPORT VerticalLineLayoutItem : public AbstractLayoutItem
    00281     {
    00282         public:
    00283             VerticalLineLayoutItem();
    00284
    00285             virtual Qt::Orientations expandingDirections() const;
    00286             virtual QRect geometry() const;
    00287             virtual bool isEmpty() const;
    00288             virtual QSize maximumSize() const;
    00289             virtual QSize minimumSize() const;
    00290             virtual void setGeometry( const QRect& r );
    00291             virtual QSize sizeHint() const;
    00292
    00293             virtual void paint( QPainter* );
    00294
    00295         private:
    00296             QRect mRect;
    00297     };
    00298
    00367     class KDCHART_EXPORT AutoSpacerLayoutItem : public AbstractLayoutItem
    00368     {
    00369         public:
    00370             AutoSpacerLayoutItem(
    00371                     bool layoutIsAtTopPosition, QHBoxLayout *rightLeftLayout,
    00372                     bool layoutIsAtLeftPosition,  QVBoxLayout *topBottomLayout );
    00373
    00374             virtual Qt::Orientations expandingDirections() const;
    00375             virtual QRect geometry() const;
    00376             virtual bool isEmpty() const;
    00377             virtual QSize maximumSize() const;
    00378             virtual QSize minimumSize() const;
    00379             virtual void setGeometry( const QRect& r );
    00380             virtual QSize sizeHint() const;
    00381
    00382             virtual void paint( QPainter* );
    00383
    00384         private:
    00385             QRect mRect;
    00386             bool mLayoutIsAtTopPosition;
    00387             QHBoxLayout *mRightLeftLayout;
    00388             bool mLayoutIsAtLeftPosition;
    00389             QVBoxLayout *mTopBottomLayout;
    00390
    00391             mutable QBrush mCommonBrush;
    00392             mutable QSize mCachedSize;
    00393     };
    00394
    00395 }
    00396
    00397 #endif /* KDCHARTLAYOUTITEMS_H */
    00398