diff --git a/src/tools/UBGraphicsProtractor.cpp b/src/tools/UBGraphicsProtractor.cpp index 05b84257..eb9659fd 100644 --- a/src/tools/UBGraphicsProtractor.cpp +++ b/src/tools/UBGraphicsProtractor.cpp @@ -35,6 +35,10 @@ #include "core/memcheck.h" +#include + +//#include + const QRectF UBGraphicsProtractor::sDefaultRect = QRectF(-175, -175, 350, 350); @@ -78,7 +82,9 @@ UBGraphicsProtractor::UBGraphicsProtractor() setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::CppTool)); //Necessary to set if we want z value to be assigned correctly setFlag(QGraphicsItem::ItemIsSelectable, false); - setTransform(QTransform::fromScale(1.5, 1.5), true); + setScale(1.5); + + } @@ -181,7 +187,6 @@ void UBGraphicsProtractor::mousePressEvent(QGraphicsSceneMouseEvent *event) event->accept(); } - void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { QPointF currentPoint = event->pos(); @@ -190,6 +195,13 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) qreal angle = startLine.angleTo(currentLine); qreal scaleFactor = currentLine.length()/startLine.length(); + qreal mod_angle = 0; + if (angle>350) + { + mod_angle= angle - 360; // only for debugging + angle= angle - 360; + } + switch (mCurrentTool) { case Rotate : @@ -197,14 +209,18 @@ void UBGraphicsProtractor::mouseMoveEvent(QGraphicsSceneMouseEvent *event) mStartAngle = mStartAngle + angle; setStartAngle(mStartAngle * 16); mPreviousMousePos = currentPoint; + + //qDebug() << "UBGraphicsProtractor Rotate"<<"mStartAngle= "<setPos(pos_close_x,pos_close_y); + mCloseSvgItem->resetTransform(); - mCloseSvgItem->setTransform(QTransform::fromTranslate(-closeButtonRect().left(),-closeButtonRect().top()), true); - mCloseSvgItem->setRotation(rotation() -mStartAngle); - mCloseSvgItem->setTransform(QTransform::fromTranslate(closeButtonRect().left(), closeButtonRect().top()), true); - mCloseSvgItem->setTransform(QTransform::fromScale(scale * antiSc, scale * antiSc), true);//this do not impact the bounding box of thr svg item... + //mCloseSvgItem->translate(-closeButtonRect().left(),-closeButtonRect().top()); -- + mCloseSvgItem->setPos(-pos_close_x,-pos_close_y); + //mCloseSvgItem->setPos(-closeButtonRect().left(),-closeButtonRect().top()); + //mCloseSvgItem->rotate(-mStartAngle); -- + mCloseSvgItem->setRotation(rotation() - mStartAngle); + //mCloseSvgItem->translate(closeButtonRect().left(), closeButtonRect().top()); -- + mCloseSvgItem->setPos(pos_close_x, pos_close_y); + + //mCloseSvgItem->setPos(closeButtonRect().left(), closeButtonRect().top()); + //mCloseSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... + mCloseSvgItem->setScale(scale );//this do not impact the bounding box of thr svg item... + - mResetSvgItem->setPos(resetButtonRect().topLeft() + rect().center()); + // Determine and apply the position on the reset button object. + //------------------------------------------------------------ + qreal pos_reset_x = resetButtonRect().topLeft().x()* co; + qreal pos_reset_y = qAbs(resetButtonRect().topLeft().x()) * si + resetButtonRect().topLeft().y(); + + mResetSvgItem->setPos(pos_reset_x,pos_reset_y); + + //mResetSvgItem->setPos(resetButtonRect().topLeft() + rect().center()); mResetSvgItem->resetTransform(); - mResetSvgItem->setTransform(QTransform::fromTranslate(-resetButtonRect().left(), -resetButtonRect().top()), true); - mResetSvgItem->setRotation(rotation() -mStartAngle); - mResetSvgItem->setTransform(QTransform::fromTranslate(resetButtonRect().left(), resetButtonRect().top()), true); - mResetSvgItem->setTransform(QTransform::fromScale(scale * antiSc, scale * antiSc), true);//this do not impact the bounding box of thr svg item... + //mResetSvgItem->translate(-resetButtonRect().left(), -resetButtonRect().top());-- + mResetSvgItem->setPos(-pos_reset_x, -pos_reset_y); + + //mResetSvgItem->rotate(-mStartAngle);-- + mResetSvgItem->setRotation(-mStartAngle); + + //mResetSvgItem->translate(resetButtonRect().left(), resetButtonRect().top());-- + mResetSvgItem->setPos(pos_reset_x, pos_reset_y); + + //mResetSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... + mResetSvgItem->setScale(scale );//this do not impact the bounding box of thr svg item... + + + // Determine and apply the position on the resize button object. + //------------------------------------------------------------ + + qreal pos_resize_x = resizeButtonRect().topLeft().x()* co; + qreal pos_resize_y = -(resizeButtonRect().topLeft().x()) * si + resizeButtonRect().topLeft().y(); + + qDebug() << "pos_resize_x ="<setPos(resizeButtonRect().topLeft() + rect().center()); + // mResizeSvgItem->setPos(resizeButtonRect().topLeft() + rect().center()); + mResizeSvgItem->setPos(pos_resize_x,pos_resize_y); mResizeSvgItem->resetTransform(); - mResizeSvgItem->setTransform(QTransform::fromTranslate(-resizeButtonRect().left(), -resizeButtonRect().top()), true); - mResizeSvgItem->setRotation(rotation() -mStartAngle); - mResizeSvgItem->setTransform(QTransform::fromTranslate(resizeButtonRect().left(), resizeButtonRect().top()), true); - mResizeSvgItem->setTransform(QTransform::fromScale(scale * antiSc, scale * antiSc), true);//this do not impact the bounding box of thr svg item... + mResizeSvgItem->setPos(-pos_resize_x, -pos_resize_y); + //mResizeSvgItem->rotate(-mStartAngle);-- + mResizeSvgItem->setRotation(-mStartAngle); - mRotateSvgItem->setPos(rotateButtonRect().topLeft() + rect().center()); + //mResizeSvgItem->translate(-resizeButtonRect().left(), -resizeButtonRect().top());-- + mResizeSvgItem->setPos(pos_resize_x, pos_resize_y); + // mResizeSvgItem->scale(scale * antiSc, scale * antiSc);//this do not impact the bounding box of thr svg item... + mResizeSvgItem->setScale(scale);//this do not impact the bounding box of thr svg item... + + // Determine and apply the position on the rotate button object. + //-------------------------------------------------------------- + qreal qPow_x = qPow(rotateButtonRect().topLeft().x(),2); + qreal qPow_y = qPow(rotateButtonRect().topLeft().y(),2); + qreal module_rotate_pos = qSqrt(qPow_x + qPow_y); + + qreal arg_rotate_pos = (qAtan2(rotateButtonRect().topLeft().y(), rotateButtonRect().topLeft().x())); //argument in radian + qreal co_r = cos(-mStartAngle * PI/180 + arg_rotate_pos); // cos(rad) + qreal si_r = sin(-mStartAngle * PI/180 + arg_rotate_pos); //sin(rad) + + + qreal pos_rotate_x = (module_rotate_pos * co_r) ; + qreal pos_rotate_y = (module_rotate_pos * si_r) ; + + mRotateSvgItem->setPos(pos_rotate_x,pos_rotate_y); + //mRotateSvgItem->setPos(rotateButtonRect().topLeft() + rect().center()); -- mRotateSvgItem->resetTransform(); - mRotateSvgItem->setTransform(QTransform::fromTranslate(-rotateButtonRect().left(), -rotateButtonRect().top()), true); - mRotateSvgItem->setRotation(rotation() -mStartAngle); - mRotateSvgItem->setTransform(QTransform::fromTranslate(rotateButtonRect().left(), rotateButtonRect().top()), true); - mRotateSvgItem->setTransform(QTransform::fromScale(scale, scale), true);//this do not impact the bounding box of thr svg item... + mRotateSvgItem->setPos(-pos_rotate_x, -pos_rotate_y); + //mRotateSvgItem->rotate(-mStartAngle);-- + mRotateSvgItem->setRotation(-mStartAngle); + + mRotateSvgItem->setPos(pos_rotate_x, pos_rotate_y); + //mRotateSvgItem->scale(scale, scale);//this do not impact the bounding box of thr svg item... + mRotateSvgItem->setScale(scale);//this do not impact the bounding box of thr svg item... + + //qDebug()<<"UBGraphicsProtractor scale()"<<"scale ="<boundingRect().height() * radius()/(10 * mCloseSvgItem->boundingRect().width()));} QSizeF markerSizeReference () const{return QSizeF(radius() / 10, mMarkerSvgItem->boundingRect().height() * radius()/(10 * mMarkerSvgItem->boundingRect().width()));} QRectF resetButtonRect () const; + QRectF closeButtonRect () const; QRectF resizeButtonRect () const; QRectF rotateButtonRect () const{return QRectF(buttonSizeReference().width() * 5.5, -buttonSizeReference().width() * 5, buttonSizeReference().width(), buttonSizeReference().width());}