diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui index e269e9d..b8eb51c 100644 --- a/ArchitectureColoredPainting/EditorWidgetItem.ui +++ b/ArchitectureColoredPainting/EditorWidgetItem.ui @@ -180,6 +180,12 @@ + + + 10 + 10 + + 图层名 @@ -190,6 +196,11 @@ 关联图元 + + + 可见 + + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index eb5f228..2693b45 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -25,6 +25,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p treeWidget->refresh(); previewWindow->refresh(); }; + connect(previewWindow, &PreviewWindow::triggerCentralRefresh, centralRefresh); connect(layerInfoDisplayWidget, &InfoDisplayWidget::triggerCentralRefresh, centralRefresh); connect(elementInfoDisplayWidget, &ElementPoolWidget::triggerCentralRefresh, centralRefresh); connect(treeWidget, &LayerTreeWidget::triggerCentralRefresh, centralRefresh); @@ -33,15 +34,15 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p 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); + //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); - connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this, - &EditorWidgetItem::triggerRefreshPreview); - connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); - connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh); + // connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, + // &EditorWidgetItem::triggerRefreshPreview); + // connect(treeWidget, &LayerTreeWidget::requireRefreshPreview, this, + // &EditorWidgetItem::triggerRefreshPreview); + //connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireSelfRefresh, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh); + // connect(elementInfoDisplayWidget, &ElementPoolWidget::refreshLayerTree, treeWidget, &LayerTreeWidget::refresh); // &EditorWidget::triggerRefreshPreview); // test QFile settingFile; @@ -73,9 +74,10 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p this->projectName = source.value("project-name").toString(); qDebug() << this->backgroundColor; qDebug() << this->projectName; - QTimer::singleShot(300, this, [this]() { + QTimer::singleShot(300, this, [this, centralRefresh]() { handleBackgroundColorChange(this->backgroundColor); handleProjectNameChange(this->projectName); + centralRefresh(); }); } diff --git a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp index 4cc2ef3..01f6df5 100644 --- a/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp +++ b/ArchitectureColoredPainting/src/Editor/GraphicElement.cpp @@ -127,7 +127,7 @@ bool SimpleElement::isClosed() const void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) { - sourceLayer->paint(painter, transform); + sourceLayer->paint(painter, transform, true); } bool GroupElement::isClosed() const diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index bf0222b..1240eb2 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -47,6 +47,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM transformJson.value("scale").toObject().value("y").toDouble()}; property.rotation = {transformJson.value("rotation").toDouble()}; selected = false; + hidden = false; } FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) @@ -199,6 +200,7 @@ void FolderLayerWrapper::delSelf() { QTreeWidgetItem* LayerWrapper::getQTreeItem() { this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this)); + this->qTreeWidgetItem->setCheckState(0, Qt::Checked); return this->qTreeWidgetItem; } @@ -280,31 +282,27 @@ int FolderLayerWrapper::getReferencedBy()const return -1; } -void LayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void LayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - if (!ignoreSelected && this->selected) - { - painter->save(); - painter->setTransform(transform, ignoreSelected); - painter->setPen(QPen(Qt::gray, 2)); - painter->setPen(Qt::DashLine); - painter->drawRect(cache.getBoundingRect()); - painter->restore(); - } + } -void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - LayerWrapper::paint(painter, transform, ignoreSelected); + if (hidden && !force) + return; + LayerWrapper::paint(painter, transform, force); transform = property.transform * transform; //qDebug() << transform; for (auto& child : children) - child->paint(painter, transform, ignoreSelected); + child->paint(painter, transform, force); } -void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool ignoreSelected) +void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) { - LayerWrapper::paint(painter, transform, ignoreSelected); + if (hidden && !force) + return; + LayerWrapper::paint(painter, transform, force); transform = property.transform * transform; //qDebug() << transform; if (wrappedElement != nullptr) @@ -347,11 +345,12 @@ void FolderLayerWrapper::collectDownReachable(std::set& reachable void LayerWrapper::refreshTreeItem() { - + hidden = qTreeWidgetItem->checkState(0) == Qt::Unchecked; } void LeafLayerWrapper::refreshTreeItem() { + LayerWrapper::refreshTreeItem(); if (typeid(*wrappedElement) == typeid(GroupElement)) { this->qTreeWidgetItem->setText(0, "@ " + this->property.name); @@ -366,6 +365,7 @@ void LeafLayerWrapper::refreshTreeItem() void FolderLayerWrapper::refreshTreeItem() { + LayerWrapper::refreshTreeItem(); for (auto& child : this->children) { child->refreshTreeItem(); } diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h index 947d90c..6312f12 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.h +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.h @@ -37,6 +37,7 @@ class LayerWrapper public: QTreeWidgetItem* qTreeWidgetItem; bool selected; + bool hidden; struct SimpleProperty { QString name = ""; @@ -58,7 +59,7 @@ class LayerWrapper FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr); LayerWrapper() = default; - virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool ignoreSelected = false); + virtual void paint(QPainter* painter, QTransform transform=QTransform(), bool force = false); // TODO : export Function // virtual LayerWrapper *addChild() = 0; // Leaf Child Only // virtual LayerWrapper *addParent() = 0; // Folder Parent Only @@ -97,7 +98,7 @@ class FolderLayerWrapper : public LayerWrapper QTreeWidgetItem* getQTreeItem() override; QJsonObject toJson() const override; int getReferencedBy()const; - void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; + void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override; void collectDownReachable(std::set& reachable) override; void refreshTreeItem() override; size_t referencedCount(bool excludeSelf = false) const override; @@ -115,7 +116,7 @@ class LeafLayerWrapper : public LayerWrapper void refresh(LayerWrapper* layer = nullptr) override; LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); QJsonObject toJson() const override; - void paint(QPainter* painter, QTransform transform = QTransform(), bool ignoreSelected = false) override; + void paint(QPainter* painter, QTransform transform = QTransform(), bool force = false) override; void collectDownReachable(std::set& reachable) override; QTreeWidgetItem* getQTreeItem() override; void refreshTreeItem() override; diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp index c4a03b5..dbe317c 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.cpp @@ -100,19 +100,18 @@ void PreviewWindow::mouseMoveEvent(QMouseEvent* event) auto index = -1; if (typeid(*layer) == typeid(FolderLayerWrapper)) index = dynamic_cast(layer)->getReferencedBy(); - if (index != -1) - emit refreshElementPreviewByIndex(index); layer = layer->getParent(); } } // һελ + emit triggerCentralRefresh(); m_lastPos = event->pos(); this->repaint(); } void PreviewWindow::mouseReleaseEvent(QMouseEvent* event) { - emit layerInfoChanged(); + //emit layerInfoChanged(); } void PreviewWindow::setBackgroundColor(QColor color) diff --git a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h index 9f9d07c..4fd002d 100644 --- a/ArchitectureColoredPainting/src/Editor/PreviewWindow.h +++ b/ArchitectureColoredPainting/src/Editor/PreviewWindow.h @@ -46,4 +46,5 @@ class PreviewWindow : public QOpenGLWidget, protected QOpenGLFunctions void layerInfoChanged(); void refreshElementPreview(GraphicElement*); void refreshElementPreviewByIndex(int); + void triggerCentralRefresh(); }; diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 6869729..56e46b4 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -21,12 +21,11 @@ void InfoDisplayWidget::generateLayerForm() { while (this->layout()->count() > 0 && (item = this->layout()->takeAt(0)) != nullptr) { - delete item->widget(); - delete item; + item->widget()->deleteLater(); + delete item; } delete this->layout(); } - QFormLayout *layout = new QFormLayout(); layout->setRowWrapPolicy(QFormLayout::WrapAllRows); if (this->displayLayer == nullptr) diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index a8ba44e..5090342 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -2,6 +2,7 @@ #include #include #include "./EditorWidgetComponent/LayerCreateWidget.h" +#include LayerTreeWidget::LayerTreeWidget(QWidget *parent) { @@ -26,6 +27,10 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent) } emit triggerCentralRefresh(); }); + connect(this, &QTreeWidget::itemChanged, this, [=]() { + emit triggerCentralRefresh(); + }); + // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked); }