diff options
author | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-18 10:36:42 (GMT) |
---|---|---|
committer | Mateusz Piekos <mateuszpiekos@gmail.com> | 2012-07-18 10:36:42 (GMT) |
commit | e6389d9be9135d5648033abea8bdb75959f64070 (patch) | |
tree | 922afb6a5e2e916cbbb033fcb311dee13b9cac22 /Swift/QtUI/Whiteboard | |
parent | 7a14385acccd599438a274d421735a7d0c4bc9fa (diff) | |
download | swift-contrib-e6389d9be9135d5648033abea8bdb75959f64070.zip swift-contrib-e6389d9be9135d5648033abea8bdb75959f64070.tar.bz2 |
Modified code to send TextItem updates
Diffstat (limited to 'Swift/QtUI/Whiteboard')
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 62 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 2 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/TextDialog.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h | 27 |
5 files changed, 41 insertions, 54 deletions
diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index 1e77b62..eead3c7 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -48,33 +48,21 @@ namespace Swift { } void GView::addItem(QGraphicsItem* item, QString id, int pos) { -// QList<QGraphicsItem*> items = scene()->items(); -// std::cout << "pos: " << pos << " size: " << items.size() << std::endl; -// if (mousePressed && pos >= items_.size()) { -// pos++; -// } itemsMap_.insert(id, item); if (pos > items_.size()) { item->setZValue(zValue++); scene()->addItem(item); items_.append(item); } else { - QList<QGraphicsItem*>::iterator it = items_.begin(); - for (int i = 1; i < pos; i++) { - ++it; - } - // std::cout << id.toStdString() << " before: " << (*it)->data(100).toString().toStdString() << std::endl; - item->setZValue((*it)->zValue()); + QGraphicsItem* temp = items_.at(pos-1); + item->setZValue(temp->zValue()); scene()->addItem(item); - item->stackBefore(*it); - // --it; - items_.insert(it, item); + item->stackBefore(temp); + items_.insert(pos-1, item); } - -// items = scene()->items(); - std::cout << "items:" << std::endl; + std::cout << "items in:" << std::endl; for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) { - std::cout << (*it)->data(100).toString().toStdString() << std::endl; + std::cout << "item: " << (*it)->data(100).toString().toStdString() << std::endl; } std::cout << std::endl; } @@ -86,6 +74,7 @@ namespace Swift { void GView::clear() { scene()->clear(); items_.clear(); + itemsMap_.clear(); } QGraphicsItem* GView::getItem(QString id) { @@ -247,15 +236,15 @@ namespace Swift { QGraphicsItem* item = scene()->items(rect).first(); QString id = item->data(100).toString(); deleteItem(id); - int i = 1; +/* int i = 1; QList<QGraphicsItem*>::const_iterator it; for (it = items_.begin(); it != items_.end(); ++it) { if (*it == item) { break; } i++; - } - itemDeleted(id, i); + }*/ + itemDeleted(id, items_.indexOf(item)+1); } } else if (mode == Circle) { @@ -301,13 +290,13 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QGraphicsTextItem* item = scene()->addText(""); QString id = getNewID(); - items_.append(item); - item->setZValue(zValue++); +// items_.append(item); +// item->setZValue(zValue++); item->setData(100, id); item->setData(101, items_.size()); item->setDefaultTextColor(pen.color()); textDialog = new TextDialog(item, this); - connect(textDialog, SIGNAL(accepted(QGraphicsItem*)), this, SIGNAL(lastItemChanged(QGraphicsItem*))); + connect(textDialog, SIGNAL(accepted(QGraphicsTextItem*)), this, SLOT(handleTextItemModified(QGraphicsTextItem*))); textDialog->setAttribute(Qt::WA_DeleteOnClose); textDialog->show(); item->setPos(point); @@ -362,20 +351,13 @@ namespace Swift { mousePressed = false; QGraphicsPolygonItem* polygon = dynamic_cast<QGraphicsPolygonItem*>(lastItem); if (polygon && polygon->polygon().size() >= 3) { - int i = 1; - for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) { - if (*it == polygon) { - break; - } - i++; - } - lastItemChanged(polygon, i, Update); + lastItemChanged(polygon, items_.indexOf(polygon)+1, Update); } else if (lastItem) { zValue++; lastItem->setZValue(zValue++); items_.append(lastItem); itemsMap_.insert(lastItem->data(100).toString(), lastItem); - std::cout << "items:" << std::endl; + std::cout << "items out:" << std::endl; for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) { std::cout << (*it)->data(100).toString().toStdString() << std::endl; } @@ -384,19 +366,15 @@ namespace Swift { lastItemChanged(lastItem, items_.size(), New); } else if (selectionRect){ QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); - int i = 1; - for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) { - if (*it == item) { - break; - } - i++; - } - lastItemChanged(item, i, Update); + lastItemChanged(item, items_.indexOf(item)+1, Update); } -// lastItem = 0; } + void GView::handleTextItemModified(QGraphicsTextItem* item) { + lastItemChanged(item, item->data(101).toInt(), Update); + } + void GView::moveUpSelectedItem() { QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index 9a26b01..e18cb74 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -42,6 +42,8 @@ namespace Swift { void moveUpSelectedItem(); void moveDownSelectedItem(); + private slots: + void handleTextItemModified(QGraphicsTextItem*); private: QString getNewID(); diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index 6df68f3..d89a7f6 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -298,7 +298,7 @@ namespace Swift { QColor color = textItem->defaultTextColor(); element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); - element->setID(rectItem->data(100).toString().toStdString()); + element->setID(textItem->data(100).toString().toStdString()); // whiteboardSession_->sendElement(element); el = element; } diff --git a/Swift/QtUI/Whiteboard/TextDialog.h b/Swift/QtUI/Whiteboard/TextDialog.h index 7f0e56a..f4d9a13 100644 --- a/Swift/QtUI/Whiteboard/TextDialog.h +++ b/Swift/QtUI/Whiteboard/TextDialog.h @@ -34,7 +34,7 @@ namespace Swift { QSpinBox* fontSizeBox; signals: - void accepted(QGraphicsItem* item); + void accepted(QGraphicsTextItem* item); private slots: void accept(); diff --git a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h index 4ed1af5..528c72a 100644 --- a/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h +++ b/Swift/QtUI/Whiteboard/WhiteboardElementDrawingVisitor.h @@ -126,17 +126,24 @@ 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())); - + QGraphicsTextItem* item; QString id = P2QSTRING(element.getID()); - item->setData(100, id); - graphicsView_->addItem(item, id, pos_); + if (type_ == GView::New) { + item = new QGraphicsTextItem; + graphicsView_->addItem(item, id, pos_); + } else { + item = qgraphicsitem_cast<QGraphicsTextItem*>(graphicsView_->getItem(id)); + } + if (item) { + item->setPlainText(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())); + item->setData(100, id); + } } void visit(WhiteboardEllipseElement& element) { |