summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-21 18:05:56 (GMT)
commit286a3d119ec95b235b09935296450ec36e640aeb (patch)
tree9146c0ebb21745bb985d24378829929ce92529e2 /Swift/QtUI/Whiteboard
parente0c79b3b885f126a2a2a34cb0d5df90796821130 (diff)
downloadswift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.zip
swift-contrib-286a3d119ec95b235b09935296450ec36e640aeb.tar.bz2
Added parsing and serialization of freehand path element
Diffstat (limited to 'Swift/QtUI/Whiteboard')
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.cpp2
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.h2
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp22
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h26
4 files changed, 38 insertions, 14 deletions
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
index af8e827..bd53843 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
@@ -86,7 +86,7 @@ namespace Swift {
return pen_;
}
- QVector<QPointF> FreehandLineItem::points() const {
+ const QVector<QPointF>& FreehandLineItem::points() const {
return points_;
}
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.h b/Swift/QtUI/Whiteboard/FreehandLineItem.h
index e995cab..b0be36b 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.h
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.h
@@ -24,7 +24,7 @@ namespace Swift {
bool collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode mode = Qt::IntersectsItemShape) const;
void setPen(const QPen& pen);
QPen pen() const;
- QVector<QPointF> points() const;
+ const QVector<QPointF>& points() const;
int type() const;
private:
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index 612e467..0a1afe3 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -245,15 +245,21 @@ namespace Swift {
}
FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item);
if (freehandLineItem != 0) {
- QVector<QPointF> points = freehandLineItem->points();
- QVector<QPointF>::iterator it;
- std::stringstream stream;
- stream << "F";
- QPoint point;
- for (it = points.begin(); it != points.end(); ++it) {
- stream << it->x() << "," << it->y() << ",";
+ WhiteboardFreehandPathElement::ref element = boost::make_shared<WhiteboardFreehandPathElement>();
+ QColor color = freehandLineItem->pen().color();
+ 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()));
}
- stream >> serialized;
+
+ element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha()));
+ element->setPenWidth(freehandLineItem->pen().width());
+ element->setPoints(points);
+
+ element->setID(freehandLineItem->data(0).toString().toStdString());
+ whiteboardSession_->sendElement(element);
+
}
}
diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
index a1715bc..3b144cc 100644
--- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
+++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
@@ -8,6 +8,7 @@
#include <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h>
#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h>
#include <Swift/QtUI/Whiteboard/GView.h>
namespace Swift {
@@ -15,16 +16,33 @@ namespace Swift {
public:
WhiteboardElementDrawingVisitor(GView* graphicsView) : graphicsView_(graphicsView) {}
- void visit(const WhiteboardLineElement* element) {
- QGraphicsLineItem *item = new QGraphicsLineItem(element->x1(), element->y1(), element->x2(), element->y2());
+ void visit(WhiteboardLineElement& element) {
+ QGraphicsLineItem *item = new QGraphicsLineItem(element.x1(), element.y1(), element.x2(), element.y2());
QPen pen;
- Color color = element->getColor();
+ Color color = element.getColor();
pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
- pen.setWidth(element->getPenWidth());
+ pen.setWidth(element.getPenWidth());
item->setPen(pen);
graphicsView_->scene()->addItem(item);
}
+ void visit(WhiteboardFreehandPathElement& element) {
+ FreehandLineItem *item = new FreehandLineItem;
+ QPen pen;
+ Color color = element.getColor();
+ pen.setColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ item->setPen(pen);
+
+ std::vector<std::pair<int, int> >::const_iterator it = element.getPoints().begin();
+ item->setStartPoint(QPointF(it->first, it->second));
+ for (++it; it != element.getPoints().end(); ++it) {
+ item->lineTo(QPointF(it->first, it->second));
+ }
+
+ graphicsView_->scene()->addItem(item);
+ }
+
private:
GView* graphicsView_;
};