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
92b664b3
Commit
92b664b3
authored
Jun 30, 2011
by
Claudio Valerio
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:Sankore/Sankore-3.1
parents
30b87f02
2b856c4c
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
755 additions
and
396 deletions
+755
-396
UBSvgSubsetAdaptor.cpp
src/adaptors/UBSvgSubsetAdaptor.cpp
+50
-0
UBSvgSubsetAdaptor.h
src/adaptors/UBSvgSubsetAdaptor.h
+3
-0
main.cpp
src/core/main.cpp
+5
-0
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+5
-5
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+1
-0
UBCoreGraphicsScene.cpp
src/frameworks/UBCoreGraphicsScene.cpp
+0
-1
UBAbstractDrawRuler.cpp
src/tools/UBAbstractDrawRuler.cpp
+126
-0
UBAbstractDrawRuler.h
src/tools/UBAbstractDrawRuler.h
+58
-4
UBGraphicsProtractor.cpp
src/tools/UBGraphicsProtractor.cpp
+51
-69
UBGraphicsProtractor.h
src/tools/UBGraphicsProtractor.h
+11
-19
UBGraphicsRuler.cpp
src/tools/UBGraphicsRuler.cpp
+146
-246
UBGraphicsRuler.h
src/tools/UBGraphicsRuler.h
+17
-50
UBGraphicsTriangle.cpp
src/tools/UBGraphicsTriangle.cpp
+223
-1
UBGraphicsTriangle.h
src/tools/UBGraphicsTriangle.h
+59
-1
No files found.
src/adaptors/UBSvgSubsetAdaptor.cpp
View file @
92b664b3
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
#include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsCompass.h"
#include "tools/UBGraphicsProtractor.h"
#include "tools/UBGraphicsProtractor.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsCurtainItem.h"
#include "tools/UBGraphicsTriangle.h"
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentProxy.h"
...
@@ -644,6 +645,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
...
@@ -644,6 +645,16 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene()
scene
->
addItem
(
protractor
);
scene
->
addItem
(
protractor
);
scene
->
registerTool
(
protractor
);
scene
->
registerTool
(
protractor
);
}
}
}
else
if
(
mXmlReader
.
name
()
==
"protractor"
)
{
UBGraphicsTriangle
*
triangle
=
triangleFromSvg
();
if
(
triangle
)
{
scene
->
addItem
(
triangle
);
scene
->
registerTool
(
triangle
);
}
}
}
else
if
(
mXmlReader
.
name
()
==
"foreignObject"
)
else
if
(
mXmlReader
.
name
()
==
"foreignObject"
)
{
{
...
@@ -2556,7 +2567,46 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg()
...
@@ -2556,7 +2567,46 @@ UBGraphicsProtractor* UBSvgSubsetAdaptor::UBSvgSubsetReader::protractorFromSvg()
return
protractor
;
return
protractor
;
}
}
UBGraphicsTriangle
*
UBSvgSubsetAdaptor
::
UBSvgSubsetReader
::
triangleFromSvg
()
{
UBGraphicsTriangle
*
triangle
=
new
UBGraphicsTriangle
();
triangle
->
setZValue
(
UBGraphicsScene
::
toolLayerStart
+
UBGraphicsScene
::
toolOffsetTriangle
);
triangle
->
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Tool
));
graphicsItemFromSvg
(
triangle
);
//QStringRef angle = mXmlReader.attributes().value(mNamespaceUri, "angle");
//if (!angle.isNull())
//{
// protractor->setAngle(angle.toString().toFloat());
//}
//QStringRef markerAngle = mXmlReader.attributes().value(mNamespaceUri, "marker-angle");
//if (!markerAngle.isNull())
//{
// protractor->setMarkerAngle(markerAngle.toString().toFloat());
//}
QStringRef
svgX
=
mXmlReader
.
attributes
().
value
(
"x"
);
QStringRef
svgY
=
mXmlReader
.
attributes
().
value
(
"y"
);
QStringRef
svgWidth
=
mXmlReader
.
attributes
().
value
(
"width"
);
QStringRef
svgHeight
=
mXmlReader
.
attributes
().
value
(
"height"
);
UBGraphicsTriangle
::
UBGraphicsTriangleOrientation
orientation
=
UBGraphicsTriangle
::
orientationFromStr
((
mXmlReader
.
attributes
().
value
(
"orientation"
)));
if
(
!
svgX
.
isNull
()
&&
!
svgY
.
isNull
()
&&
!
svgWidth
.
isNull
()
&&
!
svgHeight
.
isNull
())
{
triangle
->
setRect
(
svgX
.
toString
().
toFloat
(),
svgY
.
toString
().
toFloat
()
,
svgWidth
.
toString
().
toFloat
(),
svgHeight
.
toString
().
toFloat
(),
orientation
);
}
triangle
->
setVisible
(
true
);
return
triangle
;
}
void
UBSvgSubsetAdaptor
::
convertPDFObjectsToImages
(
UBDocumentProxy
*
proxy
)
void
UBSvgSubsetAdaptor
::
convertPDFObjectsToImages
(
UBDocumentProxy
*
proxy
)
{
{
...
...
src/adaptors/UBSvgSubsetAdaptor.h
View file @
92b664b3
...
@@ -31,6 +31,7 @@ class UBGraphicsScene;
...
@@ -31,6 +31,7 @@ class UBGraphicsScene;
class
UBDocumentProxy
;
class
UBDocumentProxy
;
class
UBGraphicsStroke
;
class
UBGraphicsStroke
;
class
UBPersistenceManager
;
class
UBPersistenceManager
;
class
UBGraphicsTriangle
;
class
UBSvgSubsetAdaptor
class
UBSvgSubsetAdaptor
{
{
...
@@ -118,6 +119,8 @@ class UBSvgSubsetAdaptor
...
@@ -118,6 +119,8 @@ class UBSvgSubsetAdaptor
UBGraphicsProtractor
*
protractorFromSvg
();
UBGraphicsProtractor
*
protractorFromSvg
();
UBGraphicsTriangle
*
triangleFromSvg
();
void
graphicsItemFromSvg
(
QGraphicsItem
*
gItem
);
void
graphicsItemFromSvg
(
QGraphicsItem
*
gItem
);
QXmlStreamReader
mXmlReader
;
QXmlStreamReader
mXmlReader
;
...
...
src/core/main.cpp
View file @
92b664b3
...
@@ -54,9 +54,14 @@ void ub_message_output(QtMsgType type, const char *msg) {
...
@@ -54,9 +54,14 @@ void ub_message_output(QtMsgType type, const char *msg) {
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
// Uncomment next section to have memory leaks information
// tracing in VC++ debug mode under Windows
/*
#if defined(_MSC_VER) && defined(_DEBUG)
#if defined(_MSC_VER) && defined(_DEBUG)
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
#endif
*/
Q_INIT_RESOURCE
(
sankore
);
Q_INIT_RESOURCE
(
sankore
);
...
...
src/domain/UBGraphicsScene.cpp
View file @
92b664b3
...
@@ -57,6 +57,7 @@ qreal UBGraphicsScene::toolLayerStart = 10000000.0;
...
@@ -57,6 +57,7 @@ qreal UBGraphicsScene::toolLayerStart = 10000000.0;
qreal
UBGraphicsScene
::
toolOffsetRuler
=
100
;
qreal
UBGraphicsScene
::
toolOffsetRuler
=
100
;
qreal
UBGraphicsScene
::
toolOffsetProtractor
=
100
;
qreal
UBGraphicsScene
::
toolOffsetProtractor
=
100
;
qreal
UBGraphicsScene
::
toolOffsetTriangle
=
100
;
qreal
UBGraphicsScene
::
toolOffsetCompass
=
100
;
qreal
UBGraphicsScene
::
toolOffsetCompass
=
100
;
qreal
UBGraphicsScene
::
toolOffsetEraser
=
200
;
qreal
UBGraphicsScene
::
toolOffsetEraser
=
200
;
...
@@ -126,7 +127,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
...
@@ -126,7 +127,6 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent)
UBGraphicsScene
::~
UBGraphicsScene
()
UBGraphicsScene
::~
UBGraphicsScene
()
{
{
int
a
=
13
;
// NOOP
// NOOP
}
}
...
@@ -1412,9 +1412,9 @@ void UBGraphicsScene::addProtractor(QPointF center)
...
@@ -1412,9 +1412,9 @@ void UBGraphicsScene::addProtractor(QPointF center)
void
UBGraphicsScene
::
addTriangle
(
QPointF
center
)
void
UBGraphicsScene
::
addTriangle
(
QPointF
center
)
{
{
//
Protractor
//
Triangle
/*
UBGraphicsTriangle*
protractor
= new UBGraphicsTriangle(); // mem : owned and destroyed by the scene
UBGraphicsTriangle
*
triangle
=
new
UBGraphicsTriangle
();
// mem : owned and destroyed by the scene
mTools
<<
triangle
;
mTools
<<
triangle
;
triangle
->
setZValue
(
toolLayerStart
+
toolOffsetProtractor
);
triangle
->
setZValue
(
toolLayerStart
+
toolOffsetProtractor
);
...
@@ -1426,7 +1426,7 @@ void UBGraphicsScene::addTriangle(QPointF center)
...
@@ -1426,7 +1426,7 @@ void UBGraphicsScene::addTriangle(QPointF center)
triangle
->
moveBy
(
center
.
x
()
-
itemSceneCenter
.
x
(),
center
.
y
()
-
itemSceneCenter
.
y
());
triangle
->
moveBy
(
center
.
x
()
-
itemSceneCenter
.
x
(),
center
.
y
()
-
itemSceneCenter
.
y
());
triangle
->
setVisible
(
true
);
triangle
->
setVisible
(
true
);
setModified(true);
*/
setModified
(
true
);
}
}
...
...
src/domain/UBGraphicsScene.h
View file @
92b664b3
...
@@ -235,6 +235,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
...
@@ -235,6 +235,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
static
qreal
toolOffsetProtractor
;
static
qreal
toolOffsetProtractor
;
static
qreal
toolOffsetCompass
;
static
qreal
toolOffsetCompass
;
static
qreal
toolOffsetCurtain
;
static
qreal
toolOffsetCurtain
;
static
qreal
toolOffsetTriangle
;
QSet
<
QGraphicsItem
*>
tools
(){
return
mTools
;}
QSet
<
QGraphicsItem
*>
tools
(){
return
mTools
;}
...
...
src/frameworks/UBCoreGraphicsScene.cpp
View file @
92b664b3
...
@@ -12,7 +12,6 @@
...
@@ -12,7 +12,6 @@
UBCoreGraphicsScene
::
UBCoreGraphicsScene
(
QObject
*
parent
)
UBCoreGraphicsScene
::
UBCoreGraphicsScene
(
QObject
*
parent
)
:
QGraphicsScene
(
parent
)
:
QGraphicsScene
(
parent
)
{
{
int
a
=
13
;
//NOOP
//NOOP
}
}
...
...
src/tools/UBAbstractDrawRuler.cpp
View file @
92b664b3
#include "UBAbstractDrawRuler.h"
#include "UBAbstractDrawRuler.h"
#include <QtSvg>
#include "core/UB.h"
#include "gui/UBResources.h"
#include "domain/UBGraphicsScene.h"
#include "board/UBDrawingController.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "core/memcheck.h"
#include "core/memcheck.h"
const
QColor
UBAbstractDrawRuler
::
sLightBackgroundMiddleFillColor
=
QColor
(
0x72
,
0x72
,
0x72
,
sFillTransparency
);
const
QColor
UBAbstractDrawRuler
::
sLightBackgroundEdgeFillColor
=
QColor
(
0xc3
,
0xc3
,
0xc3
,
sFillTransparency
);
const
QColor
UBAbstractDrawRuler
::
sLightBackgroundDrawColor
=
QColor
(
0x33
,
0x33
,
0x33
,
sDrawTransparency
);
const
QColor
UBAbstractDrawRuler
::
sDarkBackgroundMiddleFillColor
=
QColor
(
0xb5
,
0xb5
,
0xb5
,
sFillTransparency
);
const
QColor
UBAbstractDrawRuler
::
sDarkBackgroundEdgeFillColor
=
QColor
(
0xdd
,
0xdd
,
0xdd
,
sFillTransparency
);
const
QColor
UBAbstractDrawRuler
::
sDarkBackgroundDrawColor
=
QColor
(
0xff
,
0xff
,
0xff
,
sDrawTransparency
);
UBAbstractDrawRuler
::
UBAbstractDrawRuler
()
UBAbstractDrawRuler
::
UBAbstractDrawRuler
()
:
mResizing
(
false
)
,
mRotating
(
false
)
,
mShowButtons
(
false
)
,
mAntiScaleRatio
(
1.0
)
{}
{}
void
UBAbstractDrawRuler
::
create
(
QGraphicsItem
&
item
)
{
item
.
setFlag
(
QGraphicsItem
::
ItemIsMovable
,
true
);
item
.
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
item
.
setFlag
(
QGraphicsItem
::
ItemSendsGeometryChanges
,
true
);
item
.
setAcceptsHoverEvents
(
true
);
mCloseSvgItem
=
new
QGraphicsSvgItem
(
":/images/closeTool.svg"
,
&
item
);
mCloseSvgItem
->
setVisible
(
false
);
mCloseSvgItem
->
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
mRotateSvgItem
=
new
QGraphicsSvgItem
(
":/images/rotateTool.svg"
,
&
item
);
mRotateSvgItem
->
setVisible
(
false
);
mRotateSvgItem
->
setData
(
UBGraphicsItemData
::
ItemLayerType
,
QVariant
(
UBItemLayerType
::
Control
));
updateResizeCursor
(
item
);
}
UBAbstractDrawRuler
::~
UBAbstractDrawRuler
()
UBAbstractDrawRuler
::~
UBAbstractDrawRuler
()
{
}
void
UBAbstractDrawRuler
::
updateResizeCursor
(
QGraphicsItem
&
item
)
{
QPixmap
pix
(
":/images/cursors/resize.png"
);
QTransform
itemTransform
=
item
.
sceneTransform
();
QRectF
itemRect
=
item
.
boundingRect
();
QPointF
topLeft
=
itemTransform
.
map
(
itemRect
.
topLeft
());
QPointF
topRight
=
itemTransform
.
map
(
itemRect
.
topRight
());
QLineF
topLine
(
topLeft
,
topRight
);
qreal
angle
=
topLine
.
angle
();
QTransform
tr
;
tr
.
rotate
(
-
angle
);
QCursor
resizeCursor
=
QCursor
(
pix
.
transformed
(
tr
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
mResizeCursor
=
resizeCursor
;
}
QCursor
UBAbstractDrawRuler
::
moveCursor
()
const
{
return
Qt
::
SizeAllCursor
;
}
QCursor
UBAbstractDrawRuler
::
resizeCursor
()
const
{
return
mResizeCursor
;
}
QCursor
UBAbstractDrawRuler
::
rotateCursor
()
const
{
return
UBResources
::
resources
()
->
rotateCursor
;
}
QCursor
UBAbstractDrawRuler
::
closeCursor
()
const
{
return
Qt
::
ArrowCursor
;
}
QCursor
UBAbstractDrawRuler
::
drawRulerLineCursor
()
const
{
return
UBResources
::
resources
()
->
drawLineRulerCursor
;
}
QColor
UBAbstractDrawRuler
::
drawColor
()
const
{
return
scene
()
->
isDarkBackground
()
?
sDarkBackgroundDrawColor
:
sLightBackgroundDrawColor
;
}
QColor
UBAbstractDrawRuler
::
middleFillColor
()
const
{
return
scene
()
->
isDarkBackground
()
?
sDarkBackgroundMiddleFillColor
:
sLightBackgroundMiddleFillColor
;
}
QColor
UBAbstractDrawRuler
::
edgeFillColor
()
const
{
return
scene
()
->
isDarkBackground
()
?
sDarkBackgroundEdgeFillColor
:
sLightBackgroundEdgeFillColor
;
}
QFont
UBAbstractDrawRuler
::
font
()
const
{
QFont
font
(
"Arial"
);
font
.
setPixelSize
(
16
);
return
font
;
}
void
UBAbstractDrawRuler
::
StartLine
(
const
QPointF
&
position
,
qreal
width
)
{}
void
UBAbstractDrawRuler
::
DrawLine
(
const
QPointF
&
position
,
qreal
width
)
{}
void
UBAbstractDrawRuler
::
EndLine
()
{}
{}
void
UBAbstractDrawRuler
::
paint
()
{
mAntiScaleRatio
=
1
/
(
UBApplication
::
boardController
->
systemScaleFactor
()
*
UBApplication
::
boardController
->
currentZoom
());
QTransform
antiScaleTransform
;
antiScaleTransform
.
scale
(
mAntiScaleRatio
,
mAntiScaleRatio
);
mCloseSvgItem
->
setTransform
(
antiScaleTransform
);
mCloseSvgItem
->
setPos
(
closeButtonRect
().
topLeft
());
mRotateSvgItem
->
setTransform
(
antiScaleTransform
);
mRotateSvgItem
->
setPos
(
rotateButtonRect
().
topLeft
());
}
src/tools/UBAbstractDrawRuler.h
View file @
92b664b3
...
@@ -3,18 +3,72 @@
...
@@ -3,18 +3,72 @@
#include <QtGui>
#include <QtGui>
class
UBGraphicsScene
;
class
UBGraphicsScene
;
class
QGraphicsSvgItem
;
class
UBAbstractDrawRuler
:
public
QObject
class
UBAbstractDrawRuler
:
public
QObject
{
{
Q_OBJECT
;
Q_OBJECT
public
:
public
:
UBAbstractDrawRuler
();
UBAbstractDrawRuler
();
~
UBAbstractDrawRuler
();
~
UBAbstractDrawRuler
();
virtual
void
StartLine
(
const
QPointF
&
position
,
qreal
width
)
=
0
;
void
create
(
QGraphicsItem
&
item
);
virtual
void
DrawLine
(
const
QPointF
&
position
,
qreal
width
)
=
0
;
virtual
void
EndLine
()
=
0
;
virtual
void
StartLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
DrawLine
(
const
QPointF
&
position
,
qreal
width
);
virtual
void
EndLine
();
protected
:
void
paint
();
virtual
UBGraphicsScene
*
scene
()
const
=
0
;
virtual
void
rotateAroundTopLeftOrigin
(
qreal
angle
)
=
0
;
virtual
QPointF
topLeftOrigin
()
const
=
0
;
virtual
QRectF
resizeButtonRect
()
const
=
0
;
virtual
QRectF
closeButtonRect
()
const
=
0
;
virtual
QRectF
rotateButtonRect
()
const
=
0
;
void
updateResizeCursor
(
QGraphicsItem
&
item
);
bool
mResizing
;
bool
mRotating
;
bool
mShowButtons
;
QGraphicsSvgItem
*
mCloseSvgItem
;
QGraphicsSvgItem
*
mRotateSvgItem
;
QCursor
mResizeCursor
;
qreal
mAntiScaleRatio
;
QPointF
startDrawPosition
;
QCursor
moveCursor
()
const
;
QCursor
resizeCursor
()
const
;
QCursor
rotateCursor
()
const
;
QCursor
closeCursor
()
const
;
QCursor
drawRulerLineCursor
()
const
;
QColor
drawColor
()
const
;
QColor
middleFillColor
()
const
;
QColor
edgeFillColor
()
const
;
QFont
font
()
const
;
static
const
QColor
sLightBackgroundEdgeFillColor
;
static
const
QColor
sLightBackgroundMiddleFillColor
;
static
const
QColor
sLightBackgroundDrawColor
;
static
const
QColor
sDarkBackgroundEdgeFillColor
;
static
const
QColor
sDarkBackgroundMiddleFillColor
;
static
const
QColor
sDarkBackgroundDrawColor
;
static
const
int
sLeftEdgeMargin
=
10
;
static
const
int
sMinLength
=
150
;
static
const
int
sDegreeToQtAngleUnit
=
16
;
static
const
int
sRotationRadius
=
15
;
static
const
int
sPixelsPerMillimeter
=
5
;
static
const
int
sFillTransparency
=
127
;
static
const
int
sDrawTransparency
=
192
;
static
const
int
sRoundingRadius
=
sLeftEdgeMargin
/
2
;
};
};
...
...
src/tools/UBGraphicsProtractor.cpp
View file @
92b664b3
This diff is collapsed.
Click to expand it.
src/tools/UBGraphicsProtractor.h
View file @
92b664b3
...
@@ -13,12 +13,12 @@
...
@@ -13,12 +13,12 @@
#include <QtSvg>
#include <QtSvg>
#include "core/UB.h"
#include "core/UB.h"
#include "tools/UBAbstractDrawRuler.h"
#include "domain/UBItem.h"
#include "domain/UBItem.h"
class
UBGraphicsScene
;
class
UBGraphicsScene
;
class
UBGraphicsProtractor
:
public
QObject
,
public
QGraphicsEllipseItem
,
public
UBItem
class
UBGraphicsProtractor
:
public
UBAbstractDrawRuler
,
public
QGraphicsEllipseItem
,
public
UBItem
{
{
Q_OBJECT
;
Q_OBJECT
;
...
@@ -66,16 +66,15 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
...
@@ -66,16 +66,15 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
Tool
toolFromPos
(
QPointF
pos
);
Tool
toolFromPos
(
QPointF
pos
);
qreal
antiScale
()
const
;
qreal
antiScale
()
const
;
UBGraphicsScene
*
scene
()
const
;
UBGraphicsScene
*
scene
()
const
;
QColor
drawColor
()
const
;
QBrush
fillBrush
()
const
;
QBrush
fillBrush
()
const
;
QSizeF
buttonSizeReference
()
const
{
return
QSizeF
(
radius
()
/
10
,
mCloseSvgItem
->
boundingRect
().
height
()
*
radius
()
/
(
10
*
mCloseSvgItem
->
boundingRect
().
width
()));}
QSizeF
buttonSizeReference
()
const
{
return
QSizeF
(
radius
()
/
10
,
mCloseSvgItem
->
boundingRect
().
height
()
*
radius
()
/
(
10
*
mCloseSvgItem
->
boundingRect
().
width
()));}
QSizeF
markerSizeReference
()
const
{
return
QSizeF
(
radius
()
/
10
,
mMarkerSvgItem
->
boundingRect
().
height
()
*
radius
()
/
(
10
*
mMarkerSvgItem
->
boundingRect
().
width
()));}
QSizeF
markerSizeReference
()
const
{
return
QSizeF
(
radius
()
/
10
,
mMarkerSvgItem
->
boundingRect
().
height
()
*
radius
()
/
(
10
*
mMarkerSvgItem
->
boundingRect
().
width
()));}
QRectF
resetButtonBounds
()
const
;
QRectF
resetButtonRect
()
const
;
QRectF
closeButtonBounds
()
const
;
QRectF
closeButtonRect
()
const
;
QRectF
resizeButton
Bounds
()
const
;
QRectF
resizeButton
Rect
()
const
;
QRectF
rotateButton
Bounds
()
const
{
return
QRectF
(
buttonSizeReference
().
width
()
*
5
.
5
,
-
buttonSizeReference
().
width
()
*
5
,
buttonSizeReference
().
width
(),
buttonSizeReference
().
width
());}
QRectF
rotateButton
Rect
()
const
{
return
QRectF
(
buttonSizeReference
().
width
()
*
5
.
5
,
-
buttonSizeReference
().
width
()
*
5
,
buttonSizeReference
().
width
(),
buttonSizeReference
().
width
());}
QRectF
markerButton
Bounds
()
const
{
return
QRectF
(
radius
()
+
3
,
-
markerSizeReference
().
height
()
/
2
,
markerSizeReference
().
width
(),
markerSizeReference
().
height
());}
QRectF
markerButton
Rect
()
const
{
return
QRectF
(
radius
()
+
3
,
-
markerSizeReference
().
height
()
/
2
,
markerSizeReference
().
width
(),
markerSizeReference
().
height
());}
inline
qreal
radius
()
const
{
return
rect
().
height
()
/
2
-
20
;}
inline
qreal
radius
()
const
{
return
rect
().
height
()
/
2
-
20
;}
// Members
// Members
...
@@ -87,21 +86,14 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
...
@@ -87,21 +86,14 @@ class UBGraphicsProtractor : public QObject, public QGraphicsEllipseItem, public
qreal
mStartAngle
;
qreal
mStartAngle
;
qreal
mScaleFactor
;
qreal
mScaleFactor
;
QGraphicsSvgItem
*
mCloseSvgItem
;
QGraphicsSvgItem
*
mResetSvgItem
;
QGraphicsSvgItem
*
mResetSvgItem
;
QGraphicsSvgItem
*
mResizeSvgItem
;
QGraphicsSvgItem
*
mResizeSvgItem
;
QGraphicsSvgItem
*
mRotateSvgItem
;
QGraphicsSvgItem
*
mMarkerSvgItem
;
QGraphicsSvgItem
*
mMarkerSvgItem
;
static
const
int
sFillTransparency
;
static
const
QRectF
sDefaultRect
;
static
const
int
sDrawTransparency
;
static
const
QRectF
sDefaultRect
;
virtual
void
rotateAroundTopLeftOrigin
(
qreal
angle
);
static
const
QColor
sFillColor
;
virtual
QPointF
topLeftOrigin
()
const
;
static
const
QColor
sFillColorCenter
;
static
const
QColor
sDrawColor
;
static
const
QColor
sDarkBackgroundFillColor
;
static
const
QColor
sDarkBackgroundFillColorCenter
;
static
const
QColor
sDarkBackgroundDrawColor
;
};
};
#endif
/* UBGRAPHICSPROTRACTOR_H_ */
#endif
/* UBGRAPHICSPROTRACTOR_H_ */
src/tools/UBGraphicsRuler.cpp
View file @
92b664b3
This diff is collapsed.
Click to expand it.
src/tools/UBGraphicsRuler.h
View file @
92b664b3
...
@@ -44,70 +44,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
...
@@ -44,70 +44,37 @@ class UBGraphicsRuler : public UBAbstractDrawRuler, public QGraphicsRectItem, pu
void
hidden
();
void
hidden
();
protected
:
protected
:
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
QVariant
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
);
virtual
QVariant
itemChange
(
GraphicsItemChange
change
,
const
QVariant
&
value
);
// Events
// Events
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
);
virtual
void
hoverMoveEvent
(
QGraphicsSceneHoverEvent
*
event
);
private
:
private
:
// Helpers
// Helpers
void
fillBackground
(
QPainter
*
painter
);
void
fillBackground
(
QPainter
*
painter
);
void
paintGraduations
(
QPainter
*
painter
);
void
paintGraduations
(
QPainter
*
painter
);
void
paintRotationCenter
(
QPainter
*
painter
);
void
paintRotationCenter
(
QPainter
*
painter
);
void
rotateAroundTopLeftOrigin
(
qreal
angle
);
virtual
void
rotateAroundTopLeftOrigin
(
qreal
angle
);
void
updateResizeCursor
();
QPointF
topLeftOrigin
()
const
;
QCursor
moveCursor
()
const
;
QCursor
resizeCursor
()
const
;
QCursor
rotateCursor
()
const
;
QCursor
closeCursor
()
const
;
QCursor
drawRulerLineCursor
()
const
;
QRectF
resizeButtonRect
()
const
;
QRectF
closeButtonRect
()
const
;
QRectF
rotateButtonRect
()
const
;
UBGraphicsScene
*
scene
()
const
;
QColor
drawColor
()
const
;
QColor
middleFillColor
()
const
;
QColor
edgeFillColor
()
const
;
QFont
font
()
const
;
int
drawLineDirection
;
QGraphicsSvgItem
*
mResizeSvgItem
;
// Members
virtual
QPointF
topLeftOrigin
()
const
;
bool
mResizing
;
virtual
QRectF
resizeButtonRect
()
const
;
bool
mRotating
;
virtual
QRectF
closeButtonRect
()
const
;
bool
mShowButtons
;
virtual
QRectF
rotateButtonRect
()
const
;
QGraphicsSvgItem
*
mCloseSvgItem
;
virtual
UBGraphicsScene
*
scene
()
const
;
QGraphicsSvgItem
*
mRotateSvgItem
;
QGraphicsSvgItem
*
mResizeSvgItem
;
QCursor
mResizeCursor
;
qreal
mAntiScaleRatio
;
QPointF
startDrawPosi
tion
;
int
drawLineDirec
tion
;
// Constants
// Constants
static
const
QRect
sDefaultRect
;
static
const
QRect
sDefaultRect
;
static
const
int
sLeftEdgeMargin
=
10
;
static
const
int
sMinLength
=
150
;
static
const
int
sDegreeToQtAngleUnit
=
16
;
static
const
int
sRotationRadius
=
15
;
static
const
int
sPixelsPerMillimeter
=
5
;
static
const
int
sFillTransparency
=
127
;
static
const
int
sDrawTransparency
=
192
;
static
const
int
sRoundingRadius
=
sLeftEdgeMargin
/
2
;
static
const
QColor
sLightBackgroundEdgeFillColor
;
static
const
QColor
sLightBackgroundMiddleFillColor
;
static
const
QColor
sLightBackgroundDrawColor
;
static
const
QColor
sDarkBackgroundEdgeFillColor
;
static
const
QColor
sDarkBackgroundMiddleFillColor
;
static
const
QColor
sDarkBackgroundDrawColor
;
};
};
#endif
/* UBGRAPHICSRULER_H_ */
#endif
/* UBGRAPHICSRULER_H_ */
src/tools/UBGraphicsTriangle.cpp
View file @
92b664b3
#include <QGraphicsPolygonItem>
#include <QPolygonF>
#include "tools/UBGraphicsTriangle.h"
#include "tools/UBGraphicsTriangle.h"
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBDrawingController.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h"
#include "core/memcheck.h"
const
QRect
UBGraphicsTriangle
::
sDefaultRect
=
QRect
(
0
,
0
,
800
,
400
);
const
UBGraphicsTriangle
::
UBGraphicsTriangleOrientation
UBGraphicsTriangle
::
sDefaultOrientation
=
UBGraphicsTriangle
::
BottomLeft
;
UBGraphicsTriangle
::
UBGraphicsTriangle
()
UBGraphicsTriangle
::
UBGraphicsTriangle
()
:
QGraphicsPolygonItem
()
{
{
setRect
(
sDefaultRect
,
sDefaultOrientation
);
create
(
*
this
);
//updateResizeCursor();
}
}
UBGraphicsTriangle
::~
UBGraphicsTriangle
()
UBGraphicsTriangle
::~
UBGraphicsTriangle
()
{}
{
\ No newline at end of file
}
UBItem
*
UBGraphicsTriangle
::
deepCopy
(
void
)
const
{
UBGraphicsTriangle
*
copy
=
new
UBGraphicsTriangle
();
copy
->
setPos
(
this
->
pos
());
copy
->
setPolygon
(
this
->
polygon
());
copy
->
setZValue
(
this
->
zValue
());
copy
->
setTransform
(
this
->
transform
());
// TODO UB 4.7 ... complete all members ?
return
copy
;
}
void
UBGraphicsTriangle
::
setRect
(
qreal
x
,
qreal
y
,
qreal
w
,
qreal
h
,
UBGraphicsTriangleOrientation
orientation
)
{
mRect
.
setCoords
(
x
,
y
,
x
+
w
,
y
+
h
);
mOrientation
=
orientation
;
QPolygonF
polygon
;
polygon
<<
QPointF
(
x
,
y
)
<<
QPoint
(
x
,
y
+
h
)
<<
QPoint
(
x
+
w
,
y
+
h
)
<<
QPoint
(
x
,
y
);
QTransform
t
;
switch
(
orientation
)
{
case
BottomLeft
:
t
.
setMatrix
(
1
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
1
);
break
;
case
BottomRight
:
t
.
setMatrix
(
-
1
,
0
,
0
,
0
,
1
,
0
,
x
,
0
,
1
);
break
;
case
TopLeft
:
t
.
setMatrix
(
1
,
0
,
0
,
0
,
-
1
,
0
,
0
,
y
,
1
);
break
;
case
TopRight
:
t
.
setMatrix
(
-
1
,
0
,
0
,
0
,
-
1
,
0
,
x
,
y
,
1
);
break
;
}
/*
switch(orientation)
{
case BottomLeft:
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x+w, y + h) << QPoint(x, y);
break;
case BottomRight:
polygon << QPointF(x, y + h) << QPoint(x + w, y + y) << QPoint(x + w, y) << QPoint(x, y + h);
break;
case TopLeft:
polygon << QPointF(x, y) << QPoint(x, y + h) << QPoint(x + w, y) << QPoint(x, y);
break;
case TopRight:
polygon << QPointF(x, y) << QPoint(x + w, y + h) << QPoint(x+w, y) << QPoint(x, y );
break;
}
*/
setPolygon
(
polygon
);
setTransform
(
t
);
}
UBGraphicsScene
*
UBGraphicsTriangle
::
scene
()
const
{
return
static_cast
<
UBGraphicsScene
*>
(
QGraphicsPolygonItem
::
scene
());
}
void
UBGraphicsTriangle
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
)
{
QPointF
A1
(
mRect
.
x
(),
mRect
.
y
());
QPointF
B1
(
mRect
.
x
(),
mRect
.
y
()
+
mRect
.
height
());
QPointF
C1
(
mRect
.
x
()
+
mRect
.
width
(),
mRect
.
y
()
+
mRect
.
height
());
qreal
d
=
70
;
qreal
C
=
sqrt
(
mRect
.
width
()
*
mRect
.
width
()
+
mRect
.
height
()
*
mRect
.
height
());
qreal
L
=
(
C
*
d
+
mRect
.
width
()
*
d
)
/
mRect
.
height
();
qreal
K
=
(
C
*
d
+
mRect
.
height
()
*
d
)
/
mRect
.
width
();
qreal
W1
=
mRect
.
height
()
*
d
/
C
;
qreal
H1
=
mRect
.
width
()
*
d
/
C
;
QPointF
A2
(
mRect
.
x
()
+
d
,
mRect
.
y
()
+
K
);
QPointF
B2
(
mRect
.
x
()
+
d
,
mRect
.
y
()
+
mRect
.
height
()
-
d
);
QPointF
C2
(
mRect
.
x
()
+
mRect
.
width
()
-
L
,
mRect
.
y
()
+
mRect
.
height
()
-
d
);
QPoint
CC
(
mRect
.
x
()
+
mRect
.
width
()
-
L
+
W1
,
mRect
.
y
()
+
mRect
.
height
()
-
d
-
H1
);
painter
->
setPen
(
Qt
::
NoPen
);
QPolygonF
polygon
;
QLinearGradient
gradient1
(
QPointF
(
A1
.
x
(),
0
),
QPointF
(
A2
.
x
(),
0
));
gradient1
.
setColorAt
(
0
,
edgeFillColor
());
gradient1
.
setColorAt
(
1
,
middleFillColor
());
painter
->
setBrush
(
gradient1
);
polygon
<<
A1
<<
A2
<<
B2
<<
B1
;
painter
->
drawPolygon
(
polygon
);
polygon
.
clear
();
QLinearGradient
gradient2
(
QPointF
(
0
,
B1
.
y
()),
QPointF
(
0
,
B2
.
y
()));
gradient2
.
setColorAt
(
0
,
edgeFillColor
());
gradient2
.
setColorAt
(
1
,
middleFillColor
());
painter
->
setBrush
(
gradient2
);
polygon
<<
B1
<<
B2
<<
C2
<<
C1
;
painter
->
drawPolygon
(
polygon
);
polygon
.
clear
();
QLinearGradient
gradient3
(
CC
,
C2
);
gradient3
.
setColorAt
(
0
,
edgeFillColor
());
gradient3
.
setColorAt
(
1
,
middleFillColor
());
painter
->
setBrush
(
gradient3
);
polygon
<<
C1
<<
C2
<<
A2
<<
A1
;
painter
->
drawPolygon
(
polygon
);
polygon
.
clear
();
painter
->
setBrush
(
Qt
::
NoBrush
);
painter
->
setPen
(
drawColor
());
polygon
<<
A1
<<
B1
<<
C1
;
painter
->
drawPolygon
(
polygon
);
polygon
.
clear
();
polygon
<<
A2
<<
B2
<<
C2
;
painter
->
drawPolygon
(
polygon
);
paintGraduations
(
painter
);
}
void
UBGraphicsTriangle
::
paintGraduations
(
QPainter
*
painter
)
{
const
int
centimeterGraduationHeight
=
15
;
const
int
halfCentimeterGraduationHeight
=
10
;
const
int
millimeterGraduationHeight
=
5
;
const
int
millimetersPerCentimeter
=
10
;
const
int
millimetersPerHalfCentimeter
=
5
;
painter
->
save
();
painter
->
setFont
(
font
());
QFontMetricsF
fontMetrics
(
painter
->
font
());
for
(
int
millimeters
=
0
;
millimeters
<
(
rect
().
width
()
-
sLeftEdgeMargin
-
sRoundingRadius
)
/
sPixelsPerMillimeter
;
millimeters
++
)
{
int
graduationX
=
topLeftOrigin
().
x
()
+
sPixelsPerMillimeter
*
millimeters
;
int
graduationHeight
=
(
0
==
millimeters
%
millimetersPerCentimeter
)
?
centimeterGraduationHeight
:
((
0
==
millimeters
%
millimetersPerHalfCentimeter
)
?
halfCentimeterGraduationHeight
:
millimeterGraduationHeight
);
// Check that grad. line inside triangle
qreal
lineY
=
rect
().
bottom
()
-
rect
().
height
()
/
rect
().
width
()
*
(
rect
().
width
()
-
graduationX
);
if
(
lineY
>=
topLeftOrigin
().
y
()
+
rect
().
height
()
-
graduationHeight
)
break
;
painter
->
drawLine
(
QLine
(
graduationX
,
topLeftOrigin
().
y
()
+
rect
().
height
(),
graduationX
,
topLeftOrigin
().
y
()
+
rect
().
height
()
-
graduationHeight
));
if
(
0
==
millimeters
%
millimetersPerCentimeter
)
{
QString
text
=
QString
(
"%1"
).
arg
((
int
)(
millimeters
/
millimetersPerCentimeter
));
int
textXRight
=
graduationX
+
fontMetrics
.
width
(
text
)
/
2
;
qreal
textWidth
=
fontMetrics
.
width
(
text
);
qreal
textHeight
=
fontMetrics
.
tightBoundingRect
(
text
).
height
()
+
5
;
int
textY
=
rect
().
bottom
()
-
5
-
centimeterGraduationHeight
-
textHeight
;
lineY
=
rect
().
bottom
()
-
rect
().
height
()
/
rect
().
width
()
*
(
rect
().
width
()
-
textXRight
);
if
(
textXRight
<
rect
().
right
()
&&
lineY
<
textY
)
{
painter
->
drawText
(
QRectF
(
graduationX
-
textWidth
/
2
,
textY
,
textWidth
,
textHeight
),
Qt
::
AlignVCenter
,
text
);
}
}
}
painter
->
restore
();
}
void
UBGraphicsTriangle
::
rotateAroundTopLeftOrigin
(
qreal
angle
)
{}
QPointF
UBGraphicsTriangle
::
topLeftOrigin
()
const
{
return
QPointF
(
mRect
.
x
()
+
sLeftEdgeMargin
,
mRect
.
y
());
}
QRectF
UBGraphicsTriangle
::
resizeButtonRect
()
const
{
return
QRectF
(
0
,
0
,
0
,
0
);
}
QRectF
UBGraphicsTriangle
::
closeButtonRect
()
const
{
return
QRectF
(
0
,
0
,
0
,
0
);
}
QRectF
UBGraphicsTriangle
::
rotateButtonRect
()
const
{
return
QRectF
(
0
,
0
,
0
,
0
);
}
src/tools/UBGraphicsTriangle.h
View file @
92b664b3
...
@@ -15,17 +15,75 @@
...
@@ -15,17 +15,75 @@
#include "core/UB.h"
#include "core/UB.h"
#include "domain/UBItem.h"
#include "domain/UBItem.h"
#include "tools/UBAbstractDrawRuler.h"
class
UBGraphicsScene
;
class
UBGraphicsScene
;
class
UBItem
;
class
UBGraphicsTriangle
:
public
QObject
,
public
QGraphicsPolygonItem
,
public
UBItem
class
UBGraphicsTriangle
:
public
UBAbstractDrawRuler
,
public
QGraphicsPolygonItem
,
public
UBItem
{
{
Q_OBJECT
;
Q_OBJECT
;
public
:
public
:
UBGraphicsTriangle
();
UBGraphicsTriangle
();
virtual
~
UBGraphicsTriangle
();
virtual
~
UBGraphicsTriangle
();
enum
{
Type
=
UBGraphicsItemType
::
TriangleItemType
};
virtual
int
type
()
const
{
return
Type
;
}
virtual
UBItem
*
deepCopy
(
void
)
const
;
enum
UBGraphicsTriangleOrientation
{
BottomLeft
=
0
,
BottomRight
,
TopLeft
,
TopRight
};
static
UBGraphicsTriangleOrientation
orientationFromStr
(
QStringRef
&
str
)
{
if
(
str
==
"BottomLeft"
)
return
BottomLeft
;
if
(
str
==
"BottomRight"
)
return
BottomRight
;
if
(
str
==
"TopLeft"
)
return
TopLeft
;
if
(
str
==
"TopRight"
)
return
TopRight
;
return
sDefaultOrientation
;
}
void
setRect
(
const
QRectF
&
rect
,
UBGraphicsTriangleOrientation
orientation
)
{
setRect
(
rect
.
x
(),
rect
.
y
(),
rect
.
width
(),
rect
.
height
(),
orientation
);
}
void
setRect
(
qreal
x
,
qreal
y
,
qreal
w
,
qreal
h
,
UBGraphicsTriangleOrientation
orientation
);
QRectF
rect
()
const
{
return
mRect
;}
UBGraphicsScene
*
scene
()
const
;
protected
:
virtual
void
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
styleOption
,
QWidget
*
widget
);
virtual
void
rotateAroundTopLeftOrigin
(
qreal
angle
);
virtual
QPointF
topLeftOrigin
()
const
;
virtual
QRectF
resizeButtonRect
()
const
;
virtual
QRectF
closeButtonRect
()
const
;
virtual
QRectF
rotateButtonRect
()
const
;
private
:
static
const
QRect
sDefaultRect
;
static
const
UBGraphicsTriangleOrientation
sDefaultOrientation
;
void
paintGraduations
(
QPainter
*
painter
);
QRectF
mRect
;
UBGraphicsTriangleOrientation
mOrientation
;
};
};
#endif
/* UBGRAPHICSTRIANGLE_H_ */
#endif
/* UBGRAPHICSTRIANGLE_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