10 #include "qwt_legend_label.h"
11 #include "qwt_legend_data.h"
12 #include "qwt_graphic.h"
16 #include <qdrawutil.h>
19 #include <qstyleoption.h>
21 static const int ButtonFrame = 2;
22 static const int Margin = 2;
29 const int ph = w->style()->pixelMetric(
30 QStyle::PM_ButtonShiftHorizontal, &option, w );
31 const int pv = w->style()->pixelMetric(
32 QStyle::PM_ButtonShiftVertical, &option, w );
33 return QSize( ph, pv );
36 class QwtLegendLabel::PrivateData
63 m_data->legendData = legendData;
65 const bool doUpdate = updatesEnabled();
67 setUpdatesEnabled(
false );
72 if ( legendData.
hasRole( QwtLegendData::ModeRole ) )
76 setUpdatesEnabled(
true );
85 return m_data->legendData;
94 m_data =
new PrivateData;
114 const int flags = Qt::AlignLeft | Qt::AlignVCenter
115 | Qt::TextExpandTabs | Qt::TextWordWrap;
132 if ( mode != m_data->itemMode )
134 m_data->itemMode = mode;
135 m_data->isDown =
false;
138 ? Qt::TabFocus : Qt::NoFocus );
151 return m_data->itemMode;
166 if (
icon.width() > 0 )
190 if (
spacing != m_data->spacing )
195 if ( m_data->icon.width() > 0 )
196 indent += m_data->icon.width() + m_data->spacing;
208 return m_data->spacing;
221 const bool isBlocked = signalsBlocked();
222 blockSignals(
true );
226 blockSignals( isBlocked );
239 if ( down == m_data->isDown )
242 m_data->isDown = down;
247 if ( m_data->isDown )
257 Q_EMIT
checked( m_data->isDown );
263 return m_data->isDown;
270 sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) );
274 sz += buttonShift(
this );
275 sz = qwtExpandedToGlobalStrut( sz );
284 const QRect cr = contentsRect();
286 QPainter painter(
this );
287 painter.setClipRegion( e->region() );
289 if ( m_data->isDown )
291 qDrawWinButton( &painter, 0, 0, width(), height(),
297 if ( m_data->isDown )
299 const QSize shiftSize = buttonShift(
this );
300 painter.translate( shiftSize.width(), shiftSize.height() );
303 painter.setClipRect( cr );
307 if ( !m_data->icon.isNull() )
310 iconRect.setX( iconRect.x() +
margin() );
312 iconRect.setX( iconRect.x() + ButtonFrame );
314 iconRect.setSize( m_data->icon.size() );
315 iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
317 painter.drawPixmap( iconRect, m_data->icon );
326 if ( e->button() == Qt::LeftButton )
328 switch ( m_data->itemMode )
343 QwtTextLabel::mousePressEvent( e );
349 if ( e->button() == Qt::LeftButton )
351 switch ( m_data->itemMode )
365 QwtTextLabel::mouseReleaseEvent( e );
371 if ( e->key() == Qt::Key_Space )
373 switch ( m_data->itemMode )
377 if ( !e->isAutoRepeat() )
383 if ( !e->isAutoRepeat() )
391 QwtTextLabel::keyPressEvent( e );
397 if ( e->key() == Qt::Key_Space )
399 switch ( m_data->itemMode )
403 if ( !e->isAutoRepeat() )
415 QwtTextLabel::keyReleaseEvent( e );
419 #include "moc_qwt_legend_label.cpp"
QPixmap toPixmap(qreal devicePixelRatio=0.0) const
Convert the graphic to a QPixmap.
Attributes of an entry on a legend.
Mode
Mode defining how a legend entry interacts.
@ Checkable
The legend item is checkable, like a checkable button.
@ Clickable
The legend item is clickable, like a push button.
@ ReadOnly
The legend item is not interactive, like a label.
bool hasRole(int role) const
A widget representing something on a QwtLegend.
virtual QSize sizeHint() const override
Return a size hint.
void checked(bool)
Signal, when the legend item has been toggled.
virtual void keyPressEvent(QKeyEvent *) override
Handle key press events.
void setItemMode(QwtLegendData::Mode)
QwtLegendLabel(QWidget *parent=0)
bool isDown() const
Return true, if the item is down.
void released()
Signal, when the legend item has been released.
virtual void setText(const QwtText &) override
QwtLegendData::Mode itemMode() const
const QwtLegendData & data() const
virtual void paintEvent(QPaintEvent *) override
Paint event.
void setData(const QwtLegendData &)
void setSpacing(int spacing)
Change the spacing between icon and text.
void setDown(bool)
Set the item being down.
virtual ~QwtLegendLabel()
Destructor.
virtual void mousePressEvent(QMouseEvent *) override
Handle mouse press events.
virtual void mouseReleaseEvent(QMouseEvent *) override
Handle mouse release events.
void clicked()
Signal, when the legend item has been clicked.
void pressed()
Signal, when the legend item has been pressed.
void setIcon(const QPixmap &)
virtual void keyReleaseEvent(QKeyEvent *) override
Handle key release events.
bool isChecked() const
Return true, if the item is checked.
A class representing a text.
void setRenderFlags(int)
Change the render flags.
A Widget which displays a QwtText.
int indent() const
Return label's text indent in pixels.
int margin() const
Return label's text margin in pixels.
const QwtText & text() const
Return the text.
virtual QSize sizeHint() const override
Return a size hint.
virtual void drawContents(QPainter *)
Redraw the text and focus indicator.
void setText(const QString &, QwtText::TextFormat textFormat=QwtText::AutoText)