KD Chart 2  [rev.2.5.1]
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
KDChartAbstractAreaWidget.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2001-2013 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 
24 #include "KDChartAbstractAreaWidget_p.h"
25 
26 #include <KDABLibFakes>
27 
28 
29 using namespace KDChart;
30 
31 
32 AbstractAreaWidget::Private::Private()
33 {
34  // this block left empty intentionally
35 }
36 
37 AbstractAreaWidget::Private::~Private()
38 {
39  // this block left empty intentionally
40 }
41 
42 
43 void AbstractAreaWidget::Private::resizeLayout(
44  AbstractAreaWidget* widget, const QSize& size )
45 {
46  if ( size == currentLayoutSize ) return;
47 
48  currentLayoutSize = size;
49 
50  // Now we call adjust the size, for the inner parts of the widget.
51  int left;
52  int top;
53  int right;
54  int bottom;
55  widget->getFrameLeadings( left, top, right, bottom );
56  const QSize innerSize( size.width() - left - right,
57  size.height() - top - bottom );
58  // With this adjusted size we call the real resizeLayout method,
59  // which normally will call resizeLayout( size ) in the derived class
60  // - which in turn is the place to resize the layout member variable
61  // of that class.
62  widget->resizeLayout( innerSize );
63 }
64 
65 
67  : QWidget( parent )
68  , AbstractAreaBase( new Private() )
69 {
70  init();
71 }
72 
74 {
75  // this block left empty intentionally
76 }
77 
78 void AbstractAreaWidget::init()
79 {
80  // this block left empty intentionally
81 }
82 
84 {
85  // this block left empty intentionally
86 }
87 
88 #define d d_func()
89 
90 void AbstractAreaWidget::resizeLayout( const QSize& size )
91 {
92  Q_UNUSED( size );
93  // this block left empty intentionally
94 }
95 
96 void AbstractAreaWidget::paintEvent( QPaintEvent* event )
97 {
98  Q_UNUSED( event );
99  QPainter painter( this );
100  if ( size() != d->currentLayoutSize ) {
101  d->resizeLayout( this, size() );
102  }
103  paintAll( painter );
104 }
105 
106 void AbstractAreaWidget::paintIntoRect( QPainter& painter, const QRect& rect )
107 {
108  if ( rect.isEmpty() ) return;
109 
110  d->resizeLayout( this, rect.size() );
111 
112  const QPoint translation( rect.topLeft() );
113  painter.translate( translation );
114  paintAll( painter );
115  painter.translate( -translation.x(), -translation.y() );
116 
117 /*
118  // make sure, the contents of the widget have been set up,
119  // so we get a useful geometry:
120  needSizeHint();
121 
122  const QRect oldGeometry( layout()->geometry() );
123  const QRect newGeo( QPoint(0,0), rect.size() );
124  const bool mustChangeGeo = layout() && oldGeometry != newGeo;
125  if ( mustChangeGeo )
126  layout()->setGeometry( newGeo );
127  painter.translate( rect.left(), rect.top() );
128  paintAll( painter );
129  painter.translate( -rect.left(), -rect.top() );
130  if ( mustChangeGeo )
131  layout()->setGeometry( oldGeometry );
132 */
133 }
134 
136 {
137  //bloc left empty intentionally
138 }
139 
140 void AbstractAreaWidget::paintAll( QPainter& painter )
141 {
142  // Paint the background and frame
143  paintBackground( painter, QRect(QPoint(0, 0), size() ) );
144  paintFrame( painter, QRect(QPoint(0, 0), size() ) );
145 
146 /*
147  we do not call setContentsMargins() now,
148  but we call resizeLayout() whenever the size or the frame has changed
149 
150  // adjust the widget's content margins,
151  // to be sure all content gets calculated
152  // to fit into the inner rectangle
153  const QRect oldGeometry( areaGeometry() );
154  const QRect inner( innerRect() );
155  //qDebug() << "areaGeometry():" << oldGeometry
156  // << " contentsRect():" << contentsRect() << " inner:" << inner;
157  if ( contentsRect() != inner ) {
158  //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner;
159  setContentsMargins(
160  inner.left(),
161  inner.top(),
162  oldGeometry.width() -inner.width()-1,
163  oldGeometry.height()-inner.height()-1 );
164  //forceRebuild();
165  }
166 */
167  int left;
168  int top;
169  int right;
170  int bottom;
171  getFrameLeadings( left, top, right, bottom );
172  const QPoint translation( left, top );
173  painter.translate( translation );
174  paint( &painter );
175  painter.translate( -translation.x(), -translation.y() );
176 }
177 
179 {
180  return geometry();
181 }
182 
184 {
185  emit positionChanged( this );
186 }

Klarälvdalens Datakonsult AB (KDAB)
Qt-related services and products
http://www.kdab.com/
http://www.kdab.com/products/kd-chart/