完成除样式外新ui接入 | #10
parent
291d112d11
commit
2b5598a81e
|
@ -196,11 +196,6 @@
|
|||
<string>关联图元</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>可见</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -7,181 +7,77 @@
|
|||
#include <QComboBox>
|
||||
#include <qtmaterialraisedbutton.h>
|
||||
#include <qtmaterialflatbutton.h>
|
||||
#include <QLabel>
|
||||
#include <QCheckBox>
|
||||
|
||||
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<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();
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -5,26 +5,23 @@
|
|||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#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();
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue