Brief description of class still missing. More...
#include <DimensionItem.h>
Public Member Functions | |
virtual QRectF | boundingRect () const |
DimensionItem (QGraphicsItem *parent=0) | |
DimensionItem (const QLineF &l, QGraphicsItem *parent=0) | |
const QLineF & | line () const |
virtual void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
void | setFont (const QFont &f) |
~DimensionItem () |
Brief description of class still missing.
Full description of class still missing TODO: same structure as ellipse, based on PainterPath
DimensionItem::DimensionItem | ( | QGraphicsItem * | parent = 0 | ) |
DimensionItem::DimensionItem | ( | const QLineF & | l, |
QGraphicsItem * | parent = 0 |
||
) |
QRectF DimensionItem::boundingRect | ( | ) | const [virtual] |
References QGpCoreTools::Rect::enlarge(), and QGpCoreTools::LinearScale.
{ Rect bRect(0.0, 0.0, _line.dx(), _line.dy()); // Circle marks bRect.enlarge(_markSize*0.25, _markSize*0.25, ::LinearScale, ::LinearScale); Angle alpha(_line.dx(), _line.dy()); qreal x,y; // Mark 1a x=- _markSize * alpha.sin(); y=_markSize * alpha.cos(); bRect.add(x, y); // Mark 1b x=_markSize * alpha.sin(); y=-_markSize * alpha.cos(); bRect.add(x, y); // Mark 2a x=_line.dx() - _markSize * alpha.sin(); y=_line.dy() + _markSize * alpha.cos(); bRect.add(x, y); // Mark 2b x=_line.dx() + _markSize * alpha.sin(); y=_line.dy() - _markSize * alpha.cos(); bRect.add(x, y); // Text qreal dist=_line.length(); QFontMetricsF f(_textFont); QRectF textRect=f.boundingRect(QString::number(dist, 'f', _textPrecision) ); qreal r1=0.5*dist+_textPos; r1-=0.5*textRect.width(); x=r1 * alpha.cos(); y=r1 * alpha.sin(); qreal r2=textRect.height()+_textGap; x += r2 * alpha.sin(); y -= r2 * alpha.cos(); bRect.add(x, y); r1+=textRect.width(); x=r1 * alpha.cos(); y=r1 * alpha.sin(); x += r2 * alpha.sin(); y -= r2 * alpha.cos(); bRect.add(x, y); // Pen width bRect.enlarge(pen().width()*0.5, ::LinearScale, ::LinearScale); return QRectF(bRect.x1(), bRect.y1(), bRect.width(), bRect.height()); }
const QLineF& DimensionItem::line | ( | ) | const [inline] |
Referenced by DimensionItemDelegate::nodes().
{return _line;}
void DimensionItem::paint | ( | QPainter * | painter, |
const QStyleOptionGraphicsItem * | option, | ||
QWidget * | widget | ||
) | [virtual] |
References str.
{ painter->save(); qreal alpha=atan2(_line.dy(), _line.dx()); painter->rotate(Angle::radiansToDegrees(alpha)); painter->setPen(pen()); qreal dist=_line.length(); painter->drawLine(QLineF(0.0, 0.0, dist, 0.0)); painter->drawEllipse(QRectF(-_markSize*0.1, -_markSize*0.1, _markSize*0.2, _markSize*0.2)); painter->drawEllipse(QRectF(dist-_markSize*0.1, -_markSize*0.1, _markSize*0.2, _markSize*0.2)); painter->drawLine(QLineF(0.0, -_markSize*0.5, 0.0, _markSize)); painter->drawLine(QLineF(dist, -_markSize*0.5, dist, _markSize)); QString str=QString::number(dist, 'f', _textPrecision); QPainterPath path; path.addText(0, 0, _textFont, str); QRectF textRect=path.boundingRect(); painter->translate(0.5*dist+_textPos-textRect.width()*0.5-textRect.x(), -_textGap); painter->setBrush(brush()); painter->setPen(Qt::NoPen); painter->drawPath(path); painter->restore(); }
void DimensionItem::setFont | ( | const QFont & | f | ) | [inline] |
Referenced by DrawScene::addDimension().
{_textFont=f;}