KDChart::AutoSpacerLayoutItem Class Reference

#include <KDChartLayoutItems.h>

Inheritance diagram for KDChart::AutoSpacerLayoutItem:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

An empty layout item.

Definition at line 383 of file KDChartLayoutItems.h.

Public Member Functions

 AutoSpacerLayoutItem (bool layoutIsAtTopPosition, QHBoxLayout *rightLeftLayout, bool layoutIsAtLeftPosition, QVBoxLayout *topBottomLayout)
virtual Qt::Orientations expandingDirections () const
virtual QRect geometry () const
virtual bool isEmpty () const
virtual QSize maximumSize () const
virtual QSize minimumSize () const
virtual void paint (QPainter *)
virtual void paintAll (QPainter &painter)
 Default impl: just call paint.
virtual void paintCtx (PaintContext *context)
 Default impl: Paint the complete item using its layouted position and size.
QLayout * parentLayout ()
void removeFromParentLayout ()
virtual void setGeometry (const QRect &r)
void setParentLayout (QLayout *lay)
virtual void setParentWidget (QWidget *widget)
 Inform the item about its widget: This enables the item, to trigger that widget's update, whenever the size of the item's contents has changed.
virtual QSize sizeHint () const
virtual void sizeHintChanged () const
 Report changed size hint: ask the parent widget to recalculate the layout.

Protected Attributes

QWidgetmParent
QLayout * mParentLayout


Constructor & Destructor Documentation

KDChart::AutoSpacerLayoutItem::AutoSpacerLayoutItem ( bool  layoutIsAtTopPosition,
QHBoxLayout *  rightLeftLayout,
bool  layoutIsAtLeftPosition,
QVBoxLayout *  topBottomLayout 
)

Definition at line 760 of file KDChartLayoutItems.cpp.

00763     : AbstractLayoutItem( Qt::AlignCenter )
00764     , mLayoutIsAtTopPosition(  layoutIsAtTopPosition )
00765     , mRightLeftLayout( rightLeftLayout )
00766     , mLayoutIsAtLeftPosition( layoutIsAtLeftPosition )
00767     , mTopBottomLayout( topBottomLayout )
00768 {
00769 }


Member Function Documentation

Qt::Orientations KDChart::AutoSpacerLayoutItem::expandingDirections (  )  const [virtual]

Definition at line 771 of file KDChartLayoutItems.cpp.

00772 {
00773     return 0; // Grow neither vertically nor horizontally
00774 }

QRect KDChart::AutoSpacerLayoutItem::geometry (  )  const [virtual]

Definition at line 776 of file KDChartLayoutItems.cpp.

00777 {
00778     return mRect;
00779 }

bool KDChart::AutoSpacerLayoutItem::isEmpty (  )  const [virtual]

Definition at line 781 of file KDChartLayoutItems.cpp.

00782 {
00783     return true; // never empty, otherwise the layout item would not exist
00784 }

QSize KDChart::AutoSpacerLayoutItem::maximumSize (  )  const [virtual]

Definition at line 786 of file KDChartLayoutItems.cpp.

References sizeHint().

00787 {
00788     return sizeHint();
00789 }

QSize KDChart::AutoSpacerLayoutItem::minimumSize (  )  const [virtual]

Definition at line 791 of file KDChartLayoutItems.cpp.

References sizeHint().

00792 {
00793     return sizeHint();
00794 }

void KDChart::AutoSpacerLayoutItem::paint ( QPainter *   )  [virtual]

Implements KDChart::AbstractLayoutItem.

Definition at line 865 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParentLayout.

