KDChartAbstractArea.cpp

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

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