Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpenBoard
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lifo
Nicolas Ollinger
OpenBoard
Commits
2491e7e3
Commit
2491e7e3
authored
Jul 05, 2011
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Graphics Triangle Tool
parent
331a82ff
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
363 additions
and
117 deletions
+363
-117
UBGraphicsTriangle.cpp
src/tools/UBGraphicsTriangle.cpp
+348
-115
UBGraphicsTriangle.h
src/tools/UBGraphicsTriangle.h
+15
-2
No files found.
src/tools/UBGraphicsTriangle.cpp
View file @
2491e7e3
...
@@ -40,9 +40,35 @@ UBGraphicsTriangle::UBGraphicsTriangle()
...
@@ -40,9 +40,35 @@ UBGraphicsTriangle::UBGraphicsTriangle()
mRotateSvgItem
->
setVisible
(
false
);
mRotateSvgItem
->
setVisible
(
false
);
mRotateSvgItem
->
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
mRotateSvgItem
->
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
//
updateResizeCursor();
updateResizeCursor
();
}
}
void
UBGraphicsTriangle
::
updateResizeCursor
()
{
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
itemTransform
=
sceneTransform
();
QRectF
itemRect
=
boundingRect
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QPointF
bottomLeft
=
itemTransform
.
map
(
itemRect
.
bottomLeft
());
QLineF
topLine
(
topLeft
,
topRight
);
QLineF
leftLine
(
topLeft
,
bottomLeft
);
qreal
angle
=
topLine
.
angle
();
QTransform
tr1
;
tr1
.
rotate
(
-
angle
);
mResizeCursor1
=
QCursor
(
pix
.
transformed
(
tr1
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
angle
=
leftLine
.
angle
();
QTransform
tr2
;
tr2
.
rotate
(
-
angle
);
mResizeCursor2
=
QCursor
(
pix
.
transformed
(
tr2
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
}
UBGraphicsTriangle
::~
UBGraphicsTriangle
()
UBGraphicsTriangle
::~
UBGraphicsTriangle
()
{
{
}
}
...
@@ -65,7 +91,7 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const
...
@@ -65,7 +91,7 @@ UBItem* UBGraphicsTriangle::deepCopy(void) const
void
UBGraphicsTriangle
::
setRect
(
qreal
x
,
qreal
y
,
qreal
w
,
qreal
h
,
UBGraphicsTriangleOrientation
orientation
)
void
UBGraphicsTriangle
::
setRect
(
qreal
x
,
qreal
y
,
qreal
w
,
qreal
h
,
UBGraphicsTriangleOrientation
orientation
)
{
{
QPolygonF
polygon
;
QPolygonF
polygon
;
polygon
<<
QPointF
(
x
,
y
)
<<
QPoint
(
x
,
y
+
h
)
<<
QPoint
(
x
+
w
,
y
+
h
)
<<
QPoint
(
x
,
y
)
;
polygon
<<
QPointF
(
x
,
y
)
<<
QPoint
(
x
,
y
+
h
)
<<
QPoint
(
x
+
w
,
y
+
h
);
setPolygon
(
polygon
);
setPolygon
(
polygon
);
setOrientation
(
orientation
);
setOrientation
(
orientation
);
...
@@ -73,30 +99,12 @@ void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsT
...
@@ -73,30 +99,12 @@ void UBGraphicsTriangle::setRect(qreal x, qreal y, qreal w, qreal h, UBGraphicsT
void
UBGraphicsTriangle
::
setOrientation
(
UBGraphicsTriangleOrientation
orientation
)
void
UBGraphicsTriangle
::
setOrientation
(
UBGraphicsTriangleOrientation
orientation
)
{
{
if
(
mOrientation
!=
orientation
)
mOrientation
=
orientation
;
{
calculatePoints
(
boundingRect
());
mOrientation
=
orientation
;
QTransform
t
;
QPolygonF
polygon
;
switch
(
orientation
)
polygon
<<
A1
<<
B1
<<
C1
;
{
setPolygon
(
polygon
);
case
BottomLeft
:
t
.
setMatrix
(
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
);
break
;
case
BottomRight
:
t
.
setMatrix
(
-
1
,
0
,
0
,
0
,
1
,
0
,
boundingRect
().
right
(),
0
,
1
);
break
;
case
TopLeft
:
t
.
setMatrix
(
1
,
0
,
0
,
0
,
-
1
,
0
,
0
,
boundingRect
().
bottom
(),
1
);
break
;
case
TopRight
:
t
.
setMatrix
(
-
1
,
0
,
0
,
0
,
-
1
,
0
,
boundingRect
().
right
(),
boundingRect
().
bottom
(),
1
);
break
;
}
this
->
angle
=
-
this
->
angle
;
rotateAroundCenter
(
t
,
rotationCenter
());
setTransform
(
t
);
}
}
}
UBGraphicsScene
*
UBGraphicsTriangle
::
scene
()
const
UBGraphicsScene
*
UBGraphicsTriangle
::
scene
()
const
...
@@ -104,25 +112,81 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const
...
@@ -104,25 +112,81 @@ UBGraphicsScene* UBGraphicsTriangle::scene() const
return
static_cast
<
UBGraphicsScene
*>
(
QGraphicsPolygonItem
::
scene
());
return
static_cast
<
UBGraphicsScene
*>
(
QGraphicsPolygonItem
::
scene
());
}
}
void
UBGraphicsTriangle
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
,
QWidget
*
)
void
UBGraphicsTriangle
::
calculatePoints
(
const
QRectF
&
r
)
{
{
QPointF
A1
(
rect
().
x
(),
rect
().
y
());
switch
(
mOrientation
)
QPointF
B1
(
rect
().
x
(),
rect
().
y
()
+
rect
().
height
());
{
QPointF
C1
(
rect
().
x
()
+
rect
().
width
(),
rect
().
y
()
+
rect
().
height
());
case
BottomLeft
:
A1
.
setX
(
r
.
left
());
A1
.
setY
(
r
.
top
());
B1
.
setX
(
r
.
left
());
B1
.
setY
(
r
.
bottom
());
C1
.
setX
(
r
.
right
());
C1
.
setY
(
r
.
bottom
());
break
;
case
TopLeft
:
A1
.
setX
(
r
.
left
());
A1
.
setY
(
r
.
bottom
());
B1
.
setX
(
r
.
left
());
B1
.
setY
(
r
.
top
());
C1
.
setX
(
r
.
right
());
C1
.
setY
(
r
.
top
());
break
;
case
TopRight
:
A1
.
setX
(
r
.
right
());
A1
.
setY
(
r
.
bottom
());
B1
.
setX
(
r
.
right
());
B1
.
setY
(
r
.
top
());
C1
.
setX
(
r
.
left
());
C1
.
setY
(
r
.
top
());
break
;
case
BottomRight
:
A1
.
setX
(
r
.
right
());
A1
.
setY
(
r
.
top
());
B1
.
setX
(
r
.
right
());
B1
.
setY
(
r
.
bottom
());
C1
.
setX
(
r
.
left
());
C1
.
setY
(
r
.
bottom
());
break
;
}
qreal
C
=
sqrt
(
rect
().
width
()
*
rect
().
width
()
+
rect
().
height
()
*
rect
().
height
());
C
=
sqrt
(
rect
().
width
()
*
rect
().
width
()
+
rect
().
height
()
*
rect
().
height
());
qreal
L
=
(
C
*
d
+
rect
().
width
()
*
d
)
/
rect
().
height
();
qreal
L
=
(
C
*
d
+
rect
().
width
()
*
d
)
/
rect
().
height
();
qreal
K
=
(
C
*
d
+
rect
().
height
()
*
d
)
/
rect
().
width
();
qreal
K
=
(
C
*
d
+
rect
().
height
()
*
d
)
/
rect
().
width
();
qreal
W1
=
rect
().
height
()
*
d
/
C
;
switch
(
mOrientation
)
qreal
H1
=
rect
().
width
()
*
d
/
C
;
{
case
BottomLeft
:
A2
.
setX
(
r
.
left
()
+
d
);
A2
.
setY
(
r
.
top
()
+
K
);
B2
.
setX
(
r
.
left
()
+
d
);
B2
.
setY
(
r
.
bottom
()
-
d
);
C2
.
setX
(
r
.
right
()
-
L
);
C2
.
setY
(
r
.
bottom
()
-
d
);
break
;
case
TopLeft
:
A2
.
setX
(
r
.
left
()
+
d
);
A2
.
setY
(
r
.
bottom
()
-
K
);
B2
.
setX
(
r
.
left
()
+
d
);
B2
.
setY
(
r
.
top
()
+
d
);
C2
.
setX
(
r
.
right
()
-
L
);
C2
.
setY
(
r
.
top
()
+
d
);
break
;
case
TopRight
:
A2
.
setX
(
r
.
right
()
-
d
);
A2
.
setY
(
r
.
bottom
()
-
K
);
B2
.
setX
(
r
.
right
()
-
d
);
B2
.
setY
(
r
.
top
()
+
d
);
C2
.
setX
(
r
.
left
()
+
L
);
C2
.
setY
(
r
.
top
()
+
d
);
break
;
case
BottomRight
:
A2
.
setX
(
r
.
right
()
-
d
);
A2
.
setY
(
r
.
top
()
+
K
);
B2
.
setX
(
r
.
right
()
-
d
);
B2
.
setY
(
r
.
bottom
()
-
d
);
C2
.
setX
(
r
.
left
()
+
L
);
C2
.
setY
(
r
.
bottom
()
-
d
);
break
;
}
W1
=
rect
().
height
()
*
d
/
C
;
H1
=
rect
().
width
()
*
d
/
C
;
QPointF
A2
(
rect
().
x
()
+
d
,
rect
().
y
()
+
K
);
switch
(
mOrientation
)
QPointF
B2
(
rect
().
x
()
+
d
,
rect
().
y
()
+
rect
().
height
()
-
d
);
{
QPointF
C2
(
rect
().
x
()
+
rect
().
width
()
-
L
,
rect
().
y
()
+
rect
().
height
()
-
d
);
case
BottomLeft
:
CC
.
setX
(
r
.
right
()
-
L
+
W1
);
CC
.
setY
(
r
.
bottom
()
-
d
-
H1
);
break
;
case
TopLeft
:
CC
.
setX
(
r
.
right
()
-
L
+
W1
);
CC
.
setY
(
r
.
top
()
+
d
+
H1
);
break
;
case
TopRight
:
CC
.
setX
(
r
.
left
()
+
L
-
W1
);
CC
.
setY
(
r
.
top
()
+
d
+
H1
);
break
;
case
BottomRight
:
CC
.
setX
(
r
.
left
()
+
L
-
W1
);
CC
.
setY
(
r
.
top
()
-
d
-
H1
);
break
;
}
}
QPoint
CC
(
rect
().
x
()
+
rect
().
width
()
-
L
+
W1
,
void
UBGraphicsTriangle
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
,
QWidget
*
)
rect
().
y
()
+
rect
().
height
()
-
d
-
H1
);
{
painter
->
setPen
(
Qt
::
NoPen
);
painter
->
setPen
(
Qt
::
NoPen
);
...
@@ -197,41 +261,76 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
...
@@ -197,41 +261,76 @@ void UBGraphicsTriangle::paintGraduations(QPainter *painter)
const
int
millimetersPerCentimeter
=
10
;
const
int
millimetersPerCentimeter
=
10
;
const
int
millimetersPerHalfCentimeter
=
5
;
const
int
millimetersPerHalfCentimeter
=
5
;
qreal
kx
=
(
mOrientation
==
TopLeft
||
mOrientation
==
BottomLeft
)
?
1
:
-
1
;
qreal
ky
=
(
mOrientation
==
BottomLeft
||
mOrientation
==
BottomRight
)
?
1
:
-
1
;
painter
->
save
();
painter
->
save
();
painter
->
setFont
(
font
());
painter
->
setFont
(
font
());
QFontMetricsF
fontMetrics
(
painter
->
font
());
QFontMetricsF
fontMetrics
(
painter
->
font
());
for
(
int
millimeters
=
0
;
millimeters
<
(
rect
().
width
()
-
sLeftEdgeMargin
-
sRoundingRadius
)
/
sPixelsPerMillimeter
;
millimeters
++
)
for
(
int
millimeters
=
0
;
millimeters
<
(
rect
().
width
()
-
sLeftEdgeMargin
-
sRoundingRadius
)
/
sPixelsPerMillimeter
;
millimeters
++
)
{
{
int
graduationX
=
rotationCenter
().
x
()
+
sPixelsPerMillimeter
*
millimeters
;
int
graduationX
=
rotationCenter
().
x
()
+
kx
*
sPixelsPerMillimeter
*
millimeters
;
int
graduationHeight
=
(
0
==
millimeters
%
millimetersPerCentimeter
)
?
int
graduationHeight
=
(
0
==
millimeters
%
millimetersPerCentimeter
)
?
centimeterGraduationHeight
:
centimeterGraduationHeight
:
((
0
==
millimeters
%
millimetersPerHalfCentimeter
)
?
((
0
==
millimeters
%
millimetersPerHalfCentimeter
)
?
halfCentimeterGraduationHeight
:
millimeterGraduationHeight
);
halfCentimeterGraduationHeight
:
millimeterGraduationHeight
);
// Check that grad. line inside triangle
// Check that grad. line inside triangle
qreal
lineY
=
rect
().
bottom
()
-
rect
().
height
()
/
rect
().
width
()
*
(
rect
().
width
()
-
graduationX
);
qreal
dx
=
(
kx
>
0
)
?
rect
().
width
()
-
graduationX
:
graduationX
-
rect
().
x
();
if
(
lineY
>=
rotationCenter
().
y
()
-
graduationHeight
)
qreal
lineY
=
rotationCenter
().
y
()
-
ky
*
rect
().
height
()
/
rect
().
width
()
*
dx
;
break
;
if
(
mOrientation
==
BottomLeft
||
mOrientation
==
BottomRight
)
{
if
(
lineY
>=
rotationCenter
().
y
()
-
ky
*
graduationHeight
)
break
;
}
else
{
if
(
lineY
<=
rotationCenter
().
y
()
-
ky
*
graduationHeight
)
break
;
}
painter
->
drawLine
(
QLine
(
graduationX
,
rotationCenter
().
y
(),
graduationX
,
rotationCenter
().
y
()
-
graduationHeight
));
painter
->
drawLine
(
QLine
(
graduationX
,
rotationCenter
().
y
(),
graduationX
,
rotationCenter
().
y
()
-
ky
*
graduationHeight
));
if
(
0
==
millimeters
%
millimetersPerCentimeter
)
if
(
0
==
millimeters
%
millimetersPerCentimeter
)
{
{
QString
text
=
QString
(
"%1"
).
arg
((
int
)(
millimeters
/
millimetersPerCentimeter
));
QString
text
=
QString
(
"%1"
).
arg
((
int
)(
millimeters
/
millimetersPerCentimeter
));
int
textXRight
=
graduationX
+
fontMetrics
.
width
(
text
)
/
2
;
int
textXRight
=
graduationX
+
fontMetrics
.
width
(
text
)
/
2
;
qreal
textWidth
=
fontMetrics
.
width
(
text
);
qreal
textWidth
=
fontMetrics
.
width
(
text
);
qreal
textHeight
=
fontMetrics
.
tightBoundingRect
(
text
).
height
()
+
5
;
qreal
textHeight
=
fontMetrics
.
tightBoundingRect
(
text
).
height
()
+
5
;
int
textY
=
rect
().
bottom
()
-
5
-
centimeterGraduationHeight
-
textHeight
;
lineY
=
rect
().
bottom
()
-
rect
().
height
()
/
rect
().
width
()
*
(
rect
().
width
()
-
textXRight
);
int
textY
=
(
ky
>
0
)
?
rotationCenter
().
y
()
-
5
-
centimeterGraduationHeight
-
textHeight
:
rotationCenter
().
y
()
+
5
+
centimeterGraduationHeight
;
if
(
textXRight
<
rect
().
right
()
bool
bText
=
false
;
&&
lineY
<
textY
)
switch
(
mOrientation
)
{
{
case
BottomLeft
:
dx
=
rect
().
width
()
-
textXRight
;
lineY
=
rotationCenter
().
y
()
-
rect
().
height
()
/
rect
().
width
()
*
dx
;
bText
=
lineY
<=
textY
;
break
;
case
TopLeft
:
dx
=
rect
().
width
()
-
textXRight
;
lineY
=
rotationCenter
().
y
()
+
rect
().
height
()
/
rect
().
width
()
*
dx
;
bText
=
lineY
>=
textY
+
textHeight
;
break
;
case
TopRight
:
dx
=
textXRight
-
textWidth
-
rect
().
left
();
lineY
=
rotationCenter
().
y
()
+
rect
().
height
()
/
rect
().
width
()
*
dx
;
bText
=
lineY
>=
textY
+
textHeight
;
break
;
case
BottomRight
:
dx
=
textXRight
-
textWidth
-
rect
().
left
();
lineY
=
rotationCenter
().
y
()
-
rect
().
height
()
/
rect
().
width
()
*
dx
;
bText
=
lineY
<=
textY
;
break
;
}
if
(
bText
)
painter
->
drawText
(
painter
->
drawText
(
QRectF
(
graduationX
-
textWidth
/
2
,
QRectF
(
graduationX
-
textWidth
/
2
,
textY
,
textWidth
,
textHeight
),
textY
,
textWidth
,
textHeight
),
Qt
::
AlignVCenter
,
text
);
Qt
::
AlignVCenter
,
text
);
}
}
}
}
}
painter
->
restore
();
painter
->
restore
();
...
@@ -258,82 +357,192 @@ void UBGraphicsTriangle::rotateAroundCenter(QTransform& transform, QPointF cente
...
@@ -258,82 +357,192 @@ void UBGraphicsTriangle::rotateAroundCenter(QTransform& transform, QPointF cente
QPointF
UBGraphicsTriangle
::
rotationCenter
()
const
QPointF
UBGraphicsTriangle
::
rotationCenter
()
const
{
{
return
QPointF
(
rect
().
x
()
+
sLeftEdgeMargin
,
rect
().
bottom
());
switch
(
mOrientation
)
{
case
BottomLeft
:
case
TopLeft
:
return
B1
+
QPointF
(
sLeftEdgeMargin
,
0
);
case
TopRight
:
case
BottomRight
:
return
B1
-
QPointF
(
sLeftEdgeMargin
,
0
);
}
return
QPointF
(
0
,
0
);
}
}
QRectF
UBGraphicsTriangle
::
closeButtonRect
()
const
QRectF
UBGraphicsTriangle
::
closeButtonRect
()
const
{
{
return
QRectF
(
rect
().
x
()
+
d
-
mCloseSvgItem
->
boundingRect
().
width
()
-
5
,
switch
(
mOrientation
)
rect
().
bottom
()
-
d
-
mCloseSvgItem
->
boundingRect
().
height
()
-
5
,
{
mCloseSvgItem
->
boundingRect
().
width
(),
case
BottomLeft
:
mCloseSvgItem
->
boundingRect
().
height
());
return
QRectF
(
B2
.
x
()
-
mCloseSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
-
mCloseSvgItem
->
boundingRect
().
height
()
-
5
,
mCloseSvgItem
->
boundingRect
().
width
(),
mCloseSvgItem
->
boundingRect
().
height
());
case
TopLeft
:
return
QRectF
(
B2
.
x
()
-
mCloseSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
+
5
,
mCloseSvgItem
->
boundingRect
().
width
(),
mCloseSvgItem
->
boundingRect
().
height
());
case
TopRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
+
5
,
mCloseSvgItem
->
boundingRect
().
width
(),
mCloseSvgItem
->
boundingRect
().
height
());
case
BottomRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
-
mCloseSvgItem
->
boundingRect
().
height
()
-
5
,
mCloseSvgItem
->
boundingRect
().
width
(),
mCloseSvgItem
->
boundingRect
().
height
());
}
return
QRectF
(
0
,
0
,
0
,
0
);
}
}
QPolygonF
UBGraphicsTriangle
::
resize1Polygon
()
const
QPolygonF
UBGraphicsTriangle
::
resize1Polygon
()
const
{
{
qreal
C
=
sqrt
(
rect
().
width
()
*
rect
().
width
()
+
rect
().
height
()
*
rect
().
height
());
qreal
x1
,
y1
;
switch
(
mOrientation
)
{
case
BottomLeft
:
x1
=
-
1
;
y1
=
-
1
;
break
;
case
TopLeft
:
x1
=
-
1
;
y1
=
1
;
break
;
case
TopRight
:
x1
=
1
;
y1
=
1
;
break
;
case
BottomRight
:
x1
=
1
;
y1
=
-
1
;
break
;
}
QPointF
P1
(
C1
.
x
()
+
x1
*
sArrowLength
,
C1
.
y
());
QPointF
P2
(
C1
.
x
()
+
x1
*
sArrowLength
*
rect
().
width
()
/
C
,
C1
.
y
()
+
y1
*
sArrowLength
*
rect
().
height
()
/
C
);
QPolygonF
p
;
QPolygonF
p
;
p
<<
C1
<<
P1
<<
P2
;
QPointF
P1
(
rect
().
right
()
-
sArrowLength
,
rect
().
bottom
());
QPointF
P2
(
rect
().
right
()
-
sArrowLength
*
rect
().
width
()
/
C
,
rect
().
bottom
()
-
sArrowLength
*
rect
().
height
()
/
C
);
p
<<
QPointF
(
rect
().
right
(),
rect
().
bottom
())
<<
P1
<<
P2
;
return
p
;
return
p
;
}
}
QPolygonF
UBGraphicsTriangle
::
resize2Polygon
()
const
QPolygonF
UBGraphicsTriangle
::
resize2Polygon
()
const
{
{
qreal
C
=
sqrt
(
rect
().
width
()
*
rect
().
width
()
+
rect
().
height
()
*
rect
().
height
());
qreal
x1
,
y1
;
switch
(
mOrientation
)
{
case
BottomLeft
:
x1
=
1
;
y1
=
1
;
break
;
case
TopLeft
:
x1
=
1
;
y1
=
-
1
;
break
;
case
TopRight
:
x1
=
-
1
;
y1
=
-
1
;
break
;
case
BottomRight
:
x1
=
-
1
;
y1
=
1
;
break
;
}
QPointF
P1
(
A1
.
x
(),
A1
.
y
()
+
y1
*
sArrowLength
);
QPointF
P2
(
A1
.
x
()
+
x1
*
sArrowLength
*
rect
().
width
()
/
C
,
A1
.
y
()
+
y1
*
sArrowLength
*
rect
().
height
()
/
C
);
QPolygonF
p
;
QPolygonF
p
;
p
<<
A1
<<
P1
<<
P2
;
QPointF
P1
(
rect
().
left
(),
rect
().
top
()
+
sArrowLength
);
QPointF
P2
(
rect
().
left
()
+
sArrowLength
*
rect
().
width
()
/
C
,
rect
().
top
()
+
sArrowLength
*
rect
().
height
()
/
C
);
p
<<
QPointF
(
rect
().
left
(),
rect
().
top
())
<<
P1
<<
P2
;
return
p
;
return
p
;
}
}
QRectF
UBGraphicsTriangle
::
hFlipRect
()
const
QRectF
UBGraphicsTriangle
::
hFlipRect
()
const
{
{
return
QRectF
(
rect
().
x
()
+
d
-
mHFlipSvgItem
->
boundingRect
().
width
()
-
5
,
qreal
dy
=
mVFlipSvgItem
->
boundingRect
().
height
()
+
mCloseSvgItem
->
boundingRect
().
height
()
+
10
;
rect
().
bottom
()
-
d
-
mCloseSvgItem
->
boundingRect
().
height
()
-
mVFlipSvgItem
->
boundingRect
().
height
()
-
switch
(
mOrientation
)
mVFlipSvgItem
->
boundingRect
().
height
()
-
15
,
{
mHFlipSvgItem
->
boundingRect
().
width
(),
case
BottomLeft
:
mHFlipSvgItem
->
boundingRect
().
height
());
return
QRectF
(
B2
.
x
()
-
mHFlipSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
-
mHFlipSvgItem
->
boundingRect
().
height
()
-
5
-
dy
,
mHFlipSvgItem
->
boundingRect
().
width
(),
mHFlipSvgItem
->
boundingRect
().
height
());
case
TopLeft
:
return
QRectF
(
B2
.
x
()
-
mHFlipSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
+
5
+
dy
,
mHFlipSvgItem
->
boundingRect
().
width
(),
mHFlipSvgItem
->
boundingRect
().
height
());
case
TopRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
+
5
+
dy
,
mHFlipSvgItem
->
boundingRect
().
width
(),
mHFlipSvgItem
->
boundingRect
().
height
());
case
BottomRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
-
mHFlipSvgItem
->
boundingRect
().
height
()
-
5
-
dy
,
mHFlipSvgItem
->
boundingRect
().
width
(),
mHFlipSvgItem
->
boundingRect
().
height
());
}
return
QRectF
(
0
,
0
,
0
,
0
);
}
}
QRectF
UBGraphicsTriangle
::
vFlipRect
()
const
QRectF
UBGraphicsTriangle
::
vFlipRect
()
const
{
{
return
QRectF
(
rect
().
x
()
+
d
-
mVFlipSvgItem
->
boundingRect
().
width
()
-
5
,
qreal
dy
=
mCloseSvgItem
->
boundingRect
().
height
()
+
5
;
rect
().
bottom
()
-
d
-
mCloseSvgItem
->
boundingRect
().
height
()
-
mVFlipSvgItem
->
boundingRect
().
height
()
-
10
,
switch
(
mOrientation
)
mVFlipSvgItem
->
boundingRect
().
width
(),
{
mVFlipSvgItem
->
boundingRect
().
height
());
case
BottomLeft
:
return
QRectF
(
B2
.
x
()
-
mVFlipSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
-
mVFlipSvgItem
->
boundingRect
().
height
()
-
5
-
dy
,
mVFlipSvgItem
->
boundingRect
().
width
(),
mVFlipSvgItem
->
boundingRect
().
height
());
case
TopLeft
:
return
QRectF
(
B2
.
x
()
-
mVFlipSvgItem
->
boundingRect
().
width
()
-
5
,
B2
.
y
()
+
5
+
dy
,
mVFlipSvgItem
->
boundingRect
().
width
(),
mVFlipSvgItem
->
boundingRect
().
height
());
case
TopRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
+
5
+
dy
,
mVFlipSvgItem
->
boundingRect
().
width
(),
mVFlipSvgItem
->
boundingRect
().
height
());
case
BottomRight
:
return
QRectF
(
B2
.
x
()
+
5
,
B2
.
y
()
-
mVFlipSvgItem
->
boundingRect
().
height
()
-
5
-
dy
,
mVFlipSvgItem
->
boundingRect
().
width
(),
mVFlipSvgItem
->
boundingRect
().
height
());
}
return
QRectF
(
0
,
0
,
0
,
0
);
}
}
QRectF
UBGraphicsTriangle
::
rotateRect
()
const
QRectF
UBGraphicsTriangle
::
rotateRect
()
const
{
{
QPointF
A1
(
rect
().
x
(),
rect
().
y
());
QPointF
p
(
C2
);
QPointF
B1
(
rect
().
x
(),
rect
().
y
()
+
rect
().
height
());
switch
(
mOrientation
)
QPointF
C1
(
rect
().
x
()
+
rect
().
width
(),
rect
().
y
()
+
rect
().
height
());
{
case
BottomLeft
:
qreal
C
=
sqrt
(
rect
().
width
()
*
rect
().
width
()
+
rect
().
height
()
*
rect
().
height
());
p
+=
QPointF
(
20
,
5
);
qreal
L
=
(
C
*
d
+
rect
().
width
()
*
d
)
/
rect
().
height
();
break
;
case
TopLeft
:
QPointF
C2
(
rect
().
x
()
+
rect
().
width
()
-
L
,
rect
().
y
()
+
rect
().
height
()
-
d
);
p
+=
QPointF
(
20
,
-
5
-
mRotateSvgItem
->
boundingRect
().
height
());
break
;
return
QRectF
(
C2
+
QPointF
(
20
,
5
),
QSizeF
(
mRotateSvgItem
->
boundingRect
().
size
()));
case
TopRight
:
p
+=
QPointF
(
-
20
-
mRotateSvgItem
->
boundingRect
().
width
(),
-
5
-
mRotateSvgItem
->
boundingRect
().
height
());
break
;
case
BottomRight
:
p
+=
QPointF
(
-
20
-
mRotateSvgItem
->
boundingRect
().
width
(),
5
);
break
;
}
return
QRectF
(
p
,
QSizeF
(
mRotateSvgItem
->
boundingRect
().
size
()));
}
QCursor
UBGraphicsTriangle
::
resizeCursor1
()
const
{
return
mResizeCursor1
;
}
}
QCursor
UBGraphicsTriangle
::
moveResizeCursor
()
const
QCursor
UBGraphicsTriangle
::
resizeCursor2
()
const
{
{
return
Qt
::
OpenHandCursor
;
return
mResizeCursor2
;
}
}
QCursor
UBGraphicsTriangle
::
flipCursor
()
const
QCursor
UBGraphicsTriangle
::
flipCursor
()
const
...
@@ -382,8 +591,16 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
...
@@ -382,8 +591,16 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if
(
mResizing1
)
if
(
mResizing1
)
{
{
QPointF
delta
=
event
->
pos
()
-
event
->
lastPos
();
QPointF
delta
=
event
->
pos
()
-
event
->
lastPos
();
if
(
rect
().
width
()
+
delta
.
x
()
<
sMinWidth
)
if
(
mOrientation
==
TopLeft
||
mOrientation
==
BottomLeft
)
delta
.
setX
(
sMinWidth
-
rect
().
width
());
{
if
(
rect
().
width
()
+
delta
.
x
()
<
sMinWidth
)
delta
.
setX
(
sMinWidth
-
rect
().
width
());
}
else
{
if
(
rect
().
width
()
-
delta
.
x
()
<
sMinWidth
)
delta
.
setX
(
sMinWidth
-
rect
().
width
());
}
if
(
mOrientation
==
TopLeft
||
mOrientation
==
BottomLeft
)
if
(
mOrientation
==
TopLeft
||
mOrientation
==
BottomLeft
)
{
{
setRect
(
QRectF
(
setRect
(
QRectF
(
...
@@ -395,9 +612,9 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
...
@@ -395,9 +612,9 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
else
else
{
{
setRect
(
QRectF
(
setRect
(
QRectF
(
rect
().
left
()
-
delta
.
x
(),
rect
().
left
()
+
delta
.
x
(),
rect
().
top
(),
rect
().
top
(),
rect
().
width
()
+
delta
.
x
(),
rect
().
width
()
-
delta
.
x
(),
rect
().
height
()),
rect
().
height
()),
mOrientation
mOrientation
);
);
...
@@ -406,18 +623,30 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
...
@@ -406,18 +623,30 @@ void UBGraphicsTriangle::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if
(
mResizing2
)
if
(
mResizing2
)
{
{
QPointF
delta
=
event
->
pos
()
-
event
->
lastPos
();
QPointF
delta
=
event
->
pos
()
-
event
->
lastPos
();
if
(
rect
().
height
()
-
delta
.
y
()
<
sMinHeight
)
if
(
mOrientation
==
BottomRight
||
mOrientation
==
BottomLeft
)
delta
.
setY
(
sMinHeight
-
rect
().
height
());
{
qDebug
()
<<
event
->
pos
()
<<
event
->
lastPos
()
<<
delta
;
if
(
rect
().
height
()
-
delta
.
y
()
<
sMinHeight
)
QRectF
r
(
delta
.
setY
(
sMinHeight
-
rect
().
height
());
rect
().
left
(),
}
rect
().
top
()
+
delta
.
y
(),
else
rect
().
width
(),
{
rect
().
height
()
-
delta
.
y
());
if
(
rect
().
height
()
+
delta
.
y
()
<
sMinHeight
)
qDebug
()
<<
r
;
delta
.
setY
(
sMinHeight
-
rect
().
height
());
setRect
(
r
,
mOrientation
);
}
if
(
mOrientation
==
BottomRight
||
mOrientation
==
BottomLeft
)
setRect
(
QRectF
(
rect
().
left
(),
rect
().
top
()
+
delta
.
y
(),
rect
().
width
(),
rect
().
height
()
-
delta
.
y
()),
mOrientation
);
else
setRect
(
QRectF
(
rect
().
left
(),
rect
().
top
(),
rect
().
width
(),
rect
().
height
()
+
delta
.
y
()),
mOrientation
);
}
}
if
(
mRotating
)
if
(
mRotating
)
{
{
...
@@ -434,6 +663,8 @@ void UBGraphicsTriangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
...
@@ -434,6 +663,8 @@ void UBGraphicsTriangle::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
{
if
(
mResizing1
||
mResizing2
||
mRotating
)
if
(
mResizing1
||
mResizing2
||
mRotating
)
{
{
if
(
mRotating
)
updateResizeCursor
();
mResizing1
=
false
;
mResizing1
=
false
;
mResizing2
=
false
;
mResizing2
=
false
;
mRotating
=
false
;
mRotating
=
false
;
...
@@ -505,9 +736,10 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
...
@@ -505,9 +736,10 @@ void UBGraphicsTriangle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
mVFlipSvgItem
->
setVisible
(
true
);
mVFlipSvgItem
->
setVisible
(
true
);
mRotateSvgItem
->
setVisible
(
true
);
mRotateSvgItem
->
setVisible
(
true
);
if
(
resize1Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
)
||
if
(
resize1Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
resize2Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
setCursor
(
resizeCursor1
());
setCursor
(
moveResizeCursor
());
else
if
(
resize2Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
setCursor
(
resizeCursor2
());
else
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
else
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
setCursor
(
closeCursor
());
else
if
(
hFlipRect
().
contains
(
event
->
pos
())
else
if
(
hFlipRect
().
contains
(
event
->
pos
())
...
@@ -546,9 +778,10 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
...
@@ -546,9 +778,10 @@ void UBGraphicsTriangle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
mHFlipSvgItem
->
setVisible
(
mShowButtons
);
mHFlipSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
mRotateSvgItem
->
setVisible
(
mShowButtons
);
if
(
resize1Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
)
||
if
(
resize1Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
resize2Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
setCursor
(
resizeCursor1
());
setCursor
(
moveResizeCursor
());
else
if
(
resize2Polygon
().
containsPoint
(
event
->
pos
().
toPoint
(),
Qt
::
OddEvenFill
))
setCursor
(
resizeCursor2
());
else
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
else
if
(
closeButtonRect
().
contains
(
event
->
pos
()))
setCursor
(
closeCursor
());
setCursor
(
closeCursor
());
else
if
(
hFlipRect
().
contains
(
event
->
pos
())
else
if
(
hFlipRect
().
contains
(
event
->
pos
())
...
...
src/tools/UBGraphicsTriangle.h
View file @
2491e7e3
...
@@ -67,6 +67,8 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
...
@@ -67,6 +67,8 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
protected
:
protected
:
void
updateResizeCursor
();
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
void
rotateAroundCenter
(
qreal
angle
);
virtual
void
rotateAroundCenter
(
qreal
angle
);
...
@@ -80,7 +82,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
...
@@ -80,7 +82,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
QRectF
vFlipRect
()
const
;
QRectF
vFlipRect
()
const
;
QRectF
rotateRect
()
const
;
QRectF
rotateRect
()
const
;
QCursor
moveResizeCursor
()
const
;
QCursor
resizeCursor1
()
const
;
QCursor
resizeCursor2
()
const
;
QCursor
flipCursor
()
const
;
QCursor
flipCursor
()
const
;
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
...
@@ -92,6 +96,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
...
@@ -92,6 +96,9 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
private
:
private
:
QCursor
mResizeCursor1
;
QCursor
mResizeCursor2
;
QTransform
calculateRotationTransform
();
QTransform
calculateRotationTransform
();
qreal
angle
;
qreal
angle
;
void
rotateAroundCenter
(
QTransform
&
transform
,
QPointF
center
);
void
rotateAroundCenter
(
QTransform
&
transform
,
QPointF
center
);
...
@@ -112,9 +119,15 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
...
@@ -112,9 +119,15 @@ class UBGraphicsTriangle : public UBAbstractDrawRuler, public QGraphicsPolygonIt
UBGraphicsTriangleOrientation
mOrientation
;
UBGraphicsTriangleOrientation
mOrientation
;
QPointF
A1
,
B1
,
C1
,
A2
,
B2
,
C2
;
// coordinates of points in ext and int triangles
qreal
C
;
qreal
W1
,
H1
;
// Neccessary for filling
QPointF
CC
;
// Hyp. fillining gradient - top point
void
calculatePoints
(
const
QRectF
&
rect
);
static
const
int
d
=
70
;
// width of triangle border
static
const
int
d
=
70
;
// width of triangle border
static
const
int
sArrowLength
=
30
;
static
const
int
sArrowLength
=
30
;
static
const
int
sMinWidth
=
20
0
;
static
const
int
sMinWidth
=
38
0
;
static
const
int
sMinHeight
=
200
;
static
const
int
sMinHeight
=
200
;
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment