[editor] 将图层的旋转角度限制在了(-360, 360) | #27

dev-wuyize
ArgonarioD 2023-03-22 17:01:09 +08:00
parent 512181f6a3
commit 62d887aa07
4 changed files with 18 additions and 8 deletions

View File

@ -92,6 +92,15 @@ LeafLayerWrapper::~LeafLayerWrapper()
wrappedElement->referencedCount--;
}
void LayerWrapper::SimpleProperty::setRotation(double newRotation)
{
if (newRotation <= -360 || 360 <= newRotation)
{
newRotation -= static_cast<int>(std::round(newRotation)) / 360 * 360;
}
rotation = newRotation;
}
void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
{
transform.reset();

View File

@ -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);

View File

@ -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)

View File

@ -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();
});