A legend label. More...
#include <qwt_legend_item.h>
Classes | |
class | PrivateData |
Public Types | |
enum | IdentifierMode { NoIdentifier = 0, ShowLine = 1, ShowSymbol = 2, ShowText = 4 } |
Identifier mode. More... | |
Public Slots | |
void | setChecked (bool on) |
Signals | |
void | clicked () |
Signal, when the legend item has been clicked. | |
void | pressed () |
Signal, when the legend item has been pressed. | |
void | released () |
Signal, when the legend item has been relased. | |
void | checked (bool) |
Signal, when the legend item has been toggled. | |
Public Member Functions | |
QwtLegendItem (QWidget *parent=0) | |
QwtLegendItem (const QwtSymbol &, const QPen &, const QwtText &, QWidget *parent=0) | |
virtual | ~QwtLegendItem () |
Destructor. | |
virtual void | setText (const QwtText &) |
void | setItemMode (QwtLegend::LegendItemMode) |
QwtLegend::LegendItemMode | itemMode () const |
void | setIdentifierMode (int) |
int | identifierMode () const |
void | setIdentifierWidth (int width) |
int | identifierWidth () const |
void | setSpacing (int spacing) |
int | spacing () const |
void | setSymbol (const QwtSymbol &) |
const QwtSymbol & | symbol () const |
void | setCurvePen (const QPen &) |
const QPen & | curvePen () const |
virtual void | drawIdentifier (QPainter *, const QRect &) const |
virtual void | drawItem (QPainter *p, const QRect &) const |
virtual QSize | sizeHint () const |
Return a size hint. | |
bool | isChecked () const |
Return true, if the item is checked. | |
Protected Member Functions | |
void | setDown (bool) |
Set the item being down. | |
bool | isDown () const |
Return true, if the item is down. | |
virtual void | paintEvent (QPaintEvent *) |
Paint event. | |
virtual void | mousePressEvent (QMouseEvent *) |
Handle mouse press events. | |
virtual void | mouseReleaseEvent (QMouseEvent *) |
Handle mouse release events. | |
virtual void | keyPressEvent (QKeyEvent *) |
Handle key press events. | |
virtual void | keyReleaseEvent (QKeyEvent *) |
Handle key release events. | |
virtual void | drawText (QPainter *, const QRect &) |
Redraw the text. |
A legend label.
QwtLegendItem represents a curve on a legend. It displays an curve identifier with an explaining text. The identifier might be a combination of curve symbol and line. In readonly mode it behaves like a label, otherwise like an unstylish push button.
Definition at line 35 of file qwt_legend_item.h.
Identifier mode.
Default is ShowLine | ShowText
Definition at line 47 of file qwt_legend_item.h.
{ NoIdentifier = 0, ShowLine = 1, ShowSymbol = 2, ShowText = 4 };
QwtLegendItem::QwtLegendItem | ( | QWidget * | parent = 0 ) |
[explicit] |
parent | Parent widget |
Definition at line 80 of file qwt_legend_item.cpp.
: QwtTextLabel(parent) { d_data = new PrivateData; init(QwtText()); }
QwtLegendItem::QwtLegendItem | ( | const QwtSymbol & | symbol, |
const QPen & | curvePen, | ||
const QwtText & | text, | ||
QWidget * | parent = 0 |
||
) | [explicit] |
symbol | Curve symbol |
curvePen | Curve pen |
text | Label text |
parent | Parent widget |
Definition at line 93 of file qwt_legend_item.cpp.
References QwtSymbol::clone(), curvePen(), QwtLegendItem::PrivateData::curvePen, and QwtLegendItem::PrivateData::symbol.
QwtLegendItem::~QwtLegendItem | ( | ) | [virtual] |
void QwtLegendItem::checked | ( | bool | ) | [signal] |
Signal, when the legend item has been toggled.
Referenced by setDown().
void QwtLegendItem::clicked | ( | ) | [signal] |
Signal, when the legend item has been clicked.
Referenced by setDown().
const QPen & QwtLegendItem::curvePen | ( | ) | const |
Definition at line 294 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::curvePen.
Referenced by QwtPlotPrintFilter::apply(), QwtLegendItem(), and QwtPlotPrintFilter::reset().
{ return d_data->curvePen; }
void QwtLegendItem::drawIdentifier | ( | QPainter * | painter, |
const QRect & | rect | ||
) | const [virtual] |
Paint the identifier to a given rect.
painter | Painter |
rect | Rect where to paint |
Definition at line 304 of file qwt_legend_item.cpp.
References QwtSymbol::brush(), QwtLegendItem::PrivateData::curvePen, QwtSymbol::draw(), QwtPainter::drawLine(), QwtLegendItem::PrivateData::identifierMode, QwtPainter::metricsMap(), QwtSymbol::NoSymbol, QwtSymbol::pen(), QwtPainter::scaledPen(), QwtMetricsMap::screenToLayout(), ShowLine, ShowSymbol, QwtSymbol::size(), QwtSymbol::style(), and QwtLegendItem::PrivateData::symbol.
Referenced by drawItem(), and paintEvent().
{ if ( rect.isEmpty() ) return; if ( (d_data->identifierMode & ShowLine ) && (d_data->curvePen.style() != Qt::NoPen) ) { painter->save(); painter->setPen(QwtPainter::scaledPen(d_data->curvePen)); QwtPainter::drawLine(painter, rect.left(), rect.center().y(), rect.right(), rect.center().y()); painter->restore(); } if ( (d_data->identifierMode & ShowSymbol) && (d_data->symbol->style() != QwtSymbol::NoSymbol) ) { QSize symbolSize = QwtPainter::metricsMap().screenToLayout(d_data->symbol->size()); // scale the symbol size down if it doesn't fit into rect. if ( rect.width() < symbolSize.width() ) { const double ratio = double(symbolSize.width()) / double(rect.width()); symbolSize.setWidth(rect.width()); symbolSize.setHeight(qRound(symbolSize.height() / ratio)); } if ( rect.height() < symbolSize.height() ) { const double ratio = double(symbolSize.width()) / double(rect.width()); symbolSize.setHeight(rect.height()); symbolSize.setWidth(qRound(symbolSize.width() / ratio)); } QRect symbolRect; symbolRect.setSize(symbolSize); symbolRect.moveCenter(rect.center()); painter->save(); painter->setBrush(d_data->symbol->brush()); painter->setPen(QwtPainter::scaledPen(d_data->symbol->pen())); d_data->symbol->draw(painter, symbolRect); painter->restore(); } }
void QwtLegendItem::drawItem | ( | QPainter * | painter, |
const QRect & | rect | ||
) | const [virtual] |
Draw the legend item to a given rect.
painter | Painter |
rect | Rect where to paint the button |
Definition at line 360 of file qwt_legend_item.cpp.
References QwtText::draw(), drawIdentifier(), QwtLegendItem::PrivateData::identifierWidth, identifierWidth(), QwtTextLabel::margin(), QwtPainter::metricsMap(), QwtMetricsMap::screenToLayoutX(), QwtLegendItem::PrivateData::spacing, spacing(), and QwtTextLabel::text().
Referenced by QwtPlot::printLegendItem().
{ painter->save(); const QwtMetricsMap &map = QwtPainter::metricsMap(); const int m = map.screenToLayoutX(margin()); const int spacing = map.screenToLayoutX(d_data->spacing); const int identifierWidth = map.screenToLayoutX(d_data->identifierWidth); const QRect identifierRect(rect.x() + m, rect.y(), identifierWidth, rect.height()); drawIdentifier(painter, identifierRect); // Label QRect titleRect = rect; titleRect.setX(identifierRect.right() + 2 * spacing); text().draw(painter, titleRect); painter->restore(); }
void QwtLegendItem::drawText | ( | QPainter * | painter, |
const QRect & | textRect | ||
) | [protected, virtual] |
Redraw the text.
Reimplemented from QwtTextLabel.
Definition at line 587 of file qwt_legend_item.cpp.
{ QwtTextLabel::drawText(painter, rect); }
int QwtLegendItem::identifierMode | ( | ) | const |
Or'd values of IdentifierMode.
Definition at line 194 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::identifierMode.
{ return d_data->identifierMode; }
int QwtLegendItem::identifierWidth | ( | ) | const |
Return the width of the identifier
Definition at line 222 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::identifierWidth.
Referenced by drawItem().
{ return d_data->identifierWidth; }
bool QwtLegendItem::isChecked | ( | ) | const |
Return true, if the item is checked.
Definition at line 542 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, isDown(), and QwtLegendItem::PrivateData::itemMode.
{ return d_data->itemMode == QwtLegend::CheckableItem && isDown(); }
bool QwtLegendItem::isDown | ( | ) | const [protected] |
Return true, if the item is down.
Definition at line 572 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::isDown.
Referenced by isChecked(), keyPressEvent(), and mousePressEvent().
{ return d_data->isDown; }
QwtLegend::LegendItemMode QwtLegendItem::itemMode | ( | ) | const |
Return the item mode
Definition at line 169 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::itemMode.
{ return d_data->itemMode; }
void QwtLegendItem::keyPressEvent | ( | QKeyEvent * | e ) | [protected, virtual] |
Handle key press events.
Definition at line 473 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, QwtLegend::ClickableItem, isDown(), QwtLegendItem::PrivateData::itemMode, mitk::Key_Space, and setDown().
{ if ( e->key() == Qt::Key_Space ) { switch(d_data->itemMode) { case QwtLegend::ClickableItem: { if ( !e->isAutoRepeat() ) setDown(true); return; } case QwtLegend::CheckableItem: { if ( !e->isAutoRepeat() ) setDown(!isDown()); return; } default:; } } QwtTextLabel::keyPressEvent(e); }
void QwtLegendItem::keyReleaseEvent | ( | QKeyEvent * | e ) | [protected, virtual] |
Handle key release events.
Definition at line 499 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, QwtLegend::ClickableItem, QwtLegendItem::PrivateData::itemMode, mitk::Key_Space, and setDown().
{ if ( e->key() == Qt::Key_Space ) { switch(d_data->itemMode) { case QwtLegend::ClickableItem: { if ( !e->isAutoRepeat() ) setDown(false); return; } case QwtLegend::CheckableItem: { return; // do nothing, but accept } default:; } } QwtTextLabel::keyReleaseEvent(e); }
void QwtLegendItem::mousePressEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Handle mouse press events.
Definition at line 428 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, QwtLegend::ClickableItem, isDown(), QwtLegendItem::PrivateData::itemMode, and setDown().
{ if ( e->button() == Qt::LeftButton ) { switch(d_data->itemMode) { case QwtLegend::ClickableItem: { setDown(true); return; } case QwtLegend::CheckableItem: { setDown(!isDown()); return; } default:; } } QwtTextLabel::mousePressEvent(e); }
void QwtLegendItem::mouseReleaseEvent | ( | QMouseEvent * | e ) | [protected, virtual] |
Handle mouse release events.
Definition at line 451 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, QwtLegend::ClickableItem, QwtLegendItem::PrivateData::itemMode, and setDown().
{ if ( e->button() == Qt::LeftButton ) { switch(d_data->itemMode) { case QwtLegend::ClickableItem: { setDown(false); return; } case QwtLegend::CheckableItem: { return; // do nothing, but accept } default:; } } QwtTextLabel::mouseReleaseEvent(e); }
void QwtLegendItem::paintEvent | ( | QPaintEvent * | e ) | [protected, virtual] |
Paint event.
Reimplemented from QwtTextLabel.
Definition at line 385 of file qwt_legend_item.cpp.
References ButtonFrame, buttonShift(), QwtTextLabel::drawContents(), drawIdentifier(), QwtLegendItem::PrivateData::identifierWidth, QwtLegendItem::PrivateData::isDown, QwtLegendItem::PrivateData::itemMode, QwtTextLabel::margin(), and QwtLegend::ReadOnlyItem.
{ const QRect cr = contentsRect(); QPainter painter(this); painter.setClipRegion(e->region()); if ( d_data->isDown ) { qDrawWinButton(&painter, 0, 0, width(), height(), #if QT_VERSION < 0x040000 colorGroup(), #else palette(), #endif true); } painter.save(); if ( d_data->isDown ) { const QSize shiftSize = buttonShift(this); painter.translate(shiftSize.width(), shiftSize.height()); } painter.setClipRect(cr); drawContents(&painter); QRect rect = cr; rect.setX(rect.x() + margin()); if ( d_data->itemMode != QwtLegend::ReadOnlyItem ) rect.setX(rect.x() + ButtonFrame); rect.setWidth(d_data->identifierWidth); drawIdentifier(&painter, rect); painter.restore(); }
void QwtLegendItem::pressed | ( | ) | [signal] |
Signal, when the legend item has been pressed.
Referenced by setDown().
void QwtLegendItem::released | ( | ) | [signal] |
Signal, when the legend item has been relased.
Referenced by setDown().
void QwtLegendItem::setChecked | ( | bool | on ) | [slot] |
Check/Uncheck a the item
on | check/uncheck |
Definition at line 528 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, QwtLegendItem::PrivateData::itemMode, and setDown().
{ if ( d_data->itemMode == QwtLegend::CheckableItem ) { const bool isBlocked = signalsBlocked(); blockSignals(true); setDown(on); blockSignals(isBlocked); } }
void QwtLegendItem::setCurvePen | ( | const QPen & | pen ) |
Set curve pen.
pen | Curve pen |
Definition at line 281 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::curvePen.
Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), and QwtPlotCurve::updateLegend().
void QwtLegendItem::setDown | ( | bool | down ) | [protected] |
Set the item being down.
Definition at line 548 of file qwt_legend_item.cpp.
References QwtLegend::CheckableItem, checked(), QwtLegend::ClickableItem, clicked(), QwtLegendItem::PrivateData::isDown, QwtLegendItem::PrivateData::itemMode, pressed(), and released().
Referenced by keyPressEvent(), keyReleaseEvent(), mousePressEvent(), mouseReleaseEvent(), and setChecked().
void QwtLegendItem::setIdentifierMode | ( | int | mode ) |
Set identifier mode. Default is ShowLine | ShowText.
mode | Or'd values of IdentifierMode |
Definition at line 181 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::identifierMode.
Referenced by QwtPlotCurve::updateLegend().
{ if ( mode != d_data->identifierMode ) { d_data->identifierMode = mode; update(); } }
void QwtLegendItem::setIdentifierWidth | ( | int | width ) |
Set the width for the identifier Default is 8 pixels
width | New width |
Definition at line 207 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::identifierWidth, QwtTextLabel::margin(), qwtMax, QwtTextLabel::setIndent(), and QwtLegendItem::PrivateData::spacing.
{ width = qwtMax(width, 0); if ( width != d_data->identifierWidth ) { d_data->identifierWidth = width; setIndent(margin() + d_data->identifierWidth + 2 * d_data->spacing); } }
void QwtLegendItem::setItemMode | ( | QwtLegend::LegendItemMode | mode ) |
Set the item mode The default is QwtLegend::ReadOnlyItem
mode | Item mode |
Definition at line 150 of file qwt_legend_item.cpp.
References ButtonFrame, QwtLegendItem::PrivateData::isDown, QwtLegendItem::PrivateData::itemMode, Margin, QwtLegend::ReadOnlyItem, and QwtTextLabel::setMargin().
Referenced by QwtPlotItem::updateLegend().
{ d_data->itemMode = mode; d_data->isDown = false; #if QT_VERSION >= 0x040000 using namespace Qt; #endif setFocusPolicy(mode != QwtLegend::ReadOnlyItem ? TabFocus : NoFocus); setMargin(ButtonFrame + Margin); updateGeometry(); }
void QwtLegendItem::setSpacing | ( | int | spacing ) |
Change the spacing
spacing | Spacing |
Definition at line 232 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::identifierWidth, QwtTextLabel::margin(), qwtMax, QwtTextLabel::setIndent(), spacing(), and QwtLegendItem::PrivateData::spacing.
void QwtLegendItem::setSymbol | ( | const QwtSymbol & | symbol ) |
Set curve symbol.
symbol | Symbol |
Definition at line 258 of file qwt_legend_item.cpp.
References QwtSymbol::clone(), and QwtLegendItem::PrivateData::symbol.
Referenced by QwtPlotPrintFilter::apply(), QwtPlotPrintFilter::reset(), and QwtPlotCurve::updateLegend().
void QwtLegendItem::setText | ( | const QwtText & | text ) | [virtual] |
Set the text to the legend item
text | Text label |
Reimplemented from QwtTextLabel.
Definition at line 128 of file qwt_legend_item.cpp.
References QwtText::setRenderFlags(), and QwtTextLabel::text().
Referenced by QwtPlotItem::updateLegend(), and QwtPlotCurve::updateLegend().
{ const int flags = Qt::AlignLeft | Qt::AlignVCenter #if QT_VERSION < 0x040000 | Qt::WordBreak | Qt::ExpandTabs; #else | Qt::TextExpandTabs | Qt::TextWordWrap; #endif QwtText txt = text; txt.setRenderFlags(flags); QwtTextLabel::setText(txt); }
QSize QwtLegendItem::sizeHint | ( | ) | const [virtual] |
Return a size hint.
Reimplemented from QwtTextLabel.
Definition at line 578 of file qwt_legend_item.cpp.
References buttonShift(), QwtLegendItem::PrivateData::itemMode, and QwtLegend::ReadOnlyItem.
{ QSize sz = QwtTextLabel::sizeHint(); if ( d_data->itemMode != QwtLegend::ReadOnlyItem ) sz += buttonShift(this); return sz; }
int QwtLegendItem::spacing | ( | ) | const |
Return the spacing
Definition at line 247 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::spacing.
Referenced by drawItem(), and setSpacing().
{ return d_data->spacing; }
const QwtSymbol & QwtLegendItem::symbol | ( | ) | const |
Definition at line 269 of file qwt_legend_item.cpp.
References QwtLegendItem::PrivateData::symbol.
Referenced by QwtPlotPrintFilter::apply(), and QwtPlotPrintFilter::reset().
{ return *d_data->symbol; }