00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 QPointF rotatedPoint( const QPointF& pt, qreal rotation, const QPointF& center = QPointF() );
00043 QRectF rotatedRect( const QRectF& pt, qreal rotation, const QPointF& center = QPointF() );
00044
00045 namespace KDChart {
00046 class AbstractDiagram;
00047 class PaintContext;
00048
00053 class KDCHART_EXPORT AbstractLayoutItem : public QLayoutItem
00054 {
00055 public:
00056 AbstractLayoutItem( Qt::Alignment itemAlignment = 0 ) :
00057 QLayoutItem( itemAlignment ),
00058 mParent( 0 ),
00059 mParentLayout( 0 ) {}
00060
00067 virtual void paintAll( QPainter& painter );
00068
00069 virtual void paint( QPainter* ) = 0;
00070
00071 virtual void paintCtx( PaintContext* context );
00072 virtual void setParentWidget( QWidget* widget );
00073 virtual void sizeHintChanged()const;
00074
00075 void setParentLayout( QLayout* lay )
00076 {
00077 mParentLayout = lay;
00078 }
00079 QLayout* parentLayout()
00080 {
00081 return mParentLayout;
00082 }
00083 void removeFromParentLayout()
00084 {
00085 if( mParentLayout ){
00086 if( widget() )
00087 mParentLayout->removeWidget( widget() );
00088 else
00089 mParentLayout->removeItem( this );
00090 }
00091 }
00092 protected:
00093 QWidget* mParent;
00094 QLayout* mParentLayout;
00095 };
00096
00101 class KDCHART_EXPORT TextLayoutItem : public AbstractLayoutItem
00102 {
00103 public:
00104 TextLayoutItem();
00105 TextLayoutItem( const QString& text,
00106 const TextAttributes& attributes,
00107 const QObject* autoReferenceArea,
00108 KDChartEnums::MeasureOrientation autoReferenceOrientation,
00109 Qt::Alignment alignment = 0 );
00110
00111 void setAutoReferenceArea( const QObject* area );
00112 const QObject* autoReferenceArea() const;
00113
00114 void setText(const QString & text);
00115 QString text() const;
00116
00117 void setTextAlignment( Qt::Alignment );
00118 Qt::Alignment textAlignment() const;
00119
00120 void setTextAttributes( const TextAttributes& a );
00121 TextAttributes textAttributes() const;
00122
00124 virtual bool isEmpty() const;
00126 virtual Qt::Orientations expandingDirections() const;
00128 virtual QSize maximumSize() const;
00130 virtual QSize minimumSize() const;
00132 virtual QSize sizeHint() const;
00134 virtual void setGeometry( const QRect& r );
00136 virtual QRect geometry() const;
00137
00138 virtual QSize sizeHintAndRotatedCorners(
00139 QPoint& topLeftPt, QPoint& topRightPt, QPoint& bottomRightPt, QPoint& bottomLeftPt) const;
00140 virtual QSize sizeHintUnrotated() const;
00141
00142 virtual bool intersects( const TextLayoutItem& other, const QPointF& myPos, const QPointF& otherPos ) const;
00143 virtual bool intersects( const TextLayoutItem& other, const QPoint& myPos, const QPoint& otherPos ) const;
00144
00145 virtual qreal realFontSize() const;
00146 virtual QFont realFont() const;
00147
00148 virtual void paint( QPainter* );
00149
00150 private:
00151 QPolygon rotatedCorners() const;
00152 bool realFontWasRecalculated() const;
00153 QSize unrotatedSizeHint( QFont fnt = QFont() ) const;
00154 QSize calcSizeHint( QFont fnt,
00155 QPoint& topLeftPt, QPoint& topRightPt, QPoint& bottomRightPt, QPoint& bottomLeftPt ) const;
00156
00157 qreal fitFontSizeToGeometry() const;
00158
00159 QRect mRect;
00160 QString mText;
00161 Qt::Alignment mTextAlignment;
00162 TextAttributes mAttributes;
00163 const QObject* mAutoReferenceArea;
00164 KDChartEnums::MeasureOrientation mAutoReferenceOrientation;
00165 mutable QSize cachedSizeHint;
00166 mutable QPoint cachedTopLeft;
00167 mutable QPoint cachedTopRight;
00168 mutable QPoint cachedBottomRight;
00169 mutable QPoint cachedBottomLeft;
00170 mutable qreal cachedFontSize;
00171 mutable QFont cachedFont;
00172 };
00173
00174 class KDCHART_EXPORT TextBubbleLayoutItem : public AbstractLayoutItem
00175 {
00176 public:
00177 TextBubbleLayoutItem();
00178 TextBubbleLayoutItem( const QString& text,
00179 const TextAttributes& attributes,
00180 const QObject* autoReferenceArea,
00181 KDChartEnums::MeasureOrientation autoReferenceOrientation,
00182 Qt::Alignment alignment = 0 );
00183
00184 ~TextBubbleLayoutItem();
00185
00186 void setAutoReferenceArea( const QObject* area );
00187 const QObject* autoReferenceArea() const;
00188
00189 void setText(const QString & text);
00190 QString text() const;
00191
00192 void setTextAttributes( const TextAttributes& a );
00193 TextAttributes textAttributes() const;
00194
00196 virtual bool isEmpty() const;
00198 virtual Qt::Orientations expandingDirections() const;
00200 virtual QSize maximumSize() const;
00202 virtual QSize minimumSize() const;
00204 virtual QSize sizeHint() const;
00206 virtual void setGeometry( const QRect& r );
00208 virtual QRect geometry() const;
00209
00210 virtual void paint( QPainter* painter );
00211
00212 protected:
00213 int borderWidth() const;
00214
00215 private:
00216 TextLayoutItem* const m_text;
00217 };
00218
00223 class KDCHART_EXPORT MarkerLayoutItem : public AbstractLayoutItem
00224 {
00225 public:
00226 MarkerLayoutItem( AbstractDiagram* diagram,
00227 const MarkerAttributes& marker,
00228 const QBrush& brush,
00229 const QPen& pen,
00230 Qt::Alignment alignment = 0 );
00231
00232 virtual Qt::Orientations expandingDirections() const;
00233 virtual QRect geometry() const;
00234 virtual bool isEmpty() const;
00235 virtual QSize maximumSize() const;
00236 virtual QSize minimumSize() const;
00237 virtual void setGeometry( const QRect& r );
00238 virtual QSize sizeHint() const;
00239
00240 virtual void paint( QPainter* );
00241
00242 static void paintIntoRect(
00243 QPainter* painter,
00244 const QRect& rect,
00245 AbstractDiagram* diagram,
00246 const MarkerAttributes& marker,
00247 const QBrush& brush,
00248 const QPen& pen );
00249
00250 private:
00251 AbstractDiagram* mDiagram;
00252 QRect mRect;
00253 MarkerAttributes mMarker;
00254 QBrush mBrush;
00255 QPen mPen;
00256 };
00257
00262 class KDCHART_EXPORT LineLayoutItem : public AbstractLayoutItem
00263 {
00264 public:
00265 LineLayoutItem( AbstractDiagram* diagram,
00266 int length,
00267 const QPen& pen,
00268 Qt::Alignment alignment = 0 );
00269
00270 virtual Qt::Orientations expandingDirections() const;
00271 virtual QRect geometry() const;
00272 virtual bool isEmpty() const;
00273 virtual QSize maximumSize() const;
00274 virtual QSize minimumSize() const;
00275 virtual void setGeometry( const QRect& r );
00276 virtual QSize sizeHint() const;
00277
00278 virtual void paint( QPainter* );
00279
00280 static void paintIntoRect(
00281 QPainter* painter,
00282 const QRect& rect,
00283 const QPen& pen );
00284
00285 private:
00286 AbstractDiagram* mDiagram;
00287 int mLength;
00288 QPen mPen;
00289 QRect mRect;
00290 };
00291
00296 class KDCHART_EXPORT LineWithMarkerLayoutItem : public AbstractLayoutItem
00297 {
00298 public:
00299 LineWithMarkerLayoutItem( AbstractDiagram* diagram,
00300 int lineLength,
00301 const QPen& linePen,
00302 int markerOffs,
00303 const MarkerAttributes& marker,
00304 const QBrush& markerBrush,
00305 const QPen& markerPen,
00306 Qt::Alignment alignment = 0 );
00307
00308 virtual Qt::Orientations expandingDirections() const;
00309 virtual QRect geometry() const;
00310 virtual bool isEmpty() const;
00311 virtual QSize maximumSize() const;
00312 virtual QSize minimumSize() const;
00313 virtual void setGeometry( const QRect& r );
00314 virtual QSize sizeHint() const;
00315
00316 virtual void paint( QPainter* );
00317
00318 private:
00319 AbstractDiagram* mDiagram;
00320 QRect mRect;
00321 int mLineLength;
00322 QPen mLinePen;
00323 int mMarkerOffs;
00324 MarkerAttributes mMarker;
00325 QBrush mMarkerBrush;
00326 QPen mMarkerPen;
00327 };
00328
00329
00334 class KDCHART_EXPORT HorizontalLineLayoutItem : public AbstractLayoutItem
00335 {
00336 public:
00337 HorizontalLineLayoutItem();
00338
00339 virtual Qt::Orientations expandingDirections() const;
00340 virtual QRect geometry() const;
00341 virtual bool isEmpty() const;
00342 virtual QSize maximumSize() const;
00343 virtual QSize minimumSize() const;
00344 virtual void setGeometry( const QRect& r );
00345 virtual QSize sizeHint() const;
00346
00347 virtual void paint( QPainter* );
00348
00349 private:
00350 QRect mRect;
00351 };
00352
00357 class KDCHART_EXPORT VerticalLineLayoutItem : public AbstractLayoutItem
00358 {
00359 public:
00360 VerticalLineLayoutItem();
00361
00362 virtual Qt::Orientations expandingDirections() const;
00363 virtual QRect geometry() const;
00364 virtual bool isEmpty() const;
00365 virtual QSize maximumSize() const;
00366 virtual QSize minimumSize() const;
00367 virtual void setGeometry( const QRect& r );
00368 virtual QSize sizeHint() const;
00369
00370 virtual void paint( QPainter* );
00371
00372 private:
00373 QRect mRect;
00374 };
00375
00446 class KDCHART_EXPORT AutoSpacerLayoutItem : public AbstractLayoutItem
00447 {
00448 public:
00449 AutoSpacerLayoutItem(
00450 bool layoutIsAtTopPosition, QHBoxLayout *rightLeftLayout,
00451 bool layoutIsAtLeftPosition, QVBoxLayout *topBottomLayout );
00452
00453 virtual Qt::Orientations expandingDirections() const;
00454 virtual QRect geometry() const;
00455 virtual bool isEmpty() const;
00456 virtual QSize maximumSize() const;
00457 virtual QSize minimumSize() const;
00458 virtual void setGeometry( const QRect& r );
00459 virtual QSize sizeHint() const;
00460
00461 virtual void paint( QPainter* );
00462
00463 private:
00464 QRect mRect;
00465 bool mLayoutIsAtTopPosition;
00466 QHBoxLayout *mRightLeftLayout;
00467 bool mLayoutIsAtLeftPosition;
00468 QVBoxLayout *mTopBottomLayout;
00469
00470 mutable QBrush mCommonBrush;
00471 mutable QSize mCachedSize;
00472 };
00473
00474 }
00475
00476 #endif