2024-08-26 17:27:37 +08:00
|
|
|
|
#include "util/rotationSelector.h"
|
|
|
|
|
|
#include <QGraphicsSceneMouseEvent>
|
|
|
|
|
|
#include <QGraphicsView>
|
|
|
|
|
|
#include <graphicsItem/graphicsBaseItem.h>
|
|
|
|
|
|
|
|
|
|
|
|
RotationSelector::RotationSelector(QObject *parent)
|
|
|
|
|
|
: BaseSelector(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_type = ST_rotation;
|
|
|
|
|
|
}
|
|
|
|
|
|
RotationSelector::~RotationSelector()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RotationSelector::mousePressEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RotationSelector::mouseMoveEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
|
|
|
|
{
|
|
|
|
|
|
ms_ptMouseLast = event->scenePos();
|
|
|
|
|
|
QList<QGraphicsItem *> items = scene->selectedItems();
|
|
|
|
|
|
if (items.count() == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
GraphicsBaseItem* item = qgraphicsitem_cast<GraphicsBaseItem*>(items.first());
|
|
|
|
|
|
if(item)
|
|
|
|
|
|
{
|
|
|
|
|
|
//计算夹角
|
|
|
|
|
|
QPointF originPoint = item->mapToScene(item->boundingRect().center());
|
|
|
|
|
|
double dLengthY = ms_ptMouseLast.y() - originPoint.y();
|
|
|
|
|
|
double dLengthX = ms_ptMouseLast.x() - originPoint.x();
|
|
|
|
|
|
double dAngleMouseToItem = atan2(dLengthY, dLengthX) * 180 / M_PI;
|
2024-08-28 19:47:41 +08:00
|
|
|
|
// if(atan2(dLengthY, dLengthX) < 0)
|
|
|
|
|
|
// dAngleMouseToItem += 360.0;
|
2024-08-26 17:27:37 +08:00
|
|
|
|
|
|
|
|
|
|
double rotationAngle = item->rotation() + (dAngleMouseToItem - ms_dAngleMouseDownToItem);
|
2024-08-28 19:47:41 +08:00
|
|
|
|
//让角度保持在正负180的区间,也就是上下两个半圈,这样易于象限判断
|
|
|
|
|
|
if (rotationAngle > 180)
|
2024-08-26 17:27:37 +08:00
|
|
|
|
rotationAngle -= 360;
|
2024-08-28 19:47:41 +08:00
|
|
|
|
if (rotationAngle < -180)
|
2024-08-26 17:27:37 +08:00
|
|
|
|
rotationAngle += 360;
|
|
|
|
|
|
|
|
|
|
|
|
item->rotateOperationCopy(rotationAngle);
|
2024-08-28 19:47:41 +08:00
|
|
|
|
//qDebug() << " rotationAngle:" << rotationAngle;
|
2024-08-26 17:27:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RotationSelector::mouseReleaseEvent(QGraphicsSceneMouseEvent* event, DesignerScene* scene)
|
|
|
|
|
|
{
|
|
|
|
|
|
QList<QGraphicsItem *> items = scene->selectedItems();
|
|
|
|
|
|
for(int n = 0; n < items.size(); n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
GraphicsBaseItem* item = qgraphicsitem_cast<GraphicsBaseItem*>(items.at(n));
|
|
|
|
|
|
if(item)
|
2024-08-28 19:47:41 +08:00
|
|
|
|
{
|
2024-08-26 17:27:37 +08:00
|
|
|
|
item->removeOperationCopy();
|
2024-08-28 19:47:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-08-26 17:27:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ms_nDragHandle = H_none;
|
|
|
|
|
|
setCursor(scene, Qt::ArrowCursor);
|
|
|
|
|
|
emit setWorkingSelector(ST_base);
|
|
|
|
|
|
}
|