diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-26 12:23:47 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-06-26 12:23:47 (GMT) |
commit | 60076b8e5dc557716e82d7588ff9a99247e485bf (patch) | |
tree | 9d8cc54bed7036f93098cf60b76288217c1f06e3 /Swift | |
parent | 99bc38e1d21b0081618485e49b0ab1bcd5bef22f (diff) | |
download | swift-contrib-60076b8e5dc557716e82d7588ff9a99247e485bf.zip swift-contrib-60076b8e5dc557716e82d7588ff9a99247e485bf.tar.bz2 |
Added handling of text elements
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 17 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/TextDialog.cpp | 5 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/TextDialog.h | 4 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h | 9 |
5 files changed, 27 insertions, 10 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index badbb8e..a450808 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -5,6 +5,7 @@ */ #include "GView.h" +#include <QtSwiftUtil.h> namespace Swift { GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), brush(QColor(Qt::white)) @@ -162,7 +163,7 @@ namespace Swift { if (mode == Line) { QPointF point = this->mapToScene(event->pos()); QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, id); @@ -171,7 +172,7 @@ namespace Swift { else if (mode == Rect) { QPointF point = this->mapToScene(event->pos()); QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); @@ -193,7 +194,7 @@ namespace Swift { else if (mode == Circle) { QPointF point = this->mapToScene(event->pos()); QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); @@ -203,7 +204,7 @@ namespace Swift { else if (mode == HandLine) { QPointF point = this->mapToScene(event->pos()); FreehandLineItem* item = new FreehandLineItem; - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setPen(pen); item->setStartPoint(point); @@ -216,7 +217,7 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QPainterPath path; QGraphicsPathItem* item = scene()->addPath(path, pen, brush); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, point); @@ -226,13 +227,13 @@ namespace Swift { else if (mode == Text) { QPointF point = this->mapToScene(event->pos()); QGraphicsTextItem* item = scene()->addText(""); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, id); item->setDefaultTextColor(pen.color()); textDialog = new TextDialog(item, this); - connect(textDialog, SIGNAL(accepted()), this, SIGNAL(lastItemChanged(textDialog))); + connect(textDialog, SIGNAL(accepted(QGraphicsItem*)), this, SIGNAL(lastItemChanged(QGraphicsItem*))); textDialog->setAttribute(Qt::WA_DeleteOnClose); textDialog->show(); item->setPos(point); @@ -246,7 +247,7 @@ namespace Swift { polygon.append(point); polygon.append(point); item = scene()->addPolygon(polygon, pen, brush); - QString id = QString::fromStdString(idGenerator.generateID()); + QString id = P2QSTRING(idGenerator.generateID()); items_.insert(id, item); item->setZValue(zValue++); item->setData(0, id); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 55d3479..6e259a2 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -266,7 +266,7 @@ namespace Swift { QPointF point = textItem->pos(); WhiteboardTextElement::ref element = boost::make_shared<WhiteboardTextElement>(point.x(), point.y()); element->setText(textItem->toPlainText().toStdString()); - + element->setSize(textItem->font().pointSize()); QColor color = textItem->defaultTextColor(); element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); diff --git a/Swift/QtUI/Whiteboard/TextDialog.cpp b/Swift/QtUI/Whiteboard/TextDialog.cpp index caa78ce..021895a 100644 --- a/Swift/QtUI/Whiteboard/TextDialog.cpp +++ b/Swift/QtUI/Whiteboard/TextDialog.cpp @@ -44,4 +44,9 @@ namespace Swift { font.setPointSize(i); item->setFont(font); } + + void TextDialog::accept() { + emit accepted(item); + done(QDialog::Accepted); + } } diff --git a/Swift/QtUI/Whiteboard/TextDialog.h b/Swift/QtUI/Whiteboard/TextDialog.h index 8b31d5b..7f0e56a 100644 --- a/Swift/QtUI/Whiteboard/TextDialog.h +++ b/Swift/QtUI/Whiteboard/TextDialog.h @@ -33,7 +33,11 @@ namespace Swift { QHBoxLayout* hLayout; QSpinBox* fontSizeBox; + signals: + void accepted(QGraphicsItem* item); + private slots: + void accept(); void changeItemText(const QString &text); void changeItemFontSize(int i); }; diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h index 4b2f7ed..214ea10 100644 --- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h +++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h @@ -85,7 +85,14 @@ namespace Swift { } void visit(WhiteboardTextElement& element) { - + QGraphicsTextItem* item = new QGraphicsTextItem(P2QSTRING(element.getText())); + item->setPos(QPointF(element.getX(), element.getY())); + QFont font = item->font(); + font.setPointSize(element.getSize()); + item->setFont(font); + Color color = element.getColor(); + item->setDefaultTextColor(QColor(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha())); + graphicsView_->scene()->addItem(item); } void visit(WhiteboardEllipseElement& element) { |