完成除样式外新ui接入 | #10

dev-wuyize
karlis 2023-03-21 15:18:57 +08:00
parent 291d112d11
commit 2b5598a81e
6 changed files with 67 additions and 172 deletions

View File

@ -196,11 +196,6 @@
<string>关联图元</string> <string>关联图元</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>可见</string>
</property>
</column>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -36,7 +36,6 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange); connect(editorSettingWidget, &EditorSettingWidget::backgroundColorChanged, this, &EditorWidgetItem::handleBackgroundColorChange);
connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange); connect(editorSettingWidget, &EditorSettingWidget::projectNameChanged, this, &EditorWidgetItem::handleProjectNameChange);
connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex); connect(previewWindow, &PreviewWindow::refreshElementPreviewByIndex, elementInfoDisplayWidget, &ElementPoolWidget::refreshPictureByIndex);
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged); connect(treeWidget, &LayerTreeWidget::displayLayerChange, previewWindow, &PreviewWindow::currentLayerChanged);
//connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); //connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
// connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);

View File

@ -46,6 +46,8 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
property.scale = {transformJson.value("scale").toObject().value("x").toDouble(), property.scale = {transformJson.value("scale").toObject().value("x").toDouble(),
transformJson.value("scale").toObject().value("y").toDouble()}; transformJson.value("scale").toObject().value("y").toDouble()};
property.rotation = {transformJson.value("rotation").toDouble()}; property.rotation = {transformJson.value("rotation").toDouble()};
property.flipX = { transformJson.value("flipX").toBool() };
property.flipY = { transformJson.value("flipY").toBool() };
selected = false; selected = false;
hidden = false; hidden = false;
} }
@ -100,6 +102,10 @@ void LayerWrapper::SimpleProperty::apply(PixelPath&cache)
transform.translate(centerX, centerY); transform.translate(centerX, centerY);
transform.translate(offset.x(), offset.y()); transform.translate(offset.x(), offset.y());
transform.rotate(rotation); transform.rotate(rotation);
if (flipX)
transform.scale(-1, 1);
if (flipY)
transform.scale(1, -1);
transform.scale(scale.x(), scale.y()); transform.scale(scale.x(), scale.y());
transform.translate(-centerX, -centerY); transform.translate(-centerX, -centerY);
cache = cache.trans(transform); cache = cache.trans(transform);
@ -245,6 +251,8 @@ QJsonObject LayerWrapper::toJson() const
QJsonObject transformJson; QJsonObject transformJson;
transformJson.insert("offset", QJsonObject({ {"x", property.offset.x()}, {"y", property.offset.y()} })); 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("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); transformJson.insert("rotation", property.rotation);
json.insert("transform", transformJson); json.insert("transform", transformJson);
return json; return json;

View File

@ -44,8 +44,8 @@ class LayerWrapper
QPointF scale = {1.0, 1.0}; QPointF scale = {1.0, 1.0};
QPointF offset = {0, 0}; QPointF offset = {0, 0};
double rotation = 0; double rotation = 0;
bool flipHorizontally = 0; bool flipX = 0;
bool flipVertically = 0; bool flipY = 0;
QTransform transform; QTransform transform;
// TODO: 将QPainterPath改为BitmapPath // TODO: 将QPainterPath改为BitmapPath
void apply(PixelPath&cache); void apply(PixelPath&cache);

View File

@ -7,181 +7,77 @@
#include <QComboBox> #include <QComboBox>
#include <qtmaterialraisedbutton.h> #include <qtmaterialraisedbutton.h>
#include <qtmaterialflatbutton.h> #include <qtmaterialflatbutton.h>
#include <QLabel>
#include <QCheckBox>
void InfoDisplayWidget::setLayer(LayerWrapper *layer) void InfoDisplayWidget::setLayer(LayerWrapper *layer)
{ {
this->displayLayer = layer; this->displayLayer = layer;
generateLayerForm(); this->refresh();
} }
void InfoDisplayWidget::generateLayerForm() InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent)
{ {
QLayoutItem *item; ui.setupUi(this);
if (this->layout() != nullptr) this->displayLayer = nullptr;
{ ui.name->setDisabled(true);
while (this->layout()->count() > 0 && (item = this->layout()->takeAt(0)) != nullptr) ui.offsetX->setLabel(("水平偏移"));
{ ui.offsetY->setLabel(("垂直偏移"));
item->widget()->deleteLater(); ui.rotation->setLabel(("旋转角度"));
delete item; ui.scaleX->setLabel(("水平缩放"));
} ui.scaleY->setLabel(("垂直缩放"));
delete this->layout(); ui.rotation->setValidator(new QIntValidator(-10000, 10000, this));
} connect(ui.rotation, &QLineEdit::textChanged, [=](QString content) {
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(); this->displayLayer->property.rotation = content.toDouble();
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
offsetX->setValidator(new QIntValidator(-10000, 10000, this)); ui.offsetX->setValidator(new QIntValidator(-10000, 10000, this));
connect(offsetX, &QLineEdit::textChanged, [=](QString content) { connect(ui.offsetX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()}; this->displayLayer->property.offset = { content.toDouble(), this->displayLayer->property.offset.y() };
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
offsetY->setValidator(new QIntValidator(-10000, 10000, this)); ui.offsetY->setValidator(new QIntValidator(-10000, 10000, this));
connect(offsetY, &QLineEdit::textChanged, [=](QString content) { connect(ui.offsetY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()}; this->displayLayer->property.offset = { this->displayLayer->property.offset.x(), content.toDouble() };
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
scaleX->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); ui.scaleX->setValidator(new QDoubleValidator(0, 1000, 4, this));
connect(scaleX, &QLineEdit::textChanged, [=](QString content) { connect(ui.scaleX, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()}; this->displayLayer->property.scale = { content.toDouble(), this->displayLayer->property.scale.y() };
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
scaleY->setValidator(new QDoubleValidator(-1000, 1000, 4, this)); ui.scaleY->setValidator(new QDoubleValidator(0, 1000, 4, this));
connect(scaleY, &QLineEdit::textChanged, [=](QString content) { connect(ui.scaleY, &QLineEdit::textChanged, [=](QString content) {
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()}; this->displayLayer->property.scale = { this->displayLayer->property.scale.x(), content.toDouble() };
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
connect(ui.flipX, &QtMaterialCheckBox::toggled, [=](bool state) {
layout->addRow("layer name:", name); this->displayLayer->property.flipX = state;
layout->addRow("rotation:", rotation); emit triggerCentralRefresh();
layout->addRow("offset-X:", offsetX); });
layout->addRow("offset-Y:", offsetY); connect(ui.flipY, &QtMaterialCheckBox::toggled, [=](bool state) {
layout->addRow("scale-X:", scaleX); this->displayLayer->property.flipY = state;
layout->addRow("scale-Y:", scaleY);
layout->setRowWrapPolicy(QFormLayout::DontWrapRows);
if (auto* leafP = dynamic_cast<LeafLayerWrapper*>(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(); 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->setHidden(!visiable);
this->generateLayerForm();
} }
void InfoDisplayWidget::refresh() void InfoDisplayWidget::refresh()
{ {
if (this->displayLayer != nullptr) 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);
}
} }

View File

@ -5,26 +5,23 @@
#include <QLabel> #include <QLabel>
#include <QWidget> #include <QWidget>
#include "ElementPoolWidget.h" #include "ElementPoolWidget.h"
#include "ui_EditorLayerInfoWidget.h"
class InfoDisplayWidget : public QWidget class InfoDisplayWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
LayerWrapper *displayLayer; LayerWrapper *displayLayer;
Ui::EditorLayerInfoWidget ui;
public: public:
InfoDisplayWidget(QWidget* parent=nullptr);
void setLayer(LayerWrapper *layer); void setLayer(LayerWrapper *layer);
void generateLayerForm();
void refresh(); void refresh();
void setVisiable(bool visiable);
public slots:
void triggerSelfRefresh();
signals: signals:
void triggerCentralRefresh(); void triggerCentralRefresh();
void requireRefreshPreview();
void requireSelfRefresh();
void requireRefreshElementWidget();
}; };