KDChart::TextLayoutItem Class Reference

#include <KDChartLayoutItems.h>

Inheritance diagram for KDChart::TextLayoutItem:

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

Collaboration graph
[legend]
List of all members.

Detailed Description

Layout item showing a text.

Definition at line 98 of file KDChartLayoutItems.h.

Public Member Functions

const QObjectautoReferenceArea () const
virtual Qt::Orientations expandingDirections () const
 pure virtual in QLayoutItem
virtual QRect geometry () const
 pure virtual in QLayoutItem
virtual bool intersects (const TextLayoutItem &other, const QPoint &myPos, const QPoint &otherPos) const
virtual bool intersects (const TextLayoutItem &other, const QPointF &myPos, const QPointF &otherPos) const
virtual bool isEmpty () const
 pure virtual in QLayoutItem
virtual QSize maximumSize () const
 pure virtual in QLayoutItem
virtual QSize minimumSize () const
 pure virtual in QLayoutItem
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 ()
virtual QFont realFont () const
virtual qreal realFontSize () const
void removeFromParentLayout ()
void setAutoReferenceArea (const QObject *area)
virtual void setGeometry (const QRect &r)
 pure virtual in QLayoutItem
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.
void setText (const QString &text)
void setTextAttributes (const TextAttributes &a)
 Use this to specify the text attributes to be used for this item.
virtual QSize sizeHint () const
 pure virtual in QLayoutItem
virtual void sizeHintChanged () const
 Report changed size hint: ask the parent widget to recalculate the layout.
QString text () const
TextAttributes textAttributes () const
 Returns the text attributes to be used for this item.
 TextLayoutItem (const QString &text, const TextAttributes &attributes, const QObject *autoReferenceArea, KDChartEnums::MeasureOrientation autoReferenceOrientation, Qt::Alignment alignment=0)
 TextLayoutItem ()

Protected Attributes

QWidgetmParent
QLayout * mParentLayout


Constructor & Destructor Documentation

KDChart::TextLayoutItem::TextLayoutItem (  ) 

Definition at line 115 of file KDChartLayoutItems.cpp.

00116     : AbstractLayoutItem( Qt::AlignLeft )
00117     , mText()
00118     , mAttributes()
00119     , mAutoReferenceArea( 0 )
00120     , mAutoReferenceOrientation( KDChartEnums::MeasureOrientationHorizontal )
00121     , cachedSizeHint() // default this to invalid to force just-in-time calculation before first use of sizeHint()
00122     , cachedFontSize( 0.0 )
00123     , cachedFont( mAttributes.font() )
00124 {
00125 
00126 }

KDChart::TextLayoutItem::TextLayoutItem ( const QString &  text,
const TextAttributes attributes,
const QObject autoReferenceArea,
KDChartEnums::MeasureOrientation  autoReferenceOrientation,
Qt::Alignment  alignment = 0 
)

Definition at line 99 of file KDChartLayoutItems.cpp.

00104     : AbstractLayoutItem( alignment )
00105     , mText( text )
00106     , mAttributes( attributes )
00107     , mAutoReferenceArea( area )
00108     , mAutoReferenceOrientation( orientation )
00109     , cachedSizeHint() // default this to invalid to force just-in-time calculation before first use of sizeHint()
00110     , cachedFontSize( 0.0 )
00111     , cachedFont( mAttributes.font() )
00112 {
00113 }


Member Function Documentation

const QObject * KDChart::TextLayoutItem::autoReferenceArea (  )  const

Definition at line 135 of file KDChartLayoutItems.cpp.

Referenced by KDChart::HeaderFooter::compare(), and KDChart::HeaderFooter::setParent().

00136 {
00137     return mAutoReferenceArea;
00138 }

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

pure virtual in QLayoutItem

Definition at line 179 of file KDChartLayoutItems.cpp.

00180 {
00181     return 0; // Grow neither vertically nor horizontally
00182 }

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

pure virtual in QLayoutItem

Definition at line 184 of file KDChartLayoutItems.cpp.

Referenced by KDChart::TextArea::areaGeometry(), paint(), KDChart::TextArea::paintAll(), KDChart::CartesianAxis::paintCtx(), and KDChart::TextArea::paintIntoRect().

00185 {
00186     return mRect;
00187 }

bool KDChart::TextLayoutItem::intersects ( const TextLayoutItem other,
const QPoint &  myPos,
const QPoint &  otherPos 
) const [virtual]

Definition at line 258 of file KDChartLayoutItems.cpp.

