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 446 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 1007 of file KDChartLayoutItems.cpp.

01010     : AbstractLayoutItem( Qt::AlignCenter )
01011     , mLayoutIsAtTopPosition(  layoutIsAtTopPosition )
01012     , mRightLeftLayout( rightLeftLayout )
01013     , mLayoutIsAtLeftPosition( layoutIsAtLeftPosition )
01014     , mTopBottomLayout( topBottomLayout )
01015 {
01016 }


Member Function Documentation

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

Definition at line 1018 of file KDChartLayoutItems.cpp.

01019 {
01020     return 0; // Grow neither vertically nor horizontally
01021 }

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

Definition at line 1023 of file KDChartLayoutItems.cpp.

01024 {
01025     return mRect;
01026 }

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

Definition at line 1028 of file KDChartLayoutItems.cpp.

01029 {
01030     return true; // never empty, otherwise the layout item would not exist
01031 }

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

Definition at line 1033 of file KDChartLayoutItems.cpp.

References sizeHint().

01034 {
01035     return sizeHint();
01036 }

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

Definition at line 1038 of file KDChartLayoutItems.cpp.

References sizeHint().

01039 {
01040     return sizeHint();
01041 }

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

Implements KDChart::AbstractLayoutItem.

Definition at line 1112 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParentLayout.

01113 {
01114     if( mParentLayout && mRect.isValid() && mCachedSize.isValid() &&
01115         mCommonBrush.style() != Qt::NoBrush )
01116     {
01117         QPoint p1( mRect.topLeft() );
01118         QPoint p2( mRect.bottomRight() );
01119         if( mLayoutIsAtLeftPosition )
01120             p1.rx() += mCachedSize.width() - mParentLayout->spacing();
01121         else
01122             p2.rx() -= mCachedSize.width() - mParentLayout->spacing();
01123         if( mLayoutIsAtTopPosition ){
01124             p1.ry() += mCachedSize.height() - mParentLayout->spacing() - 1;
01125             p2.ry() -= 1;
01126         }else
01127             p2.ry() -= mCachedSize.height() - mParentLayout->spacing() - 1;
01128         //qDebug() << mLayoutIsAtTopPosition << mLayoutIsAtLeftPosition;
01129         //qDebug() << mRect;
01130         //qDebug() << mParentLayout->margin();
01131         //qDebug() << QRect( p1, p2 );
01132         const QPoint oldBrushOrigin( painter->brushOrigin() );
01133         const QBrush oldBrush( painter->brush() );
01134         const QPen   oldPen(   painter->pen() );
01135         const QPointF newTopLeft( painter->deviceMatrix().map( p1 ) );
01136         painter->setBrushOrigin( newTopLeft );
01137         painter->setBrush( mCommonBrush );
01138         painter->setPen( Qt::NoPen );
01139         painter->drawRect( QRect( p1, p2 ) );
01140         painter->setBrushOrigin( oldBrushOrigin );
01141         painter->setBrush( oldBrush );
01142         painter->setPen( oldPen );
01143     }
01144     // debug code:
01145 #if 0
01146     //qDebug() << "KDChart::AutoSpacerLayoutItem::paint()";
01147     if( !mRect.isValid() )
01148         return;
01149 
01150     painter->drawRect( mRect );
01151     painter->drawLine( QPointF( mRect.x(), mRect.top() ),
01152                        QPointF( mRect.right(), mRect.bottom() ) );
01153     painter->drawLine( QPointF( mRect.right(), mRect.top() ),
01154                        QPointF( mRect.x(), mRect.bottom() ) );
01155 #endif
01156 }

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 70 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::paint().

00071 {
00072     paint( &painter );
00073 }

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

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

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

Definition at line 78 of file KDChartLayoutItems.cpp.

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

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

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

Definition at line 79 of file KDChartLayoutItems.h.

00080         {
00081             return mParentLayout;
00082         }

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

Definition at line 83 of file KDChartLayoutItems.h.

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

00084         {
00085             if( mParentLayout ){
00086                 if( widget() )
00087                     mParentLayout->removeWidget( widget() );
00088                 else
00089                     mParentLayout->removeItem( this );
00090             }
00091         }

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

Definition at line 1043 of file KDChartLayoutItems.cpp.

01044 {
01045     mRect = r;
01046 }

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

Definition at line 75 of file KDChartLayoutItems.h.

00076         {
00077             mParentLayout = lay;
00078         }

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 65 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent.

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

00066 {
00067     mParent = widget;
00068 }

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

Definition at line 1068 of file KDChartLayoutItems.cpp.

References KDChart::AbstractArea::bottomOverlap(), KDChart::AbstractArea::leftOverlap(), KDChart::AbstractArea::rightOverlap(), KDChart::AbstractArea::topOverlap(), and updateCommonBrush().

Referenced by maximumSize(), and minimumSize().

01069 {
01070     QBrush commonBrush;
01071     bool bStart=true;
01072     // calculate the maximal overlap of the top/bottom axes:
01073     int topBottomOverlap = 0;
01074     if( mTopBottomLayout ){
01075         for (int i = 0; i < mTopBottomLayout->count(); ++i){
01076             AbstractArea* area = dynamic_cast<AbstractArea*>(mTopBottomLayout->itemAt(i));
01077             if( area ){
01078                 //qDebug() << "AutoSpacerLayoutItem testing" << area;
01079                 topBottomOverlap =
01080                     mLayoutIsAtLeftPosition
01081                     ? qMax( topBottomOverlap, area->rightOverlap() )
01082                     : qMax( topBottomOverlap, area->leftOverlap() );
01083                 updateCommonBrush( commonBrush, bStart, *area );
01084             }
01085         }
01086     }
01087     // calculate the maximal overlap of the left/right axes:
01088     int leftRightOverlap = 0;
01089     if( mRightLeftLayout ){
01090         for (int i = 0; i < mRightLeftLayout->count(); ++i){
01091             AbstractArea* area = dynamic_cast<AbstractArea*>(mRightLeftLayout->itemAt(i));
01092             if( area ){
01093                 //qDebug() << "AutoSpacerLayoutItem testing" << area;
01094                 leftRightOverlap =
01095                         mLayoutIsAtTopPosition
01096                         ? qMax( leftRightOverlap, area->bottomOverlap() )
01097                         : qMax( leftRightOverlap, area->topOverlap() );
01098                 updateCommonBrush( commonBrush, bStart, *area );
01099             }
01100         }
01101     }
01102     if( topBottomOverlap > 0 && leftRightOverlap > 0 )
01103         mCommonBrush = commonBrush;
01104     else
01105         mCommonBrush = QBrush();
01106     mCachedSize = QSize( topBottomOverlap, leftRightOverlap );
01107     //qDebug() << mCachedSize;
01108     return mCachedSize;
01109 }

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

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

Definition at line 87 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent.

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

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


Member Data Documentation

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

Definition at line 93 of file KDChartLayoutItems.h.

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

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

Definition at line 94 of file KDChartLayoutItems.h.

Referenced by paint().


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