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 "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 setParentWidget( qobject_cast<QWidget*>( parent ) ); 00071 if( parent && ! autoReferenceArea() ) 00072 setAutoReferenceArea( parent ); 00073 } 00074 00075 void HeaderFooter::init() 00076 { 00077 TextAttributes ta; 00078 ta.setPen( QPen(Qt::black) ); 00079 ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) ); 00080 00081 Measure m( 35.0 ); 00082 m.setRelativeMode( autoReferenceArea(), KDChartEnums::MeasureOrientationMinimum ); 00083 ta.setFontSize( m ); 00084 00085 m.setValue( 8.0 ); 00086 m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute ); 00087 ta.setMinimalFontSize( m ); 00088 00089 setTextAttributes( ta ); 00090 } 00091 00095 HeaderFooter * HeaderFooter::clone() const 00096 { 00097 HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), 0 ); 00098 headerFooter->setType( type() ); 00099 headerFooter->setPosition( position() ); 00100 headerFooter->setTextAttributes( textAttributes() ); 00101 return headerFooter; 00102 } 00103 00104 bool HeaderFooter::compare( const HeaderFooter& other )const 00105 { 00106 return (type() == other.type()) && 00107 (position() == other.position()) && 00108 // also compare members inherited from the base class: 00109 (autoReferenceArea() == other.autoReferenceArea()) && 00110 (text() == other.text()) && 00111 (textAttributes() == other.textAttributes()); 00112 } 00113 00114 void HeaderFooter::setType( HeaderFooterType type ) 00115 { 00116 d->type = type; 00117 emit positionChanged( this ); 00118 } 00119 00120 HeaderFooter::HeaderFooterType HeaderFooter::type() const 00121 { 00122 return d->type; 00123 } 00124 00125 void HeaderFooter::setPosition( Position position ) 00126 { 00127 d->position = position; 00128 emit positionChanged( this ); 00129 } 00130 00131 Position HeaderFooter::position() const 00132 { 00133 return d->position; 00134 }