Compare commits
2 Commits
631f0f8af7
...
e3217aa134
Author | SHA1 | Date |
---|---|---|
karlis | e3217aa134 | |
karlis | 2cb25b8607 |
|
@ -28,7 +28,17 @@ void LayerCreateWidget::accept()
|
||||||
jsonObj.insert("is-folder", true);
|
jsonObj.insert("is-folder", true);
|
||||||
jsonObj.insert("children", QJsonArray());
|
jsonObj.insert("children", QJsonArray());
|
||||||
}
|
}
|
||||||
jsonObj.insert("tranform", "{\"offset\":{\"x\":0,\"y\":0},\"scale\":{\"x\":1,\"y\":1},\"rotation\":0}");
|
QJsonObject transform;
|
||||||
|
QJsonObject offset;
|
||||||
|
QJsonObject scale;
|
||||||
|
scale.insert("x", 1);
|
||||||
|
scale.insert("y", 1);
|
||||||
|
offset.insert("x", 0);
|
||||||
|
offset.insert("y", 0);
|
||||||
|
transform.insert("offset", offset);
|
||||||
|
transform.insert("scale", scale);
|
||||||
|
transform.insert("rotation", 0);
|
||||||
|
jsonObj.insert("transform", transform);
|
||||||
jsonObj.insert("referenced-by", QJsonValue());
|
jsonObj.insert("referenced-by", QJsonValue());
|
||||||
emit LayerInfoReturned(jsonObj);
|
emit LayerInfoReturned(jsonObj);
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
|
|
|
@ -14,6 +14,8 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
||||||
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
||||||
qDebug() << layerInfoDisplayWidget;
|
qDebug() << layerInfoDisplayWidget;
|
||||||
qDebug() << elementInfoDisplayWidget;
|
qDebug() << elementInfoDisplayWidget;
|
||||||
|
connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||||
|
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||||
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);
|
||||||
|
|
|
@ -10,7 +10,7 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
||||||
elements.push_back(new GroupElement());
|
elements.push_back(new GroupElement());
|
||||||
else
|
else
|
||||||
elements.push_back(new SimpleElement(elementJson.toObject()));
|
elements.push_back(new SimpleElement(elementJson.toObject()));
|
||||||
|
(*elements.rbegin())->name = elementJson.toObject().value("name").toString();
|
||||||
(*elements.rbegin())->renderer = renderer;
|
(*elements.rbegin())->renderer = renderer;
|
||||||
}
|
}
|
||||||
for (auto element : elements)
|
for (auto element : elements)
|
||||||
|
@ -19,10 +19,19 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
||||||
|
|
||||||
void ElementManager::addElement(GraphicElement *element)
|
void ElementManager::addElement(GraphicElement *element)
|
||||||
{
|
{
|
||||||
|
this->elements.push_back(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElementManager::removeElement(GraphicElement *pElement)
|
void ElementManager::removeElement(GraphicElement *pElement)
|
||||||
{
|
{
|
||||||
|
for (auto& element : elements)
|
||||||
|
{
|
||||||
|
if (element == pElement)
|
||||||
|
{
|
||||||
|
elements.erase(std::find(elements.begin(), elements.end(), element));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicElement *ElementManager::getElementById(int index)
|
GraphicElement *ElementManager::getElementById(int index)
|
||||||
|
@ -67,4 +76,27 @@ int ElementManager::getLayerReferencedBy(const FolderLayerWrapper* layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ElementManager::removeElement(int index)
|
||||||
|
{
|
||||||
|
if (index < elements.size())
|
||||||
|
elements.erase(elements.begin() + index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ElementManager::createGroupElement(QString name, FolderLayerWrapper* sourceLayer) {
|
||||||
|
auto element = new GroupElement();
|
||||||
|
element->name = name;
|
||||||
|
element->setSourceLayer(sourceLayer);
|
||||||
|
addElement(element);
|
||||||
|
}
|
||||||
|
void ElementManager::createSimpleElement(QString name, QString filePath) {
|
||||||
|
QJsonObject json;
|
||||||
|
QJsonObject data;
|
||||||
|
data.insert("include", filePath);
|
||||||
|
json.insert("data", data);
|
||||||
|
auto element = new SimpleElement(json);
|
||||||
|
element->name = name;
|
||||||
|
addElement(element);
|
||||||
}
|
}
|
|
@ -20,6 +20,9 @@ class ElementManager
|
||||||
~ElementManager();
|
~ElementManager();
|
||||||
void addElement(GraphicElement *element);
|
void addElement(GraphicElement *element);
|
||||||
void removeElement(GraphicElement *pElement);
|
void removeElement(GraphicElement *pElement);
|
||||||
|
void removeElement(int index);
|
||||||
|
void createGroupElement(QString name, FolderLayerWrapper* sourceLayer);
|
||||||
|
void createSimpleElement(QString name, QString filePath);
|
||||||
QJsonObject toJson()const;
|
QJsonObject toJson()const;
|
||||||
/**
|
/**
|
||||||
* only used in initialization
|
* only used in initialization
|
||||||
|
|
|
@ -4,7 +4,7 @@ ElementPoolWidget::ElementPoolWidget(QWidget* parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
{
|
{
|
||||||
elementManager = nullptr;
|
elementManager = nullptr;
|
||||||
iconWidth = 100, iconHeight = 75;
|
iconWidth = 120, iconHeight = 90;
|
||||||
pictureList = new QListWidget();
|
pictureList = new QListWidget();
|
||||||
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
||||||
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
@ -48,7 +48,7 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
|
||||||
//p->show();
|
//p->show();
|
||||||
|
|
||||||
QListWidgetItem* pItem = new QListWidgetItem(
|
QListWidgetItem* pItem = new QListWidgetItem(
|
||||||
itemPixmap.scaled(QSize(iconWidth - 15, iconHeight - 15)),
|
itemPixmap.scaled(QSize(iconWidth - 25, iconHeight - 25)),
|
||||||
elements[index]->name);
|
elements[index]->name);
|
||||||
pItem->setSizeHint(QSize(iconWidth, iconHeight));
|
pItem->setSizeHint(QSize(iconWidth, iconHeight));
|
||||||
pictureList->insertItem(index, pItem);
|
pictureList->insertItem(index, pItem);
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SimpleElement(QJsonObject jsonSource);
|
SimpleElement(QJsonObject jsonSource);
|
||||||
|
SimpleElement(QString filePath);
|
||||||
~SimpleElement() = default;
|
~SimpleElement() = default;
|
||||||
PixelPath getPaintObject() const override;
|
PixelPath getPaintObject() const override;
|
||||||
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
|
PixelPath getPaintObject(std::vector<std::shared_ptr<LayerStyle>>*) const override;
|
||||||
|
|
|
@ -46,26 +46,31 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
rotation->setValidator(new QIntValidator(-10000, 10000, this));
|
rotation->setValidator(new QIntValidator(-10000, 10000, this));
|
||||||
connect(rotation, &QLineEdit::textChanged, [=](QString content) {
|
connect(rotation, &QLineEdit::textChanged, [=](QString content) {
|
||||||
this->displayLayer->property.rotation = content.toDouble();
|
this->displayLayer->property.rotation = content.toDouble();
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
offsetX->setValidator(new QIntValidator(-10000, 10000, this));
|
offsetX->setValidator(new QIntValidator(-10000, 10000, this));
|
||||||
connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
|
connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
|
||||||
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
|
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
offsetY->setValidator(new QIntValidator(-10000, 10000, this));
|
offsetY->setValidator(new QIntValidator(-10000, 10000, this));
|
||||||
connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
|
connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
|
||||||
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
|
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||||
connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
|
connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
|
||||||
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
|
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||||
connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
|
connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
|
||||||
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
|
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -106,6 +111,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
leafP->styles.push_back(dialog->layerStyle);
|
leafP->styles.push_back(dialog->layerStyle);
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
emit requireSelfRefresh();
|
emit requireSelfRefresh();
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
}
|
}
|
||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
});
|
});
|
||||||
|
@ -201,6 +207,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
(*styleIterator) = dialog->layerStyle;
|
(*styleIterator) = dialog->layerStyle;
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
emit requireSelfRefresh();
|
emit requireSelfRefresh();
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
}
|
}
|
||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
});
|
});
|
||||||
|
@ -211,6 +218,7 @@ void InfoDisplayWidget::generateLayerForm()
|
||||||
styles->erase(styleIterator);
|
styles->erase(styleIterator);
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
emit requireSelfRefresh();
|
emit requireSelfRefresh();
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
});
|
});
|
||||||
|
|
||||||
QWidget* styleDisplayWidget = (*styleIterator)->getListDisplayWidget();
|
QWidget* styleDisplayWidget = (*styleIterator)->getListDisplayWidget();
|
||||||
|
|
|
@ -23,6 +23,6 @@ class InfoDisplayWidget : public QWidget
|
||||||
signals:
|
signals:
|
||||||
void requireRefreshPreview();
|
void requireRefreshPreview();
|
||||||
void requireSelfRefresh();
|
void requireSelfRefresh();
|
||||||
|
void requireRefreshElementWidget();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,20 +50,22 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
||||||
newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||||
else
|
else
|
||||||
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||||
|
|
||||||
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
|
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
|
||||||
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
|
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
|
||||||
qDebug() << jsonObj<<"----------------------";
|
qDebug() << jsonObj<<"----------------------";
|
||||||
this->refresh();
|
this->refresh();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
});
|
});
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
});
|
});
|
||||||
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
menu.addAction(QString::fromLocal8Bit("删除(保留子节点)"), this, [this]() {
|
||||||
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
auto layer = this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>();
|
||||||
layer->delSelf();
|
layer->delSelf();
|
||||||
layer->getParent()->removeChild(layer);
|
layer->getParent()->removeChild(layer);
|
||||||
this->refresh();
|
this->refresh();
|
||||||
emit requireRefreshPreview();
|
emit requireRefreshPreview();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (layer != root) {
|
if (layer != root) {
|
||||||
|
@ -76,6 +78,21 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
||||||
});
|
});
|
||||||
menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent);
|
menu.addAction(QString::fromLocal8Bit("重命名"), this, &LayerTreeWidget::onRenameEvent);
|
||||||
}
|
}
|
||||||
|
if (typeid(*layer) == typeid(FolderLayerWrapper) && ((FolderLayerWrapper*)layer)->getReferencedBy() == -1) {
|
||||||
|
menu.addAction(QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"), this, [this]() {
|
||||||
|
auto layer = dynamic_cast<FolderLayerWrapper*>(this->selectedItem->data(0, Qt::UserRole).value<LayerWrapper*>());
|
||||||
|
if (layer != nullptr) {
|
||||||
|
bool ok;
|
||||||
|
QString name = QInputDialog::getText(this, QString::fromLocal8Bit("´´½¨×éºÏÔªËØ"),
|
||||||
|
QString::fromLocal8Bit("×éºÏÔªËØÃû³Æ:"), QLineEdit::Normal,
|
||||||
|
"", &ok);
|
||||||
|
if (ok && !name.isEmpty()) {
|
||||||
|
elementManager->createGroupElement(name, layer);
|
||||||
|
emit requireRefreshElementWidget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.exec(mapToGlobal(pos));
|
menu.exec(mapToGlobal(pos));
|
||||||
|
|
|
@ -23,4 +23,5 @@ class LayerTreeWidget : public QTreeWidget
|
||||||
signals:
|
signals:
|
||||||
void displayLayerChange(LayerWrapper *);
|
void displayLayerChange(LayerWrapper *);
|
||||||
void requireRefreshPreview();
|
void requireRefreshPreview();
|
||||||
|
void requireRefreshElementWidget();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue