KD Chart 2  [rev.2.7]
KDChartHeaderFooter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2020 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 
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 );
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 }
void setAutoReferenceArea(const QObject *area)
A chart with one or more diagrams.
Definition: KDChartChart.h:98
void setPen(const QPen &pen)
Set the pen to use for rendering the text.
TextAttributes textAttributes() const
Returns the text attributes to be used for this item.
virtual void setParentWidget(QWidget *widget)
Inform the item about its widget: This enables the item, to trigger that widget&#39;s update...
A text area in the chart with a background, a frame, etc.
const QObject * autoReferenceArea() const
void setText(const QString &text)
void setValue(qreal val)
void setFontSize(const Measure &measure)
Set the size of the font used for rendering text.
void setFont(const QFont &font)
Set the font to be used for rendering the text.
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for this item.
void setRelativeMode(const QObject *area, KDChartEnums::MeasureOrientation orientation)
The reference area must either be derived from AbstractArea or from QWidget, so it can also be derive...
Measure is used to specify relative and absolute sizes in KDChart, e.g.
Class only listed here to document inheritance of some KDChart classes.
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
Defines a position, using compass terminology.
void setCalculationMode(KDChartEnums::MeasureCalculationMode mode)
A set of text attributes.

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