KDChart::AbstractAreaWidget Class Reference

#include <KDChartAbstractAreaWidget.h>

Inheritance diagram for KDChart::AbstractAreaWidget:

Inheritance graph
[legend]
Collaboration diagram for KDChart::AbstractAreaWidget:

Collaboration graph
[legend]

List of all members.


Detailed Description

An area in the chart with a background, a frame, etc.

AbstractAreaWidget is the base for all widget classes that have a set of background attributes and frame attributes, such as KDChart::Chart and KDChart::Legend.

Definition at line 51 of file KDChartAbstractAreaWidget.h.


Signals

void positionChanged (AbstractAreaWidget *)

Public Member Functions

 AbstractAreaWidget (QWidget *parent=0)
void alignToReferencePoint (const RelativePosition &position)
BackgroundAttributes backgroundAttributes () const
bool compare (const AbstractAreaBase *other) const
 Returns true if both areas have the same settings.
virtual void forceRebuild ()
 Call this to trigger an unconditional re-building of the widget's internals.
FrameAttributes frameAttributes () const
void getFrameLeadings (int &left, int &top, int &right, int &bottom) const
virtual void needSizeHint ()
 Call this to trigger an conditional re-building of the widget's internals.
virtual void paint (QPainter *painter)=0
 Overwrite this to paint the inner contents of your widget.
void paintAll (QPainter &painter)
 Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically.
virtual void paintBackground (QPainter &painter, const QRect &rectangle)
virtual void paintEvent (QPaintEvent *event)
 Draws the background and frame, then calls paint().
virtual void paintFrame (QPainter &painter, const QRect &rectangle)
virtual void paintIntoRect (QPainter &painter, const QRect &rect)
 Draws the background and frame, then calls paint().
virtual void resizeLayout (const QSize &)
void setBackgroundAttributes (const BackgroundAttributes &a)
void setFrameAttributes (const FrameAttributes &a)

Static Public Member Functions

static void paintBackgroundAttributes (QPainter &painter, const QRect &rectangle, const KDChart::BackgroundAttributes &attributes)
static void paintFrameAttributes (QPainter &painter, const QRect &rectangle, const KDChart::FrameAttributes &attributes)

Protected Member Functions

virtual QRect areaGeometry () const
QRect innerRect () const
virtual void positionHasChanged ()
virtual ~AbstractAreaWidget ()

Constructor & Destructor Documentation

AbstractAreaWidget::AbstractAreaWidget ( QWidget parent = 0  )  [explicit]

Definition at line 69 of file KDChartAbstractAreaWidget.cpp.

References StockDiagram::init().

00070     : QWidget( parent )
00071     , AbstractAreaBase( new Private() )
00072 {
00073     init();
00074 }

AbstractAreaWidget::~AbstractAreaWidget (  )  [protected, virtual]

Definition at line 76 of file KDChartAbstractAreaWidget.cpp.

00077 {
00078     // this block left empty intentionally
00079 }


Member Function Documentation

void AbstractAreaBase::alignToReferencePoint ( const RelativePosition position  )  [inherited]

Definition at line 91 of file KDChartAbstractAreaBase.cpp.

00092 {
00093     Q_UNUSED( position );
00094     // PENDING(kalle) FIXME
00095     qWarning( "Sorry, not implemented: void AbstractAreaBase::alignToReferencePoint( const RelativePosition& position )" );
00096 }

QRect AbstractAreaWidget::areaGeometry (  )  const [protected, virtual]

Implements KDChart::AbstractAreaBase.

Definition at line 186 of file KDChartAbstractAreaWidget.cpp.

00187 {
00188     return geometry();
00189 }

BackgroundAttributes AbstractAreaBase::backgroundAttributes (  )  const [inherited]

Definition at line 121 of file KDChartAbstractAreaBase.cpp.

References d.

Referenced by KDChart::AbstractAreaBase::compare(), and updateCommonBrush().

00122 {
00123     return d->backgroundAttributes;
00124 }

bool AbstractAreaBase::compare ( const AbstractAreaBase other  )  const [inherited]

