实现element导入,添加滚动条,修复空白打开
parent
5d88ddf0ca
commit
c234c0e9b3
|
@ -37,38 +37,87 @@
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="MainWindow" native="true">
|
<widget class="QWidget" name="MainWindow" native="true">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="30">
|
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="20,1">
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,12,5">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,12,5">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QWidget" name="LeftBar" native="true"/>
|
<widget class="QWidget" name="LeftBar" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="PreviewWindow" name="Preview">
|
<widget class="QScrollArea" name="scrollArea">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>1080</width>
|
<width>0</width>
|
||||||
<height>1080</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<property name="maximumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>1080</width>
|
<width>10801080</width>
|
||||||
<height>1080</height>
|
<height>10801080</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="widgetResizable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>1024</width>
|
||||||
|
<height>1024</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>1024</width>
|
||||||
|
<height>1024</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>10241024</width>
|
||||||
|
<height>10241024</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="PreviewWindow" name="Preview">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>1024</width>
|
||||||
|
<height>1024</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>1024</width>
|
||||||
|
<height>1024</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
@ -138,6 +187,19 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -24,7 +24,8 @@ EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent)
|
||||||
});
|
});
|
||||||
connect(this->openButton, &QPushButton::clicked, this, [this]() {
|
connect(this->openButton, &QPushButton::clicked, this, [this]() {
|
||||||
QString fileName = QFileDialog::getOpenFileName(this->saveAsButton, QString::fromLocal8Bit("´ò¿ª"), "", QString::fromLocal8Bit("JSONÎļþ(*.json)"));
|
QString fileName = QFileDialog::getOpenFileName(this->saveAsButton, QString::fromLocal8Bit("´ò¿ª"), "", QString::fromLocal8Bit("JSONÎļþ(*.json)"));
|
||||||
this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName);
|
if(!fileName.isEmpty())
|
||||||
|
this->tabWidget->addTab(new EditorWidgetItem(fileName, this), fileName);
|
||||||
});
|
});
|
||||||
connect(this->closeButton, &QPushButton::clicked, this, [this]() {
|
connect(this->closeButton, &QPushButton::clicked, this, [this]() {
|
||||||
this->tabWidget->removeTab(this->tabWidget->currentIndex());
|
this->tabWidget->removeTab(this->tabWidget->currentIndex());
|
||||||
|
|
|
@ -12,6 +12,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
this->filePath = filePath;
|
this->filePath = filePath;
|
||||||
layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
|
layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
|
||||||
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
||||||
|
elementInfoDisplayWidget->enableEdit();
|
||||||
qDebug() << layerInfoDisplayWidget;
|
qDebug() << layerInfoDisplayWidget;
|
||||||
qDebug() << elementInfoDisplayWidget;
|
qDebug() << elementInfoDisplayWidget;
|
||||||
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||||
|
@ -37,7 +38,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
qDebug() << jError.errorString();
|
qDebug() << jError.errorString();
|
||||||
// end test
|
// end test
|
||||||
QJsonObject source = jsonDoc.object();
|
QJsonObject source = jsonDoc.object();
|
||||||
elementManager = new ElementManager(source,previewWindow->getRenderer());
|
elementManager = new ElementManager(source,Renderer::ElementRenderer::instance());
|
||||||
layerManager = new LayerManager(source, elementManager);
|
layerManager = new LayerManager(source, elementManager);
|
||||||
elementInfoDisplayWidget->setElementManager(elementManager);
|
elementInfoDisplayWidget->setElementManager(elementManager);
|
||||||
treeWidget->elementManager = elementManager;
|
treeWidget->elementManager = elementManager;
|
||||||
|
|
|
@ -97,6 +97,7 @@ void ElementManager::createSimpleElement(QString name, QString filePath) {
|
||||||
data.insert("include", filePath);
|
data.insert("include", filePath);
|
||||||
json.insert("data", data);
|
json.insert("data", data);
|
||||||
auto element = new SimpleElement(json);
|
auto element = new SimpleElement(json);
|
||||||
|
qDebug() << element->painterPath;
|
||||||
element->name = name;
|
element->name = name;
|
||||||
addElement(element);
|
addElement(element);
|
||||||
}
|
}
|
|
@ -1,11 +1,16 @@
|
||||||
#include "ElementPoolWidget.h"
|
#include "ElementPoolWidget.h"
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
ElementPoolWidget::ElementPoolWidget(QWidget* parent)
|
ElementPoolWidget::ElementPoolWidget(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
elementManager = nullptr;
|
elementManager = nullptr;
|
||||||
iconWidth = 120, iconHeight = 90;
|
iconWidth = 120, iconHeight = 90;
|
||||||
pictureList = new QListWidget();
|
pictureList = new QListWidget(this);
|
||||||
|
pictureList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
||||||
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
pictureList->setResizeMode(QListWidget::Adjust);
|
pictureList->setResizeMode(QListWidget::Adjust);
|
||||||
|
@ -88,4 +93,50 @@ void ElementPoolWidget::refreshPicture(GraphicElement* element) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementPoolWidget::enableEdit()
|
||||||
|
{
|
||||||
|
connect(this->pictureList, &QListWidget::customContextMenuRequested, this, &ElementPoolWidget::popMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementPoolWidget::popMenu(const QPoint& pos)
|
||||||
|
{
|
||||||
|
QListWidgetItem* item = pictureList->itemAt(pos);
|
||||||
|
int currentIndex = -1;
|
||||||
|
if (item != nullptr)
|
||||||
|
{
|
||||||
|
currentIndex = pictureList->row(item);
|
||||||
|
}
|
||||||
|
QMenu* menu = new QMenu(this);
|
||||||
|
if (currentIndex >= 0 && currentIndex < elementManager->elements.size())
|
||||||
|
{
|
||||||
|
auto currentElement = this->elementManager->elements[currentIndex];
|
||||||
|
menu->addAction(QString::fromLocal8Bit("重命名"), this, [this, currentElement]() {
|
||||||
|
bool bOk = false;
|
||||||
|
QString sName =
|
||||||
|
QInputDialog::getText(this, QString::fromLocal8Bit("重命名"), QString::fromLocal8Bit("新名称:"), QLineEdit::Normal, currentElement->name, &bOk);
|
||||||
|
if (bOk && !sName.isEmpty())
|
||||||
|
{
|
||||||
|
currentElement->name = sName;
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu->addAction(QString::fromLocal8Bit("删除"), this, [this, currentElement]() {
|
||||||
|
this->elementManager->removeElement(currentElement);
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menu->addAction(QString::fromLocal8Bit("添加元素(从svg导入)"), this, [this]() {
|
||||||
|
QString filePath = QFileDialog::getOpenFileName(this, QString::fromLocal8Bit("打开文件"), "", "SVG Files (*.svg)");
|
||||||
|
QFileInfo fileInfo(filePath);
|
||||||
|
QString fileName = fileInfo.fileName();
|
||||||
|
qDebug() << fileName << " " << filePath;
|
||||||
|
this->elementManager->createSimpleElement(fileName, filePath);
|
||||||
|
refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
menu->popup(mapToGlobal(pos));
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ public:
|
||||||
void setElementList(std::vector<GraphicElement*> elementList);
|
void setElementList(std::vector<GraphicElement*> elementList);
|
||||||
void setElementManager(ElementManager* element);
|
void setElementManager(ElementManager* element);
|
||||||
~ElementPoolWidget();
|
~ElementPoolWidget();
|
||||||
|
void enableEdit();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void elementSelected(GraphicElement* element);
|
void elementSelected(GraphicElement* element);
|
||||||
|
@ -29,5 +30,6 @@ public slots:
|
||||||
int pictureItemClicked(QListWidgetItem* item);
|
int pictureItemClicked(QListWidgetItem* item);
|
||||||
void refresh();
|
void refresh();
|
||||||
void refreshPicture(GraphicElement* element);
|
void refreshPicture(GraphicElement* element);
|
||||||
|
void popMenu(const QPoint& pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,8 @@ SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
|
||||||
painterPath.clear();
|
painterPath.clear();
|
||||||
filePath = jsonSource["data"].toObject()["include"].toString();
|
filePath = jsonSource["data"].toObject()["include"].toString();
|
||||||
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
|
//loadSvgFile("D:\\Projects\\BigC\\svg\\3.svg");
|
||||||
loadSvgFile("../"/*TODO: 改成json文件所在文件夹路径*/ + jsonSource.value("data").toObject().value("include").toString());
|
QFileInfo info(filePath);
|
||||||
|
loadSvgFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupElement::GroupElement(FolderLayerWrapper* sourceLayer)
|
GroupElement::GroupElement(FolderLayerWrapper* sourceLayer)
|
||||||
|
|
|
@ -26,7 +26,6 @@ FolderLayerWrapper*LayerWrapper::getParent() const
|
||||||
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
|
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
|
||||||
{
|
{
|
||||||
this->refresh(selectedLayer);
|
this->refresh(selectedLayer);
|
||||||
qDebug() << cache.painterPath;
|
|
||||||
if (selectedLayer == this)
|
if (selectedLayer == this)
|
||||||
{
|
{
|
||||||
this->cache.highLight();
|
this->cache.highLight();
|
||||||
|
@ -131,9 +130,7 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer)
|
||||||
cache.clear();
|
cache.clear();
|
||||||
if (wrappedElement != nullptr)
|
if (wrappedElement != nullptr)
|
||||||
{
|
{
|
||||||
qDebug() << cache.painterPath;
|
|
||||||
cache.addPath(wrappedElement->getPaintObject(&(this->styles)));
|
cache.addPath(wrappedElement->getPaintObject(&(this->styles)));
|
||||||
qDebug() << cache.painterPath;
|
|
||||||
}
|
}
|
||||||
LayerWrapper::refresh();
|
LayerWrapper::refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ public:
|
||||||
QPainterPath painterPath;
|
QPainterPath painterPath;
|
||||||
int w,h;
|
int w,h;
|
||||||
public:
|
public:
|
||||||
PixelPath(int w=1080, int h= 1080);
|
PixelPath(int w=1024, int h= 1024);
|
||||||
PixelPath(QPainterPath painterPath,int w = 1080, int h = 1080);
|
PixelPath(QPainterPath painterPath,int w = 1024, int h = 1024);
|
||||||
~PixelPath() = default;
|
~PixelPath() = default;
|
||||||
QRectF getBoundingRect() const;
|
QRectF getBoundingRect() const;
|
||||||
QPixmap getPixmap() const;
|
QPixmap getPixmap() const;
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
PreviewWindow::PreviewWindow(QWidget *parent) : QOpenGLWidget(parent)
|
||||||
{
|
{
|
||||||
this->setFixedSize(QSize(1080, 1080));
|
//this->setFixedSize(QSize(108, 108));
|
||||||
|
this->setStyleSheet("border: 1px solid black");
|
||||||
this->renderer = Renderer::ElementRenderer::instance();
|
this->renderer = Renderer::ElementRenderer::instance();
|
||||||
QSurfaceFormat surfaceFormat;
|
QSurfaceFormat surfaceFormat;
|
||||||
surfaceFormat.setSamples(16);
|
surfaceFormat.setSamples(16);
|
||||||
|
|
|
@ -68,13 +68,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
||||||
});
|
});
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
});
|
});
|
||||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
|
||||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
|
||||||
layer->delSelf();
|
|
||||||
layer->getParent()->removeChild(layer);
|
|
||||||
this->refresh();
|
|
||||||
emit requireRefreshPreview();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (layer != root) {
|
if (layer != root) {
|
||||||
menu.addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this]() {
|
menu.addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this]() {
|
||||||
|
@ -85,6 +78,13 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
|
menu.addAction(QString::fromLocal8Bit("ÖØÃüÃû"), this, &LayerTreeWidget::onRenameEvent);
|
||||||
|
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||||
|
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||||
|
layer->delSelf();
|
||||||
|
layer->getParent()->removeChild(layer);
|
||||||
|
this->refresh();
|
||||||
|
emit requireRefreshPreview();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {
|
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {
|
||||||
menu.addAction(QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"), this, [this]() {
|
menu.addAction(QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"), this, [this]() {
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
"name": "ababa",
|
"name": "ababa",
|
||||||
"type": "svg-file",
|
"type": "svg-file",
|
||||||
"data": {
|
"data": {
|
||||||
"include": "./svg/2.svg"
|
"include": "../svg/2.svg"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -15,6 +15,13 @@
|
||||||
"data": {
|
"data": {
|
||||||
"reference-layer": "0.0"
|
"reference-layer": "0.0"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ababa2",
|
||||||
|
"type": "svg-file",
|
||||||
|
"data": {
|
||||||
|
"include": "../svg/0.svg"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"root-layer": {
|
"root-layer": {
|
||||||
|
|
Loading…
Reference in New Issue