KDChartAbstractArea.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 "KDChartAbstractArea.h"
00027 #include "KDChartAbstractArea_p.h"
00028 
00029 #include <qglobal.h>
00030 
00031 #include <QPainter>
00032 #include <QRect>
00033 
00034 #include <KDABLibFakes>
00035 
00036 
00037 using namespace KDChart;
00038 
00039 #define d (d_func())
00040 
00041 AbstractArea::Private::Private() :
00042     AbstractAreaBase::Private()
00043 {
00044     // this bloc left empty intentionally
00045 }
00046 
00047 
00048 AbstractArea::Private::~Private()
00049 {
00050     // this bloc left empty intentionally
00051 }
00052 
00053 
00054 AbstractArea::AbstractArea()
00055     : QObject()
00056     , KDChart::AbstractAreaBase()
00057     , KDChart::AbstractLayoutItem()
00058 {
00059     init();
00060 }
00061 
00062 AbstractArea::~AbstractArea()
00063 {
00064     // this bloc left empty intentionally
00065 }
00066 
00067 
00068 void AbstractArea::init()
00069 {
00070     d->amountOfLeftOverlap = 0;
00071     d->amountOfRightOverlap = 0;
00072     d->amountOfTopOverlap = 0;
00073     d->amountOfBottomOverlap = 0;
00074 }
00075 
00076 
00077 int AbstractArea::leftOverlap( bool doNotRecalculate ) const
00078 {
00079     // Re-calculate the sizes,
00080     // so we also get the amountOf..Overlap members set newly:
00081     if( ! doNotRecalculate )
00082         sizeHint();
00083     return d->amountOfLeftOverlap;
00084 }
00085 int AbstractArea::rightOverlap( bool doNotRecalculate ) const
00086 {
00087     // Re-calculate the sizes,
00088     // so we also get the amountOf..Overlap members set newly:
00089     if( ! doNotRecalculate )
00090         sizeHint();
00091     return d->amountOfRightOverlap;
00092 }
00093 int AbstractArea::topOverlap( bool doNotRecalculate ) const
00094 {
00095     // Re-calculate the sizes,
00096     // so we also get the amountOf..Overlap members set newly:
00097     if( ! doNotRecalculate )
00098         sizeHint();
00099     return d->amountOfTopOverlap;
00100 }
00101 int AbstractArea::bottomOverlap( bool doNotRecalculate ) const
00102 {
00103     // Re-calculate the sizes,
00104     // so we also get the amountOf..Overlap members set newly:
00105     if( ! doNotRecalculate )
00106         sizeHint();
00107     return d->amountOfBottomOverlap;
00108 }
00109 
00110 
00111 void AbstractArea::paintIntoRect( QPainter& painter, const QRect& rect )
00112 {
00113     const QRect oldGeometry( geometry() );
00114     if( oldGeometry != rect )
00115         setGeometry( rect );
00116     painter.translate( rect.left(), rect.top() );
00117     paintAll( painter );
00118     painter.translate( -rect.left(), -rect.top() );
00119     if( oldGeometry != rect )
00120         setGeometry( oldGeometry );
00121 }
00122 
00123 void AbstractArea::paintAll( QPainter& painter )
00124 {
00125     // Paint the background and frame
00126     const QRect overlappingArea( geometry().adjusted(
00127             -d->amountOfLeftOverlap,
00128             -d->amountOfTopOverlap,
00129             d->amountOfRightOverlap,
00130             d->amountOfBottomOverlap ) );
00131     paintBackground( painter, overlappingArea );
00132     paintFrame(      painter, overlappingArea );
00133 
00134     // temporarily adjust the widget size, to be sure all content gets calculated
00135     // to fit into the inner rectangle
00136     const QRect oldGeometry( areaGeometry()  );
00137     QRect inner( innerRect() );
00138     inner.moveTo(
00139         oldGeometry.left() + inner.left(),
00140         oldGeometry.top()  + inner.top() );
00141     const bool needAdjustGeometry = oldGeometry != inner;
00142     if( needAdjustGeometry )
00143         setGeometry( inner );
00144     paint( &painter );
00145     if( needAdjustGeometry )
00146         setGeometry( oldGeometry );
00147     //qDebug() << "AbstractAreaWidget::paintAll() done.";
00148 }
00149 
00150 QRect AbstractArea::areaGeometry() const
00151 {
00152     return geometry();
00153 }
00154 
00155 void AbstractArea::positionHasChanged()
00156 {
00157     emit positionChanged( this );
00158 }
00159 

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