Returns true if both areas have the same settings.

Definition at line 76 of file KDChartAbstractAreaBase.cpp.

References KDChart::AbstractAreaBase::backgroundAttributes(), and KDChart::AbstractAreaBase::frameAttributes().

00077 {
00078     if( other == this ) return true;
00079     if( ! other ){
00080         //qDebug() << "CartesianAxis::compare() cannot compare to Null pointer";
00081         return false;
00082     }
00083     /*
00084     qDebug() << "AbstractAreaBase:" << (frameAttributes() == other->frameAttributes())
00085         << (backgroundAttributes() == other->backgroundAttributes()) << "\n";
00086     */
00087     return  (frameAttributes()      == other->frameAttributes()) &&
00088             (backgroundAttributes() == other->backgroundAttributes());
00089 }

void AbstractAreaWidget::forceRebuild (  )  [virtual]

Call this to trigger an unconditional re-building of the widget's internals.

Reimplemented in KDChart::Legend.

Definition at line 140 of file KDChartAbstractAreaWidget.cpp.

00141 {
00142     //bloc left empty intentionally
00143 }

FrameAttributes AbstractAreaBase::frameAttributes (  )  const [inherited]

Definition at line 107 of file KDChartAbstractAreaBase.cpp.

References d.

Referenced by KDChart::Legend::clone(), KDChart::AbstractAreaBase::compare(), and updateCommonBrush().

00108 {
00109     return d->frameAttributes;
00110 }

void AbstractAreaBase::getFrameLeadings ( int &  left,
int &  top,
int &  right,
int &  bottom 
) const [inherited]

Definition at line 213 of file KDChartAbstractAreaBase.cpp.

References d.

Referenced by KDChart::AbstractAreaBase::innerRect(), and paintAll().

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 }

QRect AbstractAreaBase::innerRect (  )  const [protected, inherited]

Definition at line 229 of file KDChartAbstractAreaBase.cpp.

References KDChart::AbstractAreaBase::areaGeometry(), and KDChart::AbstractAreaBase::getFrameLeadings().

Referenced by KDChart::TextArea::paintAll(), and KDChart::AbstractArea::paintAll().

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 }

void AbstractAreaWidget::needSizeHint (  )  [virtual]

Call this to trigger an conditional re-building of the widget's internals.

e.g. AbstractAreaWidget call this, before calling layout()->setGeometry()

Reimplemented in KDChart::Legend.

Definition at line 86 of file KDChartAbstractAreaWidget.cpp.

00087 {
00088     // this block left empty intentionally
00089 }

virtual void KDChart::AbstractAreaWidget::paint ( QPainter *  painter  )  [pure virtual]

Overwrite this to paint the inner contents of your widget.

Note:
When overriding this method, please let your widget draw itself at the top/left corner of the painter. You should call rect() (or width(), height(), resp.) to find the drawable area's size: While the paint() method is being executed the frame of the widget is outside of its rect(), so you can use all of rect() for your custom drawing!
See also:
paint, paintIntoRect

Implemented in KDChart::Legend.

Referenced by paintAll().

void AbstractAreaWidget::paintAll ( QPainter &  painter  ) 

Call paintAll, if you want the background and the frame to be drawn before the normal paint() is invoked automatically.

Definition at line 145 of file KDChartAbstractAreaWidget.cpp.

References KDChart::AbstractAreaBase::getFrameLeadings(), paint(), KDChart::AbstractAreaBase::paintBackground(), and KDChart::AbstractAreaBase::paintFrame().

Referenced by paintEvent(), and paintIntoRect().

