#include <KDChartLayoutItems.h>
Definition at line 101 of file KDChartLayoutItems.h.
Public Member Functions | |
const QObject * | autoReferenceArea () 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 | setTextAlignment (Qt::Alignment) |
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 QSize | sizeHintAndRotatedCorners (QPoint &topLeftPt, QPoint &topRightPt, QPoint &bottomRightPt, QPoint &bottomLeftPt) const |
virtual void | sizeHintChanged () const |
Report changed size hint: ask the parent widget to recalculate the layout. | |
virtual QSize | sizeHintUnrotated () const |
QString | text () const |
Qt::Alignment | textAlignment () 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 | |
QWidget * | mParent |
QLayout * | mParentLayout |
KDChart::TextLayoutItem::TextLayoutItem | ( | ) |
Definition at line 224 of file KDChartLayoutItems.cpp.
00225 : AbstractLayoutItem( Qt::AlignLeft ) 00226 , mText() 00227 , mTextAlignment( Qt::AlignLeft ) 00228 , mAttributes() 00229 , mAutoReferenceArea( 0 ) 00230 , mAutoReferenceOrientation( KDChartEnums::MeasureOrientationHorizontal ) 00231 , cachedSizeHint() // default this to invalid to force just-in-time calculation before first use of sizeHint() 00232 , cachedFontSize( 0.0 ) 00233 , cachedFont( mAttributes.font() ) 00234 { 00235 00236 }
KDChart::TextLayoutItem::TextLayoutItem | ( | const QString & | text, | |
const TextAttributes & | attributes, | |||
const QObject * | autoReferenceArea, | |||
KDChartEnums::MeasureOrientation | autoReferenceOrientation, | |||
Qt::Alignment | alignment = 0 | |||
) |
Definition at line 207 of file KDChartLayoutItems.cpp.
00212 : AbstractLayoutItem( alignment ) 00213 , mText( text ) 00214 , mTextAlignment( alignment ) 00215 , mAttributes( attributes ) 00216 , mAutoReferenceArea( area ) 00217 , mAutoReferenceOrientation( orientation ) 00218 , cachedSizeHint() // default this to invalid to force just-in-time calculation before first use of sizeHint() 00219 , cachedFontSize( 0.0 ) 00220 , cachedFont( mAttributes.font() ) 00221 { 00222 }
const QObject * KDChart::TextLayoutItem::autoReferenceArea | ( | ) | const |
Definition at line 245 of file KDChartLayoutItems.cpp.
Referenced by KDChart::TextBubbleLayoutItem::autoReferenceArea(), KDChart::HeaderFooter::compare(), and KDChart::HeaderFooter::setParent().
Qt::Orientations KDChart::TextLayoutItem::expandingDirections | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 304 of file KDChartLayoutItems.cpp.
Referenced by KDChart::TextBubbleLayoutItem::expandingDirections().
QRect KDChart::TextLayoutItem::geometry | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 309 of file KDChartLayoutItems.cpp.
Referenced by KDChart::TextArea::areaGeometry(), KDChart::TextBubbleLayoutItem::geometry(), paint(), KDChart::TextArea::paintAll(), KDChart::CartesianAxis::paintCtx(), and KDChart::TextArea::paintIntoRect().
bool KDChart::TextLayoutItem::intersects | ( | const TextLayoutItem & | other, | |
const QPoint & | myPos, | |||
const QPoint & | otherPos | |||
) | const [virtual] |
Definition at line 470 of file KDChartLayoutItems.cpp.
References mAttributes, PI, r, rotatedCorners(), KDChart::TextAttributes::rotation(), and unrotatedSizeHint().
00471 { 00472 if ( mAttributes.rotation() != other.mAttributes.rotation() ) 00473 { 00474 // that's the code for the common case: the rotation angles don't need to match here 00475 QPolygon myPolygon( rotatedCorners() ); 00476 QPolygon otherPolygon( other.rotatedCorners() ); 00477 00478 // move the polygons to their positions 00479 myPolygon.translate( myPos ); 00480 otherPolygon.translate( otherPos ); 00481 00482 // create regions out of it 00483 QRegion myRegion( myPolygon ); 00484 QRegion otherRegion( otherPolygon ); 00485 00486 // now the question - do they intersect or not? 00487 return ! myRegion.intersect( otherRegion ).isEmpty(); 00488 00489 } else { 00490 // and that's the code for the special case: the rotation angles match, which is less time consuming in calculation 00491 const qreal angle = mAttributes.rotation() * PI / 180.0; 00492 // both sizes 00493 const QSizeF mySize( unrotatedSizeHint() ); 00494 const QSizeF otherSize( other.unrotatedSizeHint() ); 00495 00496 // that's myP1 relative to myPos 00497 QPointF myP1( mySize.height() * sin( angle ), 0.0 ); 00498 // that's otherP1 to myPos 00499 QPointF otherP1 = QPointF( otherSize.height() * sin( angle ), 0.0 ) + otherPos - myPos; 00500 00501 // now rotate both points the negative angle around myPos 00502 myP1 = QPointF( myP1.x() * cos( -angle ), myP1.x() * sin( -angle ) ); 00503 qreal r = sqrt( otherP1.x() * otherP1.x() + otherP1.y() * otherP1.y() ); 00504 otherP1 = QPointF( r * cos( -angle ), r * sin( -angle ) ); 00505 00506 // finally we look, whether both rectangles intersect or even not 00507 const bool res = QRectF( myP1, mySize ).intersects( QRectF( otherP1, otherSize ) ); 00508 //qDebug() << res << QRectF( myP1, mySize ) << QRectF( otherP1, otherSize ); 00509 return res; 00510 } 00511 }
bool KDChart::TextLayoutItem::intersects | ( | const TextLayoutItem & | other, | |
const QPointF & | myPos, | |||
const QPointF & | otherPos | |||
) | const [virtual] |
Definition at line 465 of file KDChartLayoutItems.cpp.
Referenced by KDChart::CartesianAxis::paintCtx().
00466 { 00467 return intersects( other, myPos.toPoint(), otherPos.toPoint() ); 00468 }
bool KDChart::TextLayoutItem::isEmpty | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 314 of file KDChartLayoutItems.cpp.
Referenced by KDChart::TextBubbleLayoutItem::isEmpty().
QSize KDChart::TextLayoutItem::maximumSize | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 319 of file KDChartLayoutItems.cpp.
References sizeHint().
Referenced by KDChart::TextBubbleLayoutItem::maximumSize().
00320 { 00321 return sizeHint(); // PENDING(kalle) Review, quite inflexible 00322 }
QSize KDChart::TextLayoutItem::minimumSize | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 324 of file KDChartLayoutItems.cpp.
References sizeHint().
Referenced by KDChart::TextBubbleLayoutItem::minimumSize().
00325 { 00326 return sizeHint(); // PENDING(kalle) Review, quite inflexible 00327 }
void KDChart::TextLayoutItem::paint | ( | QPainter * | painter | ) | [virtual] |
Implements KDChart::AbstractLayoutItem.
Definition at line 618 of file KDChartLayoutItems.cpp.
References KDChart::TextAttributes::autoShrink(), geometry(), KDChart::TextAttributes::pen(), realFont(), rotatedRect(), KDChart::TextAttributes::rotation(), and KDChart::PrintingParameters::scalePen().
Referenced by KDChart::TextBubbleLayoutItem::paint(), KDChart::TextArea::paintAll(), and KDChart::CartesianAxis::paintCtx().
00619 { 00620 // make sure, cached font is updated, if needed: 00621 // sizeHint(); 00622 00623 if( !mRect.isValid() ) 00624 return; 00625 00626 const PainterSaver painterSaver( painter ); 00627 QFont f = realFont(); 00628 if ( mAttributes.autoShrink() ) 00629 f.setPointSizeF( fitFontSizeToGeometry() ); 00630 painter->setFont( f ); 00631 QRectF rect( geometry() ); 00632 00633 // #ifdef DEBUG_ITEMS_PAINT 00634 // painter->setPen( Qt::black ); 00635 // painter->drawRect( rect ); 00636 // #endif 00637 painter->translate( rect.center() ); 00638 rect.moveTopLeft( QPointF( - rect.width() / 2, - rect.height() / 2 ) ); 00639 #ifdef DEBUG_ITEMS_PAINT 00640 painter->setPen( Qt::blue ); 00641 painter->drawRect( rect ); 00642 painter->drawRect( QRect(QPoint((rect.topLeft().toPoint() + rect.bottomLeft().toPoint()) / 2 - QPoint(2,2)), QSize(3,3)) ); 00643 //painter->drawRect( QRect(QPoint((rect.topRight().toPoint() + rect.bottomRight().toPoint()) / 2 - QPoint(2,2)), QSize(3,3)) ); 00644 #endif 00645 painter->rotate( mAttributes.rotation() ); 00646 rect = rotatedRect( rect, mAttributes.rotation() ); 00647 #ifdef DEBUG_ITEMS_PAINT 00648 painter->setPen( Qt::red ); 00649 painter->drawRect( rect ); 00650 painter->drawRect( QRect(QPoint((rect.topLeft().toPoint() + rect.bottomLeft().toPoint()) / 2 - QPoint(2,2)), QSize(3,3)) ); 00651 //painter->drawRect( QRect(QPoint((rect.topRight().toPoint() + rect.bottomRight().toPoint()) / 2 - QPoint(2,2)), QSize(3,3)) ); 00652 #endif 00653 painter->setPen( PrintingParameters::scalePen( mAttributes.pen() ) ); 00654 QFontMetrics fontMetrics( f ); 00655 const int AHight = fontMetrics.boundingRect( QChar::fromAscii( 'A' ) ).height(); 00656 const qreal AVCenter = fontMetrics.ascent() - AHight / 2.0; 00657 // Make sure that capital letters are vertically centered. This looks much 00658 // better than just centering the text's bounding rect. 00659 rect.translate( 0.0, rect.height() / 2.0 - AVCenter ); 00660 //painter->drawText( rect, Qt::AlignHCenter | Qt::AlignTop, mText ); 00661 painter->drawText( rect, mTextAlignment, mText ); 00662 00663 // if ( calcSizeHint( realFont() ).width() > rect.width() ) 00664 // qDebug() << "rect.width()" << rect.width() << "text.width()" << calcSizeHint( realFont() ).width(); 00665 // 00666 // //painter->drawText( rect, Qt::AlignHCenter | Qt::AlignVCenter, mText ); 00667 }
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] |
QFont KDChart::TextLayoutItem::realFont | ( | ) | const [virtual] |
Definition at line 442 of file KDChartLayoutItems.cpp.
Referenced by paint(), and KDChart::CartesianAxis::paintCtx().
00443 { 00444 realFontWasRecalculated(); // we can safely ignore the boolean return value 00445 return cachedFont; 00446 }
qreal KDChart::TextLayoutItem::realFontSize | ( | ) | const [virtual] |
Definition at line 422 of file KDChartLayoutItems.cpp.
References KDChart::TextAttributes::calculatedFontSize().
00423 { 00424 return mAttributes.calculatedFontSize( mAutoReferenceArea, mAutoReferenceOrientation ); 00425 }
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::TextLayoutItem::setAutoReferenceArea | ( | const QObject * | area | ) |
Definition at line 238 of file KDChartLayoutItems.cpp.
References sizeHint().
Referenced by KDChart::TextBubbleLayoutItem::setAutoReferenceArea(), and KDChart::HeaderFooter::setParent().
00239 { 00240 mAutoReferenceArea = area; 00241 cachedSizeHint = QSize(); 00242 sizeHint(); 00243 }
void KDChart::TextLayoutItem::setGeometry | ( | const QRect & | r | ) | [virtual] |
pure virtual in QLayoutItem
Definition at line 329 of file KDChartLayoutItems.cpp.
Referenced by KDChart::TextArea::paintAll(), KDChart::CartesianAxis::paintCtx(), KDChart::TextArea::paintIntoRect(), and KDChart::TextBubbleLayoutItem::setGeometry().
00330 { 00331 mRect = r; 00332 }
void KDChart::AbstractLayoutItem::setParentLayout | ( | QLayout * | lay | ) | [inherited] |
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 }
void KDChart::TextLayoutItem::setText | ( | const QString & | text | ) |
Definition at line 250 of file KDChartLayoutItems.cpp.
References KDChart::AbstractLayoutItem::mParent, and sizeHint().
Referenced by KDChart::Widget::addHeaderFooter(), KDChart::HeaderFooter::clone(), KDChart::CartesianAxis::paintCtx(), and KDChart::TextBubbleLayoutItem::setText().
00251 { 00252 mText = text; 00253 cachedSizeHint = QSize(); 00254 sizeHint(); 00255 if( mParent ) 00256 mParent->update(); 00257 }
void KDChart::TextLayoutItem::setTextAlignment | ( | Qt::Alignment | alignment | ) |
Definition at line 264 of file KDChartLayoutItems.cpp.
References KDChart::AbstractLayoutItem::mParent.
00265 { 00266 if( mTextAlignment == alignment ) 00267 return; 00268 mTextAlignment = alignment; 00269 if( mParent ) 00270 mParent->update(); 00271 }
void KDChart::TextLayoutItem::setTextAttributes | ( | const TextAttributes & | a | ) |
Use this to specify the text attributes to be used for this item.
Definition at line 283 of file KDChartLayoutItems.cpp.
References KDChart::TextAttributes::font(), KDChart::AbstractLayoutItem::mParent, and sizeHint().
Referenced by KDChart::HeaderFooter::clone(), and KDChart::TextBubbleLayoutItem::setTextAttributes().
00284 { 00285 mAttributes = a; 00286 cachedFont = a.font(); 00287 cachedSizeHint = QSize(); // invalidate size hint 00288 sizeHint(); 00289 if( mParent ) 00290 mParent->update(); 00291 }
QSize KDChart::TextLayoutItem::sizeHint | ( | ) | const [virtual] |
pure virtual in QLayoutItem
Definition at line 513 of file KDChartLayoutItems.cpp.
References sizeHintAndRotatedCorners().
Referenced by maximumSize(), minimumSize(), KDChart::CartesianAxis::paintCtx(), setAutoReferenceArea(), setText(), setTextAttributes(), and KDChart::TextBubbleLayoutItem::sizeHint().
00514 { 00515 QPoint dummy; 00516 return sizeHintAndRotatedCorners(dummy,dummy,dummy,dummy); 00517 }
QSize KDChart::TextLayoutItem::sizeHintAndRotatedCorners | ( | QPoint & | topLeftPt, | |
QPoint & | topRightPt, | |||
QPoint & | bottomRightPt, | |||
QPoint & | bottomLeftPt | |||
) | const [virtual] |
Definition at line 519 of file KDChartLayoutItems.cpp.
References KDChart::TextAttributes::rotation(), and KDChart::AbstractLayoutItem::sizeHintChanged().
Referenced by KDChart::CartesianAxis::paintCtx(), and sizeHint().
00521 { 00522 if( realFontWasRecalculated() || mAttributes.rotation() ) 00523 { 00524 const QSize newSizeHint( calcSizeHint( cachedFont, 00525 topLeftPt, topRightPt, bottomRightPt, bottomLeftPt ) ); 00526 if( newSizeHint != cachedSizeHint ){ 00527 cachedSizeHint = newSizeHint; 00528 sizeHintChanged(); 00529 } 00530 cachedTopLeft = topLeftPt; 00531 cachedTopRight = topRightPt; 00532 cachedBottomRight = bottomRightPt; 00533 cachedBottomLeft = bottomLeftPt; 00534 }else{ 00535 topLeftPt = cachedTopLeft; 00536 topRightPt = cachedTopRight; 00537 bottomRightPt = cachedBottomRight; 00538 bottomLeftPt = cachedBottomLeft; 00539 } 00540 //qDebug() << "-------- KDChart::TextLayoutItem::sizeHint() returns:"<<cachedSizeHint<<" ----------"; 00541 return cachedSizeHint; 00542 }
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 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 }
QSize KDChart::TextLayoutItem::sizeHintUnrotated | ( | ) | const [virtual] |
Definition at line 544 of file KDChartLayoutItems.cpp.
Referenced by KDChart::CartesianAxis::paintCtx().
00545 { 00546 realFontWasRecalculated(); // make sure the cached font is updated if needed 00547 return unrotatedSizeHint( cachedFont ); 00548 }
QString KDChart::TextLayoutItem::text | ( | ) | const |
Definition at line 259 of file KDChartLayoutItems.cpp.
Referenced by KDChart::HeaderFooter::clone(), KDChart::HeaderFooter::compare(), KDChart::CartesianAxis::paintCtx(), and KDChart::TextBubbleLayoutItem::text().
Qt::Alignment KDChart::TextLayoutItem::textAlignment | ( | ) | const |
KDChart::TextAttributes KDChart::TextLayoutItem::textAttributes | ( | ) | const |
Returns the text attributes to be used for this item.
Definition at line 298 of file KDChartLayoutItems.cpp.
Referenced by KDChart::HeaderFooter::clone(), KDChart::HeaderFooter::compare(), and KDChart::TextBubbleLayoutItem::textAttributes().
QWidget* KDChart::AbstractLayoutItem::mParent [protected, inherited] |
Definition at line 93 of file KDChartLayoutItems.h.
Referenced by KDChart::AbstractLayoutItem::setParentWidget(), setText(), setTextAlignment(), setTextAttributes(), and KDChart::AbstractLayoutItem::sizeHintChanged().
QLayout* KDChart::AbstractLayoutItem::mParentLayout [protected, inherited] |
Definition at line 94 of file KDChartLayoutItems.h.
Referenced by KDChart::AutoSpacerLayoutItem::paint().