diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-02 16:23:59 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-02 16:23:59 (GMT) |
commit | 7520c7fed383d4f7631f5572ef40379022126264 (patch) | |
tree | ee87b26bb923d0289a670defce96e2012f3623e3 /Swift/QtUI/Whiteboard | |
parent | e8ab1af885ff61715ab0350c3cb22ed6988a082a (diff) | |
download | swift-contrib-7520c7fed383d4f7631f5572ef40379022126264.zip swift-contrib-7520c7fed383d4f7631f5572ef40379022126264.tar.bz2 |
Added whiteboard controller with simple sharing
Whiteboard controller is handled in ChatController only for
testing purposes.
Diffstat (limited to 'Swift/QtUI/Whiteboard')
-rw-r--r-- | Swift/QtUI/Whiteboard/FreehandLineItem.cpp | 32 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/FreehandLineItem.h | 7 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 97 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.h | 10 |
6 files changed, 120 insertions, 32 deletions
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; |