00866 {
00867     if( mParentLayout && mRect.isValid() && mCachedSize.isValid() &&
00868         mCommonBrush.style() != Qt::NoBrush )
00869     {
00870         QPoint p1( mRect.topLeft() );
00871         QPoint p2( mRect.bottomRight() );
00872         if( mLayoutIsAtLeftPosition )
00873             p1.rx() += mCachedSize.width() - mParentLayout->spacing();
00874         else
00875             p2.rx() -= mCachedSize.width() - mParentLayout->spacing();
00876         if( mLayoutIsAtTopPosition ){
00877             p1.ry() += mCachedSize.height() - mParentLayout->spacing() - 1;
00878             p2.ry() -= 1;
00879         }else
00880             p2.ry() -= mCachedSize.height() - mParentLayout->spacing() - 1;
00881         //qDebug() << mLayoutIsAtTopPosition << mLayoutIsAtLeftPosition;
00882         //qDebug() << mRect;
00883         //qDebug() << mParentLayout->margin();
00884         //qDebug() << QRect( p1, p2 );
00885         const QPoint oldBrushOrigin( painter->brushOrigin() );
00886         const QBrush oldBrush( painter->brush() );
00887         const QPen   oldPen(   painter->pen() );
00888         const QPointF newTopLeft( painter->deviceMatrix().map( p1 ) );
00889         painter->setBrushOrigin( newTopLeft );
00890         painter->setBrush( mCommonBrush );
00891         painter->setPen( Qt::NoPen );
00892         painter->drawRect( QRect( p1, p2 ) );
00893         painter->setBrushOrigin( oldBrushOrigin );
00894         painter->setBrush( oldBrush );
00895         painter->setPen( oldPen );
00896     }
00897     // debug code:
00898 #if 0
00899     //qDebug() << "KDChart::AutoSpacerLayoutItem::paint()";
00900     if( !mRect.isValid() )
00901         return;
00902 
00903     painter->drawRect( mRect );
00904     painter->drawLine( QPointF( mRect.x(), mRect.top() ),
00905                        QPointF( mRect.right(), mRect.bottom() ) );
00906     painter->drawLine( QPointF( mRect.right(), mRect.top() ),
00907                        QPointF( mRect.x(), mRect.bottom() ) );
00908 #endif
00909 }

void KDChart::AbstractLayoutItem::paintAll ( QPainter &  painter  )  [virtual, inherited]

Default impl: just call paint.

Derived classes like KDChart::AbstractArea are providing additional action here.

Reimplemented in KDChart::AbstractArea, KDChart::TextArea, and KDChart::TernaryAxis.

Definition at line 69 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::paint().

00070 {
00071     paint( &painter );
00072 }

void KDChart::AbstractLayoutItem::paintCtx ( PaintContext context  )  [virtual, inherited]

Default impl: Paint the complete item using its layouted position and size.

Reimplemented in KDChart::CartesianAxis, and KDChart::TernaryAxis.

Definition at line 77 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::paint(), and KDChart::PaintContext::painter().

00078 {
00079     if( context )
00080         paint( context->painter() );
00081 }

QLayout* KDChart::AbstractLayoutItem::parentLayout (  )  [inherited]

Definition at line 76 of file KDChartLayoutItems.h.

00077         {
00078             return mParentLayout;
00079         }

void KDChart::AbstractLayoutItem::removeFromParentLayout (  )  [inherited]

Definition at line 80 of file KDChartLayoutItems.h.

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

00081         {
00082             if( mParentLayout ){
00083                 if( widget() )
00084                     mParentLayout->removeWidget( widget() );
00085                 else
00086                     mParentLayout->removeItem( this );
00087             }
00088         }

void KDChart::AutoSpacerLayoutItem::setGeometry ( const QRect &  r  )  [virtual]

Definition at line 796 of file KDChartLayoutItems.cpp.

00797 {
00798     mRect = r;
00799 }

void KDChart::AbstractLayoutItem::setParentLayout ( QLayout *  lay  )  [inherited]

Definition at line 72 of file KDChartLayoutItems.h.

00073         {
00074             mParentLayout = lay;
00075         }

void KDChart::AbstractLayoutItem::setParentWidget ( QWidget widget  )  [virtual, inherited]

Inform the item about its widget: This enables the item, to trigger that widget's update, whenever the size of the item's contents has changed.

