KChart

KChartAbstractArea.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 "KChartAbstractArea.h"
10#include "KChartAbstractArea_p.h"
11
12#include "KChartMath_p.h"
13
14#include <qglobal.h>
15
16#include <QPainter>
17#include <QRect>
18
19
20using namespace KChart;
21
22#define d (d_func())
23
24AbstractArea::Private::Private() :
25 AbstractAreaBase::Private()
26{
27 // this block left empty intentionally
28}
29
30
31AbstractArea::Private::~Private()
32{
33 // this block left empty intentionally
34}
35
36
37AbstractArea::AbstractArea()
38 : QObject()
41{
42 init();
43}
44
45AbstractArea::~AbstractArea()
46{
47 // this block left empty intentionally
48}
49
50
51void AbstractArea::init()
52{
53 d->amountOfLeftOverlap = 0;
54 d->amountOfRightOverlap = 0;
55 d->amountOfTopOverlap = 0;
56 d->amountOfBottomOverlap = 0;
57}
58
59
60int AbstractArea::leftOverlap( bool doNotRecalculate ) const
61{
62 // Re-calculate the sizes,
63 // so we also get the amountOf..Overlap members set newly:
64 if ( ! doNotRecalculate )
65 sizeHint();
66 return d->amountOfLeftOverlap;
67}
68int AbstractArea::rightOverlap( bool doNotRecalculate ) const
69{
70 // Re-calculate the sizes,
71 // so we also get the amountOf..Overlap members set newly:
72 if ( ! doNotRecalculate )
73 sizeHint();
74 return d->amountOfRightOverlap;
75}
76int AbstractArea::topOverlap( bool doNotRecalculate ) const
77{
78 // Re-calculate the sizes,
79 // so we also get the amountOf..Overlap members set newly:
80 if ( ! doNotRecalculate )
81 sizeHint();
82 return d->amountOfTopOverlap;
83}
84int AbstractArea::bottomOverlap( bool doNotRecalculate ) const
85{
86 // Re-calculate the sizes,
87 // so we also get the amountOf..Overlap members set newly:
88 if ( ! doNotRecalculate )
89 sizeHint();
90 return d->amountOfBottomOverlap;
91}
92
93
94void AbstractArea::paintIntoRect( QPainter& painter, const QRect& rect )
95{
96 const QRect oldGeometry( geometry() );
97 if ( oldGeometry != rect )
98 setGeometry( rect );
99 painter.translate( rect.left(), rect.top() );
100 paintAll( painter );
101 painter.translate( -rect.left(), -rect.top() );
102 if ( oldGeometry != rect )
103 setGeometry( oldGeometry );
104}
105
107{
108 // Paint the background and frame
109 const QRect overlappingArea( geometry().adjusted( -d->amountOfLeftOverlap, -d->amountOfTopOverlap,
110 d->amountOfRightOverlap, d->amountOfBottomOverlap ) );
111 paintBackground( painter, overlappingArea );
112 paintFrame( painter, overlappingArea );
113
114 // temporarily adjust the widget size, to be sure all content gets calculated
115 // to fit into the inner rectangle
116 const QRect oldGeometry( areaGeometry() );
117 QRect inner( innerRect() );
118 inner.moveTo( oldGeometry.left() + inner.left(), oldGeometry.top() + inner.top() );
119 const bool needAdjustGeometry = oldGeometry != inner;
120 if ( needAdjustGeometry ) {
121 // don't notify others of this change for internal purposes
122 bool prevSignalBlocked = signalsBlocked();
123 blockSignals( true );
124 setGeometry( inner );
125 blockSignals( prevSignalBlocked );
126 }
127 paint( &painter );
128 if ( needAdjustGeometry ) {
129 bool prevSignalBlocked = signalsBlocked();
130 blockSignals( true );
131 setGeometry( oldGeometry );
132 blockSignals( prevSignalBlocked );
133 }
134 //qDebug() << "AbstractAreaWidget::paintAll() done.";
135}
136
138{
139 return geometry();
140}
141
143{
144 Q_EMIT positionChanged( this );
145}
146
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background,...
virtual int bottomOverlap(bool doNotRecalculate=false) const
This is called at layout time by KChart:AutoSpacerLayoutItem::sizeHint().
virtual int rightOverlap(bool doNotRecalculate=false) const
This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint().
void paintAll(QPainter &painter) override
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
virtual int topOverlap(bool doNotRecalculate=false) const
This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint().
virtual int leftOverlap(bool doNotRecalculate=false) const
This is called at layout time by KChart::AutoSpacerLayoutItem::sizeHint().
void positionHasChanged() override
QRect areaGeometry() const override
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
Base class for all layout items of KChart.
void init(KXmlGuiWindow *window, KGameDifficulty *difficulty=nullptr)
virtual QRect geometry() const const=0
virtual void setGeometry(const QRect &r)=0
virtual QSize sizeHint() const const=0
Q_EMITQ_EMIT
bool blockSignals(bool block)
bool signalsBlocked() const const
void translate(const QPoint &offset)
int left() const const
void moveTo(const QPoint &position)
int top() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:51:58 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.