diff options
Diffstat (limited to 'Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp')
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 97 |
1 files changed, 83 insertions, 14 deletions
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); + } + } } |