summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/UIInterfaces/WhiteboardWindow.h4
-rw-r--r--Swift/QtUI/Whiteboard/GView.h1
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp45
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h3
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h26
5 files changed, 38 insertions, 41 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_;
+ };
+}