实现显示/隐藏图层功能 | #16

dev-LayerStyle
karlis 2023-03-20 15:52:27 +08:00
parent f06fbbaef6
commit 8a34f57251
6 changed files with 39 additions and 21 deletions

View File

@ -180,6 +180,12 @@
<property name="accessibleName"> <property name="accessibleName">
<string/> <string/>
</property> </property>
<property name="iconSize">
<size>
<width>10</width>
<height>10</height>
</size>
</property>
<column> <column>
<property name="text"> <property name="text">
<string>图层名</string> <string>图层名</string>
@ -190,6 +196,11 @@
<string>关联图元</string> <string>关联图元</string>
</property> </property>
</column> </column>
<column>
<property name="text">
<string>可见</string>
</property>
</column>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -74,9 +74,10 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
this->projectName = source.value("project-name").toString(); this->projectName = source.value("project-name").toString();
qDebug() << this->backgroundColor; qDebug() << this->backgroundColor;
qDebug() << this->projectName; qDebug() << this->projectName;
QTimer::singleShot(300, this, [this]() { QTimer::singleShot(300, this, [this, centralRefresh]() {
handleBackgroundColorChange(this->backgroundColor); handleBackgroundColorChange(this->backgroundColor);
handleProjectNameChange(this->projectName); handleProjectNameChange(this->projectName);
centralRefresh();
}); });
} }

View File

@ -127,7 +127,7 @@ bool SimpleElement::isClosed() const
void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles) void GroupElement::paint(QPainter* painter, QTransform transform, const LayerStyleContainer& styles)
{ {
sourceLayer->paint(painter, transform); sourceLayer->paint(painter, transform, true);
} }
bool GroupElement::isClosed() const bool GroupElement::isClosed() const

View File

@ -47,6 +47,7 @@ LayerWrapper::LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementM
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()};
selected = false; selected = false;
hidden = false;
} }
FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent) FolderLayerWrapper::FolderLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent)
@ -199,6 +200,7 @@ void FolderLayerWrapper::delSelf() {
QTreeWidgetItem* LayerWrapper::getQTreeItem() QTreeWidgetItem* LayerWrapper::getQTreeItem()
{ {
this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this)); this->qTreeWidgetItem->setData(0, Qt::UserRole, QVariant::fromValue(this));
this->qTreeWidgetItem->setCheckState(0, Qt::Checked);
return this->qTreeWidgetItem; return this->qTreeWidgetItem;
} }
@ -280,31 +282,27 @@ int FolderLayerWrapper::getReferencedBy()const
return -1; 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; transform = property.transform * transform;
//qDebug() << transform; //qDebug() << transform;
for (auto& child : children) 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; transform = property.transform * transform;
//qDebug() << transform; //qDebug() << transform;
if (wrappedElement != nullptr) if (wrappedElement != nullptr)
@ -347,11 +345,12 @@ void FolderLayerWrapper::collectDownReachable(std::set<LayerWrapper*>& reachable
void LayerWrapper::refreshTreeItem() void LayerWrapper::refreshTreeItem()
{ {
hidden = qTreeWidgetItem->checkState(0) == Qt::Unchecked;
} }
void LeafLayerWrapper::refreshTreeItem() void LeafLayerWrapper::refreshTreeItem()
{ {
LayerWrapper::refreshTreeItem();
if (typeid(*wrappedElement) == typeid(GroupElement)) if (typeid(*wrappedElement) == typeid(GroupElement))
{ {
this->qTreeWidgetItem->setText(0, "@ " + this->property.name); this->qTreeWidgetItem->setText(0, "@ " + this->property.name);
@ -366,6 +365,7 @@ void LeafLayerWrapper::refreshTreeItem()
void FolderLayerWrapper::refreshTreeItem() void FolderLayerWrapper::refreshTreeItem()
{ {
LayerWrapper::refreshTreeItem();
for (auto& child : this->children) { for (auto& child : this->children) {
child->refreshTreeItem(); child->refreshTreeItem();
} }

View File

@ -37,6 +37,7 @@ class LayerWrapper
public: public:
QTreeWidgetItem* qTreeWidgetItem; QTreeWidgetItem* qTreeWidgetItem;
bool selected; bool selected;
bool hidden;
struct SimpleProperty struct SimpleProperty
{ {
QString name = ""; QString name = "";
@ -58,7 +59,7 @@ class LayerWrapper
FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles FolderLayerWrapper*getParent() const; // invoke by manager, then invoke parent's applyStyles
LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr); LayerWrapper(QJsonObject json, FolderLayerWrapper*parent, ElementManager* elementManager=nullptr);
LayerWrapper() = default; 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 // TODO : export Function
// virtual LayerWrapper *addChild() = 0; // Leaf Child Only // virtual LayerWrapper *addChild() = 0; // Leaf Child Only
// virtual LayerWrapper *addParent() = 0; // Folder Parent Only // virtual LayerWrapper *addParent() = 0; // Folder Parent Only
@ -97,7 +98,7 @@ class FolderLayerWrapper : public LayerWrapper
QTreeWidgetItem* getQTreeItem() override; QTreeWidgetItem* getQTreeItem() override;
QJsonObject toJson() const override; QJsonObject toJson() const override;
int getReferencedBy()const; 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<LayerWrapper*>& reachable) override; void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
void refreshTreeItem() override; void refreshTreeItem() override;
size_t referencedCount(bool excludeSelf = false) const override; size_t referencedCount(bool excludeSelf = false) const override;
@ -115,7 +116,7 @@ class LeafLayerWrapper : public LayerWrapper
void refresh(LayerWrapper* layer = nullptr) override; void refresh(LayerWrapper* layer = nullptr) override;
LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent); LeafLayerWrapper(QJsonObject json, ElementManager *elementManager, FolderLayerWrapper*parent);
QJsonObject toJson() const override; 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<LayerWrapper*>& reachable) override; void collectDownReachable(std::set<LayerWrapper*>& reachable) override;
QTreeWidgetItem* getQTreeItem() override; QTreeWidgetItem* getQTreeItem() override;
void refreshTreeItem() override; void refreshTreeItem() override;

View File

@ -2,6 +2,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QMenu> #include <QMenu>
#include "./EditorWidgetComponent/LayerCreateWidget.h" #include "./EditorWidgetComponent/LayerCreateWidget.h"
#include <QTimer>
LayerTreeWidget::LayerTreeWidget(QWidget *parent) LayerTreeWidget::LayerTreeWidget(QWidget *parent)
{ {
@ -26,6 +27,10 @@ LayerTreeWidget::LayerTreeWidget(QWidget *parent)
} }
emit triggerCentralRefresh(); emit triggerCentralRefresh();
}); });
connect(this, &QTreeWidget::itemChanged, this, [=]() {
emit triggerCentralRefresh();
});
// connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked); // connect(this, &QTreeWidget::itemDoubleClicked, this, &LayerTreeWidget::onItemDoubleClicked);
} }