summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp28
-rw-r--r--Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp19
-rw-r--r--Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h23
3 files changed, 63 insertions, 7 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp
index e904b32..badbb8e 100644
--- a/Swift/QtUI/Whiteboard/GView.cpp
+++ b/Swift/QtUI/Whiteboard/GView.cpp
@@ -90,14 +90,29 @@ namespace Swift {
}
}
else if (mode == Circle) {
- QGraphicsPathItem* item = qgraphicsitem_cast<QGraphicsPathItem*>(lastItem);
+ QGraphicsEllipseItem* item = qgraphicsitem_cast<QGraphicsEllipseItem*>(lastItem);
QPainterPath path;
QPointF beginPoint = item->data(0).toPointF();
QPointF newPoint = this->mapToScene(event->pos());
- path.moveTo((newPoint.x()+beginPoint.x())/2, beginPoint.y());
- path.cubicTo(beginPoint.x(), beginPoint.y(), beginPoint.x(), newPoint.y(), (newPoint.x()+beginPoint.x())/2, newPoint.y());
- path.cubicTo(newPoint.x(), newPoint.y(), newPoint.x(), beginPoint.y(), (newPoint.x()+beginPoint.x())/2, beginPoint.y());
- item->setPath(path);
+ QRectF rect = item->rect();
+ if (beginPoint.x() <= newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopLeft(beginPoint);
+ rect.setBottomRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() <= newPoint.y()) {
+ rect.setTopRight(beginPoint);
+ rect.setBottomLeft(newPoint);
+ }
+ else if (beginPoint.x() <= newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomLeft(beginPoint);
+ rect.setTopRight(newPoint);
+ }
+ else if (beginPoint.x() > newPoint.x() && beginPoint.y() > newPoint.y()) {
+ rect.setBottomRight(beginPoint);
+ rect.setTopLeft(newPoint);
+ }
+
+ item->setRect(rect);
}
else if (mode == HandLine) {
FreehandLineItem* item = qgraphicsitem_cast<FreehandLineItem*>(lastItem);
@@ -177,7 +192,7 @@ namespace Swift {
}
else if (mode == Circle) {
QPointF point = this->mapToScene(event->pos());
- QGraphicsPathItem* item = scene()->addPath(QPainterPath(), pen, brush);
+ QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush);
QString id = QString::fromStdString(idGenerator.generateID());
items_.insert(id, item);
item->setZValue(zValue++);
@@ -217,6 +232,7 @@ namespace Swift {
item->setData(0, id);
item->setDefaultTextColor(pen.color());
textDialog = new TextDialog(item, this);
+ connect(textDialog, SIGNAL(accepted()), this, SIGNAL(lastItemChanged(textDialog)));
textDialog->setAttribute(Qt::WA_DeleteOnClose);
textDialog->show();
item->setPos(point);
diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
index a53b0dd..55d3479 100644
--- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
+++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp
@@ -295,6 +295,25 @@ namespace Swift {
element->setID(polygonItem->data(0).toString().toStdString());
whiteboardSession_->sendElement(element);
}
+
+ QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item);
+ if (ellipseItem) {
+ QRectF rect = ellipseItem->rect();
+ int cx = rect.x()+rect.width()/2;
+ int cy = rect.y()+rect.height()/2;
+ int rx = rect.width()/2;
+ int ry = rect.height()/2;
+ WhiteboardEllipseElement::ref element = boost::make_shared<WhiteboardEllipseElement>(cx, cy, rx, ry);
+
+ QColor penColor = ellipseItem->pen().color();
+ QColor brushColor = ellipseItem->brush().color();
+ element->setPenColor(Color(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha()));
+ element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha()));
+ element->setPenWidth(ellipseItem->pen().width());
+
+ element->setID(ellipseItem->data(1).toString().toStdString());
+ whiteboardSession_->sendElement(element);
+ }
}
void QtWhiteboardWindow::handleSessionTerminate() {
diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
index ebc9045..4b2f7ed 100644
--- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
+++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h
@@ -10,8 +10,10 @@
#include <Swiften/Whiteboard/Elements/WhiteboardLineElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardPolygonElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardTextElement.h>
+#include <Swiften/Whiteboard/Elements/WhiteboardEllipseElement.h>
#include <Swiften/Whiteboard/Elements/WhiteboardFreehandPathElement.h>
#include <Swift/QtUI/Whiteboard/GView.h>
+#include <QtSwiftUtil.h>
namespace Swift {
class WhiteboardElementDrawingVisitor : public WhiteboardElementVisitor {
@@ -60,7 +62,7 @@ namespace Swift {
}
void visit(WhiteboardPolygonElement& element) {
- QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(QString::fromStdString(element.getID())));
+ QGraphicsPolygonItem* item = qgraphicsitem_cast<QGraphicsPolygonItem*>(graphicsView_->getItem(P2QSTRING(element.getID())));
if (item == 0) {
item = new QGraphicsPolygonItem();
QPen pen;
@@ -86,6 +88,25 @@ namespace Swift {
}
+ void visit(WhiteboardEllipseElement& element) {
+ QRectF rect;
+
+ rect.setTopLeft(QPointF(element.getCX()-element.getRX(), element.getCY()-element.getRY()));
+ rect.setBottomRight(QPointF(element.getCX()+element.getRX(), element.getCY()+element.getRY()));
+
+ QGraphicsEllipseItem* item = new QGraphicsEllipseItem(rect);
+ QPen pen;
+ QBrush brush(Qt::SolidPattern);
+ Color penColor = element.getPenColor();
+ Color brushColor = element.getBrushColor();
+ pen.setColor(QColor(penColor.getRed(), penColor.getGreen(), penColor.getBlue(), penColor.getAlpha()));
+ pen.setWidth(element.getPenWidth());
+ brush.setColor(QColor(brushColor.getRed(), brushColor.getGreen(), brushColor.getBlue(), brushColor.getAlpha()));
+ item->setPen(pen);
+ item->setBrush(brush);
+ graphicsView_->scene()->addItem(item);
+ }
+
private:
GView* graphicsView_;
};