10#include "qwt_legend_label.h" 
   11#include "qwt_legend_data.h" 
   12#include "qwt_graphic.h" 
   13#include "qwt_painter.h" 
   20#include <qstyleoption.h> 
   22static const int ButtonFrame = 2;
 
   23static const int Margin = 2;
 
   30    const int ph = w->style()->pixelMetric(
 
   31        QStyle::PM_ButtonShiftHorizontal, &option, w );
 
   32    const int pv = w->style()->pixelMetric(
 
   33        QStyle::PM_ButtonShiftVertical, &option, w );
 
   34    return QSize( ph, pv );
 
   37class QwtLegendLabel::PrivateData
 
   64    m_data->legendData = legendData;
 
   66    const bool doUpdate = updatesEnabled();
 
   68        setUpdatesEnabled( 
false );
 
   73    if ( legendData.
hasRole( QwtLegendData::ModeRole ) )
 
   77        setUpdatesEnabled( 
true );
 
 
   86    return m_data->legendData;
 
 
   95    m_data = 
new PrivateData;
 
 
  115    const int flags = Qt::AlignLeft | Qt::AlignVCenter
 
  116        | Qt::TextExpandTabs | Qt::TextWordWrap;
 
 
  133    if ( mode != m_data->itemMode )
 
  135        m_data->itemMode = mode;
 
  136        m_data->isDown = 
false;
 
  139            ? Qt::TabFocus : Qt::NoFocus );
 
 
  152    return m_data->itemMode;
 
 
  167    if ( 
icon.width() > 0 )
 
  170        indent += 
icon.width() / devicePixelRatio + m_data->spacing;
 
 
  194    if ( 
spacing != m_data->spacing )
 
  199        if ( m_data->icon.width() > 0 )
 
  200            indent += m_data->icon.width() + m_data->spacing;
 
 
  212    return m_data->spacing;
 
 
  225        const bool isBlocked = signalsBlocked();
 
  226        blockSignals( 
true );
 
  230        blockSignals( isBlocked );
 
 
  243    if ( down == m_data->isDown )
 
  246    m_data->isDown = down;
 
  251        if ( m_data->isDown )
 
  261        Q_EMIT 
checked( m_data->isDown );
 
 
  267    return m_data->isDown;
 
 
  274    sz.setHeight( qMax( sz.height(), m_data->icon.height() + 4 ) );
 
  278        sz += buttonShift( 
this );
 
  279        sz = qwtExpandedToGlobalStrut( sz );
 
 
  288    const QRect cr = contentsRect();
 
  290    QPainter painter( 
this );
 
  291    painter.setClipRegion( e->region() );
 
  293    if ( m_data->isDown )
 
  295        qDrawWinButton( &painter, 0, 0, width(), height(),
 
  301    if ( m_data->isDown )
 
  303        const QSize shiftSize = buttonShift( 
this );
 
  304        painter.translate( shiftSize.width(), shiftSize.height() );
 
  307    painter.setClipRect( cr );
 
  311    if ( !m_data->icon.isNull() )
 
  314        iconRect.setX( iconRect.x() + 
margin() );
 
  316            iconRect.setX( iconRect.x() + ButtonFrame );
 
  319        iconRect.setSize( m_data->icon.size() / devicePixelRatio );
 
  320        iconRect.moveCenter( QPoint( iconRect.center().x(), cr.center().y() ) );
 
  322        painter.drawPixmap( iconRect, m_data->icon );
 
 
  331    if ( e->button() == Qt::LeftButton )
 
  333        switch ( m_data->itemMode )
 
  348    QwtTextLabel::mousePressEvent( e );
 
 
  354    if ( e->button() == Qt::LeftButton )
 
  356        switch ( m_data->itemMode )
 
  370    QwtTextLabel::mouseReleaseEvent( e );
 
 
  376    if ( e->key() == Qt::Key_Space )
 
  378        switch ( m_data->itemMode )
 
  382                if ( !e->isAutoRepeat() )
 
  388                if ( !e->isAutoRepeat() )
 
  396    QwtTextLabel::keyPressEvent( e );
 
 
  402    if ( e->key() == Qt::Key_Space )
 
  404        switch ( m_data->itemMode )
 
  408                if ( !e->isAutoRepeat() )
 
  420    QwtTextLabel::keyReleaseEvent( e );
 
 
  423#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.
static qreal devicePixelRatio(const QPaintDevice *)
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)