References mAttributes, PI, rotatedCorners(), KDChart::TextAttributes::rotation(), and unrotatedSizeHint().

00259 {
00260     if ( mAttributes.rotation() != other.mAttributes.rotation() )
00261     {
00262         // that's the code for the common case: the rotation angles don't need to match here
00263         QPolygon myPolygon(          rotatedCorners() );
00264         QPolygon otherPolygon( other.rotatedCorners() );
00265 
00266         // move the polygons to their positions
00267         myPolygon.translate( myPos );
00268         otherPolygon.translate( otherPos );
00269 
00270         // create regions out of it
00271         QRegion myRegion( myPolygon );
00272         QRegion otherRegion( otherPolygon );
00273 
00274         // now the question - do they intersect or not?
00275         return ! myRegion.intersect( otherRegion ).isEmpty();
00276 
00277     } else {
00278         // and that's the code for the special case: the rotation angles match, which is less time consuming in calculation
00279         const qreal angle = mAttributes.rotation() * PI / 180.0;
00280         // both sizes
00281         const QSizeF mySize(          unrotatedSizeHint() );
00282         const QSizeF otherSize( other.unrotatedSizeHint() );
00283 
00284         // that's myP1 relative to myPos
00285         QPointF myP1( mySize.height() * sin( angle ), 0.0 );
00286         // that's otherP1 to myPos
00287         QPointF otherP1 = QPointF( otherSize.height() * sin( angle ), 0.0 ) + otherPos - myPos;
00288 
00289         // now rotate both points the negative angle around myPos
00290         myP1 = QPointF( myP1.x() * cos( -angle ), myP1.x() * sin( -angle ) );
00291         qreal r = sqrt( otherP1.x() * otherP1.x() + otherP1.y() * otherP1.y() );
00292         otherP1 = QPointF( r * cos( -angle ), r * sin( -angle ) );
00293 
00294         // finally we look, whether both rectangles intersect or even not
00295         return QRectF( myP1, mySize ).intersects( QRectF( otherP1, otherSize ) );
00296     }
00297 }

bool KDChart::TextLayoutItem::intersects ( const TextLayoutItem other,
const QPointF &  myPos,
const QPointF &  otherPos 
) const [virtual]

Definition at line 253 of file KDChartLayoutItems.cpp.

Referenced by KDChart::CartesianAxis::paintCtx().

00254 {
00255     return intersects( other, myPos.toPoint(), otherPos.toPoint() );
00256 }

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

pure virtual in QLayoutItem

Definition at line 189 of file KDChartLayoutItems.cpp.

00190 {
00191     return false; // never empty, otherwise the layout item would not exist
00192 }

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

pure virtual in QLayoutItem

Definition at line 194 of file KDChartLayoutItems.cpp.

References sizeHint().

00195 {
00196     return sizeHint(); // PENDING(kalle) Review, quite inflexible
00197 }

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

pure virtual in QLayoutItem

Definition at line 199 of file KDChartLayoutItems.cpp.

References sizeHint().

00200 {
00201     return sizeHint(); // PENDING(kalle) Review, quite inflexible
00202 }

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

Implements KDChart::AbstractLayoutItem.

Definition at line 386 of file KDChartLayoutItems.cpp.

References geometry(), KDChart::TextAttributes::pen(), rotatedRect(), and KDChart::TextAttributes::rotation().

Referenced by KDChart::TextArea::paintAll(), and KDChart::CartesianAxis::paintCtx().

00387 {
00388     // make sure, cached font is updated, if needed:
00389     // sizeHint();
00390 
00391     if( !mRect.isValid() )
00392         return;
00393 
00394     PainterSaver painterSaver( painter );
00395     painter->setFont( cachedFont );
00396     QRectF rect( geometry() );
00397 
00398 // #ifdef DEBUG_ITEMS_PAINT
00399 //     painter->setPen( Qt::black );
00400 //     painter->drawRect( rect );
00401 // #endif
00402     painter->translate( rect.center() );
00403     rect.moveTopLeft( QPointF( - rect.width() / 2, - rect.height() / 2 ) );
00404 #ifdef DEBUG_ITEMS_PAINT
00405     painter->setPen( Qt::blue );
00406     painter->drawRect( rect );
00407 #endif
00408     painter->rotate( mAttributes.rotation() );
00409     rect = rotatedRect( rect, mAttributes.rotation() );
00410 #ifdef DEBUG_ITEMS_PAINT
00411     painter->setPen( Qt::red );
00412     painter->drawRect( rect );
00413 #endif
00414     painter->setPen( mAttributes.pen() );
00415     painter->drawText( rect, Qt::AlignHCenter | Qt::AlignVCenter, mText );
00416 //    if (  calcSizeHint( cachedFont ).width() > rect.width() )
00417 //        qDebug() << "rect.width()" << rect.width() << "text.width()" << calcSizeHint( cachedFont ).width();
00418 //
00419 //    //painter->drawText( rect, Qt::AlignHCenter | Qt::AlignVCenter, mText );
00420 }

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         }

