实现element导入,添加滚动条,修复空白打开
parent
5d88ddf0ca
commit
c234c0e9b3
|
@ -37,38 +37,87 @@
|
|||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="MainWindow" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="30">
|
||||
<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>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="20,1">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,12,5">
|
||||
<item>
|
||||
<widget class="QWidget" name="LeftBar" native="true"/>
|
||||
</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">
|
||||
<size>
|
||||
<width>1080</width>
|
||||
<height>1080</height>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>1080</width>
|
||||
<height>1080</height>
|
||||
<width>10801080</width>
|
||||
<height>10801080</height>
|
||||
</size>
|
||||
</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>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -138,6 +187,19 @@
|
|||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
</widget>
|
||||
</item>
|
||||
|
|
|
@ -24,6 +24,7 @@ EditorWidget::EditorWidget(QWidget* parent) : QWidget(parent)
|
|||
});
|
||||
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]() {
|
||||
|
|
|
@ -12,6 +12,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
this->filePath = filePath;
|
||||
layerInfoDisplayWidget = dynamic_cast<InfoDisplayWidget *>(tabWidget->widget(0));
|
||||
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
||||
elementInfoDisplayWidget->enableEdit();
|
||||
qDebug() << layerInfoDisplayWidget;
|
||||
qDebug() << elementInfoDisplayWidget;
|
||||
connect(previewWindow, &PreviewWindow::layerInfoChanged, layerInfoDisplayWidget, &InfoDisplayWidget::triggerSelfRefresh);
|
||||
|
@ -37,7 +38,7 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
qDebug() << jError.errorString();
|
||||
// end test
|
||||
QJsonObject source = jsonDoc.object();
|
||||
elementManager = new ElementManager(source,previewWindow->getRenderer());
|
||||
elementManager = new ElementManager(source,Renderer::ElementRenderer::instance());
|
||||
layerManager = new LayerManager(source, elementManager);
|
||||
elementInfoDisplayWidget->setElementManager(elementManager);
|
||||
treeWidget->elementManager = elementManager;
|
||||
|
|
|
@ -97,6 +97,7 @@ void ElementManager::createSimpleElement(QString name, QString filePath) {
|
|||
data.insert("include", filePath);
|
||||
json.insert("data", data);
|
||||
auto element = new SimpleElement(json);
|
||||
qDebug() << element->painterPath;
|
||||
element->name = name;
|
||||
addElement(element);
|
||||
}
|
|
@ -1,11 +1,16 @@
|
|||
#include "ElementPoolWidget.h"
|
||||
#include <QMenu>
|
||||
#include <QInputDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
ElementPoolWidget::ElementPoolWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
elementManager = nullptr;
|
||||
iconWidth = 120, iconHeight = 90;
|
||||
pictureList = new QListWidget();
|
||||
pictureList = new QListWidget(this);
|
||||
pictureList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
||||
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
||||
pictureList->setResizeMode(QListWidget::Adjust);
|
||||
|
@ -89,3 +94,49 @@ void ElementPoolWidget::refreshPicture(GraphicElement* element) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 setElementManager(ElementManager* element);
|
||||
~ElementPoolWidget();
|
||||
void enableEdit();
|
||||
|
||||
signals:
|
||||
void elementSelected(GraphicElement* element);
|
||||
|
@ -29,5 +30,6 @@ public slots:
|
|||
int pictureItemClicked(QListWidgetItem* item);
|
||||
void refresh();
|
||||
void refreshPicture(GraphicElement* element);
|
||||
void popMenu(const QPoint& pos);
|
||||
};
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ SimpleElement::SimpleElement(QJsonObject jsonSource) : jsonSource(jsonSource)
|
|||
painterPath.clear();
|
||||
filePath = jsonSource["data"].toObject()["include"].toString();
|
||||
//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)
|
||||
|
|
|
@ -26,7 +26,6 @@ FolderLayerWrapper*LayerWrapper::getParent() const
|
|||
PixelPath LayerWrapper::getCache(LayerWrapper* selectedLayer)
|
||||
{
|
||||
this->refresh(selectedLayer);
|
||||
qDebug() << cache.painterPath;
|
||||
if (selectedLayer == this)
|
||||
{
|
||||
this->cache.highLight();
|
||||
|
@ -131,9 +130,7 @@ void LeafLayerWrapper::refresh(LayerWrapper* layer)
|
|||
cache.clear();
|
||||
if (wrappedElement != nullptr)
|
||||
{
|
||||
qDebug() << cache.painterPath;
|
||||
cache.addPath(wrappedElement->getPaintObject(&(this->styles)));
|
||||
qDebug() << cache.painterPath;
|
||||
}
|
||||
LayerWrapper::refresh();
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ public:
|
|||
QPainterPath painterPath;
|
||||
int w,h;
|
||||
public:
|
||||
PixelPath(int w=1080, int h= 1080);
|
||||
PixelPath(QPainterPath painterPath,int w = 1080, int h = 1080);
|
||||
PixelPath(int w=1024, int h= 1024);
|
||||
PixelPath(QPainterPath painterPath,int w = 1024, int h = 1024);
|
||||
~PixelPath() = default;
|
||||
QRectF getBoundingRect() const;
|
||||
QPixmap getPixmap() const;
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
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();
|
||||
QSurfaceFormat surfaceFormat;
|
||||
surfaceFormat.setSamples(16);
|
||||
|
|
|
@ -68,13 +68,6 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
});
|
||||
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) {
|
||||
menu.addAction(QString::fromLocal8Bit("ɾ³ý"), this, [this]() {
|
||||
|
@ -85,6 +78,13 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
emit requireRefreshPreview();
|
||||
});
|
||||
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) {
|
||||
menu.addAction(QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"), this, [this]() {
|
||||
|
|
Loading…
Reference in New Issue