From 1df0122f25e50d2887af3e5dcca1ba7a8afd3711 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 30 Aug 2013 16:51:47 +0200 Subject: [PATCH] fixed strokes with pressure on rules and triangle --- src/tools/UBGraphicsRuler.cpp | 13 ++++++++----- src/tools/UBGraphicsRuler.h | 4 +++- src/tools/UBGraphicsTriangle.cpp | 14 ++++++++------ src/tools/UBGraphicsTriangle.h | 1 + 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/tools/UBGraphicsRuler.cpp b/src/tools/UBGraphicsRuler.cpp index 0abc02b5..be2871f7 100644 --- a/src/tools/UBGraphicsRuler.cpp +++ b/src/tools/UBGraphicsRuler.cpp @@ -449,12 +449,14 @@ void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width) { QPointF itemPos = mapFromScene(scenePos); + mStrokeWidth = width; + qreal y; if (itemPos.y() > rect().y() + rect().height() / 2) { drawLineDirection = 0; - y = rect().y() + rect().height() + width / 2; + y = rect().y() + rect().height() + mStrokeWidth / 2; } else { @@ -471,21 +473,22 @@ void UBGraphicsRuler::StartLine(const QPointF& scenePos, qreal width) itemPos = mapToScene(itemPos); scene()->moveTo(itemPos); - scene()->drawLineTo(itemPos, width, true); + scene()->drawLineTo(itemPos, mStrokeWidth, true); } void UBGraphicsRuler::DrawLine(const QPointF& scenePos, qreal width) { + Q_UNUSED(width); QPointF itemPos = mapFromScene(scenePos); qreal y; if (drawLineDirection == 0) { - y = rect().y() + rect().height() + width / 2; + y = rect().y() + rect().height() + mStrokeWidth / 2; } else { - y = rect().y() - width /2; + y = rect().y() - mStrokeWidth /2; } if (itemPos.x() < rect().x() + sLeftEdgeMargin) itemPos.setX(rect().x() + sLeftEdgeMargin); @@ -496,7 +499,7 @@ void UBGraphicsRuler::DrawLine(const QPointF& scenePos, qreal width) itemPos = mapToScene(itemPos); // We have to use "pointed" line for marker tool - scene()->drawLineTo(itemPos, width, UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker); + scene()->drawLineTo(itemPos, mStrokeWidth, UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker); } void UBGraphicsRuler::EndLine() diff --git a/src/tools/UBGraphicsRuler.h b/src/tools/UBGraphicsRuler.h index 61dbe57d..4b37571b 100644 --- a/src/tools/UBGraphicsRuler.h +++ b/src/tools/UBGraphicsRuler.h @@ -60,7 +60,7 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu virtual void EndLine(); protected: - + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *styleOption, QWidget *widget); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); @@ -105,6 +105,8 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu static const int sMinLength = 150; // 3sm static const int sMaxLength = 35000; // 700sm + + qreal mStrokeWidth; }; #endif /* UBGRAPHICSRULER_H_ */ diff --git a/src/tools/UBGraphicsTriangle.cpp b/src/tools/UBGraphicsTriangle.cpp index d1b5cf1b..821420bd 100644 --- a/src/tools/UBGraphicsTriangle.cpp +++ b/src/tools/UBGraphicsTriangle.cpp @@ -855,13 +855,14 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event) void UBGraphicsTriangle::StartLine(const QPointF &scenePos, qreal width) { QPointF itemPos = mapFromScene(scenePos); + mStrokeWidth = width; qreal y; if (mOrientation == 0 || mOrientation == 1) { - y = rect().y() + rect().height() + width / 2; + y = rect().y() + rect().height() + mStrokeWidth / 2; } else if (mOrientation == 2 || mOrientation == 3) { - y = rect().y() - width / 2; + y = rect().y() - mStrokeWidth / 2; } if (itemPos.x() < rect().x() + sLeftEdgeMargin) @@ -873,19 +874,20 @@ void UBGraphicsTriangle::StartLine(const QPointF &scenePos, qreal width) itemPos = mapToScene(itemPos); scene()->moveTo(itemPos); - scene()->drawLineTo(itemPos, width, true); + scene()->drawLineTo(itemPos, mStrokeWidth, true); } void UBGraphicsTriangle::DrawLine(const QPointF &scenePos, qreal width) { + Q_UNUSED(width); QPointF itemPos = mapFromScene(scenePos); qreal y; if (mOrientation == 0 || mOrientation == 1) { - y = rect().y() + rect().height() + width / 2; + y = rect().y() + rect().height() + mStrokeWidth / 2; } else if (mOrientation == 2 || mOrientation == 3) { - y = rect().y() - width / 2; + y = rect().y() - mStrokeWidth / 2; } if (itemPos.x() < rect().x() + sLeftEdgeMargin) @@ -897,7 +899,7 @@ void UBGraphicsTriangle::DrawLine(const QPointF &scenePos, qreal width) itemPos = mapToScene(itemPos); // We have to use "pointed" line for marker tool - scene()->drawLineTo(itemPos, width, + scene()->drawLineTo(itemPos, mStrokeWidth, UBDrawingController::drawingController()->stylusTool() != UBStylusTool::Marker); } diff --git a/src/tools/UBGraphicsTriangle.h b/src/tools/UBGraphicsTriangle.h index ca5131ef..44b8e455 100644 --- a/src/tools/UBGraphicsTriangle.h +++ b/src/tools/UBGraphicsTriangle.h @@ -168,6 +168,7 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt static const int sArrowLength = 30; static const int sMinWidth = 380; static const int sMinHeight = 200; + qreal mStrokeWidth; }; #endif /* UBGRAPHICSTRIANGLE_H_ */