mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added overriden boundingRect method in RiuQwtSymbol to include label.
This commit is contained in:
@@ -128,20 +128,10 @@ void RiuQwtSymbol::renderSymbols(QPainter *painter, const QPointF *points, int n
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RiuQwtSymbol::renderSymbolLabel(QPainter *painter, const QPointF& position) const
|
void RiuQwtSymbol::renderSymbolLabel(QPainter *painter, const QPointF& position) const
|
||||||
{
|
{
|
||||||
int symbolWidth = this->size().width();
|
QSize symbolSize = QwtSymbol::size();
|
||||||
int labelWidth = painter->fontMetrics().width(m_label);
|
QRect symbolRect (position.x(), position.y(), symbolSize.width(), symbolSize.height());
|
||||||
if (m_labelPosition == LabelAboveSymbol)
|
QRect labelRect = labelBoundingRect(symbolRect);
|
||||||
{
|
painter->drawText(labelRect.topLeft(), m_label);
|
||||||
painter->drawText(position.x() - labelWidth / 2, position.y() - 5, m_label);
|
|
||||||
}
|
|
||||||
else if (m_labelPosition == LabelLeftOfSymbol)
|
|
||||||
{
|
|
||||||
painter->drawText(position.x() - labelWidth - symbolWidth, position.y(), m_label);
|
|
||||||
}
|
|
||||||
else if (m_labelPosition == LabelRightOfSymbol)
|
|
||||||
{
|
|
||||||
painter->drawText(position.x() + symbolWidth + 3, position.y(), m_label);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@@ -151,3 +141,41 @@ void RiuQwtSymbol::setLabelPosition(LabelPosition labelPosition)
|
|||||||
{
|
{
|
||||||
m_labelPosition = labelPosition;
|
m_labelPosition = labelPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QRect RiuQwtSymbol::boundingRect() const
|
||||||
|
{
|
||||||
|
QRect symbolRect = QwtSymbol::boundingRect();
|
||||||
|
QRect labelRect = labelBoundingRect(symbolRect);
|
||||||
|
return symbolRect.united(labelRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
QRect RiuQwtSymbol::labelBoundingRect(const QRect& symbolRect) const
|
||||||
|
{
|
||||||
|
QPoint symbolPosition = symbolRect.topLeft();
|
||||||
|
|
||||||
|
int symbolWidth = symbolRect.width();
|
||||||
|
|
||||||
|
int labelWidth = QPainter().fontMetrics().width(m_label);
|
||||||
|
int labelHeight = QPainter().fontMetrics().height();
|
||||||
|
|
||||||
|
QPoint labelPosition;
|
||||||
|
if (m_labelPosition == LabelAboveSymbol)
|
||||||
|
{
|
||||||
|
labelPosition = QPoint(symbolPosition.x() - labelWidth / 2, symbolPosition.y() - 5);
|
||||||
|
}
|
||||||
|
else if (m_labelPosition == LabelLeftOfSymbol)
|
||||||
|
{
|
||||||
|
labelPosition = QPoint(symbolPosition.x() - labelWidth - symbolWidth, symbolPosition.y());
|
||||||
|
}
|
||||||
|
else if (m_labelPosition == LabelRightOfSymbol)
|
||||||
|
{
|
||||||
|
labelPosition = QPoint(symbolPosition.x() + symbolWidth + 3, symbolPosition.y());
|
||||||
|
}
|
||||||
|
return QRect(labelPosition.x(), labelPosition.y(), labelWidth, labelHeight);
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,8 +59,12 @@ public:
|
|||||||
void renderSymbolLabel(QPainter *painter, const QPointF& position) const;
|
void renderSymbolLabel(QPainter *painter, const QPointF& position) const;
|
||||||
QString label() const { return m_label; }
|
QString label() const { return m_label; }
|
||||||
|
|
||||||
void setLabelPosition(LabelPosition labelPosition);
|
void setLabelPosition(LabelPosition labelPosition);
|
||||||
|
virtual QRect boundingRect() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QRect labelBoundingRect(const QRect& symbolRect) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_label;
|
QString m_label;
|
||||||
LabelPosition m_labelPosition;
|
LabelPosition m_labelPosition;
|
||||||
|
|||||||
Reference in New Issue
Block a user