From f7e4c4e108305d3d25a674dacf50f3577e42a519 Mon Sep 17 00:00:00 2001 From: Mateusz Piekos Date: Fri, 27 Jul 2012 14:56:33 +0200 Subject: Improved graphics view clearing on close diff --git a/Swift/QtUI/Whiteboard/GView.cpp b/Swift/QtUI/Whiteboard/GView.cpp index 163cab0..a4f000b 100644 --- a/Swift/QtUI/Whiteboard/GView.cpp +++ b/Swift/QtUI/Whiteboard/GView.cpp @@ -60,6 +60,7 @@ namespace Swift { void GView::setMode(Mode mode) { this->mode = mode; lastItem = 0; + unselect(); } void GView::addItem(QGraphicsItem* item, QString id, int pos) { @@ -92,6 +93,12 @@ namespace Swift { itemsMap_.clear(); lastItem = 0; selectionRect = 0; + brush = QBrush(QColor(Qt::white)); + defaultBrush = QBrush(QColor(Qt::white)); + pen = QPen(); + pen.setWidth(1); + defaultPen = pen; + lineWidthChanged(1); } QGraphicsItem* GView::getItem(QString id) { @@ -215,14 +222,7 @@ namespace Swift { void GView::mousePressEvent(QMouseEvent *event) { mousePressed = true; - if (selectionRect != 0) { - pen = defaultPen; - brush = defaultBrush; - scene()->removeItem(selectionRect); - delete selectionRect; - selectionRect = 0; - lineWidthChanged(pen.width()); - } + unselect(); if (mode == Line) { QPointF point = this->mapToScene(event->pos()); QGraphicsItem* item = scene()->addLine(point.x(), point.y(), point.x(), point.y(), pen); @@ -327,6 +327,9 @@ namespace Swift { else if (mode == Select) { QPointF point = this->mapToScene(event->pos()); int w = pen.width(); + if (w == 0) { + w = 1; + } QRectF rect(point.x()-w, point.y()-w, w*2, w*2); QList list = scene()->items(rect); if (!list.isEmpty()) { @@ -334,7 +337,6 @@ 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); @@ -342,6 +344,7 @@ namespace Swift { QVariant var(QVariant::UserType); var.setValue(item); selectionRect->setData(1, var); + setActualPenAndBrushFromItem(item); } } } @@ -457,4 +460,15 @@ namespace Swift { } lineWidthChanged(pen.width()); } + + void GView::unselect() { + if (selectionRect != 0) { + pen = defaultPen; + brush = defaultBrush; + scene()->removeItem(selectionRect); + delete selectionRect; + selectionRect = 0; + lineWidthChanged(pen.width()); + } + } } diff --git a/Swift/QtUI/Whiteboard/GView.h b/Swift/QtUI/Whiteboard/GView.h index dc6a3c2..f219929 100644 --- a/Swift/QtUI/Whiteboard/GView.h +++ b/Swift/QtUI/Whiteboard/GView.h @@ -48,6 +48,7 @@ namespace Swift { private: void changePenAndBrush(QGraphicsItem* item, QPen pen, QBrush brush); void setActualPenAndBrushFromItem(QGraphicsItem* item); + void unselect(); int zValue; bool mousePressed; -- cgit v0.10.2-6-g49f6