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

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/