diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 36 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 6 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 13 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h | 25 |
4 files changed, 53 insertions, 27 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index 588f369..fe0e5f9 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -55,6 +55,14 @@ namespace Swift { items_.insert(id, item); } + void GView::setIDPrefix(QString prefix) { + idPrefix = prefix; + } + + QString GView::getNewID() { + return idPrefix + P2QSTRING(idGenerator.generateID()); + } + void GView::mouseMoveEvent(QMouseEvent* event) { if (!mousePressed) { @@ -168,20 +176,20 @@ namespace Swift { if (mode == Line) { QPointF point = this->mapToScene(event->pos()); QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); - item->setData(0, id); + item->setData(100, id); lastItem = item; } else if (mode == Rect) { QPointF point = this->mapToScene(event->pos()); QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); - item->setData(1, id); + item->setData(100, id); lastItem = item; } else if (mode == Rubber) { @@ -199,22 +207,22 @@ namespace Swift { else if (mode == Circle) { QPointF point = this->mapToScene(event->pos()); QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); - item->setData(1, id); + item->setData(100, id); lastItem = item; } else if (mode == HandLine) { QPointF point = this->mapToScene(event->pos()); FreehandLineItem* item = new FreehandLineItem; - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setPen(pen); item->setStartPoint(point); item->setZValue(zValue++); - item->setData(0, id); + item->setData(100, id); scene()->addItem(item); lastItem = item; } @@ -222,20 +230,20 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QPainterPath path; QGraphicsPathItem* item = scene()->addPath(path, pen, brush); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); - item->setData(1, id); + item->setData(100, id); lastItem = item; } else if (mode == Text) { QPointF point = this->mapToScene(event->pos()); QGraphicsTextItem* item = scene()->addText(""); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); - item->setData(0, id); + item->setData(100, id); item->setDefaultTextColor(pen.color()); textDialog = new TextDialog(item, this); connect(textDialog, SIGNAL(accepted(QGraphicsItem*)), this, SIGNAL(lastItemChanged(QGraphicsItem*))); @@ -252,10 +260,10 @@ namespace Swift { polygon.append(point); polygon.append(point); item = scene()->addPolygon(polygon, pen, brush); - QString id = P2QSTRING(idGenerator.generateID()); + QString id = getNewID(); items_.insert(id, item); item->setZValue(zValue++); - item->setData(0, id); + item->setData(100, id); lastItem = item; } else { diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index 8b416a1..4830381 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -33,12 +33,15 @@ namespace Swift { void mouseReleaseEvent(QMouseEvent* event); QGraphicsItem* getItem(const QString id) const; void addItem(QGraphicsItem* item, QString id); + void setIDPrefix(QString prefix); public slots: void moveUpSelectedItem(); void moveDownSelectedItem(); private: + QString getNewID(); + int zValue; bool mousePressed; QPen pen; @@ -47,8 +50,9 @@ namespace Swift { QGraphicsItem* lastItem; QGraphicsRectItem* selectionRect; TextDialog* textDialog; - QHash<QString, QGraphicsItem*> items_; + QMap<QString, QGraphicsItem*> items_; SimpleIDGenerator idGenerator; + QString idPrefix; signals: void lastItemChanged(QGraphicsItem* item); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 6e259a2..9aa6eb0 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -205,6 +205,7 @@ namespace Swift { void QtWhiteboardWindow::setSession(WhiteboardSession::ref session) { whiteboardSession_ = session; + graphicsView->setIDPrefix(P2QSTRING(whiteboardSession_->getClientID())); whiteboardSession_->onElementReceived.connect(boost::bind(&QtWhiteboardWindow::handleWhiteboardElementReceive, this, _1)); whiteboardSession_->onRequestAccepted.connect(boost::bind(&QWidget::show, this)); whiteboardSession_->onSessionTerminateReceived.connect(boost::bind(&QtWhiteboardWindow::handleSessionTerminate, this)); @@ -224,7 +225,7 @@ namespace Swift { element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); element->setPenWidth(lineItem->pen().width()); - element->setID(lineItem->data(0).toString().toStdString()); + element->setID(lineItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } @@ -242,7 +243,7 @@ namespace Swift { element->setPenWidth(freehandLineItem->pen().width()); element->setPoints(points); - element->setID(freehandLineItem->data(0).toString().toStdString()); + element->setID(freehandLineItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } @@ -257,7 +258,7 @@ namespace Swift { element->setPenColor(Color(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha())); element->setPenWidth(rectItem->pen().width()); - element->setID(rectItem->data(1).toString().toStdString()); + element->setID(rectItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } @@ -270,7 +271,7 @@ namespace Swift { QColor color = textItem->defaultTextColor(); element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); - element->setID(rectItem->data(0).toString().toStdString()); + element->setID(rectItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } @@ -292,7 +293,7 @@ namespace Swift { element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha())); element->setPenWidth(polygonItem->pen().width()); - element->setID(polygonItem->data(0).toString().toStdString()); + element->setID(polygonItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } @@ -311,7 +312,7 @@ namespace Swift { element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha())); element->setPenWidth(ellipseItem->pen().width()); - element->setID(ellipseItem->data(1).toString().toStdString()); + element->setID(ellipseItem->data(100).toString().toStdString()); whiteboardSession_->sendElement(element); } } diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h index f3d2526..38ed676 100644 --- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h +++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h @@ -27,7 +27,9 @@ namespace Swift { pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())); pen.setWidth(element.getPenWidth()); item->setPen(pen); - graphicsView_->scene()->addItem(item); + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } void visit(WhiteboardFreehandPathElement& element) { @@ -44,7 +46,9 @@ namespace Swift { item->lineTo(QPointF(it->first, it->second)); } - graphicsView_->scene()->addItem(item); + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } void visit(WhiteboardRectElement& element) { @@ -58,7 +62,9 @@ namespace Swift { brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha())); item->setPen(pen); item->setBrush(brush); - graphicsView_->scene()->addItem(item); + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } void visit(WhiteboardPolygonElement& element) { @@ -74,7 +80,9 @@ namespace Swift { brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha())); item->setPen(pen); item->setBrush(brush); - graphicsView_->addItem(item, P2QSTRING(element.getID())); + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } QPolygonF polygon; std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin(); @@ -92,7 +100,10 @@ namespace Swift { item->setFont(font); Color color = element.getColor(); item->setDefaultTextColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())); - graphicsView_->scene()->addItem(item); + + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } void visit(WhiteboardEllipseElement& element) { @@ -111,7 +122,9 @@ namespace Swift { brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha())); item->setPen(pen); item->setBrush(brush); - graphicsView_->scene()->addItem(item); + QString id = P2QSTRING(element.getID()); + item->setData(100, id); + graphicsView_->addItem(item, id); } private: |