17 #include <qlayoutitem.h>
24 class LayoutItem
QWT_FINAL :
public QLayoutItem
28 virtual ~LayoutItem();
35 virtual Qt::Orientations expandingDirections() const
QWT_OVERRIDE;
41 virtual
int minimumHeightForWidth(
int ) const
QWT_OVERRIDE;
55 LayoutItem::LayoutItem(
57 : m_legendItem( legendItem )
58 , m_plotItem( plotItem)
62 LayoutItem::~LayoutItem()
81 Qt::Orientations LayoutItem::expandingDirections()
const
83 return Qt::Horizontal;
86 bool LayoutItem::hasHeightForWidth()
const
88 return !m_data.title().isEmpty();
91 int LayoutItem::minimumHeightForWidth(
int w )
const
93 return m_legendItem->heightForWidth( m_data, w );
96 int LayoutItem::heightForWidth(
int w )
const
98 return m_legendItem->heightForWidth( m_data, w );
101 bool LayoutItem::isEmpty()
const
106 QSize LayoutItem::maximumSize()
const
108 return QSize( QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX );
111 QSize LayoutItem::minimumSize()
const
113 return m_legendItem->minimumSize( m_data );
116 QSize LayoutItem::sizeHint()
const
118 return minimumSize();
121 void LayoutItem::setGeometry(
const QRect& rect )
126 QRect LayoutItem::geometry()
const
149 layout->setContentsMargins( 0, 0, 0, 0 );
406 Qt::Orientations orientations,
int numPixels )
411 bool isChanged =
false;
415 if ( orientations & Qt::Horizontal )
417 if ( numPixels != offset[0] )
419 offset[0] = numPixels;
424 if ( orientations & Qt::Vertical )
426 if ( numPixels != offset[1] )
428 offset[1] = numPixels;
445 Qt::Orientation orientation )
const
447 const int index = ( orientation == Qt::Vertical ) ? 1 : 0;
459 radius =
qwtMaxF( 0.0, radius );
589 const QRectF& canvasRect )
const
606 const LayoutItem* layoutItem =
615 layoutItem->data(), layoutItem->geometry() );
631 QPainter* painter,
const QRectF& rect )
const
639 painter->drawRoundedRect( rect, radius, radius );
657 int x = qRound( canvasRect.center().x() );
658 rect.moveCenter( QPoint(
x, rect.center().y() ) );
663 rect.moveRight(
qwtFloor( canvasRect.right() - offset ) );
668 rect.moveLeft(
qwtCeil( canvasRect.left() + offset ) );
673 int y = qRound( canvasRect.center().y() );
674 rect.moveCenter( QPoint( rect.center().x(),
y ) );
679 rect.moveBottom(
qwtFloor( canvasRect.bottom() - offset ) );
684 rect.moveTop(
qwtCeil( canvasRect.top() + offset ) );
700 if ( plotItem == NULL )
708 layoutItems = it.value();
710 bool changed =
false;
712 if (
data.size() != layoutItems.size() )
716 for (
int i = 0; i < layoutItems.size(); i++ )
719 delete layoutItems[i];
726 if ( !
data.isEmpty() )
728 layoutItems.reserve(
data.size() );
730 for (
int i = 0; i <
data.size(); i++ )
732 LayoutItem* layoutItem =
733 new LayoutItem(
this, plotItem );
735 layoutItems += layoutItem;
738 m_data->
map.insert( plotItem, layoutItems );
742 for (
int i = 0; i <
data.size(); i++ )
744 if ( layoutItems[i]->
data().values() !=
data[i].values() )
746 layoutItems[i]->setData(
data[i] );
782 const QRectF& rect )
const
784 Q_UNUSED( plotItem );
787 const QRectF r = rect.toRect().adjusted( m, m, -m, -m );
789 painter->setClipRect( r, Qt::IntersectClip );
796 QRectF iconRect( r.topLeft(), graphic.
defaultSize() );
799 QPoint( iconRect.center().x(), rect.center().y() ) );
801 graphic.
render( painter, iconRect, Qt::KeepAspectRatio );
807 if ( !text.isEmpty() )
810 painter->setFont(
font() );
812 const QRectF textRect = r.adjusted( titleOff, 0, 0, 0 );
813 text.draw( painter, textRect );
827 if ( !
data.isValid() )
839 h = graphic.height();
842 if ( !text.isEmpty() )
844 const QSizeF sz = text.textSize(
font() );
847 h = qMax( h,
qwtCeil( sz.height() ) );
850 if ( graphic.width() > 0 && !text.isEmpty() )
853 size += QSize( w, h );
870 if ( text.isEmpty() )
871 return graphic.height();
873 if ( graphic.width() > 0 )
876 int h = text.heightForWidth( width,
font() );
879 return qMax( graphic.height(), h );
903 layoutItems = it.value();
906 geometries.reserve(layoutItems.size() );
908 for (
int i = 0; i < layoutItems.size(); i++ )
909 geometries += layoutItems[i]->
geometry();