KChart

KChartHeaderFooter.cpp
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "KChartHeaderFooter.h"
21 #include "KChartHeaderFooter_p.h"
22 
23 #include "KChartChart.h"
24 #include <KChartTextAttributes.h>
25 #include "KTextDocument.h"
26 #include "KChartMath_p.h"
27 
28 #include <QFont>
29 #include <QPainter>
30 #include <QAbstractTextDocumentLayout>
31 #include <QTextDocumentFragment>
32 #include <QTextBlock>
33 #include <QtDebug>
34 #include <QLabel>
35 
36 using namespace KChart;
37 
38 HeaderFooter::Private::Private() :
39  type( Header ),
40  position( Position::North )
41 {
42 }
43 
44 HeaderFooter::Private::~Private()
45 {
46 }
47 
48 #define d d_func()
49 
50 HeaderFooter::HeaderFooter( Chart* parent ) :
51  TextArea( new Private() )
52 {
53  setParent( parent );
54  init();
55 }
56 
57 HeaderFooter::~HeaderFooter()
58 {
59  emit destroyedHeaderFooter( this );
60 }
61 
62 void HeaderFooter::setParent( QObject* parent )
63 {
64  QObject::setParent( parent );
65  setParentWidget( qobject_cast<QWidget*>( parent ) );
66  if ( parent && ! autoReferenceArea() )
67  setAutoReferenceArea( parent );
68 }
69 
70 void HeaderFooter::init()
71 {
72  TextAttributes ta;
73  ta.setPen( QPen(Qt::black) );
74  ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) );
75 
76  Measure m( 35.0 );
77  m.setRelativeMode( autoReferenceArea(), KChartEnums::MeasureOrientationMinimum );
78  ta.setFontSize( m );
79 
80  m.setValue( 8.0 );
81  m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
82  ta.setMinimalFontSize( m );
83 
84  setTextAttributes( ta );
85 }
86 
88 {
89  HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), nullptr );
90  headerFooter->setType( type() );
91  headerFooter->setPosition( position() );
92  headerFooter->setText( text() );
93  headerFooter->setTextAttributes( textAttributes() );
94  return headerFooter;
95 }
96 
97 bool HeaderFooter::compare( const HeaderFooter& other ) const
98 {
99  return (type() == other.type()) &&
100  (position() == other.position()) &&
101  // also compare members inherited from the base class:
102  (autoReferenceArea() == other.autoReferenceArea()) &&
103  (text() == other.text()) &&
104  (textAttributes() == other.textAttributes());
105 }
106 
107 void HeaderFooter::setType( HeaderFooterType type )
108 {
109  if ( d->type != type ) {
110  d->type = type;
111  emit positionChanged( this );
112  }
113 }
114 
115 HeaderFooter::HeaderFooterType HeaderFooter::type() const
116 {
117  return d->type;
118 }
119 
120 void HeaderFooter::setPosition( Position position )
121 {
122  if ( d->position != position ) {
123  d->position = position;
124  emit positionChanged( this );
125  }
126 }
127 
128 Position HeaderFooter::position() const
129 {
130  return d->position;
131 }
AKONADI_MIME_EXPORT const char Header[]
A text area in the chart with a background, a frame, etc.
Defines a position, using compass terminology.
void setPen(const QPen &pen)
Set the pen to use for rendering the text.
void setFont(const QFont &font)
Set the font to be used for rendering the text.
virtual HeaderFooter * clone() const
Creates an exact copy of this header/footer.
Class only listed here to document inheritance of some KChart classes.
Type type(const QSqlDatabase &db)
TextAttributes textAttributes() const
Returns the text attributes to be used for this item.
void setParent(QObject *parent)
QCA_EXPORT void init()
void setFontSize(const Measure &measure)
Set the size of the font used for rendering text.
A header or footer displaying text above or below charts.
A set of text attributes.
A chart with one or more diagrams.
Definition: KChartChart.h:95
Global namespace.
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
Measure is used to specify relative and absolute sizes in KChart, e.g.
Definition: KChartMeasure.h:48
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for this item.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:36:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.