summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-06-02 16:23:59 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-06-02 16:23:59 (GMT)
commit7520c7fed383d4f7631f5572ef40379022126264 (patch)
treeee87b26bb923d0289a670defce96e2012f3623e3
parente8ab1af885ff61715ab0350c3cb22ed6988a082a (diff)
downloadswift-contrib-7520c7fed383d4f7631f5572ef40379022126264.zip
swift-contrib-7520c7fed383d4f7631f5572ef40379022126264.tar.bz2
Added whiteboard controller with simple sharing
Whiteboard controller is handled in ChatController only for testing purposes.
-rw-r--r--Swift/Controllers/Chat/ChatController.cpp6
-rw-r--r--Swift/Controllers/Chat/ChatController.h2
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp3
-rw-r--r--Swift/Controllers/SConscript3
-rw-r--r--Swift/Controllers/UIInterfaces/UIFactory.h4
-rw-r--r--Swift/Controllers/UIInterfaces/WhiteboardWindow.h24
-rw-r--r--Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h17
-rw-r--r--Swift/Controllers/WhiteboardController.cpp45
-rw-r--r--Swift/Controllers/WhiteboardController.h31
-rw-r--r--Swift/QtUI/QtUIFactory.cpp5
-rw-r--r--Swift/QtUI/QtUIFactory.h1
-rw-r--r--Swift/QtUI/SConscript2
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.cpp32
-rw-r--r--Swift/QtUI/Whiteboard/FreehandLineItem.h7
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp2
-rw-r--r--Swift/QtUI/Whiteboard/GView.h4
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp97
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.h10
18 files changed, 259 insertions, 36 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp
index 2fa4559..38f443b 100644
--- a/Swift/Controllers/Chat/ChatController.cpp
+++ b/Swift/Controllers/Chat/ChatController.cpp
@@ -29,6 +29,8 @@
#include <Swiften/Elements/DeliveryReceipt.h>
#include <Swiften/Elements/DeliveryReceiptRequest.h>
#include <Swift/Controllers/SettingConstants.h>
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h>
+#include <Swift/Controllers/WhiteboardController.h>
#include <Swiften/Base/Log.h>
@@ -39,6 +41,8 @@ namespace Swift {
*/
ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQRouter* iqRouter, ChatWindowFactory* chatWindowFactory, const JID &contact, NickResolver* nickResolver, PresenceOracle* presenceOracle, AvatarManager* avatarManager, bool isInMUC, bool useDelayForLatency, UIEventStream* eventStream, EventController* eventController, TimerFactory* timerFactory, EntityCapsProvider* entityCapsProvider, bool userWantsReceipts, SettingsProvider* settings)
: ChatControllerBase(self, stanzaChannel, iqRouter, chatWindowFactory, contact, presenceOracle, avatarManager, useDelayForLatency, eventStream, eventController, timerFactory, entityCapsProvider), eventStream_(eventStream), userWantsReceipts_(userWantsReceipts), settings_(settings) {
+ WhiteboardWindowFactory* fac = dynamic_cast<WhiteboardWindowFactory*>(chatWindowFactory);
+ whiteboardController_ = new WhiteboardController(stanzaChannel, toJID_, fac);
isInMUC_ = isInMUC;
lastWasPresence_ = false;
chatStateNotifier_ = new ChatStateNotifier(stanzaChannel, contact, entityCapsProvider);
@@ -89,6 +93,7 @@ ChatController::~ChatController() {
nickResolver_->onNickChanged.disconnect(boost::bind(&ChatController::handleContactNickChanged, this, _1, _2));
delete chatStateNotifier_;
delete chatStateTracker_;
+ delete whiteboardController_;
}
JID ChatController::getBaseJID() {
@@ -138,6 +143,7 @@ bool ChatController::isIncomingMessageFromMe(boost::shared_ptr<Message>) {
}
void ChatController::preHandleIncomingMessage(boost::shared_ptr<MessageEvent> messageEvent) {
+ whiteboardController_->handleIncomingMessage(messageEvent);
if (messageEvent->isReadable()) {
chatWindow_->flash();
lastWasPresence_ = false;
diff --git a/Swift/Controllers/Chat/ChatController.h b/Swift/Controllers/Chat/ChatController.h
index 7043231..a6a9efa 100644
--- a/Swift/Controllers/Chat/ChatController.h
+++ b/Swift/Controllers/Chat/ChatController.h
@@ -12,6 +12,7 @@
#include <string>
#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+#include "Swift/Controllers/WhiteboardController.h"
namespace Swift {
class AvatarManager;
@@ -76,6 +77,7 @@ namespace Swift {
bool userWantsReceipts_;
std::map<std::string, FileTransferController*> ftControllers;
SettingsProvider* settings_;
+ WhiteboardController* whiteboardController_;
};
}
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index da96603..b9a5759 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -30,6 +30,7 @@
#include <Swiften/MUC/MUCManager.h>
#include <Swiften/Elements/ChatState.h>
#include <Swiften/Elements/MUCUserPayload.h>
+#include <Swiften/Elements/WhiteboardPayload.h>
#include <Swiften/Elements/DeliveryReceipt.h>
#include <Swiften/Elements/DeliveryReceiptRequest.h>
#include <Swiften/MUC/MUCBookmarkManager.h>
@@ -610,7 +611,7 @@ void ChatsManager::handleIncomingMessage(boost::shared_ptr<Message> message) {
if (isMediatedInvite) {
jid = (*message->getPayload<MUCUserPayload>()->getInvite()).from;
}
- if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject()) {
+ if (!event->isReadable() && !message->getPayload<ChatState>() && !message->getPayload<DeliveryReceipt>() && !message->getPayload<DeliveryReceiptRequest>() && !isInvite && !isMediatedInvite && !message->hasSubject() && !message->getPayload<WhiteboardPayload>()) {
return;
}
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index 70085a6..1e18d65 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -70,7 +70,8 @@ if env["SCONS_STAGE"] == "build" :
"Translator.cpp",
"XMPPURIController.cpp",
"ChatMessageSummarizer.cpp",
- "SettingConstants.cpp"
+ "SettingConstants.cpp",
+ "WhiteboardController.cpp"
])
env.Append(UNITTEST_SOURCES = [
diff --git a/Swift/Controllers/UIInterfaces/UIFactory.h b/Swift/Controllers/UIInterfaces/UIFactory.h
index cf89dab..b583bf0 100644
--- a/Swift/Controllers/UIInterfaces/UIFactory.h
+++ b/Swift/Controllers/UIInterfaces/UIFactory.h
@@ -19,6 +19,7 @@
#include <Swift/Controllers/UIInterfaces/ContactEditWindowFactory.h>
#include <Swift/Controllers/UIInterfaces/AdHocCommandWindowFactory.h>
#include <Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h>
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h>
namespace Swift {
class UIFactory :
@@ -34,7 +35,8 @@ namespace Swift {
public ProfileWindowFactory,
public ContactEditWindowFactory,
public AdHocCommandWindowFactory,
- public FileTransferListWidgetFactory {
+ public FileTransferListWidgetFactory,
+ public WhiteboardWindowFactory {
public:
virtual ~UIFactory() {}
};
diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindow.h b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h
new file mode 100644
index 0000000..bedb057
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/WhiteboardWindow.h
@@ -0,0 +1,24 @@
+/*
+ * 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/Base/boost_bsignals.h"
+
+#include <string>
+
+namespace Swift {
+
+ class WhiteboardWindow {
+ public:
+ virtual ~WhiteboardWindow() {}
+
+ virtual void show() = 0;
+ virtual void addItem(const std::string& item) = 0;
+
+ boost::signal<void (std::string)> onItemAdd;
+ };
+}
diff --git a/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h
new file mode 100644
index 0000000..a16b083
--- /dev/null
+++ b/Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+namespace Swift {
+ class WhiteboardWindow;
+ class WhiteboardWindowFactory {
+ public :
+ virtual ~WhiteboardWindowFactory() {};
+
+ virtual WhiteboardWindow* createWhiteboardWindow() = 0;
+ };
+}
diff --git a/Swift/Controllers/WhiteboardController.cpp b/Swift/Controllers/WhiteboardController.cpp
new file mode 100644
index 0000000..9228901
--- /dev/null
+++ b/Swift/Controllers/WhiteboardController.cpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <boost/bind.hpp>
+
+#include "Swift/Controllers/WhiteboardController.h"
+
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindowFactory.h>
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h>
+
+#include <Swiften/Elements/WhiteboardPayload.h>
+
+#include <iostream>
+
+namespace Swift {
+ WhiteboardController::WhiteboardController(StanzaChannel* stanzaChannel, const JID& toJID, WhiteboardWindowFactory* whiteboardWindowFactory) : stanzaChannel_(stanzaChannel), toJID_(toJID) {
+ whiteboardWindow_ = whiteboardWindowFactory->createWhiteboardWindow();
+ whiteboardWindow_->show();
+ whiteboardWindow_->onItemAdd.connect(boost::bind(&WhiteboardController::handleItemChange, this, _1));
+ }
+
+ WhiteboardController::~WhiteboardController() {
+ delete whiteboardWindow_;
+ }
+
+ void WhiteboardController::handleIncomingMessage(boost::shared_ptr<MessageEvent> message) {
+ boost::shared_ptr<WhiteboardPayload> wb = message->getStanza()->getPayload<WhiteboardPayload>();
+ if(wb) {
+ whiteboardWindow_->addItem(wb->getData());
+ }
+ }
+
+ void WhiteboardController::handleItemChange(std::string item) {
+ boost::shared_ptr<Message> mes(new Message());
+ mes->setTo(toJID_);
+ boost::shared_ptr<WhiteboardPayload> wbPayload(new WhiteboardPayload);
+ wbPayload->setData(item);
+// mes->setType(Swift::Message::Chat);
+ mes->addPayload(wbPayload);
+ stanzaChannel_->sendMessage(mes);
+ }
+}
diff --git a/Swift/Controllers/WhiteboardController.h b/Swift/Controllers/WhiteboardController.h
new file mode 100644
index 0000000..aa1ace3
--- /dev/null
+++ b/Swift/Controllers/WhiteboardController.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2012 Mateusz Piękos
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+#include <Swiften/Client/StanzaChannel.h>
+#include "Swiften/JID/JID.h"
+#include "Swift/Controllers/XMPPEvents/MessageEvent.h"
+
+namespace Swift {
+ class WhiteboardWindow;
+ class WhiteboardWindowFactory;
+
+ class WhiteboardController {
+ public:
+ WhiteboardController(StanzaChannel* stanzaChannel, const JID& toJID, WhiteboardWindowFactory* whiteboardWindowFactory);
+ ~WhiteboardController();
+ void handleIncomingMessage(boost::shared_ptr<MessageEvent> message);
+ private:
+ void handleItemChange(std::string item);
+ WhiteboardWindow* whiteboardWindow_;
+ StanzaChannel* stanzaChannel_;
+ JID toJID_;
+ };
+}
+
diff --git a/Swift/QtUI/QtUIFactory.cpp b/Swift/QtUI/QtUIFactory.cpp
index 2a50592..28c8c7c 100644
--- a/Swift/QtUI/QtUIFactory.cpp
+++ b/Swift/QtUI/QtUIFactory.cpp
@@ -25,6 +25,7 @@
#include "QtContactEditWindow.h"
#include "QtAdHocCommandWindow.h"
#include "QtFileTransferListWidget.h"
+#include "Whiteboard/QtWhiteboardWindow.h"
#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
#include <Swift/QtUI/QtUISettingConstants.h>
@@ -134,6 +135,10 @@ ContactEditWindow* QtUIFactory::createContactEditWindow() {
return new QtContactEditWindow();
}
+WhiteboardWindow* QtUIFactory::createWhiteboardWindow() {
+ return new QtWhiteboardWindow();
+}
+
void QtUIFactory::createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command) {
new QtAdHocCommandWindow(command);
}
diff --git a/Swift/QtUI/QtUIFactory.h b/Swift/QtUI/QtUIFactory.h
index 29d9d1c..e52c663 100644
--- a/Swift/QtUI/QtUIFactory.h
+++ b/Swift/QtUI/QtUIFactory.h
@@ -42,6 +42,7 @@ namespace Swift {
virtual ProfileWindow* createProfileWindow();
virtual ContactEditWindow* createContactEditWindow();
virtual FileTransferListWidget* createFileTransferListWidget();
+ virtual WhiteboardWindow* createWhiteboardWindow();
virtual void createAdHocCommandWindow(boost::shared_ptr<OutgoingAdHocCommandSession> command);
private slots:
diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript
index d687203..5b70fc9 100644
--- a/Swift/QtUI/SConscript
+++ b/Swift/QtUI/SConscript
@@ -142,7 +142,7 @@ sources = [
"Whiteboard/FreehandLineItem.cpp",
"Whiteboard/GView.cpp",
"Whiteboard/TextDialog.cpp",
- "Whiteboard/Window.cpp",
+ "Whiteboard/QtWhiteboardWindow.cpp",
"QtSubscriptionRequestWindow.cpp",
"QtRosterHeader.cpp",
"QtWebView.cpp",
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
index 3dc42a7..af8e827 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp
@@ -18,12 +18,12 @@ namespace Swift {
void FreehandLineItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
- painter->setPen(_pen);
- if (points.size() > 0) {
- QVector<QPointF>::const_iterator it = points.begin();
+ painter->setPen(pen_);
+ if (points_.size() > 0) {
+ QVector<QPointF>::const_iterator it = points_.begin();
QPointF previous = *it;
++it;
- for (; it != points.end(); ++it) {
+ for (; it != points_.end(); ++it) {
painter->drawLine(previous, *it);
previous = *it;
}
@@ -32,8 +32,8 @@ namespace Swift {
void FreehandLineItem::setStartPoint(QPointF point)
{
- points.clear();
- points.append(point);
+ points_.clear();
+ points_.append(point);
QRectF rect(point, point);
boundRect = rect;
update(rect);
@@ -42,9 +42,9 @@ namespace Swift {
void FreehandLineItem::lineTo(QPointF point)
{
qreal x1, x2, y1, y2;
- x1 = points.last().x();
+ x1 = points_.last().x();
x2 = point.x();
- y1 = points.last().y();
+ y1 = points_.last().y();
y2 = point.y();
if (x1 > x2) {
qreal temp = x1;
@@ -58,7 +58,7 @@ namespace Swift {
}
QRectF rect(x1-1, y1-1, x2+1-x1, y2+1-y1);
- points.append(point);
+ points_.append(point);
boundRect |= rect;
update(rect);
@@ -68,7 +68,7 @@ namespace Swift {
{
QVector<QPointF>::const_iterator it;
QSizeF size(1,1);
- for (it = points.begin(); it != points.end(); ++it) {
+ for (it = points_.begin(); it != points_.end(); ++it) {
if (path.intersects(QRectF(*it, size))) {
return true;
}
@@ -78,11 +78,19 @@ namespace Swift {
void FreehandLineItem::setPen(const QPen& pen)
{
- _pen = pen;
+ pen_ = pen;
}
QPen FreehandLineItem::pen() const
{
- return _pen;
+ return pen_;
+ }
+
+ QVector<QPointF> FreehandLineItem::points() const {
+ return points_;
+ }
+
+ int FreehandLineItem::type() const {
+ return Type;
}
}
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.h b/Swift/QtUI/Whiteboard/FreehandLineItem.h
index aa9fdff..e995cab 100644
--- a/Swift/QtUI/Whiteboard/FreehandLineItem.h
+++ b/Swift/QtUI/Whiteboard/FreehandLineItem.h
@@ -15,6 +15,7 @@ using namespace std;
namespace Swift {
class FreehandLineItem : public QGraphicsItem {
public:
+ enum {Type = UserType + 1};
FreehandLineItem(QGraphicsItem* parent = 0);
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
@@ -23,10 +24,12 @@ 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;
+ int type() const;
private:
- QPen _pen;
- QVector<QPointF> points;
+ QPen pen_;
+ QVector<QPointF> points_;
QRectF boundRect;
};
}
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
index c3782db..634ff75 100644
--- a/Swift/QtUI/Whiteboard/GView.cpp
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -5,7 +5,6 @@
*/
#include "GView.h"
-#include "FreehandLineItem.h"
namespace Swift {
GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), brush(QColor(Qt::white))
@@ -242,6 +241,7 @@ namespace Swift {
void GView::mouseReleaseEvent(QMouseEvent *event)
{
mousePressed = false;
+ lastItemChanged(lastItem);
}
diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h
index dd620e8..5ac00da 100644
--- a/Swift/QtUI/Whiteboard/GView.h
+++ b/Swift/QtUI/Whiteboard/GView.h
@@ -13,6 +13,7 @@
#include <iostream>
#include "TextDialog.h"
+#include "FreehandLineItem.h"
using namespace std;
@@ -45,5 +46,8 @@ namespace Swift {
QGraphicsItem* lastItem;
QGraphicsRectItem* selectionRect;
TextDialog* textDialog;
+
+ signals:
+ void lastItemChanged(QGraphicsItem* item);
};
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index 4423d17..19d64ae 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -4,14 +4,14 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
-#include "Window.h"
+#include "QtWhiteboardWindow.h"
#include<iostream>
using namespace std;
namespace Swift {
- Window::Window() : QWidget() {
+ QtWhiteboardWindow::QtWhiteboardWindow() : QWidget() {
layout = new QVBoxLayout(this);
hLayout = new QHBoxLayout;
sidebarLayout = new QVBoxLayout;
@@ -23,6 +23,7 @@ namespace Swift {
graphicsView = new GView(scene, this);
graphicsView->setMode(GView::Line);
+ connect(graphicsView, SIGNAL(lastItemChanged(QGraphicsItem*)), this, SLOT(handleLastItemChanged(QGraphicsItem*)));
widthBox = new QSpinBox(this);
connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int)));
@@ -116,67 +117,135 @@ namespace Swift {
this->setLayout(layout);
}
- void Window::changeLineWidth(int i)
+ 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);
+ }
+ 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)
{
graphicsView->setLineWidth(i);
}
- void Window::showColorDialog()
+ void QtWhiteboardWindow::showColorDialog()
{
QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel);
if(color.isValid())
graphicsView->setLineColor(color);
}
- void Window::showBrushColorDialog()
+ void QtWhiteboardWindow::showBrushColorDialog()
{
QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel);
if(color.isValid())
graphicsView->setBrushColor(color);
}
- void Window::setRubberMode()
+ void QtWhiteboardWindow::setRubberMode()
{
graphicsView->setMode(GView::Rubber);
}
- void Window::setLineMode()
+ void QtWhiteboardWindow::setLineMode()
{
graphicsView->setMode(GView::Line);
}
- void Window::setRectMode()
+ void QtWhiteboardWindow::setRectMode()
{
graphicsView->setMode(GView::Rect);
}
- void Window::setCircleMode()
+ void QtWhiteboardWindow::setCircleMode()
{
graphicsView->setMode(GView::Circle);
}
- void Window::setHandLineMode()
+ void QtWhiteboardWindow::setHandLineMode()
{
graphicsView->setMode(GView::HandLine);
}
- void Window::setFilledHandLineMode()
+ void QtWhiteboardWindow::setFilledHandLineMode()
{
graphicsView->setMode(GView::FilledHandLine);
}
- void Window::setTextMode()
+ void QtWhiteboardWindow::setTextMode()
{
graphicsView->setMode(GView::Text);
}
- void Window::setPolygonMode()
+ void QtWhiteboardWindow::setPolygonMode()
{
graphicsView->setMode(GView::Polygon);
}
- void Window::setSelectMode()
+ void QtWhiteboardWindow::setSelectMode()
{
graphicsView->setMode(GView::Select);
}
+ void QtWhiteboardWindow::show()
+ {
+ QWidget::show();
+ }
+ void QtWhiteboardWindow::handleLastItemChanged(QGraphicsItem* item) {
+ std::string serialized;
+ 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;
+ }
+ 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() << ",";
+ }
+ stream >> serialized;
+ }
+ if (!serialized.empty()) {
+ cout << "serialized: " << serialized << endl;
+ onItemAdd(serialized);
+ }
+ }
}
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
index 4423f7c..f472629 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h
@@ -6,6 +6,8 @@
#pragma once
+#include <Swift/Controllers/UIInterfaces/WhiteboardWindow.h>
+
#include <QWidget>
#include <QGraphicsView>
#include <QGraphicsScene>
@@ -21,11 +23,13 @@
#include "GView.h"
namespace Swift {
- class Window : public QWidget
+ class QtWhiteboardWindow : public QWidget, public WhiteboardWindow
{
Q_OBJECT;
public:
- Window();
+ QtWhiteboardWindow();
+ void addItem(const std::string& item);
+ void show();
private slots:
void changeLineWidth(int i);
@@ -40,7 +44,7 @@ namespace Swift {
void setTextMode();
void setPolygonMode();
void setSelectMode();
-
+ void handleLastItemChanged(QGraphicsItem* item);
private:
QGraphicsScene* scene;
GView* graphicsView;