From f3cc4c80787657ea770468915ec716dea2676d22 Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Fri, 15 Jun 2012 15:47:48 +0200 Subject: Moved elements parsing to WhiteboardParser diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h index b821940..d40ff08 100644 --- a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h +++ b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h @@ -12,16 +12,14 @@ namespace Swift { class WhiteboardSession; + class WhiteboardElement; class WhiteboardWindow { public: virtual ~WhiteboardWindow() {} virtual void show() = 0; - virtual void addItem(const std::string& item) = 0; virtual void setSession(boost::shared_ptr session) = 0; virtual void activateWindow() = 0; - - boost::signal onItemAdd; }; } diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index 5ac00da..6a141ee 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -46,6 +46,7 @@ namespace Swift { QGraphicsItem* lastItem; QGraphicsRectItem* selectionRect; TextDialog* textDialog; + QHash items_; signals: void lastItemChanged(QGraphicsItem* item); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 80c4447..24eb6cf 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include using namespace std; @@ -127,24 +129,10 @@ namespace Swift { setSession(whiteboardSession); } - void QtWhiteboardWindow::addItem(const std::string& item) { - string temp; - char mode; - int x1, x2, y1, y2; - std::istringstream stream(item); - stream.get(mode); - if (mode == 'L') { - getline(stream, temp, ','); - x1 = atoi(temp.c_str()); - getline(stream, temp, ','); - y1 = atoi(temp.c_str()); - getline(stream, temp, ','); - x2 = atoi(temp.c_str()); - getline(stream, temp, ','); - y2 = atoi(temp.c_str()); - QGraphicsLineItem *lineItem = new QGraphicsLineItem(x1, y1, x2, y2); - graphicsView->scene()->addItem(lineItem); - } + void QtWhiteboardWindow::handleWhiteboardElementReceive(const WhiteboardElement::ref element) { + WhiteboardElementDrawingVisitor visitor(graphicsView); + element->accept(visitor); +/* else if (mode == 'F') { FreehandLineItem *freehandLineItem = new FreehandLineItem(); getline(stream, temp, ','); @@ -159,7 +147,7 @@ namespace Swift { freehandLineItem->lineTo(QPointF(x1, y1)); } graphicsView->scene()->addItem(freehandLineItem); - } + }*/ } void QtWhiteboardWindow::changeLineWidth(int i) @@ -233,7 +221,7 @@ namespace Swift { void QtWhiteboardWindow::setSession(WhiteboardSession::ref session) { whiteboardSession_ = session; - whiteboardSession_->onDataReceived.connect(boost::bind(&QtWhiteboardWindow::addItem, this, _1)); + 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)); } @@ -247,10 +235,6 @@ namespace Swift { QGraphicsLineItem* lineItem = qgraphicsitem_cast(item); if (lineItem != 0) { QLine line = lineItem->line().toLine(); -/* std::stringstream stream; - stream << "L"; - stream << line.x1() << "," << line.y1() << "," << line.x2() << "," << line.y2(); - stream >> serialized;*/ WhiteboardLineElement::ref element = boost::make_shared(line.x1(), line.y1(), line.x2(), line.y2()); whiteboardSession_->sendElement(element); @@ -258,8 +242,6 @@ namespace Swift { FreehandLineItem* freehandLineItem = qgraphicsitem_cast(item); if (freehandLineItem != 0) { QVector points = freehandLineItem->points(); - - QVector::iterator it; std::stringstream stream; stream << "F"; @@ -269,17 +251,6 @@ namespace Swift { } stream >> serialized; } - if (!serialized.empty()) { - cout << "serialized: " << serialized << endl; -/* boost::shared_ptr mes(new Message()); - mes->setTo(jid_); - boost::shared_ptr wbPayload(new WhiteboardPayload); - wbPayload->setData(serialized); -// mes->setType(Swift::Message::Chat); - mes->addPayload(wbPayload); -// stanzaChannel_->sendMessage(mes);*/ - whiteboardSession_->sendData(serialized); - } } void QtWhiteboardWindow::handleSessionTerminate() { diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h index 5db19e9..fc55495 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -31,7 +32,6 @@ namespace Swift { Q_OBJECT; public: QtWhiteboardWindow(WhiteboardSession::ref whiteboardSession); - void addItem(const std::string& item); void show(); void setSession(WhiteboardSession::ref session); void activateWindow(); @@ -53,6 +53,7 @@ namespace Swift { private: void handleSessionTerminate(); + void handleWhiteboardElementReceive(const WhiteboardElement::ref element); void closeEvent(QCloseEvent* event); private: diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h new file mode 100644 index 0000000..962fd79 --- /dev/null +++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include +#include +#include + +namespace Swift { + class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor { + public: + WhiteboardElementDrawingVisitor(GView* graphicsView) : graphicsView_(graphicsView) {} + + void visit(const WhiteboardLineElement* element) { + QGraphicsLineItem *item = new QGraphicsLineItem(element->x1(), element->y1(), element->x2(), element->y2()); + graphicsView_->scene()->addItem(item); + } + + private: + GView* graphicsView_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp index 4306497..ef3c119 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -5,7 +5,9 @@ */ #include +#include #include +#include namespace Swift { WhiteboardParser::WhiteboardParser() : level_(0) { @@ -13,8 +15,16 @@ namespace Swift { void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { if (level_ == 0) { -// std::string type = attributes.getAttribute("type"); getPayloadInternal()->setType(stringToType(attributes.getAttributeValue("type").get_value_or(""))); + } else if (level_ == 1) { + if (element == "line") { + int x1 = std::atoi(attributes.getAttributeValue("x1").get_value_or("0").c_str()); + int y1 = std::atoi(attributes.getAttributeValue("y1").get_value_or("0").c_str()); + int x2 = std::atoi(attributes.getAttributeValue("x2").get_value_or("0").c_str()); + int y2 = std::atoi(attributes.getAttributeValue("y2").get_value_or("0").c_str()); + WhiteboardLineElement::ref whiteboardElement = boost::make_shared(x1, y1, x2, y2); + getPayloadInternal()->setElement(whiteboardElement); + } } ++level_; } diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h index faa698b..79d0f27 100644 --- a/Swiften/Parser/PayloadParsers/WhiteboardParser.h +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.h @@ -8,6 +8,7 @@ #include #include +#include namespace Swift { class WhiteboardParser : public Swift::GenericPayloadParser { diff --git a/Swiften/Whiteboard/WhiteboardSession.cpp b/Swiften/Whiteboard/WhiteboardSession.cpp index 9e4fd9f..18dea52 100644 --- a/Swiften/Whiteboard/WhiteboardSession.cpp +++ b/Swiften/Whiteboard/WhiteboardSession.cpp @@ -27,7 +27,7 @@ namespace Swift { switch (payload->getType()) { case WhiteboardPayload::Data: - onDataReceived(payload->getData()); + onElementReceived(payload->getElement()); break; case WhiteboardPayload::SessionAccept: onRequestAccepted(toJID_); diff --git a/Swiften/Whiteboard/WhiteboardSession.h b/Swiften/Whiteboard/WhiteboardSession.h index fb4305c..e7deb85 100644 --- a/Swiften/Whiteboard/WhiteboardSession.h +++ b/Swiften/Whiteboard/WhiteboardSession.h @@ -32,7 +32,7 @@ namespace Swift { const JID& getTo() const; public: - boost::signal< void(const std::string& data)> onDataReceived; + boost::signal< void(const WhiteboardElement::ref element)> onElementReceived; boost::signal< void(const JID& contact)> onSessionTerminateReceived; boost::signal< void(const JID& contact)> onRequestAccepted; boost::signal< void(const JID& contact)> onSessionCancelled; -- cgit v0.10.2-6-g49f6