添加Layer的组合元素创建
parent
c92a3553ce
commit
2cb25b8607
|
@ -28,7 +28,17 @@ void LayerCreateWidget::accept()
|
|||
jsonObj.insert("is-folder", true);
|
||||
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());
|
||||
emit LayerInfoReturned(jsonObj);
|
||||
QDialog::accept();
|
||||
|
|
|
@ -14,6 +14,8 @@ EditorWidgetItem::EditorWidgetItem(QString filePath,QWidget *parent) : QWidget(p
|
|||
elementInfoDisplayWidget = dynamic_cast<ElementPoolWidget *>(tabWidget->widget(1));
|
||||
qDebug() << layerInfoDisplayWidget;
|
||||
qDebug() << elementInfoDisplayWidget;
|
||||
connect(treeWidget, &LayerTreeWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshElementWidget, elementInfoDisplayWidget, &ElementPoolWidget::refresh);
|
||||
connect(treeWidget, &LayerTreeWidget::displayLayerChange, this, &EditorWidgetItem::onLayerChange);
|
||||
connect(layerInfoDisplayWidget, &InfoDisplayWidget::requireRefreshPreview, this,
|
||||
&EditorWidgetItem::triggerRefreshPreview);
|
||||
|
|
|
@ -10,7 +10,7 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
|||
elements.push_back(new GroupElement());
|
||||
else
|
||||
elements.push_back(new SimpleElement(elementJson.toObject()));
|
||||
|
||||
(*elements.rbegin())->name = elementJson.toObject().value("name").toString();
|
||||
(*elements.rbegin())->renderer = renderer;
|
||||
}
|
||||
for (auto element : elements)
|
||||
|
@ -19,10 +19,19 @@ ElementManager::ElementManager(QJsonObject source,Renderer::ElementRenderer* ren
|
|||
|
||||
void ElementManager::addElement(GraphicElement *element)
|
||||
{
|
||||
this->elements.push_back(element);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -68,3 +77,26 @@ int ElementManager::getLayerReferencedBy(const FolderLayerWrapper* layer)
|
|||
|
||||
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();
|
||||
void addElement(GraphicElement *element);
|
||||
void removeElement(GraphicElement *pElement);
|
||||
void removeElement(int index);
|
||||
void createGroupElement(QString name, FolderLayerWrapper* sourceLayer);
|
||||
void createSimpleElement(QString name, QString filePath);
|
||||
QJsonObject toJson()const;
|
||||
/**
|
||||
* only used in initialization
|
||||
|
|
|
@ -4,7 +4,7 @@ ElementPoolWidget::ElementPoolWidget(QWidget* parent)
|
|||
: QWidget(parent)
|
||||
{
|
||||
elementManager = nullptr;
|
||||
iconWidth = 100, iconHeight = 75;
|
||||
iconWidth = 120, iconHeight = 90;
|
||||
pictureList = new QListWidget();
|
||||
pictureList->setIconSize(QSize(iconWidth, iconHeight));
|
||||
pictureList->setWindowFlags(Qt::FramelessWindowHint);
|
||||
|
@ -48,7 +48,7 @@ void ElementPoolWidget::setElementList(std::vector<GraphicElement*> elements) {
|
|||
//p->show();
|
||||
|
||||
QListWidgetItem* pItem = new QListWidgetItem(
|
||||
itemPixmap.scaled(QSize(iconWidth - 15, iconHeight - 15)),
|
||||
itemPixmap.scaled(QSize(iconWidth - 25, iconHeight - 25)),
|
||||
elements[index]->name);
|
||||
pItem->setSizeHint(QSize(iconWidth, iconHeight));
|
||||
pictureList->insertItem(index, pItem);
|
||||
|
|
|
@ -40,6 +40,7 @@ private:
|
|||
|
||||
public:
|
||||
SimpleElement(QJsonObject jsonSource);
|
||||
SimpleElement(QString filePath);
|
||||
~SimpleElement() = default;
|
||||
PixelPath getPaintObject() 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));
|
||||
connect(rotation, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.rotation = content.toDouble();
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
offsetX->setValidator(new QIntValidator(-10000, 10000, this));
|
||||
connect(offsetX, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.offset = {content.toDouble(), this->displayLayer->property.offset.y()};
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
offsetY->setValidator(new QIntValidator(-10000, 10000, this));
|
||||
connect(offsetY, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.offset = {this->displayLayer->property.offset.x(), content.toDouble()};
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
scaleX->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||
connect(scaleX, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.scale = {content.toDouble(), this->displayLayer->property.scale.y()};
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
scaleY->setValidator(new QDoubleValidator(0.001, 1000, 4, this));
|
||||
connect(scaleY, &QLineEdit::textChanged, [=](QString content) {
|
||||
this->displayLayer->property.scale = {this->displayLayer->property.scale.x(), content.toDouble()};
|
||||
emit requireRefreshElementWidget();
|
||||
emit requireRefreshPreview();
|
||||
});
|
||||
|
||||
|
@ -106,6 +111,7 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
leafP->styles.push_back(dialog->layerStyle);
|
||||
emit requireRefreshPreview();
|
||||
emit requireSelfRefresh();
|
||||
emit requireRefreshElementWidget();
|
||||
}
|
||||
dialog->deleteLater();
|
||||
});
|
||||
|
@ -201,6 +207,7 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
(*styleIterator) = dialog->layerStyle;
|
||||
emit requireRefreshPreview();
|
||||
emit requireSelfRefresh();
|
||||
emit requireRefreshElementWidget();
|
||||
}
|
||||
dialog->deleteLater();
|
||||
});
|
||||
|
@ -211,6 +218,7 @@ void InfoDisplayWidget::generateLayerForm()
|
|||
styles->erase(styleIterator);
|
||||
emit requireRefreshPreview();
|
||||
emit requireSelfRefresh();
|
||||
emit requireRefreshElementWidget();
|
||||
});
|
||||
|
||||
QWidget* styleDisplayWidget = (*styleIterator)->getListDisplayWidget();
|
||||
|
|
|
@ -23,6 +23,6 @@ class InfoDisplayWidget : public QWidget
|
|||
signals:
|
||||
void requireRefreshPreview();
|
||||
void requireSelfRefresh();
|
||||
|
||||
void requireRefreshElementWidget();
|
||||
|
||||
};
|
||||
|
|
|
@ -50,11 +50,13 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
newLayer = new FolderLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||
else
|
||||
newLayer = new LeafLayerWrapper(jsonObj, this->elementManager, folderLayer);
|
||||
|
||||
folderLayer->addChild(std::shared_ptr<LayerWrapper>(newLayer));
|
||||
folderLayer->qTreeWidgetItem->addChild(newLayer->getQTreeItem());
|
||||
qDebug() << jsonObj<<"----------------------";
|
||||
this->refresh();
|
||||
emit requireRefreshPreview();
|
||||
emit requireRefreshElementWidget();
|
||||
});
|
||||
dialog->exec();
|
||||
});
|
||||
|
@ -76,6 +78,21 @@ void LayerTreeWidget::popMenu(const QPoint &pos)
|
|||
});
|
||||
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));
|
||||
|
|
|
@ -23,4 +23,5 @@ class LayerTreeWidget : public QTreeWidget
|
|||
signals:
|
||||
void displayLayerChange(LayerWrapper *);
|
||||
void requireRefreshPreview();
|
||||
void requireRefreshElementWidget();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue