KDChartHeaderFooter.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002  ** Copyright (C) 2007 Klar�vdalens Datakonsult AB.  All rights reserved.
00003  **
00004  ** This file is part of the KD Chart library.
00005  **
00006  ** This file may be distributed and/or modified under the terms of the
00007  ** GNU General Public License version 2 as published by the Free Software
00008  ** Foundation and appearing in the file LICENSE.GPL included in the
00009  ** packaging of this file.
00010  **
00011  ** Licensees holding valid commercial KD Chart licenses may use this file in
00012  ** accordance with the KD Chart Commercial License Agreement provided with
00013  ** the Software.
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  ** See http://www.kdab.net/kdchart for
00019  **   information about KDChart Commercial License Agreements.
00020  **
00021  ** Contact info@kdab.net if any conditions of this
00022  ** licensing are not clear to you.
00023  **
00024  **********************************************************************/
00025 
00026 #include "KDChartHeaderFooter.h"
00027 #include "KDChartHeaderFooter_p.h"
00028 
00029 #include "KDChartChart.h"
00030 #include <KDChartTextAttributes.h>
00031 #include <QFont>
00032 #include <QPainter>
00033 #include <QAbstractTextDocumentLayout>
00034 #include <QTextDocumentFragment>
00035 #include <QTextBlock>
00036 #include <QtDebug>
00037 #include <QLabel>
00038 #include "KDTextDocument.h"
00039 
00040 #include <KDABLibFakes>
00041 
00042 using namespace KDChart;
00043 
00044 HeaderFooter::Private::Private() :
00045     type( Header ),
00046     position( Position::North )
00047 {
00048 }
00049 
00050 HeaderFooter::Private::~Private()
00051 {
00052 }
00053 
00054 #define d d_func()
00055 
00056 HeaderFooter::HeaderFooter( Chart* parent ) :
00057     TextArea( new Private() )
00058 {
00059     setParent( parent );
00060     init();
00061 }
00062 
00063 HeaderFooter::~HeaderFooter()
00064 {
00065     emit destroyedHeaderFooter( this );
00066 }
00067 
00068 void HeaderFooter::setParent( QObject* parent )
00069 {
00070     QObject::setParent( parent );
00071     setParentWidget( qobject_cast<QWidget*>( parent ) );
00072     if( parent && ! autoReferenceArea() )
00073         setAutoReferenceArea( parent );
00074 }
00075 
00076 void HeaderFooter::init()
00077 {
00078     TextAttributes ta;
00079     ta.setPen( QPen(Qt::black) );
00080     ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) );
00081 
00082     Measure m( 35.0 );
00083     m.setRelativeMode( autoReferenceArea(), KDChartEnums::MeasureOrientationMinimum );
00084     ta.setFontSize( m );
00085 
00086     m.setValue( 8.0 );
00087     m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
00088     ta.setMinimalFontSize( m  );
00089 
00090     setTextAttributes( ta );
00091 }
00092 
00096 HeaderFooter * HeaderFooter::clone() const
00097 {
00098     HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), 0 );
00099     headerFooter->setType( type() );
00100     headerFooter->setPosition( position() );
00101     headerFooter->setText( text() );
00102     headerFooter->setTextAttributes( textAttributes() );
00103     return headerFooter;
00104 }
00105 
00106 bool HeaderFooter::compare( const HeaderFooter& other )const
00107 {
00108     return  (type()           == other.type()) &&
00109             (position()       == other.position()) &&
00110             // also compare members inherited from the base class:
00111             (autoReferenceArea() == other.autoReferenceArea()) &&
00112             (text()              == other.text()) &&
00113             (textAttributes()    == other.textAttributes());
00114 }
00115 
00116 void HeaderFooter::setType( HeaderFooterType type )
00117 {
00118     d->type = type;
00119     emit positionChanged( this );
00120 }
00121 
00122 HeaderFooter::HeaderFooterType HeaderFooter::type() const
00123 {
00124     return d->type;
00125 }
00126 
00127 void HeaderFooter::setPosition( Position position )
00128 {
00129     d->position = position;
00130     emit positionChanged( this );
00131 }
00132 
00133 Position HeaderFooter::position() const
00134 {
00135     return d->position;
00136 }

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