diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index aea28b0..73f9357 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -37,38 +37,87 @@ - - - 0 - - - 0 - - - 0 - - - 0 - + - + + + + 0 + 0 + + - 1080 - 1080 + 0 + 0 - 1080 - 1080 + 10801080 + 10801080 + + true + + + + + 0 + 0 + 1024 + 1024 + + + + + 0 + 0 + + + + + 1024 + 1024 + + + + + 10241024 + 10241024 + + + + + + + + 0 + 0 + + + + + 1024 + 1024 + + + + + 1024 + 1024 + + + + + + @@ -138,6 +187,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp index 2c990de..b51987b 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp @@ -24,7 +24,8 @@ EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent) }); connect(this->openButton, &QPushButton::clicked, this, [this]() { QString fileName = QFileDialog::getOpenFileName(this->saveAsButton, QString::fromLocal8Bit("打开"), "", QString::fromLocal8Bit("JSON文件(*.json)")); - this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName); + if(!fileName.isEmpty()) + this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName); }); connect(this->closeButton, &QPushButton::clicked, this, [this]() { this->tabWidget->removeTab(this->tabWidget->currentIndex()); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index ab1f096..9525287 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -12,6 +12,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p this->filePath = filePath; layerInfoDisplayWidget = dynamic_cast(tabWidget->widget(0)); elementInfoDisplayWidget = dynamic_cast(tabWidget->widget(1)); + elementInfoDisplayWidget->enableEdit(); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); @@ -37,7 +38,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p qDebug() << jError.errorString(); // end test QJsonObject source = jsonDoc.object(); - elementManager = new ElementManager(source,previewWindow->getRenderer()); + elementManager = new ElementManager(source,Renderer::ElementRenderer::instance()); layerManager = new LayerManager(source, elementManager); elementInfoDisplayWidget->setElementManager(elementManager); treeWidget->elementManager = elementManager; diff --git a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp index daed263..7b5b80c 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementManager.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementManager.cpp @@ -97,6 +97,7 @@ void ElementManager::createSimpleElement(QString name, QString filePath) { data.insert("include", filePath); json.insert("data", data); auto element = new SimpleElement(json); + qDebug() << element->painterPath; element->name = name; addElement(element); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp index 1c5dc3c..0ec51b0 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp @@ -1,11 +1,16 @@ #include "ElementPoolWidget.h" +#include +#include +#include +#include ElementPoolWidget::ElementPoolWidget(QWidget* parent) : QWidget(parent) { elementManager = nullptr; iconWidth = 120, iconHeight = 90; - pictureList = new QListWidget(); + pictureList = new QListWidget(this); + pictureList->setContextMenuPolicy(Qt::CustomContextMenu); pictureList->setIconSize(QSize(iconWidth, iconHeight)); pictureList->setWindowFlags(Qt::FramelessWindowHint); pictureList->setResizeMode(QListWidget::Adjust); @@ -88,4 +93,50 @@ void ElementPoolWidget::refreshPicture(GraphicElement* element) { return; } } +} + +void ElementPoolWidget::enableEdit() +{ + connect(this->pictureList, &QListWidget::customContextMenuRequested, this, &ElementPoolWidget::popMenu); +} + +void ElementPoolWidget::popMenu(const QPoint& pos) +{ + QListWidgetItem* item = pictureList->itemAt(pos); + int currentIndex = -1; + if (item != nullptr) + { + currentIndex = pictureList->row(item); + } + QMenu* menu = new QMenu(this); + if (currentIndex >= 0 && currentIndex < elementManager->elements.size()) + { + auto currentElement = this->elementManager->elements[currentIndex]; + menu->addAction(QString::fromLocal8Bit("重命名"), this, [this, currentElement]() { + bool bOk = false; + QString sName = + QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("新名称:"), QLineEdit::Normal, currentElement->name, &bOk); + if (bOk && !sName.isEmpty()) + { + currentElement->name = sName; + refresh(); + } + }); + menu->addAction(QString::fromLocal8Bit("删除"), this, [this, currentElement]() { + this->elementManager->removeElement(currentElement); + refresh(); + }); + } + else + { + menu->addAction(QString::fromLocal8Bit("添加元素(从svg导入)"), this, [this]() { + QString filePath = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("打开文件"), "", "SVG Files (*.svg)"); + QFileInfo fileInfo(filePath); + QString fileName = fileInfo.fileName(); + qDebug() << fileName << " " << filePath; + this->elementManager->createSimpleElement(fileName, filePath); + refresh(); + }); + } + menu->popup(mapToGlobal(pos)); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h index f6c253e..d4c9cef 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.h @@ -21,6 +21,7 @@ public: void setElementList(std::vector elementList); void setElementManager(ElementManager* element); ~ElementPoolWidget(); + void enableEdit(); signals: void elementSelected(GraphicElement* element); @@ -29,5 +30,6 @@ public slots: int pictureItemClicked(QListWidgetItem* item); void refresh(); void refreshPicture(GraphicElement* element); + void popMenu(const QPoint& pos); }; diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 02af86d..36f81dc 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -25,7 +25,8 @@ SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource) painterPath.clear(); filePath = jsonSource["data"].toObject()["include"].toString(); //loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg"); - loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString()); + QFileInfo info(filePath); + loadSvgFile(filePath); } GroupElement::GroupElement(FolderLayerWrapper* sourceLayer) diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 8b07e72..d5f28e7 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -26,7 +26,6 @@ FolderLayerWrapper*LayerWrapper::getParent() const PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer) { this->refresh(selectedLayer); - qDebug() << cache.painterPath; if (selectedLayer == this) { this->cache.highLight(); @@ -131,9 +130,7 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer) cache.clear(); if (wrappedElement != nullptr) { - qDebug() << cache.painterPath; cache.addPath(wrappedElement->getPaintObject(&(this->styles))); - qDebug() << cache.painterPath; } LayerWrapper::refresh(); } diff --git a/ArchitectureColoredPainting/src/Editor/PixelPath.h b/ArchitectureColoredPainting/src/Editor/PixelPath.h index ced76ff..5ab8614 100644 --- a/ArchitectureColoredPainting/src/Editor/PixelPath.h +++ b/ArchitectureColoredPainting/src/Editor/PixelPath.h @@ -13,8 +13,8 @@ public: QPainterPath painterPath; int w,h; public: - PixelPath(int w=1080, int h= 1080); - PixelPath(QPainterPath painterPath,int w = 1080, int h = 1080); + PixelPath(int w=1024, int h= 1024); + PixelPath(QPainterPath painterPath,int w = 1024, int h = 1024); ~PixelPath() = default; QRectF getBoundingRect() const; QPixmap getPixmap() const; diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index 485977d..9fb8060 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -2,7 +2,8 @@ PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent) { - this->setFixedSize(QSize(1080, 1080)); + //this->setFixedSize(QSize(108, 108)); + this->setStyleSheet("border: 1px solid black"); this->renderer = Renderer::ElementRenderer::instance(); QSurfaceFormat surfaceFormat; surfaceFormat.setSamples(16); diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index 1e84c88..a27da25 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -68,13 +68,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos) }); 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(); - }); } if (layer != root) { menu.addAction(QString::fromLocal8Bit("删除"), this, [this]() { @@ -85,6 +78,13 @@ void LayerTreeWidget::popMenu(const QPoint &pos) emit requireRefreshPreview(); }); menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent); + 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(); + }); } if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) { menu.addAction(QString::fromLocal8Bit("创建组合元素"), this, [this]() { diff --git a/data.json b/data.json index 150cb6c..4f381cb 100644 --- a/data.json +++ b/data.json @@ -6,7 +6,7 @@ "name": "ababa", "type": "svg-file", "data": { - "include": "./svg/2.svg" + "include": "../svg/2.svg" } }, { @@ -15,6 +15,13 @@ "data": { "reference-layer": "0.0" } + }, + { + "name": "ababa2", + "type": "svg-file", + "data": { + "include": "../svg/0.svg" + } } ], "root-layer": {