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
qtmaterialcheckbox.h
+ + 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 @@ -63,12 +63,12 @@ - 新建 + 文件 - + 80 @@ -82,70 +82,7 @@ - 打开 - - - - - - - - 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 +
../FluentMenuButton.h
+
+
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 +#include +#include +#include "LayerStyle.h" + +class LayerContainerListWidget : public QListWidget +{ + Q_OBJECT + using PLayerStyleContainer = LayerStyleContainer*; +private: + QWidget* headerWidget; + QPushButton* addButton; + PLayerStyleContainer styleContainer; + std::map styleItemMap; + + void initHeader(); + void resetAddButton(); + QWidget* buildStyleListWidget(std::shared_ptr style); + +public: + LayerContainerListWidget(QWidget* parent = nullptr, const PLayerStyleContainer& styleContainer = nullptr); + void setStyleContainer(const PLayerStyleContainer& styleContainer, bool forceRefresh = false); + PLayerStyleContainer getStyleContainer() const; + +protected slots: + void onAddLayerStyle(const std::shared_ptr& style); + void onRemoveLayerStyle(const QString& styleName); + +signals: + void addLayerStyle(const std::shared_ptr& style); + void editLayerStyle(const std::shared_ptr& style); + void removeLayerStyle(const QString& styleName); +}; + diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp index 40c2555..4974229 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp @@ -4,10 +4,10 @@ #include LayerStyleDialog::LayerStyleDialog( - LayerStyleContainer& styles, + LayerStyleContainer* pStyles, const std::shared_ptr& existedStyle, QWidget* parent -) : QDialog(parent), styles(&styles) +) : QDialog(parent), styles(pStyles) { dialogLayout = new QGridLayout; dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); @@ -23,13 +23,13 @@ LayerStyleDialog::LayerStyleDialog( } else { - QStringList unusedStyleNames = styles.unusedStyleNames(); + QStringList unusedStyleNames = styles->unusedStyleNames(); auto* typeSelector = new QComboBox(this); if (!unusedStyleNames.empty()) { typeSelector->addItems(unusedStyleNames); - this->modifyingStyle = std::move(styles.makeUnusedStyle(unusedStyleNames[0])); + this->modifyingStyle = std::move(styles->makeUnusedStyle(unusedStyleNames[0])); dialogLayout->addWidget(typeSelector, 0, 0); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h index 485b58c..7940ab7 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h @@ -13,7 +13,7 @@ private: std::unique_ptr modifyingStyle; public: LayerStyleDialog( - LayerStyleContainer& styles, + LayerStyleContainer* pStyles, const std::shared_ptr& existedStyle = nullptr, QWidget* parent = nullptr ); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp deleted file mode 100644 index 5b011a7..0000000 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "StrokeStyleListView.h" -#include "ColorPicker.h" -#include - -constexpr int COLUMN_WIDTH = 0; -constexpr int COLUMN_COLOR = 1; -constexpr int COLUMN_METALLIC = 2; -constexpr int COLUMN_ROUGHNESS = 3; -constexpr int COLUMN_OPERATIONS = 4; - -// TODO: Ϊ̳QWidgettableתΪеһԪأаťͿ -StrokeStyleListView::StrokeStyleListView( - std::shared_ptr stroke, - QWidget* parent -) : QTableWidget(parent), stroke(stroke) -{ - this->setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContentsOnFirstShow); - this->setColumnCount(5); - this->setRowCount(stroke->materialMap.size()); - QStringList headers; - headers.append(QStringLiteral("ľռ")); - headers.append(QStringLiteral("ɫ")); - headers.append(QStringLiteral("")); - headers.append(QStringLiteral("ֲڶ")); - headers.append(QStringLiteral("")); - this->setHorizontalHeaderLabels(headers); - for (int row = 0; auto& strokePair : stroke->materialMap) - { - QTableWidgetItem* widthItem = new QTableWidgetItem; - widthItem->setData(Qt::EditRole, strokePair.first); - this->setItem(row, COLUMN_WIDTH, widthItem); - - QColor* colorPtr = &(strokePair.second.color); - QTableWidgetItem* colorItem = new QTableWidgetItem; - colorItem->setData(Qt::DisplayRole, *colorPtr); - this->setItem(row, COLUMN_COLOR, colorItem); - ColorPicker* colorPicker = new ColorPicker(*colorPtr, this); - this->setCellWidget(row, COLUMN_COLOR, colorPicker); - connect(colorPicker, &ColorPicker::colorChanged, [this, colorPtr](QColor color) { - *colorPtr = color; - this->update(); - }); - - QTableWidgetItem* metallicItem = new QTableWidgetItem; - metallicItem->setData(Qt::EditRole, strokePair.second.metallic); - this->setItem(row, COLUMN_METALLIC, metallicItem); - - QTableWidgetItem* roughnessItem = new QTableWidgetItem; - roughnessItem->setData(Qt::EditRole, strokePair.second.roughness); - this->setItem(row, COLUMN_ROUGHNESS, roughnessItem); - - QtMaterialRaisedButton* removeButton = new QtMaterialRaisedButton("-", this); - removeButton->setFixedSize(20, 20); - this->setCellWidget(row, COLUMN_OPERATIONS, removeButton); - connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { - this->stroke->materialMap.erase(this->item(row, COLUMN_WIDTH)->text().toFloat()); - this->removeRow(row); - }); - - row++; - } - connect(this, &StrokeStyleListView::currentItemChanged, this, &StrokeStyleListView::onCurrentItemChanged); - connect(this, &StrokeStyleListView::cellChanged, this, &StrokeStyleListView::onCellChanged); - this->adjustSize(); -} - -void StrokeStyleListView::onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous) -{ - if (!current) return; - int column = current->column(); - if (column != COLUMN_COLOR && column != COLUMN_OPERATIONS) - { - this->currentItemValue = current->text(); - } -} - -void StrokeStyleListView::onCellChanged(int row, int column) -{ - auto changedItem = this->item(row, column); - auto changedItemValue = changedItem->text().toFloat(); - if (changedItemValue < 0 || 1 < changedItemValue) - { - changedItem->setData(Qt::EditRole, this->currentItemValue.toFloat()); - return; - } - auto changedWidth = this->item(row, COLUMN_WIDTH)->text().toFloat(); - switch (row) - { - case COLUMN_WIDTH: - { - float oldWidth = this->currentItemValue.toFloat(); - auto node = stroke->materialMap.extract(oldWidth); - node.key() = changedWidth; - stroke->materialMap.insert(std::move(node)); - break; - } - case COLUMN_METALLIC: - { - stroke->materialMap[changedWidth].metallic = changedItemValue; - break; - } - case COLUMN_ROUGHNESS: - { - stroke->materialMap[changedWidth].roughness = changedItemValue; - break; - } - } -} \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.h deleted file mode 100644 index f12e400..0000000 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleListView.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "LayerStyle.h" -#include "../Renderer/Painting/MaterialStyleStroke.h" -#include -#include -#include -class StrokeStyleListView : public QTableWidget -{ - Q_OBJECT -private: - QString currentItemValue; - -public: - StrokeStyleListView(std::shared_ptr stroke, QWidget* parent = nullptr); - std::shared_ptr stroke; - -protected slots: - void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); - void onCellChanged(int row, int column); -}; - diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index c126a78..e9aeae0 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -17,9 +17,9 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p treeWidget = ui.LayerTree; tabWidget = ui.DisplayTab; this->filePath = filePath; - layerInfoDisplayWidget = dynamic_cast(tabWidget->widget(0)); - elementInfoDisplayWidget = dynamic_cast(tabWidget->widget(1)); - editorSettingWidget = dynamic_cast(tabWidget->widget(2)); + elementInfoDisplayWidget = ui.ElementDisplay; + layerInfoDisplayWidget = dynamic_cast(tabWidget->widget(0)); + editorSettingWidget = dynamic_cast(tabWidget->widget(1)); elementInfoDisplayWidget->enableEdit(); qDebug() << layerInfoDisplayWidget; qDebug() << elementInfoDisplayWidget; diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index d8bbae3..582d01d 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #define _USE_JOIN_VIEW_INPUT_RANGE #include #include @@ -193,6 +194,16 @@ bool LayerStyleContainer::useStyle(const std::shared_ptr& style) return true; } +bool LayerStyleContainer::overrideStyle(const std::shared_ptr& style) +{ + if (!styles.contains(style->getDisplayName())) + { + return false; + } + styles[style->getDisplayName()] = style; + return true; +} + bool LayerStyleContainer::dropStyle(const QString& styleName) { auto styleNode = usedStyles.extract(styleName); @@ -205,6 +216,11 @@ bool LayerStyleContainer::dropStyle(const QString& styleName) return true; } +std::shared_ptr LayerStyleContainer::getStyle(const QString& styleName) const +{ + return styles.at(styleName); +} + float LayerStyleContainer::boundingBoxAffectValue() const { float maxLineWidth = 0; const auto strokeStyle = styles.find(StrokeElementLayerStyle::displayName()); @@ -234,6 +250,15 @@ size_t LayerStyleContainer::getHash() const return hash; } +bool LayerStyleContainer::operator==(const LayerStyleContainer& other) const +{ + if (getHash() != other.getHash() || unusedStyleNames() != other.unusedStyleNames()) + { + return false; + } + return std::ranges::equal(styles | std::views::values, other.styles | std::views::values); +} + std::unique_ptr StrokeElementLayerStyle::fromJson(const QJsonObject& json) { auto ptr = std::make_unique( @@ -298,6 +323,20 @@ std::unique_ptr StrokeElementLayerStyle::clone() const return std::make_unique(StrokeElementLayerStyle(*this)); } +bool StrokeElementLayerStyle::operator==(const LayerStyle& other) const +{ + if (!LayerStyle::operator==(other)) + { + return false; + } + const auto otherStyle = dynamic_cast(&other); + if (!otherStyle) + { + return false; + } + return this->strokePair.first == otherStyle->strokePair.first && this->strokePair.second == otherStyle->strokePair.second; +} + std::unique_ptr FillElementLayerStyle::fromJson(const QJsonObject& json) { auto ptr = std::make_unique( @@ -359,6 +398,20 @@ std::unique_ptr FillElementLayerStyle::clone() const return std::make_unique(FillElementLayerStyle(*this)); } +bool FillElementLayerStyle::operator==(const LayerStyle& other) const +{ + if (!LayerStyle::operator==(other)) + { + return false; + } + const auto otherStyle = dynamic_cast(&other); + if (!otherStyle) + { + return false; + } + return this->fillMaterialStyle == otherStyle->fillMaterialStyle; +} + std::unique_ptr LayerStyle::fromJson(const QJsonObject& json) { QString type = json["type"].toString(); @@ -379,3 +432,8 @@ QJsonObject LayerStyle::toJson() const json["type"] = this->getTypeName(); return json; } + +bool LayerStyle::operator==(const LayerStyle& other) const +{ + return this->getTypeName() == other.getTypeName(); +} diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.h b/ArchitectureColoredPainting/src/Editor/LayerStyle.h index 45888a1..d497194 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.h +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.h @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include "../Renderer/Painting/ElementStyle.h" @@ -36,6 +35,8 @@ public: virtual QJsonObject toJson() const; virtual std::unique_ptr clone() const = 0; + + virtual bool operator==(const LayerStyle& other) const; }; class StrokeElementLayerStyle : public LayerStyle @@ -57,6 +58,8 @@ public: QJsonObject toJson() const override; std::unique_ptr clone() const override; + bool operator==(const LayerStyle& other) const override; + std::pair strokePair; bool enableEachSideIndependent = false; }; @@ -79,6 +82,8 @@ public: QJsonObject toJson() const override; std::unique_ptr clone() const override; + bool operator==(const LayerStyle& other) const override; + PMaterialStyleFill fillMaterialStyle; }; @@ -125,10 +130,14 @@ public: QStringList unusedStyleNames() const; std::unique_ptr makeUnusedStyle(const QString& styleName) const; bool useStyle(const std::shared_ptr& style); + bool overrideStyle(const std::shared_ptr& style); bool dropStyle(const QString& styleName); + std::shared_ptr getStyle(const QString& styleName) const; float boundingBoxAffectValue() const; size_t getHash() const; + bool operator==(const LayerStyleContainer& other) const; + /** * Ҫÿθĺֶ */ diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp index 4c86ad0..df61f0a 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.cpp @@ -2,12 +2,7 @@ #include "./EditorWidgetComponent/LayerStyleDialog.h" #include #include -#include -#include #include -#include -#include -#include #include void InfoDisplayWidget::setLayer(LayerWrapper *layer) @@ -27,6 +22,7 @@ InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent) ui.scaleX->setLabel(("水平缩放")); ui.scaleY->setLabel(("垂直缩放")); ui.rotation->setValidator(new QIntValidator(-10000, 10000, this)); + ui.styleList->setDisabled(true); connect(ui.rotation, &QLineEdit::textChanged, [=](QString content) { this->displayLayer->property.rotation = content.toDouble(); emit triggerCentralRefresh(); @@ -59,6 +55,15 @@ InfoDisplayWidget::InfoDisplayWidget(QWidget* parent) :QWidget(parent) this->displayLayer->property.flipY = state; emit triggerCentralRefresh(); }); + connect(ui.styleList, &LayerContainerListWidget::addLayerStyle, [this](const std::shared_ptr& style) { + emit triggerCentralRefresh(); + }); + connect(ui.styleList, &LayerContainerListWidget::editLayerStyle, [this](const std::shared_ptr& style) { + emit triggerCentralRefresh(); + }); + connect(ui.styleList, &LayerContainerListWidget::removeLayerStyle, [this](const QString& styleName) { + emit triggerCentralRefresh(); + }); } void InfoDisplayWidget::setVisiable(bool visiable) @@ -79,5 +84,14 @@ void InfoDisplayWidget::refresh() ui.scaleY->setText(QString::number(this->displayLayer->property.scale.y())); ui.flipX->setChecked(this->displayLayer->property.flipX); ui.flipY->setChecked(this->displayLayer->property.flipY); + if (this->displayLayer->canApplyStyles()) + { + ui.styleList->setDisabled(false); + ui.styleList->setStyleContainer(&static_cast(this->displayLayer)->styles); + } + else + { + ui.styleList->setDisabled(true); + } } } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h index c0a08a0..33f452e 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/InfoDisplayWidget.h @@ -1,8 +1,5 @@ #pragma once #include "GraphicElement.h" -#include "LayerWrapper.h" -#include -#include #include #include "ElementPoolWidget.h" #include "ui_EditorLayerInfoWidget.h"