From 62d887aa07f458f93c11e59eb4a273b7062f95c1 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Wed, 22 Mar 2023 17:01:09 +0800 Subject: [PATCH] =?UTF-8?q?[editor]=20=E5=B0=86=E5=9B=BE=E5=B1=82=E7=9A=84?= =?UTF-8?q?=E6=97=8B=E8=BD=AC=E8=A7=92=E5=BA=A6=E9=99=90=E5=88=B6=E5=9C=A8?= =?UTF-8?q?=E4=BA=86(-360,=20360)=20|=20#27?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/LayerWrapper.cpp | 9 +++++++++ .../src/Editor/LayerWrapper.h | 1 + .../src/Editor/PreviewWindow.cpp | 2 +- .../src/Editor/RightBar/InfoDisplayWidget.cpp | 14 +++++++------- 4 files changed, 18 insertions(+), 8 deletions(-) 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(); });