diff options
-rw-r--r-- | Swift/Controllers/UIInterfaces/WhiteboardWindow.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 1 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 45 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.h | 3 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h | 26 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/WhiteboardParser.cpp | 12 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/WhiteboardParser.h | 1 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.cpp | 2 | ||||
-rw-r--r-- | Swiften/Whiteboard/WhiteboardSession.h | 2 |
9 files changed, 52 insertions, 44 deletions
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<WhiteboardSession> session) = 0; virtual void activateWindow() = 0; - - boost::signal<void (std::string)> 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<QString, QGraphicsItem*> 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 <Swiften/Whiteboard/WhiteboardSession.h> #include <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> +#include <Swiften/Base/SimpleIDGenerator.h> +#include <Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h> #include <QMessageBox> 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<QGraphicsLineItem*>(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<WhiteboardLineElement>(line.x1(), line.y1(), line.x2(), line.y2()); whiteboardSession_->sendElement(element); @@ -258,8 +242,6 @@ 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"; @@ -269,17 +251,6 @@ namespace Swift { } stream >> serialized; } - if (!serialized.empty()) { - cout << "serialized: " << serialized << endl; -/* boost::shared_ptr<Message> mes(new Message()); - mes->setTo(jid_); - boost::shared_ptr<WhiteboardPayload> 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 <Swift/Controllers/UIInterfaces/WhiteboardWindow.h> #include <Swiften/Elements/Message.h> #include <Swiften/Whiteboard/WhiteboardSession.h> +#include <Swiften/Whiteboard/Elements/WhiteboardElement.h> #include <QWidget> #include <QGraphicsView> @@ -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 <Swiften/Whiteboard/Elements/WhiteboardElementVisitor.h> +#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> +#include <Swift/QtUI/Whiteboard/GView.h> + +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 <Swiften/Parser/PayloadParsers/WhiteboardParser.h> +#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h> #include <boost/optional.hpp> +#include <boost/smart_ptr/make_shared.hpp> 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<WhiteboardLineElement>(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 <Swiften/Elements/WhiteboardPayload.h> #include <Swiften/Parser/GenericPayloadParser.h> +#include <Swiften/Whiteboard/Elements/WhiteboardElement.h> namespace Swift { class WhiteboardParser : public Swift::GenericPayloadParser<WhiteboardPayload> { 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; |