From 855dd2e075f9fbc7e5a380459250a4d1e56fd875 Mon Sep 17 00:00:00 2001 From: ArgonarioD Date: Mon, 20 Mar 2023 02:48:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[editor]=20=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E4=BC=9A=E5=AF=BC=E8=87=B4warning=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20|=20#15=20=20*=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BA=86ColorHelper=20=20*=20LayerStyleDialog=E9=87=8D?= =?UTF-8?q?=E5=A4=8DsetLayer=E5=AF=BC=E8=87=B4=E7=9A=84warning=20=20*=20QC?= =?UTF-8?q?olorDialog::getColor=E6=97=B6=E7=94=B1=E4=BA=8EQt=E7=9A=84bug?= =?UTF-8?q?=E6=9C=AA=E6=AD=A3=E7=A1=AE=E8=AE=BE=E7=BD=AE=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArchitectureColoredPainting.vcxproj | 1 + ...rchitectureColoredPainting.vcxproj.filters | 3 ++ .../src/ColorHelper.hpp | 49 +++++++++++++++++++ .../EditorWidgetComponent/ColorPicker.cpp | 6 +-- .../EditorWidgetComponent/ColorPicker.h | 3 +- .../EditorWidgetComponent/FillStyleWidget.cpp | 2 +- .../LayerStyleDialog.cpp | 25 +++++----- .../EditorWidgetComponent/LayerStyleDialog.h | 4 +- .../StrokeStyleWidget.cpp | 20 ++++---- .../EditorWidgetComponent/StrokeStyleWidget.h | 4 +- .../src/Editor/LayerStyle.cpp | 3 +- .../Editor/RightBar/EditorSettingWidget.cpp | 4 +- ArchitectureColoredPainting/src/main.cpp | 6 +-- 13 files changed, 90 insertions(+), 40 deletions(-) create mode 100644 ArchitectureColoredPainting/src/ColorHelper.hpp diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj index c403fad..7414c08 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj @@ -202,6 +202,7 @@ + diff --git a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters index e198184..835a354 100644 --- a/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters +++ b/ArchitectureColoredPainting/ArchitectureColoredPainting.vcxproj.filters @@ -519,6 +519,9 @@ Header Files\Editor\Layer + + Header Files + diff --git a/ArchitectureColoredPainting/src/ColorHelper.hpp b/ArchitectureColoredPainting/src/ColorHelper.hpp new file mode 100644 index 0000000..f337382 --- /dev/null +++ b/ArchitectureColoredPainting/src/ColorHelper.hpp @@ -0,0 +1,49 @@ +#pragma once +#include +#include +#include + +class ColorHelper +{ + QtMaterialTheme theme; + QColor primary1; +public: + + void setPrimary1(const QColor& color) + { + theme.setColor("primary1", color); + primary1 = color; + } + + [[nodiscard]] QColor getPrimary1() const + { + return primary1; + } + + ColorHelper() + { + setPrimary1(QColor::fromRgb(0, 90, 158)); + QtMaterialStyle::instance().setTheme(&theme); + } + + static ColorHelper& instance() + { + static ColorHelper instance; + return instance; + } + + static QColor execColorDialog( + const QColor& initial = instance().getPrimary1(), + QWidget* parent = nullptr, + const QString& title = "" + ) { + auto dialog = QColorDialog(initial, parent); + if (!title.isEmpty()) + { + dialog.setWindowTitle(title); + } + dialog.adjustSize(); + dialog.exec(); + return dialog.selectedColor(); + } +}; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp index 7010ae4..4ccb504 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.cpp @@ -1,5 +1,6 @@ #include "ColorPicker.h" #include +#include QString getStyleSheet(const QColor& color) { @@ -26,9 +27,8 @@ QColor ColorPicker::getColor() const void ColorPicker::onClicked() { - QColorDialog dialog(this->color, this); - dialog.exec(); - QColor newColor = dialog.selectedColor(); + //const QColor newColor = QColorDialog::getColor(this->color, this); + const QColor newColor = ColorHelper::execColorDialog(this->color, this); if (newColor.isValid() && this->color != newColor) { this->color = newColor; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h index a8edd67..50c1c34 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/ColorPicker.h @@ -1,4 +1,5 @@ #pragma once +#include "../ColorHelper.hpp" #include class ColorPicker : public QPushButton { @@ -6,7 +7,7 @@ class ColorPicker : public QPushButton private: QColor color; public: - ColorPicker(const QColor& color = QColor::fromRgb(0, 0, 0), QWidget* parent = nullptr); + ColorPicker(const QColor& color = ColorHelper::instance().getPrimary1(), QWidget* parent = nullptr); QColor getColor() const; public slots: void onClicked(); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp index bf78dbc..662ff47 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/FillStyleWidget.cpp @@ -4,7 +4,7 @@ #include #include -FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent) +FillStyleWidget::FillStyleWidget(std::shared_ptr fill, QWidget* parent) : QWidget(parent), fill(fill) { auto* layout = new QGridLayout(this); diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp index 33a3568..40c2555 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.cpp @@ -1,28 +1,25 @@ #include "LayerStyleDialog.h" #include #include -#include #include LayerStyleDialog::LayerStyleDialog( LayerStyleContainer& styles, - std::shared_ptr existedStyle, + const std::shared_ptr& existedStyle, QWidget* parent ) : QDialog(parent), styles(&styles) { - auto* dialogLayout = new QVBoxLayout(this); + dialogLayout = new QGridLayout; dialogLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter); this->setLayout(dialogLayout); if (existedStyle) { this->modifyingStyle = existedStyle->clone(); - - this->styleContainer = nullptr; + this->styleWidget = modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - dialogLayout->addWidget(styleWidget); - // do something + dialogLayout->addWidget(styleWidget, 1, 0); } else { @@ -34,13 +31,12 @@ LayerStyleDialog::LayerStyleDialog( typeSelector->addItems(unusedStyleNames); this->modifyingStyle = std::move(styles.makeUnusedStyle(unusedStyleNames[0])); - dialogLayout->addWidget(typeSelector); - this->styleContainer = new QGridLayout(this); - dialogLayout->addLayout(styleContainer); + dialogLayout->addWidget(typeSelector, 0, 0); + this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - this->styleContainer->addWidget(styleWidget); + this->dialogLayout->addWidget(styleWidget, 1, 0); connect(typeSelector, &QComboBox::currentTextChanged, this, &LayerStyleDialog::onStyleTypeSelectorChanged); } @@ -48,7 +44,8 @@ LayerStyleDialog::LayerStyleDialog( auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); connect(buttonBox, &QDialogButtonBox::accepted, this, &LayerStyleDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, this, &LayerStyleDialog::reject); - dialogLayout->addWidget(buttonBox); + dialogLayout->addWidget(buttonBox, 2, 0); + this->adjustSize(); } void LayerStyleDialog::accept() @@ -61,14 +58,14 @@ void LayerStyleDialog::onStyleTypeSelectorChanged(const QString& current) { if (this->styleWidget) { - this->styleContainer->removeWidget(this->styleWidget); + this->dialogLayout->removeWidget(this->styleWidget); this->styleWidget->setParent(nullptr); delete styleWidget; } this->modifyingStyle = std::move(styles->makeUnusedStyle(current)); this->styleWidget = this->modifyingStyle->getInputWidget(); this->styleWidget->setParent(this); - this->styleContainer->addWidget(styleWidget, 0, 0, 1, 1); + this->dialogLayout->addWidget(styleWidget, 1, 0); this->styleWidget->adjustSize(); this->adjustSize(); } diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h index b703e80..485b58c 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/LayerStyleDialog.h @@ -8,13 +8,13 @@ class LayerStyleDialog : public QDialog Q_OBJECT private: QWidget* styleWidget; - QGridLayout* styleContainer; + QGridLayout* dialogLayout; LayerStyleContainer* styles; std::unique_ptr modifyingStyle; public: LayerStyleDialog( LayerStyleContainer& styles, - std::shared_ptr existedStyle = nullptr, + const std::shared_ptr& existedStyle = nullptr, QWidget* parent = nullptr ); std::shared_ptr layerStyle; diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp index e2c9ce7..e9999bb 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.cpp @@ -1,8 +1,8 @@ #include "StrokeStyleWidget.h" #include "ColorPicker.h" +#include "../ColorHelper.hpp" #include #include -#include constexpr int COLUMN_WIDTH = 0; constexpr int COLUMN_COLOR = 1; @@ -105,8 +105,8 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetBackgroundColor(QtMaterialStyle::instance().themeColor("primary1")); + auto* addButton = new QtMaterialRaisedButton("+", strokeTable); + addButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); strokeTable->setSpan(row, 0, 1, 5); strokeTable->setCellWidget(row, 0, addButton); strokeTable->setMinimumHeight(strokeTable->rowHeight(row) * 5); @@ -114,18 +114,18 @@ void StrokeStyleWidget::initTable(std::shared_ptrsetFixedHeight(strokeTable->rowHeight(row)); connect(addButton, &QtMaterialRaisedButton::clicked, [this]() { handlingRowInsert = true; - auto materialMap = &(radialStroke(this->stroke)->materialMap); - float newWidth = 0; - if (materialMap->size() == 0) + auto materialMap = &radialStroke(this->stroke)->materialMap; + float newWidth; + if (materialMap->empty()) { newWidth = 0.1; } else { - auto lastPair = materialMap->rbegin(); + const auto lastPair = materialMap->rbegin(); newWidth = lastPair->first + 0.01; } - Renderer::Material newMaterial(QColor::fromRgb(0, 0, 0)); + const Renderer::Material newMaterial(ColorHelper::instance().getPrimary1()); (*materialMap)[newWidth] = newMaterial; int newRow = this->strokeTable->rowCount() - 1; this->strokeTable->insertRow(newRow); @@ -143,7 +143,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma widthItem->setData(Qt::EditRole, width); strokeTable->setItem(row, COLUMN_WIDTH, widthItem); - QColor* colorPtr = &(material.color); + QColor* colorPtr = &material.color; auto* colorItem = new QTableWidgetItem; colorItem->setData(Qt::DisplayRole, *colorPtr); strokeTable->setItem(row, COLUMN_COLOR, colorItem); @@ -163,7 +163,7 @@ void StrokeStyleWidget::setTableRow(int row, float width, Renderer::Material& ma strokeTable->setItem(row, COLUMN_ROUGHNESS, roughnessItem); auto* removeButton = new QtMaterialRaisedButton("-", strokeTable); - removeButton->setBackgroundColor(QtMaterialStyle::instance().themeColor("primary1")); + removeButton->setBackgroundColor(ColorHelper::instance().getPrimary1()); removeButton->setFixedSize(20, 20); strokeTable->setCellWidget(row, COLUMN_OPERATIONS, removeButton); connect(removeButton, &QtMaterialRaisedButton::clicked, [this, row]() { diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h index 6d5dbdd..67af3ee 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetComponent/StrokeStyleWidget.h @@ -23,8 +23,8 @@ private: void setTableRow(int row, float width, Renderer::Material& material); public: - StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr); - std::shared_ptr stroke; + StrokeStyleWidget(std::shared_ptr stroke, QWidget* parent = nullptr); + std::shared_ptr stroke; protected slots: void onCurrentItemChanged(QTableWidgetItem* current, QTableWidgetItem* previous); diff --git a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp index 16ff56c..292d0ca 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerStyle.cpp @@ -2,6 +2,7 @@ #include "./EditorWidgetComponent/StrokeStyleWidget.h" #include "./EditorWidgetComponent/FillStyleWidget.h" #include "./util/EncodeUtil.hpp" +#include "../ColorHelper.hpp" #include #include #include @@ -334,7 +335,7 @@ FillElementLayerStyle::FillElementLayerStyle(const PMaterialStyleFill& fillMater if (!fillMaterialStyle) { this->fillMaterialStyle = std::make_shared( - std::make_shared(Renderer::Material(QColor::fromRgb(0, 0, 0))) + std::make_shared(ColorHelper::instance().getPrimary1()) ); } } diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp index 2f54a22..979af0b 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/EditorSettingWidget.cpp @@ -1,6 +1,6 @@ #include "EditorSettingWidget.h" +#include "../ColorHelper.hpp" #include -#include #include EditorSettingWidget::EditorSettingWidget(QWidget* parent) @@ -8,7 +8,7 @@ EditorSettingWidget::EditorSettingWidget(QWidget* parent) { ui.setupUi(this); connect(ui.backgroundColorButton, &QPushButton::clicked, this, [this]() { - QColor color = QColorDialog::getColor(Qt::white, this, QString::fromLocal8Bit("选择背景颜色")); + QColor color = ColorHelper::execColorDialog(Qt::white, this, QString::fromLocal8Bit("选择背景颜色")); if (color.isValid()) { emit backgroundColorChanged(color); diff --git a/ArchitectureColoredPainting/src/main.cpp b/ArchitectureColoredPainting/src/main.cpp index 5bf6bbe..0e3d73b 100644 --- a/ArchitectureColoredPainting/src/main.cpp +++ b/ArchitectureColoredPainting/src/main.cpp @@ -1,11 +1,11 @@ #include "MainWindow.h" +#include "ColorHelper.hpp" #include #include #include #include #include #include "consoleapi2.h" -#include extern "C" { @@ -51,9 +51,7 @@ int main(int argc, char* argv[]) QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); QApplication a(argc, argv); Q_INIT_RESOURCE(resources); - QtMaterialTheme theme; - theme.setColor("primary1", QColor(0, 90, 158)); - QtMaterialStyle::instance().setTheme(&theme); + ColorHelper::instance(); //FramelessHelper::Core::setApplicationOSThemeAware(); FramelessConfig::instance()->set(Global::Option::ForceNonNativeBackgroundBlur); //FramelessConfig::instance()->set(Global::Option::EnableBlurBehindWindow); From f06fbbaef6a238066323c4360a7dbdf0ac778530 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 14:44:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?FIX:=20=E6=9A=82=E6=97=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E5=B1=82=E5=B1=9E=E6=80=A7=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84crash?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 17 +++++++++-------- .../src/Editor/PreviewWindow.cpp | 5 ++--- .../src/Editor/PreviewWindow.h | 1 + .../src/Editor/RightBar/InfoDisplayWidget.cpp | 5 ++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index eb5f228..b9930ab 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; 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) From 8a34f57251647a80fbed0d0b97f0a0161ae6b213 Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Mon, 20 Mar 2023 15:52:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=98=BE=E7=A4=BA/?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E5=9B=BE=E5=B1=82=E5=8A=9F=E8=83=BD=20|=20#1?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditorWidgetItem.ui | 11 +++++++ .../src/Editor/EditorWidgetItem.cpp | 3 +- .../src/Editor/GraphicElement.cpp | 2 +- .../src/Editor/LayerWrapper.cpp | 32 +++++++++---------- .../src/Editor/LayerWrapper.h | 7 ++-- .../src/Editor/RightBar/LayerTreeWidget.cpp | 5 +++ 6 files changed, 39 insertions(+), 21 deletions(-) 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 b9930ab..2693b45 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -74,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/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); }