00146 {
00147     //qDebug() << "AbstractAreaWidget::paintAll() called";
00148 
00149     // Paint the background and frame
00150     paintBackground( painter, QRect(QPoint(0, 0), size() ) );
00151     paintFrame(      painter, QRect(QPoint(0, 0), size() ) );
00152 
00153 /*
00154     we do not call setContentsMargins() now,
00155     but we call resizeLayout() whenever the size or the frame has changed
00156 
00157     // adjust the widget's content margins,
00158     // to be sure all content gets calculated
00159     // to fit into the inner rectangle
00160     const QRect oldGeometry( areaGeometry()  );
00161     const QRect inner( innerRect() );
00162     //qDebug() << "areaGeometry():" << oldGeometry
00163     //         << "  contentsRect():" << contentsRect() << "  inner:" << inner;
00164     if( contentsRect() != inner ){
00165         //qDebug() << "old contentsRect():" << contentsRect() << "  new innerRect:" << inner;
00166         setContentsMargins(
00167             inner.left(),
00168             inner.top(),
00169             oldGeometry.width() -inner.width()-1,
00170             oldGeometry.height()-inner.height()-1 );
00171         //forceRebuild();
00172     }
00173 */
00174     int left;
00175     int top;
00176     int right;
00177     int bottom;
00178     getFrameLeadings( left, top, right, bottom );
00179     const QPoint translation( left, top );
00180     painter.translate( translation );
00181     paint( &painter );
00182     painter.translate( -translation.x(), -translation.y() );
00183      //qDebug() << "AbstractAreaWidget::paintAll() done.";
00184 }

void AbstractAreaBase::paintBackground ( QPainter &  painter,
const QRect &  rectangle 
) [virtual, inherited]

Definition at line 197 of file KDChartAbstractAreaBase.cpp.

References d, and KDChart::AbstractAreaBase::paintBackgroundAttributes().

Referenced by KDChart::TextArea::paintAll(), paintAll(), and KDChart::AbstractArea::paintAll().

00198 {
00199     Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintBackground()",
00200                 "Private class was not initialized!" );
00201     paintBackgroundAttributes( painter, rect, d->backgroundAttributes );
00202 }

void AbstractAreaBase::paintBackgroundAttributes ( QPainter &  painter,
const QRect &  rectangle,
const KDChart::BackgroundAttributes attributes 
) [static, inherited]

Definition at line 128 of file KDChartAbstractAreaBase.cpp.

References KDChart::BackgroundAttributes::BackgroundPixmapModeCentered, KDChart::BackgroundAttributes::BackgroundPixmapModeNone, KDChart::BackgroundAttributes::BackgroundPixmapModeScaled, KDChart::BackgroundAttributes::BackgroundPixmapModeStretched, KDChart::BackgroundAttributes::brush(), KDChart::BackgroundAttributes::isVisible(), m, KDChart::BackgroundAttributes::pixmap(), and KDChart::BackgroundAttributes::pixmapMode().

Referenced by KDChart::AbstractAreaBase::paintBackground().

00130 {
00131     if( !attributes.isVisible() ) return;
00132 
00133     /* first draw the brush (may contain a pixmap)*/
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     /* next draw the backPixmap over the brush */
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                 ; // Cannot happen, previously checked
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 }

void AbstractAreaWidget::paintEvent ( QPaintEvent *  event  )  [virtual]

Draws the background and frame, then calls paint().

In most cases there is no need to overwrite this method in a derived class, but you would overwrite paint() instead.

See also:
paint

Definition at line 99 of file KDChartAbstractAreaWidget.cpp.

References d, and paintAll().

00100 {
00101     Q_UNUSED( event );
00102     QPainter painter( this );
00103     if( size() != d->currentLayoutSize ){
00104         d->resizeLayout( this, size() );
00105     }
00106     paintAll( painter );
00107 }

void AbstractAreaBase::paintFrame ( QPainter &  painter,
const QRect &  rectangle 
) [virtual, inherited]

Definition at line 205 of file KDChartAbstractAreaBase.cpp.

References d, and KDChart::AbstractAreaBase::paintFrameAttributes().

Referenced by KDChart::TextArea::paintAll(), paintAll(), and KDChart::AbstractArea::paintAll().

00206 {
00207     Q_ASSERT_X ( d != 0, "AbstractAreaBase::paintFrame()",
00208                 "Private class was not initialized!" );
00209     paintFrameAttributes( painter, rect, d->frameAttributes );
00210 }

