KDChartAbstractAreaWidget.cpp

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

Generated on Thu Mar 4 23:19:09 2010 for KD Chart 2 by  doxygen 1.5.4