diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/Whiteboard/FreehandLineItem.cpp | 8 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.cpp | 142 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/GView.h | 5 | ||||
-rw-r--r-- | Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp | 9 |
4 files changed, 115 insertions, 49 deletions
diff --git a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp index 9beb47b..8821062 100644 --- a/Swift/QtUI/Whiteboard/FreehandLineItem.cpp +++ b/Swift/QtUI/Whiteboard/FreehandLineItem.cpp @@ -32,18 +32,15 @@ namespace Swift { void FreehandLineItem::setStartPoint(QPointF point) { - prepareGeometryChange(); points_.clear(); points_.append(point); QRectF rect(point, point); + prepareGeometryChange(); boundRect = rect; - update(rect); } void FreehandLineItem::lineTo(QPointF point) { - prepareGeometryChange(); - qreal x1, x2, y1, y2; x1 = points_.last().x(); x2 = point.x(); @@ -63,8 +60,8 @@ namespace Swift { points_.append(point); + prepareGeometryChange(); boundRect |= rect; - update(rect); } bool FreehandLineItem::collidesWithPath(const QPainterPath& path, Qt::ItemSelectionMode /*mode*/) const @@ -82,6 +79,7 @@ namespace Swift { void FreehandLineItem::setPen(const QPen& pen) { pen_ = pen; + update(boundRect); } QPen FreehandLineItem::pen() const diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index e82d193..8d5e2bc 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -8,41 +8,56 @@ #include <QtSwiftUtil.h> namespace Swift { - GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), brush(QColor(Qt::white)) - { + GView::GView(QGraphicsScene* scene, QWidget* parent) : QGraphicsView(scene, parent), brush(QColor(Qt::white)), defaultBrush(QColor(Qt::white)) { selectionRect = 0; lastItem = 0; zValue = 0; } - void GView::setLineWidth(int i) - { + void GView::setLineWidth(int i) { pen.setWidth(i); + if (selectionRect) { + QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); + changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush); + lastItemChanged(item, items_.indexOf(item)+1, Update); + } else { + defaultPen.setWidth(i); + } } - void GView::setLineColor(QColor color) - { + void GView::setLineColor(QColor color) { pen.setColor(color); + if (selectionRect) { + QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); + changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush); + lastItemChanged(item, items_.indexOf(item)+1, Update); + } else { + defaultPen.setColor(color); + } } - QColor GView::getLineColor() - { + QColor GView::getLineColor() { return pen.color(); } - void GView::setBrushColor(QColor color) - { + void GView::setBrushColor(QColor color) { brush.setColor(color); + if (selectionRect) { + QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); + changePenAndBrush(selectionRect->data(1).value<QGraphicsItem*>(), pen, brush); + lastItemChanged(item, items_.indexOf(item)+1, Update); + } else { + defaultBrush.setColor(color); + } + // brush.setStyle(Qt::SolidPattern); } - QColor GView::getBrushColor() - { + QColor GView::getBrushColor() { return brush.color(); } - void GView::setMode(Mode mode) - { + void GView::setMode(Mode mode) { this->mode = mode; lastItem = 0; } @@ -62,7 +77,7 @@ namespace Swift { } std::cout << "items in:" << std::endl; for (QList<QGraphicsItem*>::const_iterator it = items_.begin(); it != items_.end(); ++it) { - std::cout << "item: " << (*it)->data(100).toString().toStdString() << std::endl; + std::cout << (*it)->data(100).toString().toStdString() << std::endl; } std::cout << std::endl; } @@ -199,16 +214,17 @@ namespace Swift { { mousePressed = true; if (selectionRect != 0) { + pen = defaultPen; + brush = defaultBrush; scene()->removeItem(selectionRect); delete selectionRect; selectionRect = 0; + lineWidthChanged(pen.width()); } if (mode == Line) { QPointF point = this->mapToScene(event->pos()); QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(100, id); item->setData(101, items_.size()); @@ -218,8 +234,6 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QGraphicsRectItem* item = scene()->addRect(point.x(), point.y(), 0, 0, pen, brush); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(0, point); item->setData(100, id); @@ -236,14 +250,6 @@ namespace Swift { QGraphicsItem* item = scene()->items(rect).first(); QString id = item->data(100).toString(); deleteItem(id); -/* int i = 1; - QList<QGraphicsItem*>::const_iterator it; - for (it = items_.begin(); it != items_.end(); ++it) { - if (*it == item) { - break; - } - i++; - }*/ itemDeleted(id, items_.indexOf(item)+1); } } @@ -251,8 +257,6 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QGraphicsEllipseItem* item = scene()->addEllipse(point.x(), point.y(), 0, 0, pen, brush); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(0, point); item->setData(100, id); @@ -263,10 +267,8 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); FreehandLineItem* item = new FreehandLineItem; QString id = getNewID(); -// items_.append(item); item->setPen(pen); item->setStartPoint(point); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(100, id); item->setData(101, items_.size()); @@ -278,8 +280,6 @@ namespace Swift { QPainterPath path; QGraphicsPathItem* item = scene()->addPath(path, pen, brush); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(0, point); item->setData(100, id); @@ -290,8 +290,6 @@ namespace Swift { QPointF point = this->mapToScene(event->pos()); QGraphicsTextItem* item = scene()->addText(""); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setData(100, id); item->setData(101, items_.size()); item->setDefaultTextColor(pen.color()); @@ -311,8 +309,6 @@ namespace Swift { polygon.append(point); item = scene()->addPolygon(polygon, pen, brush); QString id = getNewID(); -// items_.append(item); -// item->setZValue(zValue++); item->setZValue(10000000); item->setData(100, id); item->setData(101, items_.size()); @@ -335,6 +331,7 @@ namespace Swift { pen.setColor(QColor(Qt::gray)); pen.setStyle(Qt::DashLine); QGraphicsItem *item = scene()->items(rect).first(); + setActualPenAndBrushFromItem(item); selectionRect = scene()->addRect(item->boundingRect(), pen); selectionRect->setZValue(1000000); selectionRect->setData(0, item->pos()-point); @@ -386,4 +383,75 @@ namespace Swift { QGraphicsItem* item = selectionRect->data(1).value<QGraphicsItem*>(); item->setZValue(item->zValue()-1); } + + void GView::changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush) { + QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item); + if (lineItem) { + lineItem->setPen(pen); + } + + FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item); + if (handLineItem) { + handLineItem->setPen(pen); + } + + QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item); + if (rectItem) { + rectItem->setPen(pen); + rectItem->setBrush(brush); + } + + QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item); + if (textItem) { + textItem->setDefaultTextColor(pen.color()); + } + + QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item); + if (polygonItem) { + polygonItem->setPen(pen); + polygonItem->setBrush(brush); + } + + QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); + if (ellipseItem) { + ellipseItem->setPen(pen); + ellipseItem->setBrush(brush); + } + } + + void GView::setActualPenAndBrushFromItem(QGraphicsItem* item) { + QGraphicsLineItem* lineItem = qgraphicsitem_cast<QGraphicsLineItem*>(item); + if (lineItem) { + pen = lineItem->pen(); + } + + FreehandLineItem* handLineItem = qgraphicsitem_cast<FreehandLineItem*>(item); + if (handLineItem) { + pen = handLineItem->pen(); + } + + QGraphicsRectItem* rectItem = qgraphicsitem_cast<QGraphicsRectItem*>(item); + if (rectItem) { + pen = rectItem->pen(); + brush = rectItem->brush(); + } + + QGraphicsTextItem* textItem = qgraphicsitem_cast<QGraphicsTextItem*>(item); + if (textItem) { + pen.setColor(textItem->defaultTextColor()); + } + + QGraphicsPolygonItem* polygonItem = qgraphicsitem_cast<QGraphicsPolygonItem*>(item); + if (polygonItem) { + pen = polygonItem->pen(); + brush = polygonItem->brush(); + } + + QGraphicsEllipseItem* ellipseItem = qgraphicsitem_cast<QGraphicsEllipseItem*>(item); + if (ellipseItem) { + pen = ellipseItem->pen(); + brush = ellipseItem->brush(); + } + lineWidthChanged(pen.width()); + } } diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index 786c1f3..443b7ab 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -46,11 +46,15 @@ namespace Swift { void handleTextItemModified(QGraphicsTextItem*); private: QString getNewID(); + void changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush); + void setActualPenAndBrushFromItem(QGraphicsItem* item); int zValue; bool mousePressed; QPen pen; QBrush brush; + QPen defaultPen; + QBrush defaultBrush; Mode mode; QGraphicsItem* lastItem; QGraphicsRectItem* selectionRect; @@ -63,5 +67,6 @@ namespace Swift { signals: void lastItemChanged(QGraphicsItem* item, int pos, GView::Type type); void itemDeleted(QString id, int pos); + void lineWidthChanged(int i); }; } diff --git a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp index d89a7f6..b3f42a9 100644 --- a/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp +++ b/Swift/QtUI/Whiteboard/QtWhiteboardWindow.cpp @@ -43,6 +43,7 @@ namespace Swift { widthBox = new QSpinBox(this); connect(widthBox, SIGNAL(valueChanged(int)), this, SLOT(changeLineWidth(int))); + connect(graphicsView, SIGNAL(lineWidthChanged(int)), widthBox, SLOT(setValue(int))); widthBox->setValue(1); moveUpButton = new QPushButton("Move Up", this); @@ -246,12 +247,10 @@ namespace Swift { QLine line = lineItem->line().toLine(); QColor color = lineItem->pen().color(); WhiteboardLineElement::ref element = boost::make_shared<WhiteboardLineElement>(line.x1()+lineItem->pos().x(), line.y1()+lineItem->pos().y(), line.x2()+lineItem->pos().x(), line.y2()+lineItem->pos().y()); -// element->setShift(lineItem->pos().x(), lineItem->pos().y()); element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); element->setPenWidth(lineItem->pen().width()); element->setID(lineItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } FreehandLineItem* freehandLineItem = qgraphicsitem_cast<FreehandLineItem*>(item); @@ -269,7 +268,6 @@ namespace Swift { element->setPoints(points); element->setID(freehandLineItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } @@ -283,9 +281,9 @@ namespace Swift { element->setBrushColor(Color(brushColor.red(), brushColor.green(), brushColor.blue(), brushColor.alpha())); element->setPenColor(Color(penColor.red(), penColor.green(), penColor.blue(), penColor.alpha())); element->setPenWidth(rectItem->pen().width()); + std::cout << penColor.red() << " " << brushColor.red() << std::endl; element->setID(rectItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } @@ -299,7 +297,6 @@ namespace Swift { element->setColor(Color(color.red(), color.green(), color.blue(), color.alpha())); element->setID(textItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } @@ -322,7 +319,6 @@ namespace Swift { element->setPenWidth(polygonItem->pen().width()); element->setID(polygonItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } @@ -342,7 +338,6 @@ namespace Swift { element->setPenWidth(ellipseItem->pen().width()); element->setID(ellipseItem->data(100).toString().toStdString()); -// whiteboardSession_->sendElement(element); el = element; } |