# KDChartTextLabelCache.h

Go to the documentation of this file.

    00001 #ifndef KDCHARTTEXTLABELCACHE_H
    00002 #define KDCHARTTEXTLABELCACHE_H
    00003
    00004 #include <QPixmap>
    00005
    00006 #include "KDChartEnums.h"
    00007
    00008 // base class for prerendered elements like labels, pixmaps, markers,
    00009 // etc
    00010 class PrerenderedElement {
    00011 public:
    00012     PrerenderedElement();
    00013     virtual ~PrerenderedElement() {}
    00014
    00018     virtual const QPixmap& pixmap() const = 0;
    00019
    00022     virtual QPointF referencePointLocation( KDChartEnums::PositionValue ) const = 0;
    00023
    00025     void setPosition( const QPointF& position );
    00027     const QPointF& position() const;
    00028
    00033     void setReferencePoint( KDChartEnums::PositionValue );
    00035     KDChartEnums::PositionValue referencePoint() const;
    00036
    00037 protected:
    00044     virtual void invalidate() const = 0;
    00045
    00046 private:
    00047     QPointF m_position;
    00048     KDChartEnums::PositionValue m_referencePoint;
    00049 };
    00050
    00065 // FIXME this is merely a prototype
    00066 // FIXME caching could be done by a second layer that can be used to,
    00067 // e.g., query for a prerendered element by id or name, or by changing
    00068 // the pixmap() method to do lazy evaluation.
    00069 class PrerenderedLabel : public PrerenderedElement
    00070 {
    00071 public:
    00072     PrerenderedLabel();
    00073     ~PrerenderedLabel();
    00074
    00075     void setFont( const QFont& font );
    00076     const QFont& font() const;
    00077
    00078     void setText( const QString& text );
    00079     const QString& text() const;
    00080
    00081     void setBrush( const QBrush& brush );
    00082     const QBrush& brush() const;
    00083
    00084     void setPen( const QPen& );
    00085     const QPen& pen() const;
    00086
    00087     void setAngle( double angle );
    00088     double angle() const;
    00089
    00090     // reimpl PrerenderedElement:
    00091     const QPixmap& pixmap() const;
    00092     QPointF referencePointLocation( KDChartEnums::PositionValue position ) const;
    00093     // overload: return location of referencePoint():
    00094     QPointF referencePointLocation() const;
    00095
    00096 protected:
    00097     void invalidate() const;
    00098
    00099 private:
    00103     void paint() const;
    00104
    00105     // store the settings (these are used for the painting):
    00106     mutable bool m_dirty;
    00107     QFont m_font;
    00108     QString m_text;
    00109     QBrush m_brush;
    00110     QPen m_pen;
    00111     double m_angle;
    00112
    00113     // these are valid once the label has been rendered:
    00114     mutable QPixmap m_pixmap;
    00115     mutable QPointF m_referenceBottomLeft;
    00116     mutable QPointF m_textBaseLineVector;
    00117     mutable QPointF m_textAscendVector;
    00118 };
    00119
    00120 #endif