void AbstractAreaBase::paintFrameAttributes ( QPainter &  painter,
const QRect &  rectangle,
const KDChart::FrameAttributes attributes 
) [static, inherited]

Definition at line 178 of file KDChartAbstractAreaBase.cpp.

References KDChart::FrameAttributes::isVisible(), KDChart::FrameAttributes::pen(), and KDChart::PrintingParameters::scalePen().

Referenced by KDChart::AbstractAreaBase::paintFrame().

00180 {
00181 
00182     if( !attributes.isVisible() ) return;
00183 
00184     // Note: We set the brush to NoBrush explicitly here.
00185     //       Otherwise we might get a filled rectangle, so any
00186     //       previously drawn background would be overwritten by that area.
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 }

void AbstractAreaWidget::paintIntoRect ( QPainter &  painter,
const QRect &  rect 
) [virtual]

Draws the background and frame, then calls paint().

In most cases there is no need to overwrite this method in a derived class, but you would overwrite paint() instead.

Definition at line 109 of file KDChartAbstractAreaWidget.cpp.

References d, and paintAll().

Referenced by KDChart::Chart::paint().

00110 {
00111     //qDebug() << "AbstractAreaWidget::paintIntoRect() called rect=" << rect;
00112 
00113     if( rect.isEmpty() ) return;
00114 
00115     d->resizeLayout( this, rect.size() );
00116 
00117     const QPoint translation( rect.topLeft() );
00118     painter.translate( translation );
00119     paintAll( painter );
00120     painter.translate( -translation.x(), -translation.y() );
00121 
00122 /*
00123     // make sure, the contents of the widget have been set up,
00124     // so we get a useful geometry:
00125     needSizeHint();
00126 
00127     const QRect oldGeometry( layout()->geometry() );
00128     const QRect newGeo( QPoint(0,0), rect.size() );
00129     const bool mustChangeGeo = layout() && oldGeometry != newGeo;
00130     if( mustChangeGeo )
00131         layout()->setGeometry( newGeo );
00132     painter.translate( rect.left(), rect.top() );
00133     paintAll( painter );
00134     painter.translate( -rect.left(), -rect.top() );
00135     if( mustChangeGeo )
00136         layout()->setGeometry( oldGeometry );
00137 */
00138 }

void KDChart::AbstractAreaWidget::positionChanged ( AbstractAreaWidget  )  [signal]

Referenced by positionHasChanged().

void AbstractAreaWidget::positionHasChanged (  )  [protected, virtual]

Reimplemented from KDChart::AbstractAreaBase.

Definition at line 191 of file KDChartAbstractAreaWidget.cpp.

References positionChanged().

00192 {
00193     emit positionChanged( this );
00194 }

void AbstractAreaWidget::resizeLayout ( const QSize &  size  )  [virtual]

Reimplemented in KDChart::Legend.

Definition at line 93 of file KDChartAbstractAreaWidget.cpp.

00094 {
00095     Q_UNUSED( size );
00096     // this block left empty intentionally
00097 }

void AbstractAreaBase::setBackgroundAttributes ( const BackgroundAttributes a  )  [inherited]

Definition at line 112 of file KDChartAbstractAreaBase.cpp.

References d, and KDChart::AbstractAreaBase::positionHasChanged().

00113 {
00114     if( d->backgroundAttributes == a )
00115         return;
00116 
00117     d->backgroundAttributes = a;
00118     positionHasChanged();
00119 }

void AbstractAreaBase::setFrameAttributes ( const FrameAttributes a  )  [inherited]

Definition at line 98 of file KDChartAbstractAreaBase.cpp.

References d, and KDChart::AbstractAreaBase::positionHasChanged().

Referenced by KDChart::Legend::clone().

00099 {
00100     if( d->frameAttributes == a )
00101         return;
00102 
00103     d->frameAttributes = a;
00104     positionHasChanged();
00105 }


The documentation for this class was generated from the following files:
Generated on Thu Mar 4 23:25:20 2010 for KD Chart 2 by  doxygen 1.5.4