diff --git a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp index 1914721..bf4dcce 100644 --- a/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp +++ b/ArchitectureColoredPainting/src/Editor/LayerWrapper.cpp @@ -309,9 +309,8 @@ void FolderLayerWrapper::paint(QPainter* painter, QTransform transform, bool for return; LayerWrapper::paint(painter, transform, force); transform = property.transform * transform; - //qDebug() << transform; - for (auto& child : children) - child->paint(painter, transform, force); + for (auto it = children.rbegin(); it != children.rend(); ++it) + (*it)->paint(painter, transform, force); } void LeafLayerWrapper::paint(QPainter* painter, QTransform transform, bool force) diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp index 448c6f6..4a2292e 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.cpp @@ -3,6 +3,7 @@ #include #include "./EditorWidgetComponent/LayerCreateWidget.h" #include +#include LayerTreeWidget::LayerTreeWidget(QWidget *parent) { @@ -131,4 +132,75 @@ void LayerTreeWidget::onRenameEvent() void LayerTreeWidget::refresh() { this->root->refreshTreeItem(); +} + +void LayerTreeWidget::keyPressEvent(QKeyEvent* event) +{ + if (QApplication::keyboardModifiers() == Qt::ALT) + { + if (event->key() == Qt::Key_Up) + { + pushUpLayer(); + } + else if (event->key() == Qt::Key_Down) + { + pushDownLayer(); + } + } +} + +void LayerTreeWidget::pushUpLayer() +{ + if (this->selectedItem == nullptr) + return; + auto layer = this->selectedItem->data(0, Qt::UserRole).value(); + if (layer == nullptr) + return; + auto parent = layer->getParent(); + int index = -1; + for (int i = 0; i < parent->children.size(); i++) + { + if (parent->children[i].get() == layer) + { + index = i; + break; + } + } + if (index == -1 || index == 0) + return; + auto temp = parent->children[index - 1]; + parent->children[index - 1] = parent->children[index]; + parent->children[index] = temp; + layer->qTreeWidgetItem->parent()->removeChild(layer->qTreeWidgetItem); + parent->qTreeWidgetItem->insertChild(index - 1, layer->qTreeWidgetItem); + this->setCurrentItem(layer->qTreeWidgetItem); + emit triggerCentralRefresh(); +} + +void LayerTreeWidget::pushDownLayer() +{ + if (this->selectedItem == nullptr) + return; + auto layer = this->selectedItem->data(0, Qt::UserRole).value(); + if (layer == nullptr) + return; + auto parent = layer->getParent(); + int index = -1; + for (int i = 0; i < parent->children.size(); i++) + { + if (parent->children[i].get() == layer) + { + index = i; + break; + } + } + if (index == -1 || index == parent->children.size() - 1) + return; + auto temp = parent->children[index + 1]; + parent->children[index + 1] = parent->children[index]; + parent->children[index] = temp; + layer->qTreeWidgetItem->parent()->removeChild(layer->qTreeWidgetItem); + parent->qTreeWidgetItem->insertChild(index + 1, layer->qTreeWidgetItem); + this->setCurrentItem(layer->qTreeWidgetItem); + emit triggerCentralRefresh(); } \ No newline at end of file diff --git a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h index a7f4c93..4dce9be 100644 --- a/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h +++ b/ArchitectureColoredPainting/src/Editor/RightBar/LayerTreeWidget.h @@ -9,6 +9,8 @@ class LayerTreeWidget : public QTreeWidget private: QTreeWidgetItem *selectedItem; LayerWrapper *copiedItem; + void pushUpLayer(); + void pushDownLayer(); public: ElementManager* elementManager; @@ -17,6 +19,7 @@ class LayerTreeWidget : public QTreeWidget void onRenameEvent(); void popMenu(const QPoint &pos); void refresh(); + void keyPressEvent(QKeyEvent* event) override; // void mouseDoubleClickEvent(QMouseEvent *event) override; // void onItemDoubleClicked(QTreeWidgetItem *item, int column = 0);