diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-24 18:37:27 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-24 18:37:27 (GMT) |
commit | 06bbc72598ece3e62b82471e474b0753d5439f00 (patch) | |
tree | b1af2cd0717aff4e8d3427e22873b87410375cd2 /Swift/QtUI | |
parent | 286a3d119ec95b235b09935296450ec36e640aeb (diff) | |
download | swift-contrib-06bbc72598ece3e62b82471e474b0753d5439f00.zip swift-contrib-06bbc72598ece3e62b82471e474b0753d5439f00.tar.bz2 |
Added handling of rects and basic handling of polygons
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 26 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 66 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h | 43 |
4 files changed, 118 insertions, 18 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index 478dee0..e904b32 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -45,6 +45,10 @@ namespace Swift { lastItem = 0; } + QGraphicsItem* GView::getItem(const QString id) const { + return items_.value(id); + } + void GView::mouseMoveEvent(QMouseEvent* event) { if (!mousePressed) { @@ -144,17 +148,19 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen); QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); item->setData(0, id); - items_.insert(id, item); 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 = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); + item->setData(1, id); lastItem = item; } else if (mode == Rubber) { @@ -172,16 +178,22 @@ namespace Swift { else if (mode == Circle) { QPointF point = this->mapToScene(event->pos()); QGraphicsPathItem* item = scene()->addPath(QPainterPath(), pen, brush); + QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); + item->setData(1, id); lastItem = item; } else if (mode == HandLine) { QPointF point = this->mapToScene(event->pos()); FreehandLineItem* item = new FreehandLineItem; + QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setPen(pen); item->setStartPoint(point); item->setZValue(zValue++); + item->setData(0, id); scene()->addItem(item); lastItem = item; } @@ -189,19 +201,26 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QPainterPath path; QGraphicsPathItem* item = scene()->addPath(path, pen, brush); + QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); + item->setData(1, id); lastItem = item; } else if (mode == Text) { QPointF point = this->mapToScene(event->pos()); QGraphicsTextItem* item = scene()->addText(""); + QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); + item->setData(0, id); item->setDefaultTextColor(pen.color()); textDialog = new TextDialog(item, this); textDialog->setAttribute(Qt::WA_DeleteOnClose); textDialog->show(); item->setPos(point); + lastItem = item; } else if (mode == Polygon) { QPointF point = this->mapToScene(event->pos()); @@ -211,7 +230,10 @@ namespace Swift { polygon.append(point); polygon.append(point); item = scene()->addPolygon(polygon, pen, brush); + QString id = QString::fromStdString(idGenerator.generateID()); + items_.insert(id, item); item->setZValue(zValue++); + item->setData(0, id); lastItem = item; } else { diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index 74da7a4..1a4dc42 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -31,6 +31,7 @@ namespace Swift { void mouseMoveEvent(QMouseEvent* event); void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); + QGraphicsItem* getItem(const QString id) const; public slots: void moveUpSelectedItem(); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 0a1afe3..a53b0dd 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -14,6 +14,7 @@ #include <Swiften/Whiteboard/WhiteboardSession.h> #include <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardRectElement.h> #include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h> #include <QMessageBox> @@ -131,22 +132,6 @@ namespace Swift { void QtWhiteboardWindow::handleWhiteboardElementReceive(const WhiteboardElement::ref element) { WhiteboardElementDrawingVisitor visitor(graphicsView); element->accept(visitor); -/* - else if (mode == 'F') { - FreehandLineItem *freehandLineItem = new FreehandLineItem(); - getline(stream, temp, ','); - x1 = atoi(temp.c_str()); - getline(stream, temp, ','); - y1 = atoi(temp.c_str()); - freehandLineItem->setStartPoint(QPointF(x1, y1)); - while (getline(stream, temp, ',')) { - x1 = atoi(temp.c_str()); - getline(stream, temp, ','); - y1 = atoi(temp.c_str()); - freehandLineItem->lineTo(QPointF(x1, y1)); - } - graphicsView->scene()->addItem(freehandLineItem); - }*/ } void QtWhiteboardWindow::changeLineWidth(int i) @@ -259,7 +244,56 @@ namespace Swift { element->setID(freehandLineItem->data(0).toString().toStdString()); whiteboardSession_->sendElement(element); + } + + 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()); + QColor penColor = rectItem->pen().color(); + QColor brushColor = rectItem->brush().color(); + + element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha())); + element->setPenColor(Color(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha())); + element->setPenWidth(rectItem->pen().width()); + + element->setID(rectItem->data(1).toString().toStdString()); + whiteboardSession_->sendElement(element); + } + + QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item); + if (textItem != 0) { + QPointF point = textItem->pos(); + WhiteboardTextElement::ref element = boost::make_shared<WhiteboardTextElement>(point.x(), point.y()); + element->setText(textItem->toPlainText().toStdString()); + + QColor color = textItem->defaultTextColor(); + element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); + + element->setID(rectItem->data(0).toString().toStdString()); + whiteboardSession_->sendElement(element); + } + QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item); + if (polygonItem) { + WhiteboardPolygonElement::ref element = boost::make_shared<WhiteboardPolygonElement>(); + QPolygonF polygon = polygonItem->polygon(); + 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())); + } + + element->setPoints(points); + + QColor penColor = polygonItem->pen().color(); + QColor brushColor = polygonItem->brush().color(); + element->setPenColor(Color(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha())); + element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha())); + element->setPenWidth(polygonItem->pen().width()); + + element->setID(polygonItem->data(0).toString().toStdString()); + whiteboardSession_->sendElement(element); } } diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h index 3b144cc..ebc9045 100644 --- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h +++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h @@ -8,6 +8,8 @@ #include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h> #include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardPolygonElement.h> +#include <Swiften/Whiteboard/Elements/WhiteboardTextElement.h> #include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h> #include <Swift/QtUI/Whiteboard/GView.h> @@ -43,6 +45,47 @@ namespace Swift { graphicsView_->scene()->addItem(item); } + void visit(WhiteboardRectElement& element) { + QGraphicsRectItem* item = new QGraphicsRectItem(element.getX(), element.getY(), element.getWidth(), element.getHeight()); + QPen pen; + QBrush brush(Qt::SolidPattern); + Color penColor = element.getPenColor(); + Color brushColor = element.getBrushColor(); + pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha())); + pen.setWidth(element.getPenWidth()); + brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha())); + item->setPen(pen); + item->setBrush(brush); + graphicsView_->scene()->addItem(item); + } + + void visit(WhiteboardPolygonElement& element) { + QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(QString::fromStdString(element.getID()))); + if (item == 0) { + item = new QGraphicsPolygonItem(); + QPen pen; + QBrush brush(Qt::SolidPattern); + Color penColor = element.getPenColor(); + Color brushColor = element.getBrushColor(); + pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha())); + pen.setWidth(element.getPenWidth()); + brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha())); + item->setPen(pen); + item->setBrush(brush); + graphicsView_->scene()->addItem(item); + } + QPolygonF polygon; + std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin(); + for (; it != element.getPoints().end(); ++it) { + polygon.append(QPointF(it->first, it->second)); + } + item->setPolygon(polygon); + } + + void visit(WhiteboardTextElement& element) { + + } + private: GView* graphicsView_; }; |