void CanvasMode_EditArc::mouseMoveEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m->accept(); double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed()) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QTransform itemMatrix = currItem->getTransform(); QPointF sPoint = currItem->PoLine.pointQF(0); QPointF smPoint = itemMatrix.map(sPoint); QLineF stLinA = QLineF(smPoint, QPointF(m_Mxp, m_Myp)); QLineF stLinM = QLineF(smPoint, QPointF(newX, newY)); double deltaAngle = stLinM.angle() - stLinA.angle(); QPainterPath pp; if (m_arcPoint == useControlStart) m_startAngle += deltaAngle; else if (m_arcPoint == useControlSweep) m_endAngle += deltaAngle; else if (m_arcPoint == useControlHeight) m_heightPoint = QPointF(m_heightPoint.x(), m_heightPoint.y() + (newY - m_Myp)); else if (m_arcPoint == useControlWidth) m_widthPoint = QPointF(m_widthPoint.x() + (newX - m_Mxp), m_widthPoint.y()); double nSweep = m_endAngle - m_startAngle; if (nSweep < 0) nSweep += 360; double nWidth = sPoint.x() - m_widthPoint.x(); double nHeight = sPoint.y() - m_heightPoint.y(); if ((nWidth > 0) && (nHeight > 0)) { pp.moveTo(sPoint); pp.arcTo(QRectF(sPoint.x() - nWidth, sPoint.y() - nHeight, nWidth * 2, nHeight * 2), m_startAngle, nSweep); pp.closeSubpath(); FPointArray ar; ar.fromQPainterPath(pp); if (m_arcPoint == useControlStart) { m_startPoint = ar.pointQF(2); QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_startPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } else if (m_arcPoint == useControlSweep) { m_endPoint = ar.pointQF(ar.size() - 4); QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_endPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } QLineF res = QLineF(m_centerPoint, m_startPoint); QLineF swe = QLineF(m_centerPoint, m_endPoint); vectorDialog->setValues(res.angle(), swe.angle(), nHeight * 2, nWidth * 2); blockUpdateFromItem(true); currItem->update(); blockUpdateFromItem(false); m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-nWidth, -nHeight, nWidth, nHeight)); } } m_Mxp = newX; m_Myp = newY; }
void CanvasMode_EditArc::mouseMoveEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m->accept(); double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed()) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QTransform itemMatrix; itemMatrix.translate(currItem->xPos(), currItem->yPos()); itemMatrix.rotate(currItem->rotation()); QPointF sPoint = currItem->PoLine.pointQF(0); QPointF smPoint = itemMatrix.map(sPoint); QLineF stLinA = QLineF(smPoint, QPointF(Mxp, Myp)); QLineF stLinM = QLineF(smPoint, QPointF(newX, newY)); double deltaAngle = stLinM.angle() - stLinA.angle(); QPainterPath pp; if (m_arcPoint == useControlStart) startAngle += deltaAngle; else if (m_arcPoint == useControlSweep) endAngle += deltaAngle; else if (m_arcPoint == useControlHeight) heightPoint = QPointF(heightPoint.x(), heightPoint.y() + (newY - Myp)); else if (m_arcPoint == useControlWidth) widthPoint = QPointF(widthPoint.x() + (newX - Mxp), widthPoint.y()); double nSweep = endAngle - startAngle; if (nSweep < 0) nSweep += 360; double nWidth = sPoint.x() - widthPoint.x(); double nHeight = sPoint.y() - heightPoint.y(); pp.moveTo(sPoint); pp.arcTo(QRectF(sPoint.x() - nWidth, sPoint.y() - nHeight, nWidth * 2, nHeight * 2), startAngle, nSweep); pp.closeSubpath(); FPointArray ar; ar.fromQPainterPath(pp); if (m_arcPoint == useControlStart) { startPoint = ar.pointQF(2); QLineF stLinA = QLineF(smPoint, itemMatrix.map(startPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } else if (m_arcPoint == useControlSweep) { endPoint = ar.pointQF(ar.size() - 4); QLineF stLinA = QLineF(smPoint, itemMatrix.map(endPoint)); m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle()); } QLineF res = QLineF(centerPoint, startPoint); QLineF swe = QLineF(centerPoint, endPoint); VectorDialog->setValues(res.angle(), swe.angle(), nHeight * 2, nWidth * 2); blockUpdateFromItem(true); currItem->update(); blockUpdateFromItem(false); QRectF upRect; upRect = QRectF(QPointF(0, 0), QPointF(currItem->width(), currItem->height())).normalized(); upRect.translate(currItem->xPos(), currItem->yPos()); m_doc->regionsChanged()->update(upRect.adjusted(-10.0 - currItem->width() / 2.0, -10.0 - currItem->height() / 2.0, 10.0 + currItem->width() / 2.0, 10.0 + currItem->height() / 2.0)); } Mxp = newX; Myp = newY; }
void CanvasMode_EditPolygon::mouseMoveEvent(QMouseEvent *m) { const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos()); m->accept(); double newX = mousePointDoc.x(); double newY = mousePointDoc.y(); if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed()) { PageItem *currItem = m_doc->m_Selection->itemAt(0); QTransform itemMatrix = currItem->getTransform(); QPointF cPoint = itemMatrix.map(centerPoint); QLineF stLinA = QLineF(cPoint, QPointF(newX, newY)); uint cx = polyUseFactor ? polyCorners * 2 : polyCorners; double seg = 360.0 / cx; double trueLength = sqrt(pow(sin(seg / 180.0 * M_PI) * (currItem->width() / 2.0), 2) + pow(cos(seg / 180.0 * M_PI) * (currItem->height() / 2.0) + (currItem->height()/2.0) - currItem->height(), 2)); if (m_polygonPoint == useControlInner) { polyInnerRot = stLinA.angle() - 90 - polyRotation - seg; double factor = stLinA.length() / sqrt(pow(sin(stLinA.angle() * M_PI / 180.0) * currItem->height() / 2.0, 2) + pow(cos(stLinA.angle() * M_PI / 180.0) * currItem->width() / 2.0, 2)); int maxF = qRound(getUserValFromFactor(factor)); if (maxF <= 100) polyFactor = factor; } if (m_polygonPoint == useControlOuter) { polyRotation = stLinA.angle() - 90; if (polyRotation < -180) polyRotation += 360; if (polyRotation > 180) polyRotation -= 360; } if (m_polygonPoint == useControlInnerCurve) { QPointF ePoint = itemMatrix.map(endPoint); QLineF stLinC = QLineF(ePoint, QPointF(newX, newY)); polyCurvature = stLinC.length() / trueLength; } if (m_polygonPoint == useControlOuterCurve) { QPointF sPoint = itemMatrix.map(startPoint); QPointF sPoint2 = itemMatrix.map(currItem->PoLine.pointQF(6)); QLineF stLinCo = QLineF(sPoint, QPointF(newX, newY)); QLineF stLinCo2 = QLineF(sPoint, sPoint2); polyOuterCurvature = stLinCo.length() / stLinCo2.length(); } QPainterPath path = RegularPolygonPath(currItem->width(), currItem->height(), polyCorners, polyUseFactor, polyFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature); FPointArray ar; ar.fromQPainterPath(path); endPoint = ar.pointQF(2); startPoint = ar.pointQF(0); QLineF innerLine = QLineF(endPoint, centerPoint); innerLine.setAngle(innerLine.angle() + 90); innerLine.setLength(trueLength * polyCurvature); innerCPoint = innerLine.p2(); QLineF outerLine = QLineF(startPoint, ar.pointQF(6)); outerLine.setLength(outerLine.length() * polyOuterCurvature); outerCPoint = outerLine.p2(); VectorDialog->setValues(polyCorners, polyFactor, polyUseFactor, polyRotation, polyCurvature, polyInnerRot, polyOuterCurvature); blockUpdateFromItem(true); currItem->update(); blockUpdateFromItem(false); path = itemMatrix.map(path); m_doc->regionsChanged()->update(path.boundingRect().adjusted(-5, -5, 10, 10)); } Mxp = newX; Myp = newY; }