KD Chart 2: KDChartHeaderFooter.cpp Source File

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# KDChartHeaderFooter.cpp

Go to the documentation of this file.

    00001 /****************************************************************************
    00002  ** Copyright (C) 2006 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 "KDChartChart.h"
    00027 #include "KDChartHeaderFooter.h"
    00028 #include "KDChartHeaderFooter_p.h"
    00029 #include <KDChartTextAttributes.h>
    00030 #include <QFont>
    00031 #include <QPainter>
    00032 #include <QAbstractTextDocumentLayout>
    00033 #include <QTextDocumentFragment>
    00034 #include <QTextBlock>
    00035 #include <QtDebug>
    00036 #include <QLabel>
    00037 #include "KDTextDocument.h"
    00038
    00039 #include <KDABLibFakes>
    00040
    00041 using namespace KDChart;
    00042
    00043 HeaderFooter::Private::Private() :
    00044     type( Header ),
    00045     position( Position::North )
    00046 {
    00047 }
    00048
    00049 HeaderFooter::Private::~Private()
    00050 {
    00051 }
    00052
    00053 #define d d_func()
    00054
    00055 HeaderFooter::HeaderFooter( Chart* parent ) :
    00056     TextArea( new Private() )
    00057 {
    00058     setParent( parent );
    00059     init();
    00060 }
    00061
    00062 HeaderFooter::~HeaderFooter()
    00063 {
    00064     emit destroyedHeaderFooter( this );
    00065 }
    00066
    00067 void HeaderFooter::setParent( QObject* parent )
    00068 {
    00069     QObject::setParent( parent );
    00070     if( parent && ! autoReferenceArea() )
    00071         setAutoReferenceArea( parent );
    00072 }
    00073
    00074 void HeaderFooter::init()
    00075 {
    00076     TextAttributes ta;
    00077     ta.setPen( QPen(Qt::black) );
    00078     ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) );
    00079
    00080     Measure m( 35.0 );
    00081     m.setRelativeMode( autoReferenceArea(), KDChartEnums::MeasureOrientationMinimum );
    00082     ta.setFontSize( m );
    00083
    00084     m.setValue( 8.0 );
    00085     m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
    00086     ta.setMinimalFontSize( m  );
    00087
    00088     setTextAttributes( ta );
    00089 }
    00090
    00091 HeaderFooter * HeaderFooter::clone() const
    00092 {
    00093     HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), 0 );
    00094     headerFooter->setType( type() );
    00095     headerFooter->setPosition( position() );
    00096     headerFooter->setTextAttributes( textAttributes() );
    00097     return headerFooter;
    00098 }
    00099
    00100 bool HeaderFooter::compare( const HeaderFooter& other )const
    00101 {
    00102     return  (type()           == other.type()) &&
    00103             (position()       == other.position()) &&
    00104             // also compare members inherited from the base class:
    00105             (autoReferenceArea() == other.autoReferenceArea()) &&
    00106             (text()              == other.text()) &&
    00107             (textAttributes()    == other.textAttributes());
    00108 }
    00109
    00110 void HeaderFooter::setType( HeaderFooterType type )
    00111 {
    00112     d->type = type;
    00113     emit positionChanged( this );
    00114 }
    00115
    00116 HeaderFooter::HeaderFooterType HeaderFooter::type() const
    00117 {
    00118     return d->type;
    00119 }
    00120
    00121 void HeaderFooter::setPosition( Position position )
    00122 {
    00123     d->position = position;
    00124     emit positionChanged( this );
    00125 }
    00126
    00127 Position HeaderFooter::position() const
    00128 {
    00129     return d->position;
    00130 }