diff options
Diffstat (limited to 'Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp')
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 5743d80..add9802 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -16,10 +16,11 @@ #include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h> #include <Swiften/Whiteboard/Operations/WhiteboardInsertOperation.h> +#include <Swiften/Whiteboard/Operations/WhiteboardUpdateOperation.h> #include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h> #include <QMessageBox> -using namespace std; +//using namespace std; namespace Swift { QtWhiteboardWindow::QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession) : QWidget() { @@ -36,7 +37,7 @@ namespace Swift { graphicsView = new GView(scene, this); graphicsView->setMode(GView::Line); - connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int))); + connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*, int, GView::Type)), this, SLOT(handleLastItemChanged(QGraphicsItem*, int, GView::Type))); widthBox = new QSpinBox(this); connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int))); @@ -132,18 +133,20 @@ namespace Swift { setSession(whiteboardSession); } - void QtWhiteboardWindow::handleWhiteboardElementReceive(const WhiteboardElement::ref element) { -// WhiteboardElementDrawingVisitor visitor(graphicsView); -// element->accept(visitor); - } - void QtWhiteboardWindow::handleWhiteboardOperationReceive(const WhiteboardOperation::ref operation) { - WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos()); WhiteboardInsertOperation::ref insertOp = boost::dynamic_pointer_cast<WhiteboardInsertOperation>(operation); if (insertOp) { + WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::New); insertOp->getElement()->accept(visitor); lastOpID = insertOp->getID(); } + + WhiteboardUpdateOperation::ref updateOp = boost::dynamic_pointer_cast<WhiteboardUpdateOperation>(operation); + if (updateOp) { + WhiteboardElementDrawingVisitor visitor(graphicsView, operation->getPos(), GView::Update); + updateOp->getElement()->accept(visitor); + lastOpID = updateOp->getID(); + } } void QtWhiteboardWindow::changeLineWidth(int i) @@ -219,7 +222,6 @@ namespace Swift { graphicsView->clear(); whiteboardSession_ = session; graphicsView->setIDPrefix(P2QSTRING(whiteboardSession_->getClientID())); - whiteboardSession_->onElementReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardElementReceive, this, _1)); whiteboardSession_->onOperationReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardOperationReceive, this, _1)); whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this)); whiteboardSession_->onSessionTerminateReceived.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this)); @@ -229,13 +231,14 @@ namespace Swift { QWidget::activateWindow(); } - void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos) { + void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item, int pos, GView::Type type) { WhiteboardElement::ref el; QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item); if (lineItem != 0) { QLine line = lineItem->line().toLine(); QColor color = lineItem->pen().color(); - WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1(), line.y1(), line.x2(), line.y2()); + WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1()+lineItem->pos().x(), line.y1()+lineItem->pos().y(), line.x2()+lineItem->pos().x(), line.y2()+lineItem->pos().y()); +// element->setShift(lineItem->pos().x(), lineItem->pos().y()); element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); element->setPenWidth(lineItem->pen().width()); @@ -250,7 +253,7 @@ namespace Swift { std::vector<std::pair<int, int> > points; QVector<QPointF>::const_iterator it = freehandLineItem->points().constBegin(); for ( ; it != freehandLineItem->points().constEnd(); ++it) { - points.push_back(std::pair<int, int>(it->x(), it->y())); + points.push_back(std::pair<int, int>(it->x()+item->pos().x(), it->y()+item->pos().y())); } element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); @@ -265,7 +268,7 @@ namespace Swift { QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item); if (rectItem != 0) { QRectF rect = rectItem->rect(); - WhiteboardRectElement::ref element = boost::make_shared<WhiteboardRectElement>(rect.x(), rect.y(), rect.width(), rect.height()); + WhiteboardRectElement::ref element = boost::make_shared<WhiteboardRectElement>(rect.x()+item->pos().x(), rect.y()+item->pos().y(), rect.width(), rect.height()); QColor penColor = rectItem->pen().color(); QColor brushColor = rectItem->brush().color(); @@ -299,7 +302,7 @@ namespace Swift { std::vector<std::pair<int, int> > points; QVector<QPointF>::const_iterator it = polygon.begin(); for (; it != polygon.end(); ++it) { - points.push_back(std::pair<int, int>(it->x(), it->y())); + points.push_back(std::pair<int, int>(it->x()+item->pos().x(), it->y()+item->pos().y())); } element->setPoints(points); @@ -318,8 +321,8 @@ namespace Swift { QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); if (ellipseItem) { QRectF rect = ellipseItem->rect(); - int cx = rect.x()+rect.width()/2; - int cy = rect.y()+rect.height()/2; + int cx = rect.x()+rect.width()/2 + item->pos().x(); + int cy = rect.y()+rect.height()/2 + item->pos().y(); int rx = rect.width()/2; int ry = rect.height()/2; WhiteboardEllipseElement::ref element = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry); @@ -334,13 +337,24 @@ namespace Swift { // whiteboardSession_->sendElement(element); el = element; } - WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); - insertOp->setID(el->getID()); - insertOp->setPos(pos); - insertOp->setElement(el); - insertOp->setParentID(lastOpID); - lastOpID = el->getID(); - whiteboardSession_->sendOperation(insertOp); + + if (type == GView::New) { + WhiteboardInsertOperation::ref insertOp = boost::make_shared<WhiteboardInsertOperation>(); + insertOp->setID(el->getID()); + insertOp->setPos(pos); + insertOp->setElement(el); + insertOp->setParentID(lastOpID); + lastOpID = el->getID(); + whiteboardSession_->sendOperation(insertOp); + } else { + WhiteboardUpdateOperation::ref updateOp = boost::make_shared<WhiteboardUpdateOperation>(); + updateOp->setID(el->getID()); + updateOp->setPos(pos); + updateOp->setElement(el); + updateOp->setParentID(lastOpID); + lastOpID = el->getID(); + whiteboardSession_->sendOperation(updateOp); + } } void QtWhiteboardWindow::handleSessionTerminate() { |