KD Chart 2  [rev.2.8]
KDChartHeaderFooter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2021 Klaralvdalens Datakonsult AB. All rights reserved.
3 **
4 ** This file is part of the KD Chart library.
5 **
6 ** Licensees holding valid commercial KD Chart licenses may use this file in
7 ** accordance with the KD Chart Commercial License Agreement provided with
8 ** the Software.
9 **
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 and version 3 as published by the
13 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included.
14 **
15 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 ** Contact info@kdab.com if any conditions of this licensing are not
19 ** clear to you.
20 **
21 **********************************************************************/
22 
23 #include "KDChartHeaderFooter.h"
24 #include "KDChartHeaderFooter_p.h"
25 
26 #include "KDChartChart.h"
27 #include <KDChartTextAttributes.h>
28 #include <QFont>
29 #include <QPainter>
30 #include <QAbstractTextDocumentLayout>
31 #include <QTextDocumentFragment>
32 #include <QTextBlock>
33 #include <QtDebug>
34 #include <QLabel>
35 #include "KDTextDocument.h"
36 
37 #include <KDABLibFakes>
38 
39 using namespace KDChart;
40 
41 HeaderFooter::Private::Private() :
42  type( Header ),
43  position( Position::North )
44 {
45 }
46 
47 HeaderFooter::Private::~Private()
48 {
49 }
50 
51 #define d d_func()
52 
53 HeaderFooter::HeaderFooter( Chart* parent ) :
54  TextArea( new Private() )
55 {
56  setParent( parent );
57  init();
58 }
59 
61 {
62  emit destroyedHeaderFooter( this );
63 }
64 
66 {
67  QObject::setParent( parent );
68  setParentWidget( qobject_cast<QWidget*>( parent ) );
69  if ( parent && ! autoReferenceArea() )
70  setAutoReferenceArea( parent );
71 }
72 
73 void HeaderFooter::init()
74 {
75  TextAttributes ta;
76  ta.setPen( QPen(Qt::black) );
77  ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) );
78 
79  Measure m( 35.0 );
81  ta.setFontSize( m );
82 
83  m.setValue( 8.0 );
84  m.setCalculationMode( KDChartEnums::MeasureCalculationModeAbsolute );
85  ta.setMinimalFontSize( m );
86 
87  setTextAttributes( ta );
88 }
89 
94 {
95  HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), 0 );
96  headerFooter->setType( type() );
97  headerFooter->setPosition( position() );
98  headerFooter->setText( text() );
99  headerFooter->setTextAttributes( textAttributes() );
100  return headerFooter;
101 }
102 
103 bool HeaderFooter::compare( const HeaderFooter& other ) const
104 {
105  return (type() == other.type()) &&
106  (position() == other.position()) &&
107  // also compare members inherited from the base class:
108  (autoReferenceArea() == other.autoReferenceArea()) &&
109  (text() == other.text()) &&
110  (textAttributes() == other.textAttributes());
111 }
112 
114 {
115  if ( d->type != type ) {
116  d->type = type;
117  emit positionChanged( this );
118  }
119 }
120 
122 {
123  return d->type;
124 }
125 
127 {
128  if ( d->position != position ) {
129  d->position = position;
130  emit positionChanged( this );
131  }
132 }
133 
135 {
136  return d->position;
137 }
KDChart::TextLayoutItem::setTextAttributes
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for this item.
Definition: KDChartLayoutItems.cpp:277
KDChart::Position
Defines a position, using compass terminology.
Definition: KDChartPosition.h:76
KDChart::TextLayoutItem::setText
void setText(const QString &text)
Definition: KDChartLayoutItems.cpp:244
KDTextDocument.h
KDChart
Definition: KDChartAbstractCartesianDiagram.h:30
KDChart::TextAttributes
A set of text attributes.
Definition: KDChartTextAttributes.h:47
KDChart::Measure
Measure is used to specify relative and absolute sizes in KDChart, e.g.
Definition: KDChartMeasure.h:52
KDChart::AbstractLayoutItem::setParentWidget
virtual void setParentWidget(QWidget *widget)
Inform the item about its widget: This enables the item, to trigger that widget's update,...
Definition: KDChartLayoutItems.cpp:59
KDChart::TextAttributes::setMinimalFontSize
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
Definition: KDChartTextAttributes.cpp:150
KDChartEnums::MeasureCalculationModeAbsolute
@ MeasureCalculationModeAbsolute
Definition: KDChartEnums.h:222
KDChart::TextAttributes::setFontSize
void setFontSize(const Measure &measure)
Set the size of the font used for rendering text.
Definition: KDChartTextAttributes.cpp:140
KDChart::TextLayoutItem::text
QString text() const
Definition: KDChartLayoutItems.cpp:253
KDChart::TextLayoutItem::textAttributes
TextAttributes textAttributes() const
Returns the text attributes to be used for this item.
Definition: KDChartLayoutItems.cpp:292
KDChartTextAttributes.h
KDChartChart.h
KDChart::TextAttributes::setPen
void setPen(const QPen &pen)
Set the pen to use for rendering the text.
Definition: KDChartTextAttributes.cpp:256
KDChart::TextArea
A text area in the chart with a background, a frame, etc.
Definition: KDChartTextArea.h:48
QObject
KDChart::TextAttributes::setFont
void setFont(const QFont &font)
Set the font to be used for rendering the text.
Definition: KDChartTextAttributes.cpp:128
KDChart::Chart
A chart with one or more diagrams.
Definition: KDChartChart.h:99
KDChart::TextLayoutItem::setAutoReferenceArea
void setAutoReferenceArea(const QObject *area)
Definition: KDChartLayoutItems.cpp:232
KDChart::TextLayoutItem::autoReferenceArea
const QObject * autoReferenceArea() const
Definition: KDChartLayoutItems.cpp:239
KDChartEnums::MeasureOrientationMinimum
@ MeasureOrientationMinimum
Definition: KDChartEnums.h:293

Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/

https://www.kdab.com/development-resources/qt-tools/kd-chart/