From 2b5598a81e5cf735c7dee6b09a013fd395ef752a Mon Sep 17 00:00:00 2001
From: karlis <2995621482@qq.com>
Date: Tue, 21 Mar 2023 15:18:57 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=99=A4=E6=A0=B7=E5=BC=8F?=
=?UTF-8?q?=E5=A4=96=E6=96=B0ui=E6=8E=A5=E5=85=A5=20|=20#10?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../EditorWidgetItem.ui | 5 -
.../src/Editor/EditorWidgetItem.cpp | 1 -
.../src/Editor/LayerWrapper.cpp | 8 +
.../src/Editor/LayerWrapper.h | 4 +-
.../src/Editor/RightBar/InfoDisplayWidget.cpp | 210 +++++-------------
.../src/Editor/RightBar/InfoDisplayWidget.h | 11 +-
6 files changed, 67 insertions(+), 172 deletions(-)
diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui
index b8eb51c..ec88bfa 100644
--- a/ArchitectureColoredPainting/EditorWidgetItem.ui
+++ b/ArchitectureColoredPainting/EditorWidgetItem.ui
@@ -196,11 +196,6 @@
关联图元
-
-
- 可见
-
-
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
index 529d648..c126a78 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp
@@ -36,7 +36,6 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange);
connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange);
connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex);
- connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged);
//connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
index caf6dc8..1914721 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
+++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp
@@ -46,6 +46,8 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
transformJson.value("scale").toObject().value("y").toDouble()};
property.rotation = {transformJson.value("rotation").toDouble()};
+ property.flipX = { transformJson.value("flipX").toBool() };
+ property.flipY = { transformJson.value("flipY").toBool() };
selected = false;
hidden = false;
}
@@ -100,6 +102,10 @@ void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
transform.translate(centerX, centerY);
transform.translate(offset.x(), offset.y());
transform.rotate(rotation);
+ if (flipX)
+ transform.scale(-1, 1);
+ if (flipY)
+ transform.scale(1, -1);
transform.scale(scale.x(), scale.y());
transform.translate(-centerX, -centerY);
cache = cache.trans(transform);
@@ -245,6 +251,8 @@ QJsonObject LayerWrapper::toJson() const
QJsonObject transformJson;
transformJson.insert("offset", QJsonObject({ {"x", property.offset.x()}, {"y", property.offset.y()} }));
transformJson.insert("scale", QJsonObject({ {"x", property.scale.x()}, {"y", property.scale.y()} }));
+ transformJson.insert("filpX", property.flipX);
+ transformJson.insert("filpY", property.flipY);
transformJson.insert("rotation", property.rotation);
json.insert("transform", transformJson);
return json;
diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
index c45ec21..35b6c1f 100644
--- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
+++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h
@@ -44,8 +44,8 @@ class LayerWrapper
QPointF scale = {1.0, 1.0};
QPointF offset = {0, 0};
double rotation = 0;
- bool flipHorizontally = 0;
- bool flipVertically = 0;
+ bool flipX = 0;
+ bool flipY = 0;
QTransform transform;
// TODO: QPainterPathΪBitmapPath
void apply(PixelPath&cache);
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp
index 56e46b4..4c86ad0 100644
--- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp
@@ -7,181 +7,77 @@
#include
#include
#include
+#include
+#include
void InfoDisplayWidget::setLayer(LayerWrapper *layer)
{
this->displayLayer = layer;
- generateLayerForm();
+ this->refresh();
}
-void InfoDisplayWidget::generateLayerForm()
+InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent)
{
- QLayoutItem *item;
- if (this->layout() != nullptr)
- {
- while (this->layout()->count() > 0 && (item = this->layout()->takeAt(0)) != nullptr)
- {
- item->widget()->deleteLater();
- delete item;
- }
- delete this->layout();
- }
- QFormLayout *layout = new QFormLayout();
- layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
- if (this->displayLayer == nullptr)
- {
- layout->addRow("no selected layer", new QLabel());
- }
- else
- {
- QLineEdit *name = new QLineEdit(this->displayLayer->property.name, this);
- QLineEdit *rotation = new QLineEdit(QString::number(this->displayLayer->property.rotation, 'f', 0), this);
- QLineEdit *offsetX = new QLineEdit(QString::number(this->displayLayer->property.offset.x()), this);
- QLineEdit *offsetY = new QLineEdit(QString::number(this->displayLayer->property.offset.y()), this);
- QLineEdit *scaleX = new QLineEdit(QString::number(this->displayLayer->property.scale.x()), this);
- QLineEdit *scaleY = new QLineEdit(QString::number(this->displayLayer->property.scale.y()), this);
- name->setDisabled(true);
- rotation->setValidator(new QIntValidator(-10000, 10000, this));
- connect(rotation, &QLineEdit::textChanged, [=](QString content) {
- this->displayLayer->property.rotation = content.toDouble();
- emit triggerCentralRefresh();
+ ui.setupUi(this);
+ this->displayLayer = nullptr;
+ ui.name->setDisabled(true);
+ ui.offsetX->setLabel(("水平偏移"));
+ ui.offsetY->setLabel(("垂直偏移"));
+ ui.rotation->setLabel(("旋转角度"));
+ ui.scaleX->setLabel(("水平缩放"));
+ ui.scaleY->setLabel(("垂直缩放"));
+ ui.rotation->setValidator(new QIntValidator(-10000, 10000, this));
+ connect(ui.rotation, &QLineEdit::textChanged, [=](QString content) {
+ this->displayLayer->property.rotation = content.toDouble();
+ emit triggerCentralRefresh();
});
- offsetX->setValidator(new QIntValidator(-10000, 10000, this));
- connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
- this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
- emit triggerCentralRefresh();
+ ui.offsetX->setValidator(new QIntValidator(-10000, 10000, this));
+ connect(ui.offsetX, &QLineEdit::textChanged, [=](QString content) {
+ this->displayLayer->property.offset = { content.toDouble(), this->displayLayer->property.offset.y() };
+ emit triggerCentralRefresh();
});
- offsetY->setValidator(new QIntValidator(-10000, 10000, this));
- connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
- this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
- emit triggerCentralRefresh();
+ ui.offsetY->setValidator(new QIntValidator(-10000, 10000, this));
+ connect(ui.offsetY, &QLineEdit::textChanged, [=](QString content) {
+ this->displayLayer->property.offset = { this->displayLayer->property.offset.x(), content.toDouble() };
+ emit triggerCentralRefresh();
});
- scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
- connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
- this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
- emit triggerCentralRefresh();
+ ui.scaleX->setValidator(new QDoubleValidator(0, 1000, 4, this));
+ connect(ui.scaleX, &QLineEdit::textChanged, [=](QString content) {
+ this->displayLayer->property.scale = { content.toDouble(), this->displayLayer->property.scale.y() };
+ emit triggerCentralRefresh();
});
- scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this));
- connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
- this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
- emit triggerCentralRefresh();
+ ui.scaleY->setValidator(new QDoubleValidator(0, 1000, 4, this));
+ connect(ui.scaleY, &QLineEdit::textChanged, [=](QString content) {
+ this->displayLayer->property.scale = { this->displayLayer->property.scale.x(), content.toDouble() };
+ emit triggerCentralRefresh();
+ });
+ connect(ui.flipX, &QtMaterialCheckBox::toggled, [=](bool state) {
+ this->displayLayer->property.flipX = state;
+ emit triggerCentralRefresh();
+ });
+ connect(ui.flipY, &QtMaterialCheckBox::toggled, [=](bool state) {
+ this->displayLayer->property.flipY = state;
+ emit triggerCentralRefresh();
});
-
- layout->addRow("layer name:", name);
- layout->addRow("rotation:", rotation);
- layout->addRow("offset-X:", offsetX);
- layout->addRow("offset-Y:", offsetY);
- layout->addRow("scale-X:", scaleX);
- layout->addRow("scale-Y:", scaleY);
- layout->setRowWrapPolicy(QFormLayout::DontWrapRows);
-
- if (auto* leafP = dynamic_cast(this->displayLayer); leafP) {
- auto* styleList = new QListWidget(this);
-
- auto* header = new QListWidgetItem;
- auto* headerWidget = new QWidget(styleList);
- auto* headerLayout = new QHBoxLayout;
-
- auto* headerLabel = new QLabel(headerWidget);
- headerLabel->setText("样式列表");
- headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
-
- //QtMaterialRaisedButton* addStyleButton = new QtMaterialRaisedButton("+", headerWidget);
- auto* addStyleButton = new QPushButton("+", headerWidget);
- addStyleButton->setFixedSize(QSize(20, 20));
- if (leafP->styles.full())
- {
- addStyleButton->setDisabled(true);
- }
- else
- {
- connect(addStyleButton, &QPushButton::clicked, [&, leafP] {
- auto* dialog = new LayerStyleDialog(leafP->styles, nullptr, this);
- dialog->exec();
- if (dialog->layerStyle)
- {
- leafP->styles.useStyle(dialog->layerStyle);
- leafP->styles.computeNewHash();
- emit triggerCentralRefresh();
- }
- });
- }
-
- headerLayout->addWidget(headerLabel);
- headerLayout->addWidget(addStyleButton);
- headerLayout->setContentsMargins(5, 0, 5, 0);
- headerWidget->setLayout(headerLayout);
-
- header->setFlags(Qt::NoItemFlags);
- styleList->addItem(header);
- styleList->setItemWidget(header, headerWidget);
-
- auto* styles = &leafP->styles;
- for (auto styleIterator = styles->begin(); styleIterator != styles->end(); ++styleIterator)
- {
- auto* item = new QListWidgetItem;
- auto* w = new QWidget(this);
- item->setSizeHint(QSize(50, 40));
- auto* layout = new QHBoxLayout(w);
- layout->setAlignment(Qt::AlignmentFlag::AlignRight);
- //QtMaterialFlatButton* detailButton = new QtMaterialFlatButton(w);
- //QtMaterialFlatButton* removeButton = new QtMaterialFlatButton(w);
- auto* detailButton = new QPushButton(w);
- auto* removeButton = new QPushButton(w);
- detailButton->setText("...");
- detailButton->setFixedSize(QSize(20, 20));
- removeButton->setText("×");
- removeButton->setFixedSize(QSize(20, 20));
-
- connect(detailButton, &QPushButton::clicked, this,
- [this, styles, styleIterator]
- {
- auto* dialog =
- new LayerStyleDialog(*styles, styleIterator->second, this);
- dialog->exec();
-
- if (dialog->layerStyle)
- {
- styleIterator->second = dialog->layerStyle;
- styles->computeNewHash();
- emit triggerCentralRefresh();
- }
- });
-
- connect(removeButton, &QPushButton::clicked, this,
- [this, styleIterator, styles]
- {
- styles->dropStyle(styleIterator->first);
- styles->computeNewHash();
- emit triggerCentralRefresh();
- });
-
- QWidget* styleDisplayWidget = styleIterator->second->getListDisplayWidget();
- styleDisplayWidget->setParent(w);
- styleDisplayWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
-
- layout->addWidget(styleDisplayWidget);
- layout->addWidget(detailButton);
- layout->addWidget(removeButton);
- w->setLayout(layout);
-
- styleList->addItem(item);
- styleList->setItemWidget(item, w);
- }
- layout->addRow(styleList);
- }
- }
- this->setLayout(layout);
}
-void InfoDisplayWidget::triggerSelfRefresh()
+void InfoDisplayWidget::setVisiable(bool visiable)
{
- if (this->displayLayer != nullptr)
- this->generateLayerForm();
+ this->setHidden(!visiable);
}
void InfoDisplayWidget::refresh()
{
if (this->displayLayer != nullptr)
- this->generateLayerForm();
+ {
+ //this->setVisiable(true);
+ ui.name->setText(this->displayLayer->property.name);
+ ui.offsetX->setText(QString::number(this->displayLayer->property.offset.x()));
+ ui.offsetY->setText(QString::number(this->displayLayer->property.offset.y()));
+ ui.rotation->setText(QString::number(this->displayLayer->property.rotation));
+ ui.scaleX->setText(QString::number(this->displayLayer->property.scale.x()));
+ ui.scaleY->setText(QString::number(this->displayLayer->property.scale.y()));
+ ui.flipX->setChecked(this->displayLayer->property.flipX);
+ ui.flipY->setChecked(this->displayLayer->property.flipY);
+ }
}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
index da314f5..c0a08a0 100644
--- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h
@@ -5,26 +5,23 @@
#include
#include
#include "ElementPoolWidget.h"
+#include "ui_EditorLayerInfoWidget.h"
class InfoDisplayWidget : public QWidget
{
Q_OBJECT
private:
LayerWrapper *displayLayer;
+ Ui::EditorLayerInfoWidget ui;
public:
+ InfoDisplayWidget(QWidget* parent=nullptr);
void setLayer(LayerWrapper *layer);
- void generateLayerForm();
void refresh();
-
- public slots:
- void triggerSelfRefresh();
+ void setVisiable(bool visiable);
signals:
void triggerCentralRefresh();
- void requireRefreshPreview();
- void requireSelfRefresh();
- void requireRefreshElementWidget();
};