Init
This commit is contained in:
73
graphicscrossitem.cpp
Normal file
73
graphicscrossitem.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "graphicscrossitem.h"
|
||||
|
||||
graphicsCrossItem::graphicsCrossItem(qreal px, qreal py)
|
||||
{
|
||||
x = px;
|
||||
y = py;
|
||||
dim=3;
|
||||
col = QColor(Qt::lightGray);
|
||||
scIndex=1;
|
||||
|
||||
}
|
||||
|
||||
QRectF graphicsCrossItem::boundingRect() const
|
||||
{
|
||||
qreal d = dim*scIndex;
|
||||
|
||||
return QRectF(x-d, y-d, 2*d, 2*d);
|
||||
}
|
||||
|
||||
|
||||
void graphicsCrossItem::setColor(QColor c)
|
||||
{
|
||||
if (col!=c) {
|
||||
prepareGeometryChange();
|
||||
col = c;
|
||||
}
|
||||
}
|
||||
|
||||
void graphicsCrossItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
qreal d = dim*scIndex;
|
||||
painter->setPen(QPen(col));
|
||||
QPointF p1(x-d, y-d);
|
||||
QPointF p2(x+d, y+d);
|
||||
QPointF p3(x-d, y+d);
|
||||
QPointF p4(x+d, y-d);
|
||||
|
||||
painter->drawLine(p1, p2);
|
||||
painter->drawLine(p3, p4);
|
||||
|
||||
}
|
||||
|
||||
void graphicsCrossItem::setPos(QPointF p)
|
||||
{
|
||||
qreal px, py;
|
||||
px= p.x(); py= p.y();
|
||||
|
||||
if ((x!=px)||(y!=py) ) {
|
||||
prepareGeometryChange();
|
||||
x=px; y=py;
|
||||
}
|
||||
}
|
||||
|
||||
void graphicsCrossItem::setPosPolar(qreal d, qreal a)
|
||||
{
|
||||
if (d>0)
|
||||
{
|
||||
setPos(cos((90-a)/180*M_PI)*d, -sin((90-a)/180*M_PI)*d);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPos(0,0);
|
||||
}
|
||||
}
|
||||
|
||||
void graphicsCrossItem::setScaleIndex(qreal s)
|
||||
{
|
||||
if (scIndex!=s){
|
||||
prepareGeometryChange();
|
||||
scIndex=s;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user