File indexing completed on 2024-05-12 04:20:33
0001 /* 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "KChartHeaderFooter.h" 0010 #include "KChartHeaderFooter_p.h" 0011 0012 #include "KChartChart.h" 0013 #include <KChartTextAttributes.h> 0014 #include "KTextDocument.h" 0015 #include "KChartMath_p.h" 0016 0017 #include <QFont> 0018 #include <QPainter> 0019 #include <QAbstractTextDocumentLayout> 0020 #include <QTextDocumentFragment> 0021 #include <QTextBlock> 0022 #include <QtDebug> 0023 #include <QLabel> 0024 0025 using namespace KChart; 0026 0027 HeaderFooter::Private::Private() : 0028 type( Header ), 0029 position( Position::North ) 0030 { 0031 } 0032 0033 HeaderFooter::Private::~Private() 0034 { 0035 } 0036 0037 #define d d_func() 0038 0039 HeaderFooter::HeaderFooter( Chart* parent ) : 0040 TextArea( new Private() ) 0041 { 0042 setParent( parent ); 0043 init(); 0044 } 0045 0046 HeaderFooter::~HeaderFooter() 0047 { 0048 Q_EMIT destroyedHeaderFooter( this ); 0049 } 0050 0051 void HeaderFooter::setParent( QObject* parent ) 0052 { 0053 QObject::setParent( parent ); 0054 setParentWidget( qobject_cast<QWidget*>( parent ) ); 0055 if ( parent && ! autoReferenceArea() ) 0056 setAutoReferenceArea( parent ); 0057 } 0058 0059 void HeaderFooter::init() 0060 { 0061 TextAttributes ta; 0062 ta.setPen( QPen(Qt::black) ); 0063 ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) ); 0064 0065 Measure m( 35.0 ); 0066 m.setRelativeMode( autoReferenceArea(), KChartEnums::MeasureOrientationMinimum ); 0067 ta.setFontSize( m ); 0068 0069 m.setValue( 8.0 ); 0070 m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute ); 0071 ta.setMinimalFontSize( m ); 0072 0073 setTextAttributes( ta ); 0074 } 0075 0076 HeaderFooter * HeaderFooter::clone() const 0077 { 0078 HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), nullptr ); 0079 headerFooter->setType( type() ); 0080 headerFooter->setPosition( position() ); 0081 headerFooter->setText( text() ); 0082 headerFooter->setTextAttributes( textAttributes() ); 0083 return headerFooter; 0084 } 0085 0086 bool HeaderFooter::compare( const HeaderFooter& other ) const 0087 { 0088 return (type() == other.type()) && 0089 (position() == other.position()) && 0090 // also compare members inherited from the base class: 0091 (autoReferenceArea() == other.autoReferenceArea()) && 0092 (text() == other.text()) && 0093 (textAttributes() == other.textAttributes()); 0094 } 0095 0096 void HeaderFooter::setType( HeaderFooterType type ) 0097 { 0098 if ( d->type != type ) { 0099 d->type = type; 0100 Q_EMIT positionChanged( this ); 0101 } 0102 } 0103 0104 HeaderFooter::HeaderFooterType HeaderFooter::type() const 0105 { 0106 return d->type; 0107 } 0108 0109 void HeaderFooter::setPosition( Position position ) 0110 { 0111 if ( d->position != position ) { 0112 d->position = position; 0113 Q_EMIT positionChanged( this ); 0114 } 0115 } 0116 0117 Position HeaderFooter::position() const 0118 { 0119 return d->position; 0120 }