KChart

KChartHeaderFooter.cpp
1/*
2 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3 *
4 * This file is part of the KD Chart library.
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9#include "KChartHeaderFooter.h"
10#include "KChartHeaderFooter_p.h"
11
12#include "KChartChart.h"
13#include <KChartTextAttributes.h>
14#include "KTextDocument.h"
15#include "KChartMath_p.h"
16
17#include <QFont>
18#include <QPainter>
19#include <QAbstractTextDocumentLayout>
20#include <QTextDocumentFragment>
21#include <QTextBlock>
22#include <QtDebug>
23#include <QLabel>
24
25using namespace KChart;
26
27HeaderFooter::Private::Private() :
28 type( Header ),
29 position( Position::North )
30{
31}
32
33HeaderFooter::Private::~Private()
34{
35}
36
37#define d d_func()
38
39HeaderFooter::HeaderFooter( Chart* parent ) :
40 TextArea( new Private() )
41{
42 setParent( parent );
43 init();
44}
45
46HeaderFooter::~HeaderFooter()
47{
48 Q_EMIT destroyedHeaderFooter( this );
49}
50
51void HeaderFooter::setParent( QObject* parent )
52{
55 if ( parent && ! autoReferenceArea() )
56 setAutoReferenceArea( parent );
57}
58
59void HeaderFooter::init()
60{
62 ta.setPen( QPen(Qt::black) );
63 ta.setFont( QFont( QLatin1String( "helvetica" ), 10, QFont::Bold, false ) );
64
65 Measure m( 35.0 );
66 m.setRelativeMode( autoReferenceArea(), KChartEnums::MeasureOrientationMinimum );
67 ta.setFontSize( m );
68
69 m.setValue( 8.0 );
70 m.setCalculationMode( KChartEnums::MeasureCalculationModeAbsolute );
71 ta.setMinimalFontSize( m );
72
74}
75
77{
78 HeaderFooter* headerFooter = new HeaderFooter( new Private( *d ), nullptr );
79 headerFooter->setType( type() );
80 headerFooter->setPosition( position() );
81 headerFooter->setText( text() );
82 headerFooter->setTextAttributes( textAttributes() );
83 return headerFooter;
84}
85
86bool HeaderFooter::compare( const HeaderFooter& other ) const
87{
88 return (type() == other.type()) &&
89 (position() == other.position()) &&
90 // also compare members inherited from the base class:
91 (autoReferenceArea() == other.autoReferenceArea()) &&
92 (text() == other.text()) &&
93 (textAttributes() == other.textAttributes());
94}
95
96void HeaderFooter::setType( HeaderFooterType type )
97{
98 if ( d->type != type ) {
99 d->type = type;
100 Q_EMIT positionChanged( this );
101 }
102}
103
104HeaderFooter::HeaderFooterType HeaderFooter::type() const
105{
106 return d->type;
107}
108
109void HeaderFooter::setPosition( Position position )
110{
111 if ( d->position != position ) {
112 d->position = position;
113 Q_EMIT positionChanged( this );
114 }
115}
116
117Position HeaderFooter::position() const
118{
119 return d->position;
120}
virtual void setParentWidget(QWidget *widget)
Inform the item about its widget: This enables the item, to trigger that widget's update,...
A header or footer displaying text above or below charts.
virtual HeaderFooter * clone() const
Creates an exact copy of this header/footer.
Measure is used to specify relative and absolute sizes in KChart, e.g.
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)
Set the size of the font used for rendering text.
void setMinimalFontSize(const Measure &measure)
Set the minimal size of the font used for rendering text.
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.
void setTextAttributes(const TextAttributes &a)
Use this to specify the text attributes to be used for this item.
TextAttributes textAttributes() const
Returns the text attributes to be used for this item.
AKONADI_MIME_EXPORT const char Header[]
Type type(const QSqlDatabase &db)
QCA_EXPORT void init()
Q_EMITQ_EMIT
QObject * parent() const const
T qobject_cast(QObject *object)
void setParent(QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.