diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 43 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 14 |
3 files changed, 52 insertions, 8 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) { diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index f219929..f0d4fef 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -21,7 +21,7 @@ namespace Swift { Q_OBJECT; public: enum Mode { Rubber, Line, Rect, Circle, HandLine, FilledHandLine, Text, Polygon, Select }; - enum Type { New, Update }; + enum Type { New, Update, MoveUp, MoveDown }; GView(QGraphicsScene* scene, QWidget* parent = 0); void setLineWidth(int i); void setLineColor(QColor color); @@ -38,6 +38,7 @@ namespace Swift { QGraphicsItem* getItem(QString id); void deleteItem(QString id); QString getNewID(); + void move(QGraphicsItem* item, int npos); public slots: void moveUpSelectedItem(); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 960254c..5654c06 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -34,7 +34,7 @@ namespace Swift { scene->setSceneRect(0, 0, 400, 400); //BspTreeIndex is buggy, there are problems after removing items //from scene - scene->setItemIndexMethod(QGraphicsScene::NoIndex); + //scene->setItemIndexMethod(QGraphicsScene::NoIndex); graphicsView = new GView(scene, this); graphicsView->setMode(GView::Line); @@ -147,6 +147,9 @@ namespace Swift { if (updateOp) { WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::Update); updateOp->getElement()->accept(visitor); + if (updateOp->getPos() != updateOp->getNewPos()) { + graphicsView->move(graphicsView->getItem(P2QSTRING(updateOp->getElement()->getID())), updateOp->getNewPos()); + } } WhiteboardDeleteOperation::ref deleteOp = boost::dynamic_pointer_cast<WhiteboardDeleteOperation>(operation); @@ -343,7 +346,6 @@ namespace Swift { if (type == GView::New) { WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); -// insertOp->setID(el->getID()); insertOp->setID(Q2PSTRING(graphicsView->getNewID())); insertOp->setPos(pos); insertOp->setElement(el); @@ -352,9 +354,15 @@ namespace Swift { whiteboardSession_->sendOperation(insertOp); } else { WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(); -// updateOp->setID(el->getID()); updateOp->setID(Q2PSTRING(graphicsView->getNewID())); updateOp->setPos(pos); + if (type == GView::Update) { + updateOp->setNewPos(pos); + } else if (type == GView::MoveUp) { + updateOp->setNewPos(pos+1); + } else if (type == GView::MoveDown) { + updateOp->setNewPos(pos-1); + } updateOp->setElement(el); updateOp->setParentID(lastOpID); lastOpID = updateOp->getID(); |