diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
index 4f07662..4d9e8c2 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj
@@ -104,6 +104,7 @@
+
@@ -205,6 +206,7 @@
+
diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
index 164cd2e..75a8390 100644
--- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
+++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters
@@ -267,6 +267,9 @@
Source Files
+
+ Source Files
+
@@ -323,6 +326,9 @@
Header Files
+
+ Header Files
+
diff --git a/ArchitectureColoredPainting/EditorLayerInfoWidget.ui b/ArchitectureColoredPainting/EditorLayerInfoWidget.ui
index 7918384..5d1bca3 100644
--- a/ArchitectureColoredPainting/EditorLayerInfoWidget.ui
+++ b/ArchitectureColoredPainting/EditorLayerInfoWidget.ui
@@ -71,7 +71,7 @@
-
-
+
@@ -86,6 +86,11 @@
QCheckBox
+
+ LayerContainerListWidget
+ QListWidget
+ EditorWidgetComponent/LayerContainerListWidget.h
+
diff --git a/ArchitectureColoredPainting/EditorWidget.ui b/ArchitectureColoredPainting/EditorWidget.ui
index 4b7d672..f5e691f 100644
--- a/ArchitectureColoredPainting/EditorWidget.ui
+++ b/ArchitectureColoredPainting/EditorWidget.ui
@@ -41,7 +41,7 @@
0
-
-
+
0
@@ -49,7 +49,7 @@
0
-
-
+
-
-
+
-
- -
-
-
-
- 80
- 40
-
-
-
-
- 80
- 16777215
-
-
-
- 保存
-
-
-
- -
-
-
-
- 80
- 40
-
-
-
-
- 80
- 16777215
-
-
-
- 另存为
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
-
- 80
- 40
-
-
-
-
- 80
- 16777215
-
-
-
- 关闭
+ 项目
@@ -178,6 +115,9 @@
0
+
+ true
+
Tab 1
@@ -194,6 +134,13 @@
+
+
+ FluentMenuButton
+ QPushButton
+
+
+
diff --git a/ArchitectureColoredPainting/EditorWidgetItem.ui b/ArchitectureColoredPainting/EditorWidgetItem.ui
index ec88bfa..a02c38d 100644
--- a/ArchitectureColoredPainting/EditorWidgetItem.ui
+++ b/ArchitectureColoredPainting/EditorWidgetItem.ui
@@ -39,7 +39,7 @@
-
-
+
-
@@ -147,18 +147,13 @@
- 2
+ 0
图层信息
-
-
- 图元池
-
-
设置
@@ -201,6 +196,23 @@
+ -
+
+
-
+
+
+ 图元
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+
+
-
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
index 97898fb..dbe7e0c 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.cpp
@@ -8,42 +8,25 @@
EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent)
{
ui.setupUi(this);
- this->createButton = ui.createButton;
- this->closeButton = ui.closeButton;
- this->saveButton = ui.saveButton;
- this->saveAsButton = ui.saveAsButton;
- this->openButton = ui.openButton;
+ this->fileMenuButton = ui.fileMenuButton;
+ this->projectMenuButton = ui.projectMenuButton;
this->tabWidget = ui.tabWidget;
while (this->tabWidget->count() > 0)
{
this->tabWidget->removeTab(0);
}
- connect(this->createButton, &QPushButton::clicked, this, [this]() {
- static int count = 0;
- this->tabWidget->addTab(new EditorWidgetItem("../data.json",this), "untitled" + QString::number(count++));
- });
- connect(this->openButton, &QPushButton::clicked, this, [this]() {
- QString fileName = QFileDialog::getOpenFileName(this->saveAsButton, QString::fromLocal8Bit(""), "", QString::fromLocal8Bit("JSONļ(*.json)"));
- if(!fileName.isEmpty())
- this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName);
- });
- connect(this->closeButton, &QPushButton::clicked, this, [this]() {
- this->tabWidget->removeTab(this->tabWidget->currentIndex());
- });
- connect(this->saveButton, &QPushButton::clicked, this, [this]() {
- EditorWidgetItem* item = dynamic_cast(this->tabWidget->currentWidget());
- if (item != nullptr)
- {
- //item->save();
- }
- });
- connect(this->saveAsButton, &QPushButton::clicked, this, [this]() {
- EditorWidgetItem* item = dynamic_cast(this->tabWidget->currentWidget());
- if (item != nullptr)
- {
- QString fileName = QFileDialog::getSaveFileName(this->saveAsButton, QString::fromLocal8Bit("Ϊ"), "", QString::fromLocal8Bit("JSONļ(*.json)"));
- item->saveAs(fileName);
- }
+
+ connect(this, &EditorWidget::tabCountChanged, this, &EditorWidget::onTabCountChanged);
+
+ initFileMenu();
+ initProjectMenu();
+
+ connect(this->tabWidget, &QTabWidget::tabCloseRequested, [this](int index) {
+ const int prevCount = this->tabWidget->count();
+ this->tabWidget->removeTab(index);
+ const int nowCount = this->tabWidget->count();
+
+ emit tabCountChanged(prevCount, nowCount);
});
}
@@ -54,4 +37,73 @@ void EditorWidget::renameTab(QWidget* target, QString name)
{
this->tabWidget->setTabText(index, name);
}
-}
\ No newline at end of file
+}
+
+void EditorWidget::onTabCountChanged(int prev, int now)
+{
+ if (now != 0)
+ {
+ this->projectMenuButton->setDisabled(false);
+ }
+ else
+ {
+ this->projectMenuButton->setDisabled(true);
+ }
+}
+
+void EditorWidget::initFileMenu()
+{
+ auto* actionCreate = new QAction(QStringLiteral("½"), fileMenuButton);
+ auto* actionOpen = new QAction(QStringLiteral(""), fileMenuButton);
+ auto* actionSave = new QAction(QStringLiteral(""), fileMenuButton);
+ auto* actionSaveAs = new QAction(QStringLiteral("Ϊ"), fileMenuButton);
+ fileMenuButton->addMenuAction(actionCreate);
+ fileMenuButton->addMenuAction(actionOpen);
+ fileMenuButton->addMenuAction(actionSave);
+ fileMenuButton->addMenuAction(actionSaveAs);
+ connect(actionCreate, &QAction::triggered, [this] {
+ static int count = 0;
+ const int prevCount = this->tabWidget->count();
+ this->tabWidget->addTab(new EditorWidgetItem("../data.json", this), "untitled" + QString::number(count++));
+ const int nowCount = this->tabWidget->count();
+
+ emit tabCountChanged(prevCount, nowCount);
+ });
+ connect(actionOpen, &QAction::triggered, this, [this] {
+ const QString fileName = QFileDialog::getOpenFileName(this, QStringLiteral(""), "", QStringLiteral("JSONļ(*.json)"));
+ if (!fileName.isEmpty())
+ {
+ const int prevCount = this->tabWidget->count();
+ this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName);
+ const int nowCount = this->tabWidget->count();
+
+ emit tabCountChanged(prevCount, nowCount);
+ }
+ });
+ connect(actionSave, &QAction::triggered, this, [this] {
+ auto* item = dynamic_cast(this->tabWidget->currentWidget());
+ if (item != nullptr)
+ {
+ //item->save();
+ }
+ });
+ connect(actionSaveAs, &QAction::triggered, this, [this] {
+ const auto* item = dynamic_cast(this->tabWidget->currentWidget());
+ if (item != nullptr)
+ {
+ const QString fileName = QFileDialog::getSaveFileName(this, QStringLiteral("Ϊ"), "", QStringLiteral("JSONļ(*.json)"));
+ item->saveAs(fileName);
+ }
+ });
+}
+
+void EditorWidget::initProjectMenu()
+{
+ if (tabWidget->count() == 0)
+ {
+ projectMenuButton->setDisabled(true);
+ }
+
+ auto* actionSettings = new QAction(QStringLiteral("Ŀ"), projectMenuButton);
+ projectMenuButton->addMenuAction(actionSettings);
+}
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidget.h
index 0986609..eedcef0 100644
--- a/ArchitectureColoredPainting/src/Editor/EditorWidget.h
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidget.h
@@ -1,5 +1,6 @@
#pragma once
#include
+#include "../FluentMenuButton.h"
#include "ui_EditorWidget.h"
class EditorWidget :
@@ -9,15 +10,21 @@ class EditorWidget :
private:
Ui::EditorWidget ui;
QTabWidget* tabWidget;
- QPushButton* createButton;
- QPushButton* closeButton;
- QPushButton* saveButton;
- QPushButton* saveAsButton;
- QPushButton* openButton;
+ FluentMenuButton* fileMenuButton;
+ FluentMenuButton* projectMenuButton;
+
+ void initFileMenu();
+ void initProjectMenu();
public:
EditorWidget(QWidget* parent = nullptr);
~EditorWidget()=default;
void renameTab(QWidget* target, QString name);
+
+protected slots:
+ void onTabCountChanged(int prev, int now);
+
+signals:
+ void tabCountChanged(int prev, int now);
};
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.cpp
new file mode 100644
index 0000000..0a76cb3
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.cpp
@@ -0,0 +1,178 @@
+#include "LayerContainerListWidget.h"
+#include "LayerStyleDialog.h"
+#include
+#include
+
+LayerContainerListWidget::LayerContainerListWidget(QWidget* parent, const PLayerStyleContainer& styleContainer)
+ : QListWidget(parent), styleContainer(styleContainer)
+{
+ connect(this, &LayerContainerListWidget::addLayerStyle,
+ this, &LayerContainerListWidget::onAddLayerStyle);
+ connect(this, &LayerContainerListWidget::removeLayerStyle,
+ this, &LayerContainerListWidget::onRemoveLayerStyle);
+
+ initHeader();
+ setStyleContainer(styleContainer, true);
+}
+
+bool comparePStyleContainersEquality(const LayerStyleContainer* a, const LayerStyleContainer* b)
+{
+ if (a == nullptr && b == nullptr)
+ {
+ return true;
+ }
+ if (a == nullptr || b == nullptr)
+ {
+ return false;
+ }
+ return a == b || *a == *b;
+}
+
+void LayerContainerListWidget::setStyleContainer(const PLayerStyleContainer& styleContainer, bool forceRefresh)
+{
+ if (!forceRefresh && comparePStyleContainersEquality(this->styleContainer, styleContainer))
+ {
+ return;
+ }
+
+ const int count = this->count();
+ for (int i = 1; i < count; i++)
+ {
+ const auto* item = this->takeItem(1);
+ delete item;
+ }
+
+ if (!styleContainer)
+ {
+ return;
+ }
+
+ this->styleContainer = styleContainer;
+
+ for (auto& style : *styleContainer | std::views::values)
+ {
+ auto* item = new QListWidgetItem(this);
+ item->setSizeHint(QSize(50, 40));
+ this->setItemWidget(item, buildStyleListWidget(style));
+ }
+ resetAddButton();
+}
+
+LayerContainerListWidget::PLayerStyleContainer LayerContainerListWidget::getStyleContainer() const
+{
+ return styleContainer;
+}
+
+void LayerContainerListWidget::resetAddButton()
+{
+ if (!styleContainer)
+ {
+ return;
+ }
+ qDebug() << "resetAddButton" << styleContainer->full();
+ addButton->setDisabled(styleContainer->full());
+}
+
+void LayerContainerListWidget::onAddLayerStyle(const std::shared_ptr& style)
+{
+ if (const bool ok = styleContainer->useStyle(style))
+ {
+ styleContainer->computeNewHash();
+ resetAddButton();
+ auto* newItem = new QListWidgetItem(this);
+ styleItemMap[style->getDisplayName()] = newItem;
+ newItem->setSizeHint(QSize(50, 40));
+ this->setItemWidget(newItem, buildStyleListWidget(style));
+ }
+}
+
+void LayerContainerListWidget::onRemoveLayerStyle(const QString& styleName)
+{
+ if (const bool ok = styleContainer->dropStyle(styleName))
+ {
+ styleContainer->computeNewHash();
+ auto* removedItem = styleItemMap.extract(styleName).mapped();
+ resetAddButton();
+ delete this->takeItem(this->row(removedItem));
+ }
+}
+
+void LayerContainerListWidget::initHeader()
+{
+ this->headerWidget = new QWidget(this);
+ auto* headerLayout = new QHBoxLayout;
+
+ auto* headerLabel = new QLabel(headerWidget);
+ headerLabel->setText(QStringLiteral("ʽб"));
+ headerLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+
+ //auto* addStyleButton = new QtMaterialRaisedButton("+", headerWidget);
+ this->addButton = new QPushButton("+", headerWidget);
+ addButton->setFixedSize(QSize(20, 20));
+ connect(addButton, &QPushButton::clicked, [this] {
+ auto* dialog = new LayerStyleDialog(this->styleContainer, nullptr, this);
+ dialog->exec();
+ if (dialog->layerStyle)
+ {
+ emit addLayerStyle(dialog->layerStyle);
+ }
+ });
+
+ headerLayout->addWidget(headerLabel);
+ headerLayout->addWidget(addButton);
+ headerLayout->setContentsMargins(5, 0, 5, 0);
+ headerWidget->setLayout(headerLayout);
+
+ auto* headerItem = new QListWidgetItem(this);
+ headerItem->setFlags(Qt::NoItemFlags);
+ this->addItem(headerItem);
+ this->setItemWidget(headerItem, headerWidget);
+}
+
+
+QWidget* LayerContainerListWidget::buildStyleListWidget(std::shared_ptr style)
+{
+ auto* w = new QWidget(this);
+ auto* layout = new QHBoxLayout;
+ 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(QStringLiteral(""));
+ removeButton->setFixedSize(QSize(20, 20));
+ const QString styleDisplayName = style->getDisplayName();
+
+ connect(detailButton, &QPushButton::clicked,
+ [this, styleDisplayName]
+ {
+ const auto targetStyle = this->styleContainer->getStyle(styleDisplayName);
+ auto* dialog = new LayerStyleDialog(this->styleContainer, targetStyle, this);
+ dialog->exec();
+
+ if (dialog->layerStyle)
+ {
+ this->styleContainer->overrideStyle(dialog->layerStyle);
+ this->styleContainer->computeNewHash();
+ emit editLayerStyle(targetStyle);
+ }
+ });
+
+ connect(removeButton, &QPushButton::clicked,
+ [this, styleDisplayName]
+ {
+ emit removeLayerStyle(styleDisplayName);
+ });
+
+ QWidget* styleDisplayWidget = style->getListDisplayWidget();
+ styleDisplayWidget->setParent(w);
+ styleDisplayWidget->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
+
+ layout->addWidget(styleDisplayWidget);
+ layout->addWidget(detailButton);
+ layout->addWidget(removeButton);
+ w->setLayout(layout);
+ return w;
+}
\ No newline at end of file
diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.h
new file mode 100644
index 0000000..4536e46
--- /dev/null
+++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerContainerListWidget.h
@@ -0,0 +1,35 @@
+#pragma once
+#include