From 578fd5da8ea417c07a64321a24b89aa537b545dd Mon Sep 17 00:00:00 2001 From: karlis <2995621482@qq.com> Date: Wed, 22 Mar 2023 20:17:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=9B=BE=E5=85=83=E6=9B=B4?= =?UTF-8?q?=E6=94=B9=E5=90=8E=E5=88=97=E8=A1=A8=E4=B8=8D=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Editor/EditorWidgetItem.cpp | 1 + .../src/Editor/ElementPoolWidget.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp index b2a04f9..d694c05 100644 --- a/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp +++ b/ArchitectureColoredPainting/src/Editor/EditorWidgetItem.cpp @@ -85,6 +85,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p this->projectName = source.value("project-name").toString(); qDebug() << this->backgroundColor; qDebug() << this->projectName; + elementInfoDisplayWidget->refresh(); QTimer::singleShot(300, this, [this, centralRefresh]() { handleBackgroundColorChange(this->backgroundColor); handleProjectNameChange(this->projectName); diff --git a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp index e6c18a2..7d9901e 100644 --- a/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/ElementPoolWidget.cpp @@ -10,7 +10,7 @@ ElementPoolWidget::ElementPoolWidget(QWidget* parent) : QWidget(parent) { elementManager = nullptr; - iconWidth = 120, iconHeight = 90; + iconWidth = 120, iconHeight = 120; pictureList = new QListWidget(this); pictureList->setContextMenuPolicy(Qt::CustomContextMenu); pictureList->setIconSize(QSize(iconWidth, iconHeight)); @@ -41,7 +41,7 @@ void ElementPoolWidget::setElementList(std::vector elements) { for (int index = 0; index < elements.size(); index++) { QListWidgetItem* pItem = new QListWidgetItem(elements[index]->name); QPainter* painter = new QPainter(); - QImage* image = new QImage(QSize(iconWidth - 12, iconHeight - 12), QImage::Format_ARGB32); + QImage* image = new QImage(QSize(iconWidth - 25, iconHeight - 25), QImage::Format_ARGB32); image->fill(Qt::transparent); pItem->setIcon(QIcon(QPixmap::fromImage(*image))); pItem->setSizeHint(QSize(iconWidth, iconHeight)); @@ -84,6 +84,9 @@ void ElementPoolWidget::refresh() { refreshWait = false; if (elementManager != nullptr) { + elements = elementManager->elements; + for (int i = elements.size(); i < pictureList->count(); i++) + pictureList->takeItem(i); for (int i = 0; i < elements.size(); i++) { QListWidgetItem* pItem = pictureList->item(i); @@ -93,7 +96,7 @@ void ElementPoolWidget::refresh() { pictureList->insertItem(i, pItem); } QPainter* painter = new QPainter(); - QImage* image = new QImage(QSize(iconWidth - 12, iconHeight - 12), QImage::Format_ARGB32); + QImage* image = new QImage(QSize(iconWidth - 25, iconHeight - 25), QImage::Format_ARGB32); image->fill(Qt::transparent); painter->begin(image); elements[i]->paintPreview(painter); @@ -101,6 +104,7 @@ void ElementPoolWidget::refresh() { pItem->setIcon(QIcon(QPixmap::fromImage(*image))); pItem->setData(Qt::UserRole, QVariant::fromValue(image)); pItem->setSizeHint(QSize(iconWidth, iconHeight)); + pItem->setText(elements[i]->name); pictureList->insertItem(i, pItem); } } @@ -154,11 +158,12 @@ void ElementPoolWidget::popMenu(const QPoint& pos) if (bOk && !sName.isEmpty()) { currentElement->name = sName; - emit triggerCentralRefresh(); + this->refresh(); } }); - menu->addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this, currentElement]() { + menu->addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this, currentElement, currentIndex]() { this->elementManager->removeElement(currentElement); + this->refresh(); }); menu->actions().last()->setDisabled(currentElement->referencedCount > 0); } @@ -175,6 +180,7 @@ void ElementPoolWidget::popMenu(const QPoint& pos) QString fileName = fileInfo.fileName(); qDebug() << fileName << " " << filePath; this->elementManager->createSimpleElement(fileName, filePath); + this->refresh(); emit triggerCentralRefresh(); }); }