diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp index a567453..ed6743a 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerCreateWidget.cpp @@ -28,7 +28,17 @@ void LayerCreateWidget::accept() jsonObj.insert("is-folder", true); jsonObj.insert("children", QJsonArray()); } - jsonObj.insert("tranform", "{\"offset\":{\"x\":0,\"y\":0},\"scale\":{\"x\":1,\"y\":1},\"rotation\":0}"); + QJsonObject transform; + QJsonObject offset; + QJsonObject scale; + scale.insert("x", 1); + scale.insert("y", 1); + offset.insert("x", 0); + offset.insert("y", 0); + transform.insert("offset", offset); + transform.insert("scale", scale); + transform.insert("rotation", 0); + jsonObj.insert("transform", transform); jsonObj.insert("referenced-by", QJsonValue()); emit LayerInfoReturned(jsonObj); QDialog::accept(); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index deebf88..01ca5b3 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -14,6 +14,8 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p elementInfoDisplayWidget = dynamic_cast(tabWidget->widget(1)); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; + connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); + connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh); connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange); connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, &EditorWidgetItem::triggerRefreshPreview); diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp index 95984c8..daed263 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp @@ -10,7 +10,7 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren elements.push_back(new GroupElement()); else elements.push_back(new SimpleElement(elementJson.toObject())); - + (*elements.rbegin())->name = elementJson.toObject().value("name").toString(); (*elements.rbegin())->renderer = renderer; } for (auto element : elements) @@ -19,10 +19,19 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren void ElementManager::addElement(GraphicElement *element) { + this->elements.push_back(element); } void ElementManager::removeElement(GraphicElement *pElement) { + for (auto& element : elements) + { + if (element == pElement) + { + elements.erase(std::find(elements.begin(), elements.end(), element)); + break; + } + } } GraphicElement *ElementManager::getElementById(int index) @@ -67,4 +76,27 @@ int ElementManager::getLayerReferencedBy(const FolderLayerWrapper* layer) } return -1; +} + + +void ElementManager::removeElement(int index) +{ + if (index < elements.size()) + elements.erase(elements.begin() + index); +} + +void ElementManager::createGroupElement(QString name, FolderLayerWrapper* sourceLayer) { + auto element = new GroupElement(); + element->name = name; + element->setSourceLayer(sourceLayer); + addElement(element); +} +void ElementManager::createSimpleElement(QString name, QString filePath) { + QJsonObject json; + QJsonObject data; + data.insert("include", filePath); + json.insert("data", data); + auto element = new SimpleElement(json); + element->name = name; + addElement(element); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.h b/ArchitectureColoredPainting/src/Editor/ElementManager.h index d077d6e..6c48feb 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.h +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.h @@ -20,6 +20,9 @@ class ElementManager ~ElementManager(); void addElement(GraphicElement *element); void removeElement(GraphicElement *pElement); + void removeElement(int index); + void createGroupElement(QString name, FolderLayerWrapper* sourceLayer); + void createSimpleElement(QString name, QString filePath); QJsonObject toJson()const; /** * only used in initialization diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp index e9d9b82..64fadfd 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp @@ -4,7 +4,7 @@ ElementPoolWidget::ElementPoolWidget(QWidget* parent) : QWidget(parent) { elementManager = nullptr; - iconWidth = 100, iconHeight = 75; + iconWidth = 120, iconHeight = 90; pictureList = new QListWidget(); pictureList->setIconSize(QSize(iconWidth, iconHeight)); pictureList->setWindowFlags(Qt::FramelessWindowHint); @@ -48,7 +48,7 @@ void ElementPoolWidget::setElementList(std::vector elements) { //p->show(); QListWidgetItem* pItem = new QListWidgetItem( - itemPixmap.scaled(QSize(iconWidth - 15, iconHeight - 15)), + itemPixmap.scaled(QSize(iconWidth - 25, iconHeight - 25)), elements[index]->name); pItem->setSizeHint(QSize(iconWidth, iconHeight)); pictureList->insertItem(index, pItem); diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.h b/ArchitectureColoredPainting/src/Editor/GraphicElement.h index cfad73e..c0b3c09 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.h +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.h @@ -40,6 +40,7 @@ private: public: SimpleElement(QJsonObject jsonSource); + SimpleElement(QString filePath); ~SimpleElement() = default; PixelPath getPaintObject() const override; PixelPath getPaintObject(std::vector>*) const override; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index f63ebed..d41d374 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -46,26 +46,31 @@ void InfoDisplayWidget::generateLayerForm() rotation->setValidator(new QIntValidator(-10000, 10000, this)); connect(rotation, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.rotation = content.toDouble(); + emit requireRefreshElementWidget(); emit requireRefreshPreview(); }); 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 requireRefreshElementWidget(); emit requireRefreshPreview(); }); 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 requireRefreshElementWidget(); emit requireRefreshPreview(); }); scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this)); connect(scaleX, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()}; + emit requireRefreshElementWidget(); emit requireRefreshPreview(); }); scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this)); connect(scaleY, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()}; + emit requireRefreshElementWidget(); emit requireRefreshPreview(); }); @@ -106,6 +111,7 @@ void InfoDisplayWidget::generateLayerForm() leafP->styles.push_back(dialog->layerStyle); emit requireRefreshPreview(); emit requireSelfRefresh(); + emit requireRefreshElementWidget(); } dialog->deleteLater(); }); @@ -201,6 +207,7 @@ void InfoDisplayWidget::generateLayerForm() (*styleIterator) = dialog->layerStyle; emit requireRefreshPreview(); emit requireSelfRefresh(); + emit requireRefreshElementWidget(); } dialog->deleteLater(); }); @@ -211,6 +218,7 @@ void InfoDisplayWidget::generateLayerForm() styles->erase(styleIterator); emit requireRefreshPreview(); emit requireSelfRefresh(); + emit requireRefreshElementWidget(); }); QWidget* styleDisplayWidget = (*styleIterator)->getListDisplayWidget(); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h index 11f642b..37b259c 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h @@ -23,6 +23,6 @@ class InfoDisplayWidget : public QWidget signals: void requireRefreshPreview(); void requireSelfRefresh(); - + void requireRefreshElementWidget(); }; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index fd04735..1889d70 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -50,20 +50,22 @@ void LayerTreeWidget::popMenu(const QPoint &pos) newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer); else newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer); + folderLayer->addChild(std::shared_ptr(newLayer)); folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem()); qDebug() << jsonObj<<"----------------------"; this->refresh(); - emit requireRefreshPreview(); + emit requireRefreshPreview(); + emit requireRefreshElementWidget(); }); dialog->exec(); }); menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() { auto layer = this->selectedItem->data(0, Qt::UserRole).value(); - layer->delSelf(); - layer->getParent()->removeChild(layer); - this->refresh(); - emit requireRefreshPreview(); + layer->delSelf(); + layer->getParent()->removeChild(layer); + this->refresh(); + emit requireRefreshPreview(); }); } if (layer != root) { @@ -76,6 +78,21 @@ void LayerTreeWidget::popMenu(const QPoint &pos) }); menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); } + if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) { + menu.addAction(QString::fromLocal8Bit("创建组合元素"), this, [this]() { + auto layer = dynamic_cast(this->selectedItem->data(0, Qt::UserRole).value()); + if (layer != nullptr) { + bool ok; + QString name = QInputDialog::getText(this, QString::fromLocal8Bit("创建组合元素"), + QString::fromLocal8Bit("组合元素名称:"), QLineEdit::Normal, + "", &ok); + if (ok && !name.isEmpty()) { + elementManager->createGroupElement(name, layer); + emit requireRefreshElementWidget(); + } + } + }); + } } } menu.exec(mapToGlobal(pos)); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h index 9c2f574..ca784fd 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h @@ -23,4 +23,5 @@ class LayerTreeWidget : public QTreeWidget signals: void displayLayerChange(LayerWrapper *); void requireRefreshPreview(); + void requireRefreshElementWidget(); };