00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "KDChartAbstractAreaBase.h"
00027 #include "KDChartAbstractAreaBase_p.h"
00028 #include <KDChartBackgroundAttributes.h>
00029 #include <KDChartFrameAttributes.h>
00030 #include <KDChartTextAttributes.h>
00031 #include "KDChartPainterSaver_p.h"
00032 #include "KDChartPrintingParameters.h"
00033 #include <QPainter>
00034
00035 #include <KDABLibFakes>
00036
00037
00038 using namespace KDChart;
00039
00040 AbstractAreaBase::Private::Private() :
00041 visible( true )
00042
00043 {
00044 init();
00045 }
00046
00047
00048 AbstractAreaBase::Private::~Private() {}
00049
00050
00051 void AbstractAreaBase::Private::init()
00052 {
00053 }
00054
00055
00056
00057
00058 AbstractAreaBase::AbstractAreaBase() :
00059 _d( new Private() )
00060 {
00061 }
00062
00063 AbstractAreaBase::~AbstractAreaBase()
00064 {
00065 delete _d; _d = 0;
00066 }
00067
00068
00069 void AbstractAreaBase::init()
00070 {
00071 }
00072
00073
00074 #define d d_func()
00075
00076 bool AbstractAreaBase::compare( const AbstractAreaBase* other )const
00077 {
00078 if( other == this ) return true;
00079 if( ! other ){
00080
00081 return false;
00082 }
00083
00084
00085
00086
00087 return (frameAttributes() == other->frameAttributes()) &&
00088 (backgroundAttributes() == other->backgroundAttributes());
00089 }
00090
00091 void AbstractAreaBase::alignToReferencePoint( const RelativePosition& position )
00092 {
00093 Q_UNUSED( position );
00094
00095 qWarning( "Sorry, not implemented: void AbstractAreaBase::alignToReferencePoint( const RelativePosition& position )" );
00096 }
00097
00098 void AbstractAreaBase::setFrameAttributes( const FrameAttributes &a )
00099 {
00100 if( d->frameAttributes == a )
00101 return;
00102
00103 d->frameAttributes = a;
00104 positionHasChanged();
00105 }
00106
00107 FrameAttributes AbstractAreaBase::frameAttributes() const
00108 {
00109 return d->frameAttributes;
00110 }
00111
00112 void AbstractAreaBase::setBackgroundAttributes( const BackgroundAttributes &a )
00113 {
00114 if( d->backgroundAttributes == a )
00115 return;
00116
00117 d->backgroundAttributes = a;
00118 positionHasChanged();
00119 }
00120
00121 BackgroundAttributes AbstractAreaBase::backgroundAttributes() const
00122 {
00123 return d->backgroundAttributes;
00124 }
00125
00126
00127
00128 void AbstractAreaBase::paintBackgroundAttributes( QPainter& painter, const QRect& rect,
00129 const KDChart::BackgroundAttributes& attributes )
00130 {
00131 if( !attributes.isVisible() ) return;
00132
00133
00134 if( Qt::NoBrush != attributes.brush().style() ) {
00135 KDChart::PainterSaver painterSaver( &painter );
00136 painter.setPen( Qt::NoPen );
00137 const QPointF newTopLeft( painter.deviceMatrix().map( rect.topLeft() ) );
00138 painter.setBrushOrigin( newTopLeft );
00139 painter.setBrush( attributes.brush() );
00140 painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) );
00141 }
00142
00143 if( !attributes.pixmap().isNull() &&
00144 attributes.pixmapMode() != BackgroundAttributes::BackgroundPixmapModeNone ) {
00145 QPointF ol = rect.topLeft();
00146 if( BackgroundAttributes::BackgroundPixmapModeCentered == attributes.pixmapMode() )
00147 {
00148 ol.setX( rect.center().x() - attributes.pixmap().width() / 2 );
00149 ol.setY( rect.center().y() - attributes.pixmap().height()/ 2 );
00150 painter.drawPixmap( ol, attributes.pixmap() );
00151 } else {
00152 QMatrix m;
00153 double zW = (double)rect.width() / (double)attributes.pixmap().width();
00154 double zH = (double)rect.height() / (double)attributes.pixmap().height();
00155 switch( attributes.pixmapMode() ) {
00156 case BackgroundAttributes::BackgroundPixmapModeScaled:
00157 {
00158 double z;
00159 z = qMin( zW, zH );
00160 m.scale( z, z );
00161 }
00162 break;
00163 case BackgroundAttributes::BackgroundPixmapModeStretched:
00164 m.scale( zW, zH );
00165 break;
00166 default:
00167 ;
00168 }
00169 QPixmap pm = attributes.pixmap().transformed( m );
00170 ol.setX( rect.center().x() - pm.width() / 2 );
00171 ol.setY( rect.center().y() - pm.height()/ 2 );
00172 painter.drawPixmap( ol, pm );
00173 }
00174 }
00175 }
00176
00177
00178 void AbstractAreaBase::paintFrameAttributes( QPainter& painter, const QRect& rect,
00179 const KDChart::FrameAttributes& attributes )
00180 {
00181
00182 if( !attributes.isVisible() ) return;
00183
00184
00185
00186
00187
00188 const QPen oldPen( painter.pen() );
00189 const QBrush oldBrush( painter.brush() );
00190 painter.setPen( PrintingParameters::scalePen( attributes.pen() ) );
00191 painter.setBrush( Qt::NoBrush );
00192 painter.drawRect( rect.adjusted( 0, 0, -1, -1 ) );
00193 painter.setBrush( oldBrush );
00194 painter.setPen( oldPen );
00195 }
00196
00197 void AbstractAreaBase::paintBackground( QPainter& painter, const QRect& rect )
00198 {
00199 Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintBackground()",
00200 "Private class was not initialized!" );
00201 paintBackgroundAttributes( painter, rect, d->backgroundAttributes );
00202 }
00203
00204
00205 void AbstractAreaBase::paintFrame( QPainter& painter, const QRect& rect )
00206 {
00207 Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintFrame()",
00208 "Private class was not initialized!" );
00209 paintFrameAttributes( painter, rect, d->frameAttributes );
00210 }
00211
00212
00213 void AbstractAreaBase::getFrameLeadings(int& left, int& top, int& right, int& bottom ) const
00214 {
00215 if( d && d->frameAttributes.isVisible() ){
00216 const int padding = qMax( d->frameAttributes.padding(), 0 );
00217 left = padding;
00218 top = padding;
00219 right = padding;
00220 bottom = padding;
00221 }else{
00222 left = 0;
00223 top = 0;
00224 right = 0;
00225 bottom = 0;
00226 }
00227 }
00228
00229 QRect AbstractAreaBase::innerRect() const
00230 {
00231 int left;
00232 int top;
00233 int right;
00234 int bottom;
00235 getFrameLeadings( left, top, right, bottom );
00236 return
00237 QRect( QPoint(0,0), areaGeometry().size() )
00238 .adjusted( left, top, -right, -bottom );
00239 }
00240
00241 void AbstractAreaBase::positionHasChanged()
00242 {
00243
00244 }
00245