KDChartTextLabelCache.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002    KDChart - a multi-platform charting engine
00003    */
00004 
00005 /****************************************************************************
00006  ** Copyright (C) 2005-2007 Klarälvdalens Datakonsult AB.  All rights reserved.
00007  **
00008  ** This file is part of the KD Chart 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 KD Chart licenses may use this file in
00016  ** accordance with the KD Chart 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.kdab.net/kdchart for
00023  **   information about KD Chart Commercial License Agreements.
00024  **
00025  ** Contact info@kdab.net if any conditions of this
00026  ** licensing are not clear to you.
00027  **
00028  **********************************************************************/
00029 
00030 #ifndef KDCHARTTEXTLABELCACHE_H
00031 #define KDCHARTTEXTLABELCACHE_H
00032 
00033 #include <QPixmap>
00034 #include <QFont>
00035 #include <QBrush>
00036 #include <QPen>
00037 
00038 #include "KDChartEnums.h"
00039 
00043 class PrerenderedElement {
00044 public:
00045     PrerenderedElement();
00046     virtual ~PrerenderedElement() {}
00047 
00051     virtual const QPixmap& pixmap() const = 0;
00052 
00055     virtual QPointF referencePointLocation( KDChartEnums::PositionValue ) const = 0;
00056 
00058     void setPosition( const QPointF& position );
00060     const QPointF& position() const;
00061 
00066     void setReferencePoint( KDChartEnums::PositionValue );
00068     KDChartEnums::PositionValue referencePoint() const;
00069 
00070 protected:
00077     virtual void invalidate() const = 0;
00078 
00079 private:
00080     QPointF m_position;
00081     KDChartEnums::PositionValue m_referencePoint;
00082 };
00083 
00100 // FIXME this is merely a prototype
00101 // FIXME caching could be done by a second layer that can be used to,
00102 // e.g., query for a prerendered element by id or name, or by changing
00103 // the pixmap() method to do lazy evaluation.
00104 class PrerenderedLabel : public PrerenderedElement
00105 {
00106 public:
00107     PrerenderedLabel();
00108     ~PrerenderedLabel();
00109 
00110     void setFont( const QFont& font );
00111     const QFont& font() const;
00112 
00113     void setText( const QString& text );
00114     const QString& text() const;
00115 
00116     void setBrush( const QBrush& brush );
00117     const QBrush& brush() const;
00118 
00119     void setPen( const QPen& );
00120     const QPen& pen() const;
00121 
00122     void setAngle( double angle );
00123     double angle() const;
00124 
00125     // reimpl PrerenderedElement:
00126     const QPixmap& pixmap() const;
00127     QPointF referencePointLocation( KDChartEnums::PositionValue position ) const;
00128     // overload: return location of referencePoint():
00129     QPointF referencePointLocation() const;
00130 
00131 protected:
00132     void invalidate() const;
00133 
00134 private:
00138     void paint() const;
00139 
00140     // store the settings (these are used for the painting):
00141     mutable bool m_dirty;
00142     QFont m_font;
00143     QString m_text;
00144     QBrush m_brush;
00145     QPen m_pen;
00146     double m_angle;
00147 
00148     // these are valid once the label has been rendered:
00149     mutable QPixmap m_pixmap;
00150     mutable QPointF m_referenceBottomLeft;
00151     mutable QPointF m_textBaseLineVector;
00152     mutable QPointF m_textAscendVector;
00153 };
00154 
00155 #endif

Generated on Thu Mar 4 23:19:13 2010 for KD Chart 2 by  doxygen 1.5.4