KD Chart API Documentation  3.1
KDChartAbstractArea.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 "KDChartAbstractArea.h"
12 #include "KDChartAbstractArea_p.h"
13 
14 #include <qglobal.h>
15 
16 #include <QPainter>
17 #include <QRect>
18 
19 #include <KDABLibFakes>
20 
21 using namespace KDChart;
22 
23 #define d (d_func())
24 
25 AbstractArea::Private::Private()
26  : AbstractAreaBase::Private()
27 {
28  // this block left empty intentionally
29 }
30 
31 AbstractArea::Private::~Private()
32 {
33  // this block left empty intentionally
34 }
35 
36 AbstractArea::AbstractArea()
37  : QObject()
40 {
41  init();
42 }
43 
45 {
46  // this block left empty intentionally
47 }
48 
49 void AbstractArea::init()
50 {
51  d->amountOfLeftOverlap = 0;
52  d->amountOfRightOverlap = 0;
53  d->amountOfTopOverlap = 0;
54  d->amountOfBottomOverlap = 0;
55 }
56 
57 int AbstractArea::leftOverlap(bool doNotRecalculate) const
58 {
59  // Re-calculate the sizes,
60  // so we also get the amountOf..Overlap members set newly:
61  if (!doNotRecalculate)
62  sizeHint();
63  return d->amountOfLeftOverlap;
64 }
65 int AbstractArea::rightOverlap(bool doNotRecalculate) const
66 {
67  // Re-calculate the sizes,
68  // so we also get the amountOf..Overlap members set newly:
69  if (!doNotRecalculate)
70  sizeHint();
71  return d->amountOfRightOverlap;
72 }
73 int AbstractArea::topOverlap(bool doNotRecalculate) const
74 {
75  // Re-calculate the sizes,
76  // so we also get the amountOf..Overlap members set newly:
77  if (!doNotRecalculate)
78  sizeHint();
79  return d->amountOfTopOverlap;
80 }
81 int AbstractArea::bottomOverlap(bool doNotRecalculate) const
82 {
83  // Re-calculate the sizes,
84  // so we also get the amountOf..Overlap members set newly:
85  if (!doNotRecalculate)
86  sizeHint();
87  return d->amountOfBottomOverlap;
88 }
89 
90 void AbstractArea::paintIntoRect(QPainter &painter, const QRect &rect)
91 {
92  const QRect oldGeometry(geometry());
93  if (oldGeometry != rect)
94  setGeometry(rect);
95  painter.translate(rect.left(), rect.top());
96  paintAll(painter);
97  painter.translate(-rect.left(), -rect.top());
98  if (oldGeometry != rect)
99  setGeometry(oldGeometry);
100 }
101 
102 void AbstractArea::paintAll(QPainter &painter)
103 {
104  // Paint the background and frame
105  const QRect overlappingArea(geometry().adjusted(-d->amountOfLeftOverlap, -d->amountOfTopOverlap,
106  d->amountOfRightOverlap, d->amountOfBottomOverlap));
107  paintBackground(painter, overlappingArea);
108  paintFrame(painter, overlappingArea);
109 
110  // temporarily adjust the widget size, to be sure all content gets calculated
111  // to fit into the inner rectangle
112  const QRect oldGeometry(areaGeometry());
113  QRect inner(innerRect());
114  inner.moveTo(oldGeometry.left() + inner.left(), oldGeometry.top() + inner.top());
115  const bool needAdjustGeometry = oldGeometry != inner;
116  if (needAdjustGeometry) {
117  // don't notify others of this change for internal purposes
118  bool prevSignalBlocked = signalsBlocked();
119  blockSignals(true);
120  setGeometry(inner);
121  blockSignals(prevSignalBlocked);
122  }
123  paint(&painter);
124  if (needAdjustGeometry) {
125  bool prevSignalBlocked = signalsBlocked();
126  blockSignals(true);
127  setGeometry(oldGeometry);
128  blockSignals(prevSignalBlocked);
129  }
130  // qDebug() << "AbstractAreaWidget::paintAll() done.";
131 }
132 
134 {
135  return geometry();
136 }
137 
139 {
140  Q_EMIT positionChanged(this);
141 }
#define d
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background,...
virtual void paintFrame(QPainter &painter, const QRect &rectangle)
virtual void paintBackground(QPainter &painter, const QRect &rectangle)
virtual int bottomOverlap(bool doNotRecalculate=false) const
virtual int rightOverlap(bool doNotRecalculate=false) const
void paintAll(QPainter &painter) override
virtual int topOverlap(bool doNotRecalculate=false) const
virtual int leftOverlap(bool doNotRecalculate=false) const
void positionHasChanged() override
void positionChanged(AbstractArea *)
QRect areaGeometry() const override
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
virtual void paint(QPainter *)=0

© 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