KD Chart 2  [rev.2.7]
KDChartAbstractArea.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 "KDChartAbstractArea.h"
24 #include "KDChartAbstractArea_p.h"
25 
26 #include <qglobal.h>
27 
28 #include <QPainter>
29 #include <QRect>
30 
31 #include <KDABLibFakes>
32 
33 
34 using namespace KDChart;
35 
36 #define d (d_func())
37 
38 AbstractArea::Private::Private() :
39  AbstractAreaBase::Private()
40 {
41  // this bloc left empty intentionally
42 }
43 
44 
45 AbstractArea::Private::~Private()
46 {
47  // this bloc left empty intentionally
48 }
49 
50 
51 AbstractArea::AbstractArea()
52  : QObject()
55 {
56  init();
57 }
58 
60 {
61  // this bloc left empty intentionally
62 }
63 
64 
65 void AbstractArea::init()
66 {
67  d->amountOfLeftOverlap = 0;
68  d->amountOfRightOverlap = 0;
69  d->amountOfTopOverlap = 0;
70  d->amountOfBottomOverlap = 0;
71 }
72 
73 
74 int AbstractArea::leftOverlap( bool doNotRecalculate ) const
75 {
76  // Re-calculate the sizes,
77  // so we also get the amountOf..Overlap members set newly:
78  if ( ! doNotRecalculate )
79  sizeHint();
80  return d->amountOfLeftOverlap;
81 }
82 int AbstractArea::rightOverlap( bool doNotRecalculate ) const
83 {
84  // Re-calculate the sizes,
85  // so we also get the amountOf..Overlap members set newly:
86  if ( ! doNotRecalculate )
87  sizeHint();
88  return d->amountOfRightOverlap;
89 }
90 int AbstractArea::topOverlap( bool doNotRecalculate ) const
91 {
92  // Re-calculate the sizes,
93  // so we also get the amountOf..Overlap members set newly:
94  if ( ! doNotRecalculate )
95  sizeHint();
96  return d->amountOfTopOverlap;
97 }
98 int AbstractArea::bottomOverlap( bool doNotRecalculate ) const
99 {
100  // Re-calculate the sizes,
101  // so we also get the amountOf..Overlap members set newly:
102  if ( ! doNotRecalculate )
103  sizeHint();
104  return d->amountOfBottomOverlap;
105 }
106 
107 
108 void AbstractArea::paintIntoRect( QPainter& painter, const QRect& rect )
109 {
110  const QRect oldGeometry( geometry() );
111  if ( oldGeometry != rect )
112  setGeometry( rect );
113  painter.translate( rect.left(), rect.top() );
114  paintAll( painter );
115  painter.translate( -rect.left(), -rect.top() );
116  if ( oldGeometry != rect )
117  setGeometry( oldGeometry );
118 }
119 
120 void AbstractArea::paintAll( QPainter& painter )
121 {
122  // Paint the background and frame
123  const QRect overlappingArea( geometry().adjusted( -d->amountOfLeftOverlap, -d->amountOfTopOverlap,
124  d->amountOfRightOverlap, d->amountOfBottomOverlap ) );
125  paintBackground( painter, overlappingArea );
126  paintFrame( painter, overlappingArea );
127 
128  // temporarily adjust the widget size, to be sure all content gets calculated
129  // to fit into the inner rectangle
130  const QRect oldGeometry( areaGeometry() );
131  QRect inner( innerRect() );
132  inner.moveTo( oldGeometry.left() + inner.left(), oldGeometry.top() + inner.top() );
133  const bool needAdjustGeometry = oldGeometry != inner;
134  if ( needAdjustGeometry ) {
135  // don't notify others of this change for internal purposes
136  bool prevSignalBlocked = signalsBlocked();
137  blockSignals( true );
138  setGeometry( inner );
139  blockSignals( prevSignalBlocked );
140  }
141  paint( &painter );
142  if ( needAdjustGeometry ) {
143  bool prevSignalBlocked = signalsBlocked();
144  blockSignals( true );
145  setGeometry( oldGeometry );
146  blockSignals( prevSignalBlocked );
147  }
148  //qDebug() << "AbstractAreaWidget::paintAll() done.";
149 }
150 
152 {
153  return geometry();
154 }
155 
157 {
158  emit positionChanged( this );
159 }
160 
void positionChanged(AbstractArea *)
virtual void paintFrame(QPainter &painter, const QRect &rectangle)
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background, a frame, etc.
virtual int leftOverlap(bool doNotRecalculate=false) const
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint().
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
virtual int bottomOverlap(bool doNotRecalculate=false) const
This is called at layout time by KDChart:AutoSpacerLayoutItem::sizeHint().
#define d
virtual void paintBackground(QPainter &painter, const QRect &rectangle)
virtual int rightOverlap(bool doNotRecalculate=false) const
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint().
void positionHasChanged() override
Base class for all layout items of KD Chart.
virtual void paint(QPainter *)=0
virtual int topOverlap(bool doNotRecalculate=false) const
This is called at layout time by KDChart::AutoSpacerLayoutItem::sizeHint().
Class only listed here to document inheritance of some KDChart classes.
void paintAll(QPainter &painter) override
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
QRect areaGeometry() const override

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/