Skip to content

Commit faba2b3

Browse files
committed
Sclae arrow head with width #84
1 parent 7945825 commit faba2b3

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* New: Add tab context menu for close all tabs and close other tabs. ([#93](https://github.com/ksnip/kImageAnnotator/issues/93))
99
* Changed: Make dropdown buttons show popup on click. ([#89](https://github.com/ksnip/kImageAnnotator/issues/89))
1010
* Changed: Hide unavailable setting widgets. ([#101](https://github.com/ksnip/kImageAnnotator/issues/101))
11+
* Changed: Make arrow size decrease with stroke size. ([#84](https://github.com/ksnip/kImageAnnotator/issues/84))
1112
* Fixed: Using select tool marks image as changed. ([#97](https://github.com/ksnip/kImageAnnotator/issues/97))
1213

1314
## Release 0.2.1

src/annotations/items/AnnotationArrow.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,25 @@ ToolTypes AnnotationArrow::toolType() const
3737

3838
void AnnotationArrow::updateShape()
3939
{
40-
QPainterPath path(mLine->p1());
41-
path.lineTo(mLine->p2());
40+
QLineF shaft(*mLine);
41+
shaft.setLength(shaft.length() - 5);
4242

43-
auto arrow = createArrow();
43+
QPainterPath path(shaft.p1());
44+
path.lineTo(shaft.p2());
45+
46+
auto arrow = createArrowHead(properties()->width() / 2);
4447
auto finishedArrow = positionArrowHeadAtEnd(arrow);
4548

4649
path.addPolygon(finishedArrow);
4750
path.closeSubpath();
4851
setShape(path);
4952
}
5053

51-
QPolygonF AnnotationArrow::createArrow() const
54+
QPolygonF AnnotationArrow::createArrowHead(int scaleFactor) const
5255
{
53-
int mArrowHeadLength = 20;
54-
int mArrowHeadWidth = 10;
55-
int mArrowHeadMid = 17;
56+
int mArrowHeadLength = 15 + scaleFactor;
57+
int mArrowHeadWidth = 5 + scaleFactor;
58+
int mArrowHeadMid = 13 + scaleFactor;
5659

5760
QPointF p0(0, 0);
5861
QPointF p1(-mArrowHeadLength, mArrowHeadWidth);

src/annotations/items/AnnotationArrow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class AnnotationArrow : public AbstractAnnotationLine
3434

3535
protected:
3636
void updateShape() override;
37-
QPolygonF createArrow() const;
37+
QPolygonF createArrowHead(int scaleFactor) const;
3838
QPolygonF positionArrowHeadAtEnd(const QPolygonF &arrow) const;
3939
};
4040

src/annotations/items/AnnotationDoubleArrow.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ ToolTypes AnnotationDoubleArrow::toolType() const
3838

3939
void AnnotationDoubleArrow::updateShape()
4040
{
41-
QPainterPath path(mLine->p1());
42-
path.lineTo(mLine->p2());
41+
QLineF shaft(mLine->p2(), mLine->p1());
42+
shaft.setLength(shaft.length() - 5);
43+
shaft.setPoints(shaft.p2(), shaft.p1());
44+
shaft.setLength(shaft.length() - 5);
4345

44-
auto arrow = createArrow();
46+
QPainterPath path(shaft.p1());
47+
path.lineTo(shaft.p2());
48+
49+
auto arrow = createArrowHead(properties()->width() / 2);
4550
auto startArrowHead = positionArrowHeadAtStart(arrow);
4651
auto endArrowHead = positionArrowHeadAtEnd(arrow);
4752

0 commit comments

Comments
 (0)