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