Thus, you need to call setParentWidget on every item, that has a non-fixed size.

Definition at line 64 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent.

Referenced by KDChart::HeaderFooter::setParent(), and KDChart::AbstractCartesianDiagram::takeAxis().

00065 {
00066     mParent = widget;
00067 }

QSize KDChart::AutoSpacerLayoutItem::sizeHint (  )  const [virtual]

Definition at line 821 of file KDChartLayoutItems.cpp.

References updateCommonBrush().

Referenced by maximumSize(), and minimumSize().

00822 {
00823     QBrush commonBrush;
00824     bool bStart=true;
00825     // calculate the maximal overlap of the top/bottom axes:
00826     int topBottomOverlap = 0;
00827     if( mTopBottomLayout ){
00828         for (int i = 0; i < mTopBottomLayout->count(); ++i){
00829             AbstractArea* area = dynamic_cast<AbstractArea*>(mTopBottomLayout->itemAt(i));
00830             if( area ){
00831                 //qDebug() << "AutoSpacerLayoutItem testing" << area;
00832                 topBottomOverlap =
00833                     mLayoutIsAtLeftPosition
00834                     ? qMax( topBottomOverlap, area->rightOverlap() )
00835                     : qMax( topBottomOverlap, area->leftOverlap() );
00836                 updateCommonBrush( commonBrush, bStart, *area );
00837             }
00838         }
00839     }
00840     // calculate the maximal overlap of the left/right axes:
00841     int leftRightOverlap = 0;
00842     if( mRightLeftLayout ){
00843         for (int i = 0; i < mRightLeftLayout->count(); ++i){
00844             AbstractArea* area = dynamic_cast<AbstractArea*>(mRightLeftLayout->itemAt(i));
00845             if( area ){
00846                 //qDebug() << "AutoSpacerLayoutItem testing" << area;
00847                 leftRightOverlap =
00848                         mLayoutIsAtTopPosition
00849                         ? qMax( leftRightOverlap, area->bottomOverlap() )
00850                         : qMax( leftRightOverlap, area->topOverlap() );
00851                 updateCommonBrush( commonBrush, bStart, *area );
00852             }
00853         }
00854     }
00855     if( topBottomOverlap > 0 && leftRightOverlap > 0 )
00856         mCommonBrush = commonBrush;
00857     else
00858         mCommonBrush = QBrush();
00859     mCachedSize = QSize( topBottomOverlap, leftRightOverlap );
00860     //qDebug() << mCachedSize;
00861     return mCachedSize;
00862 }

void KDChart::AbstractLayoutItem::sizeHintChanged (  )  const [virtual, inherited]

Report changed size hint: ask the parent widget to recalculate the layout.

Definition at line 86 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent.

Referenced by KDChart::TextLayoutItem::sizeHint().

00087 {
00088     // This is exactly like what QWidget::updateGeometry does.
00089 //  qDebug("KDChart::AbstractLayoutItem::sizeHintChanged() called");
00090     if( mParent ) {
00091         if ( mParent->layout() )
00092             mParent->layout()->invalidate();
00093         else
00094             QApplication::postEvent( mParent, new QEvent( QEvent::LayoutRequest ) );
00095     }
00096 }


Member Data Documentation

QWidget* KDChart::AbstractLayoutItem::mParent [protected, inherited]

Definition at line 90 of file KDChartLayoutItems.h.

Referenced by KDChart::AbstractLayoutItem::setParentWidget(), KDChart::TextLayoutItem::setText(), KDChart::TextLayoutItem::setTextAttributes(), and KDChart::AbstractLayoutItem::sizeHintChanged().

QLayout* KDChart::AbstractLayoutItem::mParentLayout [protected, inherited]

Definition at line 91 of file KDChartLayoutItems.h.

Referenced by paint().


The documentation for this class was generated from the following files:
Generated on Mon Sep 17 16:18:10 2007 for KD Chart 2 by  doxygen 1.5.1