00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2011 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 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 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #ifndef KDCHARTTEXTLABELCACHE_H 00024 #define KDCHARTTEXTLABELCACHE_H 00025 00026 #include <QPixmap> 00027 #include <QFont> 00028 #include <QBrush> 00029 #include <QPen> 00030 00031 #include "KDChartEnums.h" 00032 00036 class PrerenderedElement { 00037 public: 00038 PrerenderedElement(); 00039 virtual ~PrerenderedElement() {} 00040 00044 virtual const QPixmap& pixmap() const = 0; 00045 00048 virtual QPointF referencePointLocation( KDChartEnums::PositionValue ) const = 0; 00049 00051 void setPosition( const QPointF& position ); 00053 const QPointF& position() const; 00054 00059 void setReferencePoint( KDChartEnums::PositionValue ); 00061 KDChartEnums::PositionValue referencePoint() const; 00062 00063 protected: 00070 virtual void invalidate() const = 0; 00071 00072 private: 00073 QPointF m_position; 00074 KDChartEnums::PositionValue m_referencePoint; 00075 }; 00076 00093 // FIXME this is merely a prototype 00094 // FIXME caching could be done by a second layer that can be used to, 00095 // e.g., query for a prerendered element by id or name, or by changing 00096 // the pixmap() method to do lazy evaluation. 00097 class PrerenderedLabel : public PrerenderedElement 00098 { 00099 public: 00100 PrerenderedLabel(); 00101 ~PrerenderedLabel(); 00102 00103 void setFont( const QFont& font ); 00104 const QFont& font() const; 00105 00106 void setText( const QString& text ); 00107 const QString& text() const; 00108 00109 void setBrush( const QBrush& brush ); 00110 const QBrush& brush() const; 00111 00112 void setPen( const QPen& ); 00113 const QPen& pen() const; 00114 00115 void setAngle( double angle ); 00116 double angle() const; 00117 00118 // reimpl PrerenderedElement: 00119 const QPixmap& pixmap() const; 00120 QPointF referencePointLocation( KDChartEnums::PositionValue position ) const; 00121 // overload: return location of referencePoint(): 00122 QPointF referencePointLocation() const; 00123 00124 protected: 00125 void invalidate() const; 00126 00127 private: 00131 void paint() const; 00132 00133 // store the settings (these are used for the painting): 00134 mutable bool m_dirty; 00135 QFont m_font; 00136 QString m_text; 00137 QBrush m_brush; 00138 QPen m_pen; 00139 double m_angle; 00140 00141 // these are valid once the label has been rendered: 00142 mutable QPixmap m_pixmap; 00143 mutable QPointF m_referenceBottomLeft; 00144 mutable QPointF m_textBaseLineVector; 00145 mutable QPointF m_textAscendVector; 00146 }; 00147 00148 #endif