summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMateusz Piekos <mateuszpiekos@gmail.com>2012-07-27 12:56:33 (GMT)
committerMateusz Piekos <mateuszpiekos@gmail.com>2012-07-27 12:56:33 (GMT)
commitf7e4c4e108305d3d25a674dacf50f3577e42a519 (patch)
tree155074e40b9217eef1e4b075a3c79807967f76b8
parent7d59f0a441778710065cb124e719d6ecbc0d268f (diff)
downloadswift-contrib-f7e4c4e108305d3d25a674dacf50f3577e42a519.zip
swift-contrib-f7e4c4e108305d3d25a674dacf50f3577e42a519.tar.bz2
Improved graphics view clearing on close
-rw-r--r--Swift/QtUI/Whiteboard/GView.cpp32
-rw-r--r--Swift/QtUI/Whiteboard/GView.h1
2 files changed, 24 insertions, 9 deletions
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<QGraphicsItem*> 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;