diff options
Diffstat (limited to 'Swift/QtUI/Whiteboard/GView.cpp')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index a4f000b..0fb42a0 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -380,14 +380,49 @@ namespace Swift { void GView::moveUpSelectedItem() { - QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); - item->setZValue(item->zValue()+1); + if (selectionRect) { + QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); + int pos = items_.indexOf(item); + if (pos < items_.size()-1) { + lastItemChanged(item, pos+1, MoveUp); + move(item, pos+2); + } + } } void GView::moveDownSelectedItem() { - QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); - item->setZValue(item->zValue()-1); + if (selectionRect) { + QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); + int pos = items_.indexOf(item); + if (pos > 0) { + lastItemChanged(item, pos+1, MoveDown); + move(item, pos); + } + } + } + + void GView::move(QGraphicsItem* item, int npos) { + int pos = items_.indexOf(item); + QGraphicsItem* itemAfter = NULL; + if (npos-1 > pos) { + if (npos == items_.size()) { + item->setZValue(zValue++); + } else { + itemAfter = items_.at(npos); + } + + items_.insert(npos, item); + items_.removeAt(pos); + } else if (npos-1 < pos) { + itemAfter = items_.at(npos-1); + items_.insert(npos-1, item); + items_.removeAt(pos+1); + } + if (itemAfter) { + item->setZValue(itemAfter->zValue()); + item->stackBefore(itemAfter); + } } void GView::changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush) { |