From e8ab1af885ff61715ab0350c3cb22ed6988a082a Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Fri, 1 Jun 2012 19:13:40 +0200 Subject: Added simple whiteboard payload and it's parser and serializer diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp new file mode 100644 index 0000000..4423d17 --- /dev/null +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2012 Mateusz Piękos + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "Window.h" + +#include + +using namespace std; + +namespace Swift { + Window::Window() : QWidget() { + layout = new QVBoxLayout(this); + hLayout = new QHBoxLayout; + sidebarLayout = new QVBoxLayout; + toolboxLayout = new QGridLayout; + + scene = new QGraphicsScene(this); + scene->setSceneRect(0, 0, 400, 400); +// scene->setItemIndexMethod(QGraphicsScene::NoIndex); + + graphicsView = new GView(scene, this); + graphicsView->setMode(GView::Line); + + widthBox = new QSpinBox(this); + connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int))); + widthBox->setValue(1); + + moveUpButton = new QPushButton("Move Up", this); + connect(moveUpButton, SIGNAL(clicked()), graphicsView, SLOT(moveUpSelectedItem())); + + moveDownButton = new QPushButton("Move Down", this); + connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem())); + + colorDialogButton = new QPushButton("Color", this); + connect(colorDialogButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); + + brushColorDialogButton = new QPushButton("Brush", this); + connect(brushColorDialogButton, SIGNAL(clicked()), this, SLOT(showBrushColorDialog())); + + rubberButton = new QToolButton(this); + rubberButton->setCheckable(true); + rubberButton->setAutoExclusive(true); + connect(rubberButton, SIGNAL(clicked()), this, SLOT(setRubberMode())); + + lineButton = new QToolButton(this); + lineButton->setIcon(QIcon(":/icons/line.png")); + lineButton->setCheckable(true); + lineButton->setAutoExclusive(true); + lineButton->setChecked(true); + connect(lineButton, SIGNAL(clicked()), this, SLOT(setLineMode())); + + rectButton = new QToolButton(this); + rectButton->setIcon(QIcon(":/icons/rect.png")); + rectButton->setCheckable(true); + rectButton->setAutoExclusive(true); + connect(rectButton, SIGNAL(clicked()), this, SLOT(setRectMode())); + + circleButton = new QToolButton(this); + circleButton->setIcon(QIcon(":/icons/circle.png")); + circleButton->setCheckable(true); + circleButton->setAutoExclusive(true); + connect(circleButton, SIGNAL(clicked()), this, SLOT(setCircleMode())); + + handLineButton = new QToolButton(this); + handLineButton->setIcon(QIcon(":/icons/handline.png")); + handLineButton->setCheckable(true); + handLineButton->setAutoExclusive(true); + connect(handLineButton, SIGNAL(clicked()), this, SLOT(setHandLineMode())); + + filledHandLineButton = new QToolButton(this); + filledHandLineButton->setIcon(QIcon(":/icons/filledHandline.png")); + filledHandLineButton->setCheckable(true); + filledHandLineButton->setAutoExclusive(true); + connect(filledHandLineButton, SIGNAL(clicked()), this, SLOT(setFilledHandLineMode())); + + textButton = new QToolButton(this); + textButton->setIcon(QIcon(":/icons/text.png")); + textButton->setCheckable(true); + textButton->setAutoExclusive(true); + connect(textButton, SIGNAL(clicked()), this, SLOT(setTextMode())); + + polygonButton = new QToolButton(this); + polygonButton->setIcon(QIcon(":/icons/polygon.png")); + polygonButton->setCheckable(true); + polygonButton->setAutoExclusive(true); + connect(polygonButton, SIGNAL(clicked()), this, SLOT(setPolygonMode())); + + selectButton = new QToolButton(this); + selectButton->setIcon(QIcon(":/icons/cursor.png")); + selectButton->setCheckable(true); + selectButton->setAutoExclusive(true); + connect(selectButton, SIGNAL(clicked()), this, SLOT(setSelectMode())); + + toolboxLayout->addWidget(rubberButton, 0, 0); + toolboxLayout->addWidget(lineButton, 0, 1); + toolboxLayout->addWidget(rectButton, 0, 2); + toolboxLayout->addWidget(circleButton, 1, 0); + toolboxLayout->addWidget(handLineButton, 1, 1); + toolboxLayout->addWidget(filledHandLineButton, 1, 2); + toolboxLayout->addWidget(textButton, 2, 0); + toolboxLayout->addWidget(polygonButton, 2, 1); + toolboxLayout->addWidget(selectButton, 2, 2); + + sidebarLayout->addLayout(toolboxLayout); + sidebarLayout->addWidget(moveUpButton); + sidebarLayout->addWidget(moveDownButton); + sidebarLayout->addWidget(widthBox); + sidebarLayout->addWidget(colorDialogButton); + sidebarLayout->addWidget(brushColorDialogButton); + hLayout->addWidget(graphicsView); + hLayout->addLayout(sidebarLayout); + layout->addLayout(hLayout); + this->setLayout(layout); + } + + void Window::changeLineWidth(int i) + { + graphicsView->setLineWidth(i); + } + + void Window::showColorDialog() + { + QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel); + if(color.isValid()) + graphicsView->setLineColor(color); + } + + void Window::showBrushColorDialog() + { + QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel); + if(color.isValid()) + graphicsView->setBrushColor(color); + } + + void Window::setRubberMode() + { + graphicsView->setMode(GView::Rubber); + } + + void Window::setLineMode() + { + graphicsView->setMode(GView::Line); + } + + void Window::setRectMode() + { + graphicsView->setMode(GView::Rect); + } + + void Window::setCircleMode() + { + graphicsView->setMode(GView::Circle); + } + + void Window::setHandLineMode() + { + graphicsView->setMode(GView::HandLine); + } + + void Window::setFilledHandLineMode() + { + graphicsView->setMode(GView::FilledHandLine); + } + + void Window::setTextMode() + { + graphicsView->setMode(GView::Text); + } + + void Window::setPolygonMode() + { + graphicsView->setMode(GView::Polygon); + } + + void Window::setSelectMode() + { + graphicsView->setMode(GView::Select); + } +} diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h new file mode 100644 index 0000000..4423f7c --- /dev/null +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.h @@ -0,0 +1,67 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GView.h" + +namespace Swift { + class Window : public QWidget + { + Q_OBJECT; + public: + Window(); + + private slots: + void changeLineWidth(int i); + void showColorDialog(); + void showBrushColorDialog(); + void setRubberMode(); + void setLineMode(); + void setRectMode(); + void setCircleMode(); + void setHandLineMode(); + void setFilledHandLineMode(); + void setTextMode(); + void setPolygonMode(); + void setSelectMode(); + + private: + QGraphicsScene* scene; + GView* graphicsView; + QVBoxLayout* layout; + QVBoxLayout* sidebarLayout; + QHBoxLayout* hLayout; + QGridLayout* toolboxLayout; + QWidget* widget; + QPushButton* moveUpButton; + QPushButton* moveDownButton; + QPushButton* colorDialogButton; + QPushButton* brushColorDialogButton; + QSpinBox* widthBox; + QToolButton* rubberButton; + QToolButton* lineButton; + QToolButton* rectButton; + QToolButton* circleButton; + QToolButton* handLineButton; + QToolButton* filledHandLineButton; + QToolButton* textButton; + QToolButton* polygonButton; + QToolButton* selectButton; + }; +} diff --git a/Swift/QtUI/Whiteboard/Window.cpp b/Swift/QtUI/Whiteboard/Window.cpp deleted file mode 100644 index 4423d17..0000000 --- a/Swift/QtUI/Whiteboard/Window.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (c) 2012 Mateusz Piękos - * Licensed under the simplified BSD license. - * See Documentation/Licenses/BSD-simplified.txt for more information. - */ - -#include "Window.h" - -#include - -using namespace std; - -namespace Swift { - Window::Window() : QWidget() { - layout = new QVBoxLayout(this); - hLayout = new QHBoxLayout; - sidebarLayout = new QVBoxLayout; - toolboxLayout = new QGridLayout; - - scene = new QGraphicsScene(this); - scene->setSceneRect(0, 0, 400, 400); -// scene->setItemIndexMethod(QGraphicsScene::NoIndex); - - graphicsView = new GView(scene, this); - graphicsView->setMode(GView::Line); - - widthBox = new QSpinBox(this); - connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int))); - widthBox->setValue(1); - - moveUpButton = new QPushButton("Move Up", this); - connect(moveUpButton, SIGNAL(clicked()), graphicsView, SLOT(moveUpSelectedItem())); - - moveDownButton = new QPushButton("Move Down", this); - connect(moveDownButton, SIGNAL(clicked()), graphicsView, SLOT(moveDownSelectedItem())); - - colorDialogButton = new QPushButton("Color", this); - connect(colorDialogButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); - - brushColorDialogButton = new QPushButton("Brush", this); - connect(brushColorDialogButton, SIGNAL(clicked()), this, SLOT(showBrushColorDialog())); - - rubberButton = new QToolButton(this); - rubberButton->setCheckable(true); - rubberButton->setAutoExclusive(true); - connect(rubberButton, SIGNAL(clicked()), this, SLOT(setRubberMode())); - - lineButton = new QToolButton(this); - lineButton->setIcon(QIcon(":/icons/line.png")); - lineButton->setCheckable(true); - lineButton->setAutoExclusive(true); - lineButton->setChecked(true); - connect(lineButton, SIGNAL(clicked()), this, SLOT(setLineMode())); - - rectButton = new QToolButton(this); - rectButton->setIcon(QIcon(":/icons/rect.png")); - rectButton->setCheckable(true); - rectButton->setAutoExclusive(true); - connect(rectButton, SIGNAL(clicked()), this, SLOT(setRectMode())); - - circleButton = new QToolButton(this); - circleButton->setIcon(QIcon(":/icons/circle.png")); - circleButton->setCheckable(true); - circleButton->setAutoExclusive(true); - connect(circleButton, SIGNAL(clicked()), this, SLOT(setCircleMode())); - - handLineButton = new QToolButton(this); - handLineButton->setIcon(QIcon(":/icons/handline.png")); - handLineButton->setCheckable(true); - handLineButton->setAutoExclusive(true); - connect(handLineButton, SIGNAL(clicked()), this, SLOT(setHandLineMode())); - - filledHandLineButton = new QToolButton(this); - filledHandLineButton->setIcon(QIcon(":/icons/filledHandline.png")); - filledHandLineButton->setCheckable(true); - filledHandLineButton->setAutoExclusive(true); - connect(filledHandLineButton, SIGNAL(clicked()), this, SLOT(setFilledHandLineMode())); - - textButton = new QToolButton(this); - textButton->setIcon(QIcon(":/icons/text.png")); - textButton->setCheckable(true); - textButton->setAutoExclusive(true); - connect(textButton, SIGNAL(clicked()), this, SLOT(setTextMode())); - - polygonButton = new QToolButton(this); - polygonButton->setIcon(QIcon(":/icons/polygon.png")); - polygonButton->setCheckable(true); - polygonButton->setAutoExclusive(true); - connect(polygonButton, SIGNAL(clicked()), this, SLOT(setPolygonMode())); - - selectButton = new QToolButton(this); - selectButton->setIcon(QIcon(":/icons/cursor.png")); - selectButton->setCheckable(true); - selectButton->setAutoExclusive(true); - connect(selectButton, SIGNAL(clicked()), this, SLOT(setSelectMode())); - - toolboxLayout->addWidget(rubberButton, 0, 0); - toolboxLayout->addWidget(lineButton, 0, 1); - toolboxLayout->addWidget(rectButton, 0, 2); - toolboxLayout->addWidget(circleButton, 1, 0); - toolboxLayout->addWidget(handLineButton, 1, 1); - toolboxLayout->addWidget(filledHandLineButton, 1, 2); - toolboxLayout->addWidget(textButton, 2, 0); - toolboxLayout->addWidget(polygonButton, 2, 1); - toolboxLayout->addWidget(selectButton, 2, 2); - - sidebarLayout->addLayout(toolboxLayout); - sidebarLayout->addWidget(moveUpButton); - sidebarLayout->addWidget(moveDownButton); - sidebarLayout->addWidget(widthBox); - sidebarLayout->addWidget(colorDialogButton); - sidebarLayout->addWidget(brushColorDialogButton); - hLayout->addWidget(graphicsView); - hLayout->addLayout(sidebarLayout); - layout->addLayout(hLayout); - this->setLayout(layout); - } - - void Window::changeLineWidth(int i) - { - graphicsView->setLineWidth(i); - } - - void Window::showColorDialog() - { - QColor color = QColorDialog::getColor(graphicsView->getLineColor(), 0, "Select pen color", QColorDialog::ShowAlphaChannel); - if(color.isValid()) - graphicsView->setLineColor(color); - } - - void Window::showBrushColorDialog() - { - QColor color = QColorDialog::getColor(graphicsView->getBrushColor(), 0, "Select brush color", QColorDialog::ShowAlphaChannel); - if(color.isValid()) - graphicsView->setBrushColor(color); - } - - void Window::setRubberMode() - { - graphicsView->setMode(GView::Rubber); - } - - void Window::setLineMode() - { - graphicsView->setMode(GView::Line); - } - - void Window::setRectMode() - { - graphicsView->setMode(GView::Rect); - } - - void Window::setCircleMode() - { - graphicsView->setMode(GView::Circle); - } - - void Window::setHandLineMode() - { - graphicsView->setMode(GView::HandLine); - } - - void Window::setFilledHandLineMode() - { - graphicsView->setMode(GView::FilledHandLine); - } - - void Window::setTextMode() - { - graphicsView->setMode(GView::Text); - } - - void Window::setPolygonMode() - { - graphicsView->setMode(GView::Polygon); - } - - void Window::setSelectMode() - { - graphicsView->setMode(GView::Select); - } -} diff --git a/Swift/QtUI/Whiteboard/Window.h b/Swift/QtUI/Whiteboard/Window.h deleted file mode 100644 index 4423f7c..0000000 --- a/Swift/QtUI/Whiteboard/Window.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 -#include -#include -#include -#include -#include -#include -#include -#include - -#include "GView.h" - -namespace Swift { - class Window : public QWidget - { - Q_OBJECT; - public: - Window(); - - private slots: - void changeLineWidth(int i); - void showColorDialog(); - void showBrushColorDialog(); - void setRubberMode(); - void setLineMode(); - void setRectMode(); - void setCircleMode(); - void setHandLineMode(); - void setFilledHandLineMode(); - void setTextMode(); - void setPolygonMode(); - void setSelectMode(); - - private: - QGraphicsScene* scene; - GView* graphicsView; - QVBoxLayout* layout; - QVBoxLayout* sidebarLayout; - QHBoxLayout* hLayout; - QGridLayout* toolboxLayout; - QWidget* widget; - QPushButton* moveUpButton; - QPushButton* moveDownButton; - QPushButton* colorDialogButton; - QPushButton* brushColorDialogButton; - QSpinBox* widthBox; - QToolButton* rubberButton; - QToolButton* lineButton; - QToolButton* rectButton; - QToolButton* circleButton; - QToolButton* handLineButton; - QToolButton* filledHandLineButton; - QToolButton* textButton; - QToolButton* polygonButton; - QToolButton* selectButton; - }; -} diff --git a/Swiften/Elements/WhiteboardPayload.h b/Swiften/Elements/WhiteboardPayload.h new file mode 100644 index 0000000..8d40d9d --- /dev/null +++ b/Swiften/Elements/WhiteboardPayload.h @@ -0,0 +1,30 @@ +/* + * 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 + +namespace Swift { + class WhiteboardPayload : public Payload { + public: + WhiteboardPayload() { + } + + void setData(const std::string &data) { + data_ = data; + } + + std::string getData() const { + return data_; + } + + private: + std::string data_; + }; +} diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp index 01addf5..f8f68ff 100644 --- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp +++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp @@ -66,6 +66,7 @@ #include #include #include +#include using namespace boost; @@ -123,6 +124,7 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() { factories_.push_back(boost::make_shared >("received", "urn:xmpp:jingle:apps:file-transfer:3")); factories_.push_back(boost::make_shared >("checksum")); factories_.push_back(boost::make_shared >("query", "http://jabber.org/protocol/bytestreams")); + factories_.push_back(boost::make_shared >("wb")); factories_.push_back(boost::make_shared()); factories_.push_back(boost::make_shared()); diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp new file mode 100644 index 0000000..77e5c2c --- /dev/null +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.cpp @@ -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. + */ + +#include + +namespace Swift { + WhiteboardParser::WhiteboardParser() : level_(0) { + } + void WhiteboardParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) { + ++level_; + } + + void WhiteboardParser::handleEndElement(const std::string& element, const std::string&) { + --level_; + if(level_ == 0) { + getPayloadInternal()->setData(data_); + } + } + + void WhiteboardParser::handleCharacterData(const std::string& data) { + data_ += data; + } +} diff --git a/Swiften/Parser/PayloadParsers/WhiteboardParser.h b/Swiften/Parser/PayloadParsers/WhiteboardParser.h new file mode 100644 index 0000000..265e12d --- /dev/null +++ b/Swiften/Parser/PayloadParsers/WhiteboardParser.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 +#include + +namespace Swift { + class WhiteboardParser : public Swift::GenericPayloadParser { + public: + WhiteboardParser(); + + virtual void handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes); + virtual void handleEndElement(const std::string& element, const std::string&); + virtual void handleCharacterData(const std::string& data); + private: + int level_; + std::string data_; + }; +} diff --git a/Swiften/Parser/SConscript b/Swiften/Parser/SConscript index e4c2778..64e9eb9 100644 --- a/Swiften/Parser/SConscript +++ b/Swiften/Parser/SConscript @@ -72,6 +72,7 @@ sources = [ "PayloadParsers/S5BProxyRequestParser.cpp", "PayloadParsers/DeliveryReceiptParser.cpp", "PayloadParsers/DeliveryReceiptRequestParser.cpp", + "PayloadParsers/WhiteboardParser.cpp", "PlatformXMLParserFactory.cpp", "PresenceParser.cpp", "SerializingParser.cpp", diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 93fd70f..b4822cd 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include #include @@ -108,6 +109,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new SearchPayloadSerializer()); serializers_.push_back(new ReplaceSerializer()); serializers_.push_back(new LastSerializer()); + serializers_.push_back(new WhiteboardSerializer()); serializers_.push_back(new StreamInitiationFileInfoSerializer()); serializers_.push_back(new JingleContentPayloadSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h new file mode 100644 index 0000000..a7d04f1 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/WhiteboardSerializer.h @@ -0,0 +1,21 @@ +/* + * 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 + +namespace Swift { + class WhiteboardSerializer : public GenericPayloadSerializer { + public: + std::string serializePayload(boost::shared_ptr payload) const { + XMLElement element("wb"); + element.addNode(XMLTextNode::ref(new XMLTextNode(payload->getData()))); + return element.serialize(); + } + }; +} -- cgit v0.10.2-6-g49f6