31 #include <QApplication>
33 #include <QGraphicsSceneMouseEvent>
34 #include <QStyleOptionGraphicsItem>
36 #include <QGraphicsScene>
37 #include <QGraphicsView>
39 #include "../vmisc/def.h"
40 #include "../vmisc/vmath.h"
41 #include "../vmisc/vcommonsettings.h"
42 #include "../vmisc/vabstractapplication.h"
46 #define ARROW_ANGLE M_PI/9
47 #define ARROW_LENGTH 15
49 #define RESIZE_RECT_SIZE 10
50 #define ROTATE_CIRC_R 7
52 #define LINE_PEN_WIDTH 3
77 setAcceptHoverEvents(
true);
111 QColor color = QColor(
qApp->Settings()->getDefaultGrainlineColor());
113 painter->setPen(QPen(color,
m_penWidth, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
115 painter->setRenderHints(QPainter::Antialiasing);
118 painter->drawLine(mainLine.p1(), mainLine.p2());
120 painter->setBrush(color);
137 painter->setPen(QPen(Qt::black, 2, Qt::DashLine));
138 painter->setBrush(Qt::NoBrush);
144 painter->setPen(QPen(Qt::black, 3));
145 painter->setBrush(Qt::black);
150 painter->setBrush(Qt::NoBrush);
153 painter->setPen(Qt::black);
162 painter->setBrush(Qt::black);
163 painter->drawEllipse(ptC, dRad, dRad);
165 painter->setBrush(Qt::NoBrush);
167 painter->translate(ptC);
169 int iX = int(qRound(
m_dLength/2 - 0.5*dRad));
171 int iR = int(qRound(dRad*3));
172 painter->drawArc(iX - iR, iY - iR, iR, iR, 0*16, -90*16);
173 painter->drawArc(-iX, iY - iR, iR, iR, 270*16, -90*16);
174 painter->drawArc(-iX, -iY, iR, iR, 180*16, -90*16);
175 painter->drawArc(iX - iR, -iY, iR, iR, 90*16, -90*16);
199 pt.setX(pt.x() + dX);
200 pt.setY(pt.y() + dY);
226 apt[1].setX(pt.x() +
m_dLength * cos(dRot));
227 apt[1].setY(pt.y() -
m_dLength * sin(dRot));
233 QRectF rectParent = parentItem()->boundingRect();
234 for (
int i = 0; i < 2; ++i)
238 if (rectParent.contains(apt[i]) ==
false)
240 if (apt[i].x() < rectParent.left())
242 dPtX = rectParent.left() - apt[i].x();
244 else if (apt[i].x() > rectParent.right())
246 dPtX = rectParent.right() - apt[i].x();
248 if (apt[i].y() < rectParent.top())
250 dPtY = rectParent.top() - apt[i].y();
252 else if (apt[i].y() > rectParent.bottom())
254 dPtY = rectParent.bottom() - apt[i].y();
257 if (fabs(dPtX) > fabs(dX))
261 if (fabs(dPtY) > fabs(dY))
279 if (pME->button() == Qt::LeftButton && pME->type() != QEvent::GraphicsSceneMouseDoubleClick
280 && (flags() & QGraphicsItem::ItemIsMovable))
374 pt.setX(pt.x() + dX);
375 pt.setY(pt.y() + dY);
382 qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y());
383 qreal dAng = qAtan2(-ptDiff.y(), ptDiff.x());
397 QLineF grainline(this->pos().x(), this->pos().y(),
398 this->pos().x() + dPrevLen, this->pos().y());
399 grainline.setAngle(qRadiansToDegrees(
m_dRotation));
400 grainline = QLineF(grainline.p2(), grainline.p1());
402 pos = grainline.p2();
409 grainline.setAngle(qRadiansToDegrees(
m_dRotation));
410 grainline = QLineF(grainline.p2(), grainline.p1());
413 pos = grainline.p2();
433 qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y());
465 if (pME->button() == Qt::LeftButton)
473 qreal dLen = qSqrt(ptDiff.x()*ptDiff.x() + ptDiff.y()*ptDiff.y());
474 bool bShort = (dLen < 2);
519 VPieceItem::hoverEnterEvent(pME);
526 VPieceItem::hoverLeaveEvent(pME);
565 prepareGeometryChange();
585 QPointF ptRel = pt - ptCenter;
587 ptFinal.setX(ptRel.x()*qCos(dAng) + ptRel.y()*qSin(dAng));
588 ptFinal.setY(-ptRel.x()*qSin(dAng) + ptRel.y()*qCos(dAng));
606 pt1 = dDist*pt1/qSqrt(pt1.x()*pt1.x() + pt1.y()*pt1.y());
607 pt2 = dDist*pt2/qSqrt(pt2.x()*pt2.x() + pt2.y()*pt2.y());
618 if (scene()->views().count() > 0)
620 const QPoint pt0 = scene()->views().at(0)->mapFromScene(0, 0);
621 const QPoint pt = scene()->views().at(0)->mapFromScene(0, 100);
622 const QPoint p = pt - pt0;
623 qreal dScale = qSqrt(QPoint::dotProduct(p, p));
624 dScale = 100.0/dScale;
640 return QLineF(pt1, pt2);
674 QPainterPath linePath;
675 linePath.moveTo(mainLine.p1());
676 linePath.lineTo(mainLine.p2());
677 linePath.closeSubpath();
679 QPainterPathStroker stroker;
681 path.addPath((stroker.createStroke(linePath) + linePath).simplified());
688 QPainterPath polyPath;
690 path.addPath((stroker.createStroke(polyPath) + polyPath).simplified());
697 QPainterPath polyPath;
699 path.addPath((stroker.createStroke(polyPath) + polyPath).simplified());
731 if (
m_polyResize.containsPoint(pos, Qt::OddEvenFill) ==
true)
734 setCursor(Qt::SizeFDiagCursor);
751 ptA.setX(ptA.x() - dSize*cos(
m_dRotation - M_PI/2));
752 ptA.setY(ptA.y() + dSize*sin(
m_dRotation - M_PI/2));
759 ptA.setX(ptA.x() - dSize*cos(
m_dRotation + M_PI/2));
760 ptA.setY(ptA.y() + dSize*sin(
m_dRotation + M_PI/2));
bool isContained(const QPointF &pt, qreal dRot, qreal &dX, qreal &dY) const
VGrainlineItem::isContained checks, if both ends of the grainline, starting at pt,...
void itemResized(qreal dLength)
void UpdateRectangle()
VGrainlineItem::UpdateRectangle updates the polygon for the box around active item and the bounding r...
void UpdateGeometry(const QPointF &ptPos, qreal dRotation, qreal dLength, ArrowType eAT)
VGrainlineItem::UpdateGeometry updates the item with grainline parameters.
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mouseReleaseEvent handles mouse release events and emits the proper signal if the ite...
void allUserModifications(const QPointF &pos)
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mouseMoveEvent handles mouse move events, making sure that the item is moved properly...
virtual void paint(QPainter *pP, const QStyleOptionGraphicsItem *pOption, QWidget *pWidget) Q_DECL_OVERRIDE
VGrainlineItem::paint paints the item content.
virtual void mousePressEvent(QGraphicsSceneMouseEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem::mousePressEvent handles left button mouse press events.
QPainterPath MainShape() const
QPolygonF SecondArrow(qreal dArrLen) const
void itemRotated(qreal dRot, const QPointF &ptNewPos)
void userMoveAndResize(const QPointF &pos)
virtual void Update() Q_DECL_OVERRIDE
VGrainlineItem::Update updates the item.
QPointF GetInsideCorner(int i, qreal dDist) const
VGrainlineItem::GetInsideCorner calculates a point inside the bounding polygon, dDist away of i-th po...
qreal GetScale() const
GetScale gets the scale for keeping the arrows of constant size.
virtual QPainterPath shape() const Q_DECL_OVERRIDE
QPolygonF FirstArrow(qreal dArrLen) const
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *pME) Q_DECL_OVERRIDE
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pME) Q_DECL_OVERRIDE
VGrainlineItem(QGraphicsItem *pParent=nullptr)
VGrainlineItem::VGrainlineItem constructor.
QPointF Rotate(const QPointF &pt, const QPointF &ptCenter, qreal dAng) const
VGrainlineItem::Rotate rotates point pt around ptCenter by angle dAng [rad] and returns the resulting...
virtual double GetAngle(const QPointF &pt) const Q_DECL_OVERRIDE
GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis.
VPieceItem::MoveTypes m_moveType
virtual double GetAngle(const QPointF &pt) const
GetAngle calculates the angle between the line, which goes from rotation center to pt and x axis.
void itemMoved(const QPointF &ptPos)
void Reset()
Reset resets the item, putting the mode and z coordinate to normal and redraws it.
const QString cursorArrowOpenHand
double ToPixel(double val, const Unit &unit)
void SetItemOverrideCursor(QGraphicsItem *item, const QString &pixmapPath, int hotX, int hotY)
const QString cursorArrowCloseHand