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 
00035 #include "KDChartEnums.h"
00036 
00040 class PrerenderedElement {
00041 public:
00042     PrerenderedElement();
00043     virtual ~PrerenderedElement() {}
00044 
00048     virtual const QPixmap& pixmap() const = 0;
00049 
00052     virtual QPointF referencePointLocation( KDChartEnums::PositionValue ) const = 0;
00053 
00055     void setPosition( const QPointF& position );
00057     const QPointF& position() const;
00058 
00063     void setReferencePoint( KDChartEnums::PositionValue );
00065     KDChartEnums::PositionValue referencePoint() const;
00066 
00067 protected:
00074     virtual void invalidate() const = 0;
00075 
00076 private:
00077     QPointF m_position;
00078     KDChartEnums::PositionValue m_referencePoint;
00079 };
00080 
00097 // FIXME this is merely a prototype
00098 // FIXME caching could be done by a second layer that can be used to,
00099 // e.g., query for a prerendered element by id or name, or by changing
00100 // the pixmap() method to do lazy evaluation.
00101 class PrerenderedLabel : public PrerenderedElement
00102 {
00103 public:
00104     PrerenderedLabel();
00105     ~PrerenderedLabel();
00106 
00107     void setFont( const QFont& font );
00108     const QFont& font() const;
00109 
00110     void setText( const QString& text );
00111     const QString& text() const;
00112 
00113     void setBrush( const QBrush& brush );
00114     const QBrush& brush() const;
00115 
00116     void setPen( const QPen& );
00117     const QPen& pen() const;
00118 
00119     void setAngle( double angle );
00120     double angle() const;
00121 
00122     // reimpl PrerenderedElement:
00123     const QPixmap& pixmap() const;
00124     QPointF referencePointLocation( KDChartEnums::PositionValue position ) const;
00125     // overload: return location of referencePoint():
00126     QPointF referencePointLocation() const;
00127 
00128 protected:
00129     void invalidate() const;
00130 
00131 private:
00135     void paint() const;
00136 
00137     // store the settings (these are used for the painting):
00138     mutable bool m_dirty;
00139     QFont m_font;
00140     QString m_text;
00141     QBrush m_brush;
00142     QPen m_pen;
00143     double m_angle;
00144 
00145     // these are valid once the label has been rendered:
00146     mutable QPixmap m_pixmap;
00147     mutable QPointF m_referenceBottomLeft;
00148     mutable QPointF m_textBaseLineVector;
00149     mutable QPointF m_textAscendVector;
00150 };
00151 
00152 #endif

Generated on Mon Sep 17 16:16:50 2007 for KD Chart 2 by  doxygen 1.5.1