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