KD Chart 2
[rev.2.5]
|
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 if( rect.isEmpty() ) return; 00109 00110 d->resizeLayout( this, rect.size() ); 00111 00112 const QPoint translation( rect.topLeft() ); 00113 painter.translate( translation ); 00114 paintAll( painter ); 00115 painter.translate( -translation.x(), -translation.y() ); 00116 00117 /* 00118 // make sure, the contents of the widget have been set up, 00119 // so we get a useful geometry: 00120 needSizeHint(); 00121 00122 const QRect oldGeometry( layout()->geometry() ); 00123 const QRect newGeo( QPoint(0,0), rect.size() ); 00124 const bool mustChangeGeo = layout() && oldGeometry != newGeo; 00125 if( mustChangeGeo ) 00126 layout()->setGeometry( newGeo ); 00127 painter.translate( rect.left(), rect.top() ); 00128 paintAll( painter ); 00129 painter.translate( -rect.left(), -rect.top() ); 00130 if( mustChangeGeo ) 00131 layout()->setGeometry( oldGeometry ); 00132 */ 00133 } 00134 00135 void AbstractAreaWidget::forceRebuild() 00136 { 00137 //bloc left empty intentionally 00138 } 00139 00140 void AbstractAreaWidget::paintAll( QPainter& painter ) 00141 { 00142 // Paint the background and frame 00143 paintBackground( painter, QRect(QPoint(0, 0), size() ) ); 00144 paintFrame( painter, QRect(QPoint(0, 0), size() ) ); 00145 00146 /* 00147 we do not call setContentsMargins() now, 00148 but we call resizeLayout() whenever the size or the frame has changed 00149 00150 // adjust the widget's content margins, 00151 // to be sure all content gets calculated 00152 // to fit into the inner rectangle 00153 const QRect oldGeometry( areaGeometry() ); 00154 const QRect inner( innerRect() ); 00155 //qDebug() << "areaGeometry():" << oldGeometry 00156 // << " contentsRect():" << contentsRect() << " inner:" << inner; 00157 if( contentsRect() != inner ){ 00158 //qDebug() << "old contentsRect():" << contentsRect() << " new innerRect:" << inner; 00159 setContentsMargins( 00160 inner.left(), 00161 inner.top(), 00162 oldGeometry.width() -inner.width()-1, 00163 oldGeometry.height()-inner.height()-1 ); 00164 //forceRebuild(); 00165 } 00166 */ 00167 int left; 00168 int top; 00169 int right; 00170 int bottom; 00171 getFrameLeadings( left, top, right, bottom ); 00172 const QPoint translation( left, top ); 00173 painter.translate( translation ); 00174 paint( &painter ); 00175 painter.translate( -translation.x(), -translation.y() ); 00176 } 00177 00178 QRect AbstractAreaWidget::areaGeometry() const 00179 { 00180 return geometry(); 00181 } 00182 00183 void AbstractAreaWidget::positionHasChanged() 00184 { 00185 emit positionChanged( this ); 00186 }