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
519c39c8
Commit
519c39c8
authored
Sep 21, 2012
by
Guillaume Burel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed, improved, cleaned and commented aristo tool.
parent
a74b7ca1
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
357 additions
and
312 deletions
+357
-312
UBGraphicsAristo.cpp
src/tools/UBGraphicsAristo.cpp
+230
-173
UBGraphicsAristo.h
src/tools/UBGraphicsAristo.h
+127
-139
No files found.
src/tools/UBGraphicsAristo.cpp
View file @
519c39c8
This diff is collapsed.
Click to expand it.
src/tools/UBGraphicsAristo.h
View file @
519c39c8
...
...
@@ -16,150 +16,138 @@
#ifndef UBGRAPHICSARISTO_H_
#define UBGRAPHICSARISTO_H_
#include <QtGui>
#include <QtSvg>
#include <QGraphicsPolygonItem>
#include "core/UB.h"
#include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class
UBGraphicsScene
;
class
UBItem
;
class
UBGraphicsAristo
:
public
UBAbstractDrawRuler
,
public
QGraphicsPolygonItem
,
public
UBItem
#include <QBrush>
#include <QCursor>
#include <QGraphicsPathItem>
#include <QGraphicsSceneHoverEvent>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSvgItem>
#include <QPainter>
#include <QPainterPath>
#include <QPointF>
#include <QRectF>
#include <QStyleOptionGraphicsItem>
#include <QTransform>
#include <QWidget>
class
UBGraphicsAristo
:
public
UBAbstractDrawRuler
,
public
QGraphicsPathItem
,
public
UBItem
{
Q_OBJECT
public
:
UBGraphicsAristo
();
virtual
~
UBGraphicsAristo
();
enum
{
Type
=
UBGraphicsItemType
::
AristoItemType
};
enum
Tool
{
None
,
Move
,
Resize
,
Rotate
,
Close
,
MoveMarker
,
HorizontalFlip
};
virtual
int
type
()
const
{
return
Type
;
}
virtual
UBItem
*
deepCopy
(
void
)
const
;
virtual
void
copyItemParameters
(
UBItem
*
copy
)
const
;
virtual
void
StartLine
(
const
QPointF
&
scenePos
,
qreal
width
);
virtual
void
DrawLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
EndLine
();
enum
UBGraphicsAristoOrientation
{
Bottom
=
0
,
Top
};
static
UBGraphicsAristoOrientation
orientationFromStr
(
QStringRef
&
str
)
{
if
(
str
==
"Bottom"
)
return
Bottom
;
if
(
str
==
"Top"
)
return
Top
;
return
sDefaultOrientation
;
}
static
QString
orientationToStr
(
UBGraphicsAristoOrientation
orientation
)
{
QString
result
;
if
(
orientation
==
0
)
result
=
"Bottom"
;
else
if
(
orientation
==
1
)
result
=
"Top"
;
return
result
;
}
void
setRect
(
const
QRectF
&
rect
,
UBGraphicsAristoOrientation
orientation
)
{
setRect
(
rect
.
x
(),
rect
.
y
(),
rect
.
width
(),
rect
.
height
(),
orientation
);
}
void
setRect
(
qreal
x
,
qreal
y
,
qreal
w
,
qreal
h
,
UBGraphicsAristoOrientation
orientation
);
void
setOrientation
(
UBGraphicsAristoOrientation
orientation
);
UBGraphicsAristoOrientation
getOrientation
()
const
{
return
mOrientation
;}
QRectF
rect
()
const
{
return
boundingRect
();}
UBGraphicsScene
*
scene
()
const
;
protected
:
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
QPainterPath
shape
()
const
;
virtual
void
rotateAroundCenter
(
qreal
angle
);
virtual
void
resize
(
qreal
factor
);
virtual
QPointF
rotationCenter
()
const
;
virtual
QRectF
closeButtonRect
()
const
;
QRectF
resizeButtonRect
()
const
;
QRectF
hFlipRect
()
const
;
QRectF
rotateRect
()
const
;
QRectF
markerButtonRect
()
const
;
QCursor
flipCursor
()
const
;
QCursor
resizeCursor
()
const
;
QCursor
markerCursor
()
const
;
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
);
private
:
UBGraphicsAristo
::
Tool
toolFromPos
(
QPointF
pos
);
QTransform
calculateRotationTransform
();
qreal
angle
;
void
rotateAroundCenter
(
QTransform
&
transform
,
QPointF
center
);
bool
mResizing
;
bool
mRotating
;
bool
mMarking
;
QRect
lastRect
;
qreal
mSpan
;
// Coordinates are transformed....
QPoint
lastPos
;
QGraphicsSvgItem
*
mHFlipSvgItem
;
QGraphicsSvgItem
*
mRotateSvgItem
;
QGraphicsSvgItem
*
mResizeSvgItem
;
QGraphicsSvgItem
*
mMarkerSvgItem
;
qreal
mStartAngle
;
qreal
mCurrentAngle
;
static
const
QRect
sDefaultRect
;
static
const
UBGraphicsAristoOrientation
sDefaultOrientation
;
void
paintGraduations
(
QPainter
*
painter
);
void
paintRulerGraduations
(
QPainter
*
painter
);
void
paintProtractorGraduations
(
QPainter
*
painter
);
void
paintMarker
(
QPainter
*
painter
);
inline
qreal
radius
()
const
{
return
sqrt
(((
B
.
x
()
-
A
.
x
())
*
(
B
.
x
()
-
A
.
x
()))
+
((
B
.
y
()
-
A
.
y
())
*
(
B
.
y
()
-
A
.
y
())))
*
9
/
16
-
20
;
}
QBrush
fillBrush
()
const
;
UBGraphicsAristoOrientation
mOrientation
;
void
calculatePoints
(
const
QRectF
&
rect
);
QPointF
A
,
B
,
C
;
static
const
int
d
=
70
;
// width of triangle border
static
const
int
sArrowLength
=
30
;
static
const
int
sMinWidth
=
380
;
static
const
int
sMinHeight
=
200
;
static
const
int
sArcAngleMargin
=
5
;
Q_OBJECT
public
:
UBGraphicsAristo
();
virtual
~
UBGraphicsAristo
();
enum
{
Type
=
UBGraphicsItemType
::
AristoItemType
};
enum
Tool
{
None
,
Move
,
Resize
,
Rotate
,
Close
,
MoveMarker
,
HorizontalFlip
};
enum
Orientation
{
Bottom
=
0
,
Top
,
Undefined
};
void
setOrientation
(
Orientation
orientation
);
void
setBoundingRect
(
QRectF
boundingRect
);
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
copyItemParameters
(
UBItem
*
copy
)
const
;
virtual
void
StartLine
(
const
QPointF
&
scenePos
,
qreal
width
);
virtual
void
DrawLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
EndLine
();
virtual
int
type
()
const
{
return
Type
;
}
UBGraphicsScene
*
scene
()
const
;
protected
:
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
void
rotateAroundCenter
(
qreal
angle
);
virtual
void
resize
(
qreal
factor
);
virtual
QPointF
rotationCenter
()
const
;
virtual
QRectF
closeButtonRect
()
const
;
QRectF
hFlipRect
()
const
;
QRectF
markerButtonRect
()
const
;
QRectF
resizeButtonRect
()
const
;
QRectF
rotateRect
()
const
;
QCursor
flipCursor
()
const
;
QCursor
markerCursor
()
const
;
QCursor
resizeCursor
()
const
;
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
);
private
:
Tool
toolFromPos
(
QPointF
pos
);
QTransform
calculateRotationTransform
();
void
rotateAroundCenter
(
QTransform
&
transform
,
QPointF
center
);
void
calculatePoints
();
QPainterPath
determinePath
();
void
setItemsPos
();
void
makeGeometryChange
();
QBrush
fillBrush
()
const
;
void
paintGraduations
(
QPainter
*
painter
);
void
paintMarker
(
QPainter
*
painter
);
void
paintProtractorGraduations
(
QPainter
*
painter
);
void
paintRulerGraduations
(
QPainter
*
painter
);
inline
qreal
radius
()
const
{
return
sqrt
(((
B
.
x
()
-
A
.
x
())
*
(
B
.
x
()
-
A
.
x
()))
+
((
B
.
y
()
-
A
.
y
())
*
(
B
.
y
()
-
A
.
y
())))
*
9
/
16
-
20
;
}
bool
mMarking
;
bool
mResizing
;
bool
mRotating
;
Orientation
mOrientation
;
qreal
mAngle
;
qreal
mCurrentAngle
;
qreal
mStartAngle
;
qreal
mSpan
;
QGraphicsSvgItem
*
mHFlipSvgItem
;
QGraphicsSvgItem
*
mMarkerSvgItem
;
QGraphicsSvgItem
*
mResizeSvgItem
;
QGraphicsSvgItem
*
mRotateSvgItem
;
QPointF
A
,
B
,
C
;
static
const
int
sArcAngleMargin
=
5
;
static
const
Orientation
sDefaultOrientation
;
static
const
QRectF
sDefaultRect
;
};
#endif
/* UBGRAPHICSARISTO_H_ */
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