16 #include <qapplication.h> 17 #include <qscrollbar.h> 18 #include <qscrollarea.h> 21 #include <qstyleoption.h> 28 void insert(
const QVariant &,
const QList<QWidget *> & );
29 void remove(
const QVariant & );
34 QVariant
itemInfo(
const QWidget * )
const;
53 const QList<QWidget *> &
widgets )
87 QWidget *
w =
const_cast<QWidget *
>( widget );
97 QWidget *
w =
const_cast<QWidget *
>( widget );
102 if ( entry.
widgets.indexOf( w ) >= 0 )
112 if ( itemInfo.isValid() )
122 return QList<QWidget *>();
145 QScrollArea( parent )
147 contentsWidget =
new QWidget(
this );
148 contentsWidget->setObjectName(
"QwtLegendViewContents" );
150 setWidget( contentsWidget );
151 setWidgetResizable(
false );
153 viewport()->setObjectName(
"QwtLegendViewport" );
157 contentsWidget->setAutoFillBackground(
false );
158 viewport()->setAutoFillBackground(
false );
163 if ( event->type() == QEvent::PolishRequest )
165 setFocusPolicy( Qt::NoFocus );
168 if ( event->type() == QEvent::Resize )
173 const QRect cr = contentsRect();
176 int h = contentsWidget->heightForWidth( cr.width() );
179 w -= verticalScrollBar()->sizeHint().width();
180 h = contentsWidget->heightForWidth( w );
183 contentsWidget->resize( w, h );
186 return QScrollArea::event( event );
191 bool ok = QScrollArea::viewportEvent( event );
193 if ( event->type() == QEvent::Resize )
202 const int sbHeight = horizontalScrollBar()->sizeHint().height();
203 const int sbWidth = verticalScrollBar()->sizeHint().width();
205 const int cw = contentsRect().width();
206 const int ch = contentsRect().height();
217 if ( w > vw && vh == ch )
220 return QSize( vw, vh );
226 contentsWidget->layout() );
230 const QSize visibleSize = viewport()->contentsRect().size();
232 const int minW = int( tl->
maxItemWidth() ) + 2 * tl->margin();
234 int w = qMax( visibleSize.width(), minW );
237 const int vpWidth = viewportSize( w, h ).width();
240 w = qMax( vpWidth, minW );
244 contentsWidget->resize( w, h );
257 setFrameStyle( NoFrame );
262 d_data->
view->setObjectName(
"QwtLegendView" );
267 gridLayout->setAlignment( Qt::AlignHCenter | Qt::AlignTop );
271 QVBoxLayout *layout =
new QVBoxLayout(
this );
272 layout->setContentsMargins( 0, 0, 0, 0 );
391 const QList<QwtLegendData> &data )
395 if ( widgetList.size() != data.size() )
399 while ( widgetList.size() > data.size() )
401 QWidget *
w = widgetList.takeLast();
403 contentsLayout->removeWidget( w );
412 #if QT_VERSION >= 0x040700 413 widgetList.reserve( data.size() );
416 for (
int i = widgetList.size();
i < data.size();
i++ )
420 if ( contentsLayout )
421 contentsLayout->addWidget( widget );
430 widget->setVisible(
true );
433 widgetList += widget;
436 if ( widgetList.isEmpty() )
448 for (
int i = 0;
i < data.size();
i++ )
504 if ( contentsLayout )
510 for (
int i = 0;
i < contentsLayout->count();
i++ )
512 QLayoutItem *item = contentsLayout->itemAt(
i );
513 if ( w && item->widget() )
514 QWidget::setTabOrder( w, item->widget() );
525 hint += QSize( 2 * frameWidth(), 2 * frameWidth() );
536 width -= 2 * frameWidth();
540 h += 2 * frameWidth();
559 switch ( event->type() )
561 case QEvent::ChildRemoved:
563 const QChildEvent *ce =
564 static_cast<const QChildEvent *
>(event);
565 if ( ce->child()->isWidgetType() )
567 QWidget *
w =
static_cast< QWidget *
>( ce->child() );
572 case QEvent::LayoutRequest:
576 if ( parentWidget() && parentWidget()->layout() == NULL )
589 QApplication::postEvent( parentWidget(),
590 new QEvent( QEvent::LayoutRequest ) );
599 return QwtAbstractLegend::eventFilter(
object, event );
608 QWidget *
w = qobject_cast<QWidget *>( sender() );
612 if ( itemInfo.isValid() )
614 const QList<QWidget *> widgetList =
617 const int index = widgetList.indexOf( w );
619 Q_EMIT
clicked( itemInfo, index );
630 QWidget *
w = qobject_cast<QWidget *>( sender() );
634 if ( itemInfo.isValid() )
636 const QList<QWidget *> widgetList =
639 const int index = widgetList.indexOf( w );
641 Q_EMIT
checked( itemInfo, on, index );
656 const QRectF &rect,
bool fillBackground )
const 661 if ( fillBackground )
663 if ( autoFillBackground() ||
664 testAttribute( Qt::WA_StyledBackground ) )
672 if ( legendLayout == NULL )
675 int left, right, top, bottom;
676 getContentsMargins( &left, &top, &right, &bottom );
679 layoutRect.setLeft( qCeil( rect.left() ) + left );
680 layoutRect.setTop( qCeil( rect.top() ) + top );
681 layoutRect.setRight( qFloor( rect.right() ) - right );
682 layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );
685 const QList<QRect> itemRects =
690 for (
int i = 0;
i < legendLayout->
count();
i++ )
692 QLayoutItem *item = legendLayout->
itemAt(
i );
693 QWidget *
w = item->widget();
698 painter->setClipRect( itemRects[index], Qt::IntersectClip );
699 renderItem( painter, w, itemRects[index], fillBackground );
719 const QWidget *widget,
const QRectF &rect,
bool fillBackground )
const 721 if ( fillBackground )
723 if ( widget->autoFillBackground() ||
724 widget->testAttribute( Qt::WA_StyledBackground ) )
738 const QRectF iconRect( rect.x() + label->
margin(),
739 rect.center().y() - 0.5 * sz.height(),
740 sz.width(), sz.height() );
742 icon.
render( painter, iconRect, Qt::KeepAspectRatio );
746 QRectF titleRect = rect;
747 titleRect.setX( iconRect.right() + 2 * label->
spacing() );
749 painter->setFont( label->font() );
750 painter->setPen( label->palette().color( QPalette::Text ) );
751 const_cast< QwtLegendLabel *
>( label )->drawText( painter, titleRect );
774 if ( list.isEmpty() )
808 if ( orientation == Qt::Horizontal )
A widget representing something on a QwtLegend.
virtual void updateWidget(QWidget *widget, const QwtLegendData &data)
Update the widget.
virtual int heightForWidth(int) const
virtual int maxItemWidth() const
void render(QPainter *) const
Replay all recorded painter commands.
virtual bool isEmpty() const
void removeWidget(const QWidget *)
QVariant itemInfo(const QWidget *) const
virtual uint columnsForWidth(int width) const
Calculate the number of columns for a given width.
QScrollBar * horizontalScrollBar() const
virtual bool eventFilter(QObject *, QEvent *)
virtual bool viewportEvent(QEvent *event)
const QwtLegendData & data() const
QSizeF defaultSize() const
Default size.
static void drawBackgound(QPainter *painter, const QRectF &rect, const QWidget *widget)
void remove(const QVariant &)
QwtLegendData::Mode defaultItemMode() const
void setDefaultItemMode(QwtLegendData::Mode)
Set the default mode for legend labels.
LegendView(QWidget *parent)
void setMaxColumns(uint maxCols)
QSize viewportSize(int w, int h) const
virtual QSize sizeHint() const
Return a size hint.
virtual int count() const
QVariant itemInfo(const QWidget *) const
virtual QLayoutItem * itemAt(int index) const
The QwtDynGridLayout class lays out widgets in a grid, adjusting the number of columns and rows to th...
QScrollBar * verticalScrollBar() const
void insert(const QVariant &, const QList< QWidget * > &)
virtual int scrollExtent(Qt::Orientation) const
virtual void updateLegend(const QVariant &, const QList< QwtLegendData > &)
Update the entries for an item.
QVariant value(int role) const
A paint device for scalable graphics.
QwtLegend(QWidget *parent=NULL)
QwtLegendData::Mode itemMode
QList< QWidget * > legendWidgets(const QVariant &) const
QList< QWidget * > widgets
QList< QWidget * > legendWidgets(const QVariant &) const
TFSIMD_FORCE_INLINE const tfScalar & w() const
QWidget * legendWidget(const QVariant &) const
Abstract base class for legend widgets.
QWidget * contentsWidget()
int margin
Return label's text margin in pixels.
virtual QWidget * createWidget(const QwtLegendData &) const
Create a widget to be inserted into the legend.
virtual ~QwtLegend()
Destructor.
virtual void renderLegend(QPainter *, const QRectF &, bool fillBackground) const
void setMaxColumns(uint numColums)
Set the maximum number of entries in a row.
void setData(const QwtLegendData &)
virtual bool event(QEvent *event)
void checked(const QVariant &itemInfo, bool on, int index)
QList< QRect > layoutItems(const QRect &, uint numCols) const
void clicked(const QVariant &itemInfo, int index)
Mode
Mode defining how a legend entry interacts.
uint maxColumns() const
Return the upper limit for the number of columns.
virtual int heightForWidth(int w) const
Attributes of an entry on a legend.
virtual void renderItem(QPainter *, const QWidget *, const QRectF &, bool fillBackground) const
void setItemMode(QwtLegendData::Mode)