KD Chart 2 [rev.2.4]
|
00001 /**************************************************************************** 00002 ** Copyright (C) 2001-2012 Klaralvdalens Datakonsult AB. All rights reserved. 00003 ** 00004 ** This file is part of the KD Chart library. 00005 ** 00006 ** Licensees holding valid commercial KD Chart licenses may use this file in 00007 ** accordance with the KD Chart Commercial License Agreement provided with 00008 ** the Software. 00009 ** 00010 ** 00011 ** This file may be distributed and/or modified under the terms of the 00012 ** GNU General Public License version 2 and version 3 as published by the 00013 ** Free Software Foundation and appearing in the file LICENSE.GPL.txt included. 00014 ** 00015 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00016 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00017 ** 00018 ** Contact info@kdab.com if any conditions of this licensing are not 00019 ** clear to you. 00020 ** 00021 **********************************************************************/ 00022 00023 #include "KDChartAbstractAreaWidget.h" 00024 #include "KDChartAbstractAreaWidget_p.h" 00025 00026 #include <KDABLibFakes> 00027 00028 00029 using namespace KDChart; 00030 00031 00032 AbstractAreaWidget::Private::Private() 00033 { 00034 // this block left empty intentionally 00035 } 00036 00037 AbstractAreaWidget::Private::~Private() 00038 { 00039 // this block left empty intentionally 00040 } 00041 00042 00043 void AbstractAreaWidget::Private::resizeLayout( 00044 AbstractAreaWidget* widget, const QSize& size ) 00045 { 00046 if( size == currentLayoutSize ) return; 00047 00048 currentLayoutSize = size; 00049 00050 // Now we call adjust the size, for the inner parts of the widget. 00051 int left; 00052 int top; 00053 int right; 00054 int bottom; 00055 widget->getFrameLeadings( left, top, right, bottom ); 00056 const QSize innerSize( size.width() - left - right, 00057 size.height() - top - bottom ); 00058 // With this adjusted size we call the real resizeLayout method, 00059 // which normally will call resizeLayout( size ) in the derived class 00060 // - which in turn is the place to resize the layout member variable 00061 // of that class. 00062 widget->resizeLayout( innerSize ); 00063 } 00064 00065 00066 AbstractAreaWidget::AbstractAreaWidget( QWidget* parent ) 00067 : QWidget( parent ) 00068 , AbstractAreaBase( new Private() ) 00069 { 00070 init(); 00071 } 00072 00073 AbstractAreaWidget::~AbstractAreaWidget() 00074 { 00075 // this block left empty intentionally 00076 } 00077 00078 void AbstractAreaWidget::init() 00079 { 00080 // this block left empty intentionally 00081 } 00082 00083 void AbstractAreaWidget::needSizeHint() 00084 { 00085 // this block left empty intentionally 00086 } 00087 00088 #define d d_func() 00089 00090 void AbstractAreaWidget::resizeLayout( const QSize& size ) 00091 { 00092 Q_UNUSED( size ); 00093 // this block left empty intentionally 00094 } 00095 00096 void AbstractAreaWidget::paintEvent( QPaintEvent* event ) 00097 { 00098 Q_UNUSED( event ); 00099 QPainter painter( this ); 00100 if( size() != d->currentLayoutSize ){ 00101 d->resizeLayout( this, size() ); 00102 } 00103 paintAll( painter ); 00104 } 00105 00106 void AbstractAreaWidget::paintIntoRect( QPainter& painter, const QRect& rect ) 00107 { 00108 //qDebug() << "AbstractAreaWidget::paintIntoRect() called rect=" << rect; 00109 00110 if( rect.isEmpty() ) return; 00111 00112 d->resizeLayout( this, rect.size() ); 00113 00114 const QPoint translation( rect.topLeft() ); 00115 painter.translate( translation ); 00116 paintAll( painter ); 00117 painter.translate( -translation.x(), -translation.y() ); 00118 00119 /* 00120 // make sure, the contents of the widget have been set up, 00121 // so we get a useful geometry: 00122 needSizeHint(); 00123 00124 const QRect oldGeometry( layout()->geometry() ); 00125 const QRect newGeo( QPoint(0,0), rect.size() ); 00126 const bool mustChangeGeo = layout() && oldGeometry != newGeo; 00127 if( mustChangeGeo ) 00128 layout()->setGeometry( newGeo ); 00129 painter.translate( rect.left(), rect.top() ); 00130 paintAll( painter ); 00131 painter.translate( -rect.left(), -rect.top() ); 00132 if( mustChangeGeo ) 00133 layout()->setGeometry( oldGeometry ); 00134 */ 00135 } 00136 00137 void AbstractAreaWidget::forceRebuild() 00138 { 00139 //bloc left empty intentionally 00140 } 00141 00142 void AbstractAreaWidget::paintAll( QPainter& painter ) 00143 { 00144 //qDebug() << "AbstractAreaWidget::paintAll() called"; 00145 00146 // Paint the background and frame 00147 paintBackground( painter, QRect(QPoint(0, 0), size() ) ); 00148 paintFrame( painter, QRect(QPoint(0, 0), size() ) ); 00149 00150 /* 00151 we do not call setContentsMargins() now, 00152 but we call resizeLayout() whenever the size or the frame has changed 00153 00154 // adjust the widget's content margins, 00155 // to be sure all content gets calculated 00156 // to fit into the inner rectangle 00157 const QRect oldGeometry( areaGeometry() ); 00158 const QRect inner( innerRect() ); 00159 //qDebug() << "areaGeometry():" << oldGeometry 00160 // << " contentsRect():" << contentsRect() << " inner:" << inner; 00161 if( contentsRect() != inner ){ 00162 //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner; 00163 setContentsMargins( 00164 inner.left(), 00165 inner.top(), 00166 oldGeometry.width() -inner.width()-1, 00167 oldGeometry.height()-inner.height()-1 ); 00168 //forceRebuild(); 00169 } 00170 */ 00171 int left; 00172 int top; 00173 int right; 00174 int bottom; 00175 getFrameLeadings( left, top, right, bottom ); 00176 const QPoint translation( left, top ); 00177 painter.translate( translation ); 00178 paint( &painter ); 00179 painter.translate( -translation.x(), -translation.y() ); 00180 //qDebug() << "AbstractAreaWidget::paintAll() done."; 00181 } 00182 00183 QRect AbstractAreaWidget::areaGeometry() const 00184 { 00185 return geometry(); 00186 } 00187 00188 void AbstractAreaWidget::positionHasChanged() 00189 { 00190 emit positionChanged( this ); 00191 } 00192 /* 00193 void AbstractAreaWidget::setGeometry( const QRect & rect ) 00194 { 00195 qDebug() << "AbstractAreaWidget::setGeometry("<< rect << ") called"; 00196 const bool bChanged = rect != geometry(); 00197 QWidget::setGeometry( rect ); 00198 if( bChanged ) 00199 forceRebuild(); 00200 } 00201 */