diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index bf4dcce..6e5773c 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -92,6 +92,15 @@ LeafLayerWrapper::~LeafLayerWrapper() wrappedElement->referencedCount--; } +void LayerWrapper::SimpleProperty::setRotation(double newRotation) +{ + if (newRotation <= -360 || 360 <= newRotation) + { + newRotation -= static_cast(std::round(newRotation)) / 360 * 360; + } + rotation = newRotation; +} + void LayerWrapper::SimpleProperty::apply(PixelPath&cache) { transform.reset(); diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 35b6c1f..95fc5f4 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -48,6 +48,7 @@ class LayerWrapper bool flipY = 0; QTransform transform; // TODO: 将QPainterPath改为BitmapPath + void setRotation(double newRotation); void apply(PixelPath&cache); } property; virtual void setParent(FolderLayerWrapper*newParent); diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 6cc9e27..f910c5a 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -106,7 +106,7 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) else if (event->buttons() & Qt::RightButton) { // 如果按下的是右键,那么旋转图形 qreal angle = dx; - currentLayer->property.rotation += angle; + currentLayer->property.setRotation(currentLayer->property.rotation + angle); } auto layer = currentLayer; while (layer != nullptr) diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index df61f0a..a6d1e01 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -21,29 +21,29 @@ InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent) ui.rotation->setLabel(("鏃嬭浆瑙掑害")); ui.scaleX->setLabel(("姘村钩缂╂斁")); ui.scaleY->setLabel(("鍨傜洿缂╂斁")); - ui.rotation->setValidator(new QIntValidator(-10000, 10000, this)); + ui.rotation->setValidator(new QIntValidator(-360, 360, this)); ui.styleList->setDisabled(true); - connect(ui.rotation, &QLineEdit::textChanged, [=](QString content) { - this->displayLayer->property.rotation = content.toDouble(); + connect(ui.rotation, &QLineEdit::textChanged, [=](const QString& content) { + this->displayLayer->property.setRotation(content.toDouble()); emit triggerCentralRefresh(); }); ui.offsetX->setValidator(new QIntValidator(-10000, 10000, this)); - connect(ui.offsetX, &QLineEdit::textChanged, [=](QString content) { + connect(ui.offsetX, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.offset = { content.toDouble(), this->displayLayer->property.offset.y() }; emit triggerCentralRefresh(); }); ui.offsetY->setValidator(new QIntValidator(-10000, 10000, this)); - connect(ui.offsetY, &QLineEdit::textChanged, [=](QString content) { + connect(ui.offsetY, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.offset = { this->displayLayer->property.offset.x(), content.toDouble() }; emit triggerCentralRefresh(); }); ui.scaleX->setValidator(new QDoubleValidator(0, 1000, 4, this)); - connect(ui.scaleX, &QLineEdit::textChanged, [=](QString content) { + connect(ui.scaleX, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.scale = { content.toDouble(), this->displayLayer->property.scale.y() }; emit triggerCentralRefresh(); }); ui.scaleY->setValidator(new QDoubleValidator(0, 1000, 4, this)); - connect(ui.scaleY, &QLineEdit::textChanged, [=](QString content) { + connect(ui.scaleY, &QLineEdit::textChanged, [=](const QString& content) { this->displayLayer->property.scale = { this->displayLayer->property.scale.x(), content.toDouble() }; emit triggerCentralRefresh(); });