KD Chart API Documentation  3.1
KDChartAbstractAreaWidget.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 
12 #include "KDChartAbstractAreaWidget_p.h"
13 
14 #include <KDABLibFakes>
15 
16 using namespace KDChart;
17 
18 AbstractAreaWidget::Private::Private()
19 {
20  // this block left empty intentionally
21 }
22 
23 AbstractAreaWidget::Private::~Private()
24 {
25  // this block left empty intentionally
26 }
27 
28 void AbstractAreaWidget::Private::resizeLayout(
29  AbstractAreaWidget *widget, const QSize &size)
30 {
31  if (size == currentLayoutSize)
32  return;
33 
34  currentLayoutSize = size;
35 
36  // Now we call adjust the size, for the inner parts of the widget.
37  int left;
38  int top;
39  int right;
40  int bottom;
41  widget->getFrameLeadings(left, top, right, bottom);
42  const QSize innerSize(size.width() - left - right,
43  size.height() - top - bottom);
44  // With this adjusted size we call the real resizeLayout method,
45  // which normally will call resizeLayout( size ) in the derived class
46  // - which in turn is the place to resize the layout of that class.
47  widget->resizeLayout(innerSize);
48 }
49 
51  : QWidget(parent)
52  , AbstractAreaBase(new Private())
53 {
54  init();
55 }
56 
58 {
59  // this block left empty intentionally
60 }
61 
62 void AbstractAreaWidget::init()
63 {
64  // this block left empty intentionally
65 }
66 
68 {
69  // this block left empty intentionally
70 }
71 
72 #define d d_func()
73 
74 void AbstractAreaWidget::resizeLayout(const QSize &size)
75 {
76  Q_UNUSED(size);
77  // this block left empty intentionally
78 }
79 
80 void AbstractAreaWidget::paintEvent(QPaintEvent *event)
81 {
82  Q_UNUSED(event);
83  QPainter painter(this);
84  if (size() != d->currentLayoutSize) {
85  d->resizeLayout(this, size());
86  }
87  paintAll(painter);
88 }
89 
90 void AbstractAreaWidget::paintIntoRect(QPainter &painter, const QRect &rect)
91 {
92  if (rect.isEmpty())
93  return;
94 
95  d->resizeLayout(this, rect.size());
96 
97  const QPoint translation(rect.topLeft());
98  painter.translate(translation);
99  paintAll(painter);
100  painter.translate(-translation.x(), -translation.y());
101 
102  /*
103  // guide for subclassing
104 
105  // set up the contents of the widget so we get a useful geometry
106  needSizeHint();
107 
108  const QRect oldGeometry( layout()->geometry() );
109  const QRect newGeo( QPoint(0,0), rect.size() );
110  const bool mustChangeGeo = layout() && oldGeometry != newGeo;
111  if ( mustChangeGeo )
112  layout()->setGeometry( newGeo );
113  painter.translate( rect.left(), rect.top() );
114  paintAll( painter );
115  painter.translate( -rect.left(), -rect.top() );
116  if ( mustChangeGeo )
117  layout()->setGeometry( oldGeometry );
118 */
119 }
120 
122 {
123  // block left empty intentionally
124 }
125 
126 void AbstractAreaWidget::paintAll(QPainter &painter)
127 {
128  paintBackground(painter, QRect(QPoint(0, 0), size()));
129  paintFrame(painter, QRect(QPoint(0, 0), size()));
130 
131  /*
132  // guide for subclassing
133 
134  // we do not call setContentsMargins() now,
135  // but we call resizeLayout() whenever the size or the frame has changed
136 
137  // adjust the widget's content margins,
138  // to be sure all content gets calculated
139  // to fit into the inner rectangle
140  const QRect oldGeometry( areaGeometry() );
141  const QRect inner( innerRect() );
142  //qDebug() << "areaGeometry():" << oldGeometry
143  // << " contentsRect():" << contentsRect() << " inner:" << inner;
144  if ( contentsRect() != inner ) {
145  //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner;
146  setContentsMargins(
147  inner.left(),
148  inner.top(),
149  oldGeometry.width() - inner.width() - 1,
150  oldGeometry.height() - inner.height() - 1 );
151  //forceRebuild();
152  }
153 */
154  int left;
155  int top;
156  int right;
157  int bottom;
158  getFrameLeadings(left, top, right, bottom);
159  const QPoint translation(left, top);
160  painter.translate(translation);
161  paint(&painter);
162  painter.translate(-translation.x(), -translation.y());
163 }
164 
166 {
167  return geometry();
168 }
169 
171 {
172  Q_EMIT positionChanged(this);
173 }
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background,...
void getFrameLeadings(int &left, int &top, int &right, int &bottom) const
virtual void paintFrame(QPainter &painter, const QRect &rectangle)
virtual void paintBackground(QPainter &painter, const QRect &rectangle)
An area in the chart with a background, a frame, etc.
AbstractAreaWidget(QWidget *parent=nullptr)
void positionChanged(AbstractAreaWidget *)
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
void paintEvent(QPaintEvent *event) override
Draws the background and frame, then calls paint().
virtual void paint(QPainter *painter)=0
virtual void resizeLayout(const QSize &)

© 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