KD Chart API Documentation  3.1
KDChartHeaderFooter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Chart library.
4 **
5 ** SPDX-FileCopyrightText: 2001 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #include "KDChartHeaderFooter.h"
12 #include "KDChartHeaderFooter_p.h"
13 
14 #include "KDChartChart.h"
15 #include "KDTextDocument.h"
16 #include <KDChartTextAttributes.h>
17 #include <QAbstractTextDocumentLayout>
18 #include <QFont>
19 #include <QLabel>
20 #include <QPainter>
21 #include <QTextBlock>
22 #include <QTextDocumentFragment>
23 #include <QtDebug>
24 
25 #include <KDABLibFakes>
26 
27 using namespace KDChart;
28 
29 HeaderFooter::Private::Private()
30  : position(Position::North)
31 {
32 }
33 
34 HeaderFooter::Private::~Private()
35 {
36 }
37 
38 #define d d_func()
39 
40 HeaderFooter::HeaderFooter(Chart *parent)
41  : TextArea(new Private())
42 {
43  setParent(parent);
44  init();
45 }
46 
48 {
49  Q_EMIT destroyedHeaderFooter(this);
50 }
51 
52 void HeaderFooter::setParent(QObject *parent)
53 {
54  QObject::setParent(parent);
55  setParentWidget(qobject_cast<QWidget *>(parent));
56  if (parent && !autoReferenceArea())
57  setAutoReferenceArea(parent);
58 }
59 
60 void HeaderFooter::init()
61 {
62  TextAttributes ta;
63  ta.setPen(QPen(Qt::black));
64  ta.setFont(QFont(QLatin1String("helvetica"), 10, QFont::Bold, false));
65 
66  Measure m(35.0);
68  ta.setFontSize(m);
69 
70  m.setValue(8.0);
72  ta.setMinimalFontSize(m);
73 
75 }
76 
81 {
82  auto *headerFooter = new HeaderFooter(new Private(*d), nullptr);
83  headerFooter->setType(type());
84  headerFooter->setPosition(position());
85  headerFooter->setText(text());
86  headerFooter->setTextAttributes(textAttributes());
87  return headerFooter;
88 }
89 
90 bool HeaderFooter::compare(const HeaderFooter &other) const
91 {
92  return (type() == other.type()) && (position() == other.position()) &&
93  // also compare members inherited from the base class:
94  (autoReferenceArea() == other.autoReferenceArea()) && (text() == other.text()) && (textAttributes() == other.textAttributes());
95 }
96 
98 {
99  if (d->type != type) {
100  d->type = type;
101  Q_EMIT positionChanged(this);
102  }
103 }
104 
106 {
107  return d->type;
108 }
109 
111 {
112  if (d->position != position) {
113  d->position = position;
114  Q_EMIT positionChanged(this);
115  }
116 }
117 
119 {
120  return d->position;
121 }
#define d
@ MeasureCalculationModeAbsolute
Definition: KDChartEnums.h:215
@ MeasureOrientationMinimum
Definition: KDChartEnums.h:290
virtual void setParentWidget(QWidget *widget)
A chart with one or more diagrams.
Definition: KDChartChart.h:84
A header or footer displaying text above or below charts.
HeaderFooterType type() const
void setType(HeaderFooterType type)
HeaderFooter(Chart *parent=nullptr)
void setPosition(Position position)
bool compare(const HeaderFooter &other) const
void setParent(QObject *parent)
void positionChanged(HeaderFooter *)
virtual HeaderFooter * clone() const
void destroyedHeaderFooter(HeaderFooter *)
Measure is used to specify relative and absolute sizes in KDChart, e.g. font sizes.
Defines a position, using compass terminology.
A text area in the chart with a background, a frame, etc.
A set of text attributes.
void setFontSize(const Measure &measure)
void setMinimalFontSize(const Measure &measure)
void setPen(const QPen &pen)
void setFont(const QFont &font)
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for this item.
TextAttributes textAttributes() const
void setAutoReferenceArea(const QObject *area)
const QObject * autoReferenceArea() const

© 2001 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/
Generated by doxygen 1.9.1