QFont KDChart::TextLayoutItem::realFont (  )  const [virtual]

Definition at line 230 of file KDChartLayoutItems.cpp.

Referenced by KDChart::CartesianAxis::maximumSize(), and KDChart::CartesianAxis::paintCtx().

00231 {
00232     realFontWasRecalculated(); // we can safely ignore the boolean return value
00233     return cachedFont;
00234 }

qreal KDChart::TextLayoutItem::realFontSize (  )  const [virtual]

Definition at line 210 of file KDChartLayoutItems.cpp.

References KDChart::TextAttributes::calculatedFontSize().

00211 {
00212     return mAttributes.calculatedFontSize( mAutoReferenceArea, mAutoReferenceOrientation );
00213 }

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::TextLayoutItem::setAutoReferenceArea ( const QObject area  ) 

Definition at line 128 of file KDChartLayoutItems.cpp.

References sizeHint().

Referenced by KDChart::HeaderFooter::setParent().

00129 {
00130     mAutoReferenceArea = area;
00131     cachedSizeHint = QSize();
00132     sizeHint();
00133 }

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

pure virtual in QLayoutItem

Definition at line 204 of file KDChartLayoutItems.cpp.

Referenced by KDChart::TextArea::paintAll(), KDChart::CartesianAxis::paintCtx(), and KDChart::TextArea::paintIntoRect().

00205 {
00206     mRect = r;
00207 }

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 }

void KDChart::TextLayoutItem::setText ( const QString &  text  ) 

Definition at line 140 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent, and sizeHint().

Referenced by KDChart::Widget::addHeaderFooter(), KDChart::CartesianAxis::maximumSize(), and KDChart::CartesianAxis::paintCtx().

00141 {
00142     mText = text;
00143     cachedSizeHint = QSize();
00144     sizeHint();
00145     if( mParent )
00146         mParent->update();
00147 }

void KDChart::TextLayoutItem::setTextAttributes ( const TextAttributes a  ) 

Use this to specify the text attributes to be used for this item.

See also:
textAttributes

Definition at line 159 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::mParent, and sizeHint().

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

00160 {
00161     mAttributes = a;
00162     cachedSizeHint = QSize(); // invalidate size hint
00163     sizeHint();
00164     if( mParent )
00165         mParent->update();
00166 }

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

pure virtual in QLayoutItem

Definition at line 299 of file KDChartLayoutItems.cpp.

References KDChart::AbstractLayoutItem::sizeHintChanged().

Referenced by maximumSize(), KDChart::CartesianAxis::maximumSize(), minimumSize(), KDChart::CartesianAxis::paintCtx(), setAutoReferenceArea(), setText(), and setTextAttributes().

00300 {
00301     if( realFontWasRecalculated() )
00302     {
00303         const QSize newSizeHint( calcSizeHint( cachedFont ) );
00304         if( newSizeHint != cachedSizeHint ){
00305             cachedSizeHint = newSizeHint;
00306             sizeHintChanged();
00307         }
00308     }
00309     //qDebug() << "-------- KDChart::TextLayoutItem::sizeHint() returns:"<<cachedSizeHint<<" ----------";
00310     return cachedSizeHint;
00311 }

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 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 }

QString KDChart::TextLayoutItem::text (  )  const

Definition at line 149 of file KDChartLayoutItems.cpp.

Referenced by KDChart::HeaderFooter::compare(), and KDChart::CartesianAxis::paintCtx().

00150 {
00151     return mText;
00152 }

KDChart::TextAttributes KDChart::TextLayoutItem::textAttributes (  )  const

Returns the text attributes to be used for this item.

See also:
setTextAttributes

Definition at line 173 of file KDChartLayoutItems.cpp.

Referenced by KDChart::HeaderFooter::clone(), and KDChart::HeaderFooter::compare().

00174 {
00175     return mAttributes;
00176 }


Member Data Documentation

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

Definition at line 90 of file KDChartLayoutItems.h.

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

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

Definition at line 91 of file KDChartLayoutItems.h.

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


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