添加了ElementPoolWidget

TaoZhang-Branch
karlis 2023-03-07 22:36:39 +08:00
parent edb7e37b91
commit 368eaa6c89
10 changed files with 67 additions and 16 deletions

View File

@ -53,14 +53,14 @@
<item> <item>
<widget class="QTabWidget" name="DisplayTab"> <widget class="QTabWidget" name="DisplayTab">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>1</number>
</property> </property>
<widget class="InfoDisplayWidget" name="LayerDisplay"> <widget class="InfoDisplayWidget" name="LayerDisplay">
<attribute name="title"> <attribute name="title">
<string>Layer</string> <string>Layer</string>
</attribute> </attribute>
</widget> </widget>
<widget class="QWidget" name="ElementDisplay"> <widget class="ElementPoolWidget" name="ElementDisplay">
<attribute name="title"> <attribute name="title">
<string>Element</string> <string>Element</string>
</attribute> </attribute>
@ -107,6 +107,12 @@
<header location="global">InfoDisplayWidget.h</header> <header location="global">InfoDisplayWidget.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>ElementPoolWidget</class>
<extends>QWidget</extends>
<header>ElementPoolWidget.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@ -11,7 +11,9 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
tabWidget = ui.DisplayTab; tabWidget = ui.DisplayTab;
this->filePath = filePath; this->filePath = filePath;
layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0)); layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
elementInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(1)); elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
qDebug() << layerInfoDisplayWidget;
qDebug() << elementInfoDisplayWidget;
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange); connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange);
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this, connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
&EditorWidgetItem::triggerRefreshPreview); &EditorWidgetItem::triggerRefreshPreview);
@ -33,8 +35,11 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
QJsonObject source = jsonDoc.object(); QJsonObject source = jsonDoc.object();
elementManager = new ElementManager(source,previewWindow->getRenderer()); elementManager = new ElementManager(source,previewWindow->getRenderer());
layerManager = new LayerManager(source, elementManager); layerManager = new LayerManager(source, elementManager);
elementInfoDisplayWidget->setElementManager(elementManager);
qDebug() << layerManager->toJson(); qDebug() << layerManager->toJson();
previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble())); previewWindow->initialize(layerManager,QSize(jsonDoc.object().value("width").toDouble(),jsonDoc.object().value("height").toDouble()));
if (layerManager->getRoot() != nullptr) if (layerManager->getRoot() != nullptr)
{ {
treeWidget->root = layerManager->getRoot(); treeWidget->root = layerManager->getRoot();
@ -49,6 +54,7 @@ EditorWidgetItem::~EditorWidgetItem()
void EditorWidgetItem::paintEvent(QPaintEvent *event) void EditorWidgetItem::paintEvent(QPaintEvent *event)
{ {
} }
void EditorWidgetItem::onLayerChange(LayerWrapper *layer) void EditorWidgetItem::onLayerChange(LayerWrapper *layer)

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "ElementManager.h" #include "ElementManager.h"
#include "ElementPoolWidget.h"
#include "InfoDisplayWidget.h" #include "InfoDisplayWidget.h"
#include "LayerManager.h" #include "LayerManager.h"
#include "LayerTreeWidget.h" #include "LayerTreeWidget.h"
@ -23,7 +24,8 @@ class EditorWidgetItem : public QWidget
Ui::EditorWidgetItem ui; Ui::EditorWidgetItem ui;
LayerTreeWidget *treeWidget; LayerTreeWidget *treeWidget;
QTabWidget *tabWidget; QTabWidget *tabWidget;
InfoDisplayWidget *layerInfoDisplayWidget, *elementInfoDisplayWidget; InfoDisplayWidget* layerInfoDisplayWidget;
ElementPoolWidget* elementInfoDisplayWidget;
// QT DATA PART // QT DATA PART
LayerWrapper *displayLayer; LayerWrapper *displayLayer;
GraphicElement *displayElement; GraphicElement *displayElement;

View File

@ -11,7 +11,7 @@ class Renderer::ElementRenderer;
class ElementManager class ElementManager
{ {
private: public:
vector<GraphicElement *> elements; vector<GraphicElement *> elements;
public: public:

View File

@ -19,11 +19,23 @@ ElementPoolWidget::ElementPoolWidget(QWidget* parent)
void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) { void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
pictureList->clear(); pictureList->clear();
this->elements = elements;
for (int index = 0; index < elements.size(); index++) { for (int index = 0; index < elements.size(); index++) {
// //
//QString strPath = QString("C:\\Users\\86177\\Pictures\\Screenshots\\test.png"); //QString strPath = QString("C:\\Users\\86177\\Pictures\\Screenshots\\test.png");
//QPixmap itemPixmap(strPath); //QPixmap itemPixmap(strPath);
QPixmap itemPixmap = elements[index]->getPaintObject().getPixmap(); QPixmap itemPixmap(QSize(200,200));
itemPixmap.fill(Qt::red);
//QPixmap itemPixmap = elements[index]->getPaintObject().getDetail();
qDebug() << this->parentWidget()->size();
//auto p = new QWidget();
//auto lb = new QLabel(p);
//lb->setPixmap(itemPixmap);
//lb->setFixedSize(1920, 1080);
//p->setFixedSize(1920, 1080);
//lb->show();
//p->show();
QListWidgetItem* pItem = new QListWidgetItem( QListWidgetItem* pItem = new QListWidgetItem(
itemPixmap.scaled(QSize(iconWidth-20, iconHeight-20)), itemPixmap.scaled(QSize(iconWidth-20, iconHeight-20)),
elements[index]->name); elements[index]->name);
@ -38,5 +50,12 @@ ElementPoolWidget::~ElementPoolWidget() {
int ElementPoolWidget::pictureItemClicked(QListWidgetItem* item) { int ElementPoolWidget::pictureItemClicked(QListWidgetItem* item) {
//qDebug() << pictureList->currentRow(); //qDebug() << pictureList->currentRow();
emit elementSelected(this->elements[pictureList->currentRow()]);
return pictureList->currentRow(); return pictureList->currentRow();
}
void ElementPoolWidget::setElementManager(ElementManager* element)
{
this->elementManager = element;
this->setElementList(this->elementManager->elements);
} }

View File

@ -3,17 +3,26 @@
#include <vector> #include <vector>
#include <GraphicElement.h> #include <GraphicElement.h>
#include <QListWidget> #include <QListWidget>
#include <ElementManager.h>
class ElementPoolWidget : public QWidget class ElementPoolWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
//std::vector<GraphicElement*> elements; std::vector<GraphicElement*> elements;
QListWidget* pictureList; QListWidget* pictureList;
int iconWidth, iconHeight; int iconWidth, iconHeight;
ElementManager* elementManager;
public: public:
ElementPoolWidget(QWidget* parent = NULL); ElementPoolWidget(QWidget* parent = nullptr);
void setElementList(std::vector<GraphicElement*> elementList); void setElementList(std::vector<GraphicElement*> elementList);
void setElementManager(ElementManager* element);
~ElementPoolWidget(); ~ElementPoolWidget();
signals:
void elementSelected(GraphicElement* element);
public slots: public slots:
int pictureItemClicked(QListWidgetItem* item); int pictureItemClicked(QListWidgetItem* item);
}; };

View File

@ -84,4 +84,15 @@ QPixmap PixelPath::resizedPixel(QSize size)const
painter.setRenderHint(QPainter::HighQualityAntialiasing); painter.setRenderHint(QPainter::HighQualityAntialiasing);
painter.drawPixmap(0, 0, pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); painter.drawPixmap(0, 0, pixmap.scaled(size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
return result; return result;
}
QPixmap PixelPath::getDetail()const
{
QPixmap result;
auto rect = boundingRect.toRect();
rect.setHeight(rect.height() + 20);
rect.setWidth(rect.width() + 20);
qDebug() << rect;
result = pixmap.copy(rect);
return result;
} }

View File

@ -23,4 +23,5 @@ public:
void clear(); void clear();
PixelPath trans(QTransform& mat)const; PixelPath trans(QTransform& mat)const;
QPixmap resizedPixel(QSize size)const; QPixmap resizedPixel(QSize size)const;
QPixmap getDetail()const;
}; };

View File

@ -11,11 +11,7 @@ void InfoDisplayWidget::setLayer(LayerWrapper *layer)
this->displayLayer = layer; this->displayLayer = layer;
generateLayerForm(); generateLayerForm();
} }
void InfoDisplayWidget::setElement(GraphicElement *element)
{
this->displayElement = element;
generateElementForm();
}
void InfoDisplayWidget::generateLayerForm() void InfoDisplayWidget::generateLayerForm()
{ {
QLayoutItem *item; QLayoutItem *item;
@ -144,12 +140,13 @@ void InfoDisplayWidget::generateLayerForm()
void InfoDisplayWidget::generateElementForm() void InfoDisplayWidget::generateElementForm()
{ {
} }
void InfoDisplayWidget::triggerSelfRefresh() void InfoDisplayWidget::triggerSelfRefresh()
{ {
if (this->displayLayer != nullptr) if (this->displayLayer != nullptr)
this->generateLayerForm(); this->generateLayerForm();
if (this->displayElement != nullptr) else
this->generateElementForm(); this->generateElementForm();
} }

View File

@ -4,17 +4,17 @@
#include <QFormLayout> #include <QFormLayout>
#include <QLabel> #include <QLabel>
#include <QWidget> #include <QWidget>
#include "ElementPoolWidget.h"
class InfoDisplayWidget : public QWidget class InfoDisplayWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
LayerWrapper *displayLayer; LayerWrapper *displayLayer;
GraphicElement *displayElement;
public: public:
void setLayer(LayerWrapper *layer); void setLayer(LayerWrapper *layer);
void setElement(GraphicElement *element);
void generateLayerForm(); void generateLayerForm();
void generateElementForm(); void generateElementForm();