KChart

KChartAbstractAreaWidget.cpp
1 /*
2  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved.
3  *
4  * This file is part of the KD Chart library.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "KChartAbstractAreaWidget.h"
21 #include "KChartAbstractAreaWidget_p.h"
22 
23 #include "KChartMath_p.h"
24 
25 
26 using namespace KChart;
27 
28 
29 AbstractAreaWidget::Private::Private()
30 {
31  // this block left empty intentionally
32 }
33 
34 AbstractAreaWidget::Private::~Private()
35 {
36  // this block left empty intentionally
37 }
38 
39 
40 void AbstractAreaWidget::Private::resizeLayout(
41  AbstractAreaWidget* widget, const QSize& size )
42 {
43  if ( size == currentLayoutSize ) return;
44 
45  currentLayoutSize = size;
46 
47  // Now we call adjust the size, for the inner parts of the widget.
48  int left;
49  int top;
50  int right;
51  int bottom;
52  widget->getFrameLeadings( left, top, right, bottom );
53  const QSize innerSize( size.width() - left - right,
54  size.height() - top - bottom );
55  // With this adjusted size we call the real resizeLayout method,
56  // which normally will call resizeLayout( size ) in the derived class
57  // - which in turn is the place to resize the layout of that class.
58  widget->resizeLayout( innerSize );
59 }
60 
61 
62 AbstractAreaWidget::AbstractAreaWidget( QWidget* parent )
63  : QWidget( parent )
64  , AbstractAreaBase( new Private() )
65 {
66  init();
67 }
68 
69 AbstractAreaWidget::~AbstractAreaWidget()
70 {
71  // this block left empty intentionally
72 }
73 
74 void AbstractAreaWidget::init()
75 {
76  // this block left empty intentionally
77 }
78 
80 {
81  // this block left empty intentionally
82 }
83 
84 #define d d_func()
85 
86 void AbstractAreaWidget::resizeLayout( const QSize& size )
87 {
88  Q_UNUSED( size );
89  // this block left empty intentionally
90 }
91 
93 {
94  Q_UNUSED( event );
95  QPainter painter( this );
96  if ( size() != d->currentLayoutSize ) {
97  d->resizeLayout( this, size() );
98  }
99  paintAll( painter );
100 }
101 
102 void AbstractAreaWidget::paintIntoRect( QPainter& painter, const QRect& rect )
103 {
104  if ( rect.isEmpty() ) return;
105 
106  d->resizeLayout( this, rect.size() );
107 
108  const QPoint translation( rect.topLeft() );
109  painter.translate( translation );
110  paintAll( painter );
111  painter.translate( -translation.x(), -translation.y() );
112 
113 /*
114  // guide for subclassing
115 
116  // set up the contents of the widget so we get a useful geometry
117  needSizeHint();
118 
119  const QRect oldGeometry( layout()->geometry() );
120  const QRect newGeo( QPoint(0,0), rect.size() );
121  const bool mustChangeGeo = layout() && oldGeometry != newGeo;
122  if ( mustChangeGeo )
123  layout()->setGeometry( newGeo );
124  painter.translate( rect.left(), rect.top() );
125  paintAll( painter );
126  painter.translate( -rect.left(), -rect.top() );
127  if ( mustChangeGeo )
128  layout()->setGeometry( oldGeometry );
129 */
130 }
131 
133 {
134  //bloc left empty intentionally
135 }
136 
138 {
139  paintBackground( painter, QRect(QPoint(0, 0), size() ) );
140  paintFrame( painter, QRect(QPoint(0, 0), size() ) );
141 
142 /*
143  // guide for subclassing
144 
145  // we do not call setContentsMargins() now,
146  // but we call resizeLayout() whenever the size or the frame has changed
147 
148  // adjust the widget's content margins,
149  // to be sure all content gets calculated
150  // to fit into the inner rectangle
151  const QRect oldGeometry( areaGeometry() );
152  const QRect inner( innerRect() );
153  //qDebug() << "areaGeometry():" << oldGeometry
154  // << " contentsRect():" << contentsRect() << " inner:" << inner;
155  if ( contentsRect() != inner ) {
156  //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner;
157  setContentsMargins(
158  inner.left(),
159  inner.top(),
160  oldGeometry.width() - inner.width() - 1,
161  oldGeometry.height() - inner.height() - 1 );
162  //forceRebuild();
163  }
164 */
165  int left;
166  int top;
167  int right;
168  int bottom;
169  getFrameLeadings( left, top, right, bottom );
170  const QPoint translation( left, top );
171  painter.translate( translation );
172  paint( &painter );
173  painter.translate( -translation.x(), -translation.y() );
174 }
175 
177 {
178  return geometry();
179 }
180 
182 {
183  emit positionChanged( this );
184 }
Class only listed here to document inheritance of some KChart classes.
QSize size() const const
int width() const const
void paintAll(QPainter &painter)
Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invo...
void paintEvent(QPaintEvent *event) override
Draws the background and frame, then calls paint().
void getFrameLeadings(int &left, int &top, int &right, int &bottom) const
QTextStream & right(QTextStream &stream)
int x() const const
int y() const const
virtual void needSizeHint()
Call this to trigger an conditional re-building of the widget&#39;s internals.
virtual void paintIntoRect(QPainter &painter, const QRect &rect)
Draws the background and frame, then calls paint().
QTextStream & left(QTextStream &stream)
virtual void forceRebuild()
Call this to trigger an unconditional re-building of the widget&#39;s internals.
Base class for AbstractArea and AbstractAreaWidget: An area in the chart with a background, a frame, etc.
bool isEmpty() const const
QCA_EXPORT void init()
int height() const const
QPoint topLeft() const const
void translate(const QPointF &offset)
An area in the chart with a background, a frame, etc.
Global namespace.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Sep 17 2020 22:36:39 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.