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
9c8a49f8
Commit
9c8a49f8
authored
Mar 01, 2012
by
Anatoly Mihalchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SANKORE-459
parent
7f26289b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
501 additions
and
493 deletions
+501
-493
UBSvgSubsetAdaptor.h
src/adaptors/UBSvgSubsetAdaptor.h
+235
-225
UBGeometryUtils.cpp
src/frameworks/UBGeometryUtils.cpp
+224
-226
UBGeometryUtils.h
src/frameworks/UBGeometryUtils.h
+42
-42
No files found.
src/adaptors/UBSvgSubsetAdaptor.h
View file @
9c8a49f8
/*
/*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef UBSVGSUBSETADAPTOR_H_
#ifndef UBSVGSUBSETADAPTOR_H_
#define UBSVGSUBSETADAPTOR_H_
#define UBSVGSUBSETADAPTOR_H_
#include <QtGui>
#include <QtGui>
#include <QtXml>
#include <QtXml>
#include "frameworks/UBGeometryUtils.h"
#include "frameworks/UBGeometryUtils.h"
class
UBGraphicsSvgItem
;
class
UBGraphicsSvgItem
;
class
UBGraphicsPolygonItem
;
class
UBGraphicsPolygonItem
;
class
UBGraphicsPixmapItem
;
class
UBGraphicsPixmapItem
;
class
UBGraphicsPDFItem
;
class
UBGraphicsPDFItem
;
class
UBGraphicsWidgetItem
;
class
UBGraphicsWidgetItem
;
class
UBGraphicsVideoItem
;
class
UBGraphicsVideoItem
;
class
UBGraphicsAudioItem
;
class
UBGraphicsAudioItem
;
class
UBGraphicsAppleWidgetItem
;
class
UBGraphicsAppleWidgetItem
;
class
UBGraphicsW3CWidgetItem
;
class
UBGraphicsW3CWidgetItem
;
class
UBGraphicsTextItem
;
class
UBGraphicsTextItem
;
class
UBGraphicsCurtainItem
;
class
UBGraphicsCurtainItem
;
class
UBGraphicsRuler
;
class
UBGraphicsRuler
;
class
UBGraphicsCompass
;
class
UBGraphicsCompass
;
class
UBGraphicsProtractor
;
class
UBGraphicsProtractor
;
class
UBGraphicsScene
;
class
UBGraphicsScene
;
class
UBDocumentProxy
;
class
UBDocumentProxy
;
class
UBGraphicsStroke
;
class
UBGraphicsStroke
;
class
UBPersistenceManager
;
class
UBPersistenceManager
;
class
UBGraphicsTriangle
;
class
UBGraphicsTriangle
;
class
UBGraphicsCache
;
class
UBGraphicsCache
;
class
UBSvgSubsetAdaptor
class
UBSvgSubsetAdaptor
{
{
private
:
private
:
UBSvgSubsetAdaptor
()
{;}
UBSvgSubsetAdaptor
()
{;}
virtual
~
UBSvgSubsetAdaptor
()
{;}
virtual
~
UBSvgSubsetAdaptor
()
{;}
public
:
public
:
static
UBGraphicsScene
*
loadScene
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
UBGraphicsScene
*
loadScene
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
void
persistScene
(
UBDocumentProxy
*
proxy
,
UBGraphicsScene
*
pScene
,
const
int
pageIndex
);
static
void
persistScene
(
UBDocumentProxy
*
proxy
,
UBGraphicsScene
*
pScene
,
const
int
pageIndex
);
static
void
upgradeScene
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
void
upgradeScene
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
QUuid
sceneUuid
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
QUuid
sceneUuid
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
);
static
void
setSceneUuid
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
,
QUuid
pUuid
);
static
void
setSceneUuid
(
UBDocumentProxy
*
proxy
,
const
int
pageIndex
,
QUuid
pUuid
);
static
void
convertPDFObjectsToImages
(
UBDocumentProxy
*
proxy
);
static
void
convertPDFObjectsToImages
(
UBDocumentProxy
*
proxy
);
static
void
convertSvgImagesToImages
(
UBDocumentProxy
*
proxy
);
static
void
convertSvgImagesToImages
(
UBDocumentProxy
*
proxy
);
static
const
QString
nsSvg
;
static
const
QString
nsSvg
;
static
const
QString
nsXLink
;
static
const
QString
nsXLink
;
static
const
QString
nsXHtml
;
static
const
QString
nsXHtml
;
static
const
QString
nsUb
;
static
const
QString
nsUb
;
static
const
QString
xmlTrue
;
static
const
QString
xmlTrue
;
static
const
QString
xmlFalse
;
static
const
QString
xmlFalse
;
static
const
QString
sFontSizePrefix
;
static
const
QString
sFontSizePrefix
;
static
const
QString
sPixelUnit
;
static
const
QString
sPixelUnit
;
static
const
QString
sFontWeightPrefix
;
static
const
QString
sFontWeightPrefix
;
static
const
QString
sFontStylePrefix
;
static
const
QString
sFontStylePrefix
;
private
:
private
:
static
UBGraphicsScene
*
loadScene
(
UBDocumentProxy
*
proxy
,
const
QByteArray
&
pArray
);
static
UBGraphicsScene
*
loadScene
(
UBDocumentProxy
*
proxy
,
const
QByteArray
&
pArray
);
static
QDomDocument
loadSceneDocument
(
UBDocumentProxy
*
proxy
,
const
int
pPageIndex
);
static
QDomDocument
loadSceneDocument
(
UBDocumentProxy
*
proxy
,
const
int
pPageIndex
);
static
QString
uniboardDocumentNamespaceUriFromVersion
(
int
fileVersion
);
static
QString
uniboardDocumentNamespaceUriFromVersion
(
int
fileVersion
);
static
const
QString
sFormerUniboardDocumentNamespaceUri
;
static
const
QString
sFormerUniboardDocumentNamespaceUri
;
static
QString
toSvgTransform
(
const
QMatrix
&
matrix
);
static
QString
toSvgTransform
(
const
QMatrix
&
matrix
);
static
QMatrix
fromSvgTransform
(
const
QString
&
transform
);
static
QMatrix
fromSvgTransform
(
const
QString
&
transform
);
class
UBSvgSubsetReader
class
UBSvgSubsetReader
{
{
public
:
public
:
UBSvgSubsetReader
(
UBDocumentProxy
*
proxy
,
const
QByteArray
&
pXmlData
);
UBSvgSubsetReader
(
UBDocumentProxy
*
proxy
,
const
QByteArray
&
pXmlData
);
virtual
~
UBSvgSubsetReader
(){}
virtual
~
UBSvgSubsetReader
(){}
UBGraphicsScene
*
loadScene
();
UBGraphicsScene
*
loadScene
();
private
:
private
:
UBGraphicsPolygonItem
*
polygonItemFromLineSvg
(
const
QColor
&
pDefaultBrushColor
);
UBGraphicsPolygonItem
*
polygonItemFromLineSvg
(
const
QColor
&
pDefaultBrushColor
);
UBGraphicsPolygonItem
*
polygonItemFromPolygonSvg
(
const
QColor
&
pDefaultBrushColor
);
UBGraphicsPolygonItem
*
polygonItemFromPolygonSvg
(
const
QColor
&
pDefaultBrushColor
);
QList
<
UBGraphicsPolygonItem
*>
polygonItemsFromPolylineSvg
(
const
QColor
&
pDefaultColor
);
QList
<
UBGraphicsPolygonItem
*>
polygonItemsFromPolylineSvg
(
const
QColor
&
pDefaultColor
);
UBGraphicsPixmapItem
*
pixmapItemFromSvg
();
UBGraphicsPixmapItem
*
pixmapItemFromSvg
();
UBGraphicsSvgItem
*
svgItemFromSvg
();
UBGraphicsSvgItem
*
svgItemFromSvg
();
UBGraphicsPDFItem
*
pdfItemFromPDF
();
UBGraphicsPDFItem
*
pdfItemFromPDF
();
UBGraphicsVideoItem
*
videoItemFromSvg
();
UBGraphicsVideoItem
*
videoItemFromSvg
();
UBGraphicsAudioItem
*
audioItemFromSvg
();
UBGraphicsAudioItem
*
audioItemFromSvg
();
UBGraphicsAppleWidgetItem
*
graphicsAppleWidgetFromSvg
();
UBGraphicsAppleWidgetItem
*
graphicsAppleWidgetFromSvg
();
UBGraphicsW3CWidgetItem
*
graphicsW3CWidgetFromSvg
();
UBGraphicsW3CWidgetItem
*
graphicsW3CWidgetFromSvg
();
UBGraphicsTextItem
*
textItemFromSvg
();
UBGraphicsTextItem
*
textItemFromSvg
();
UBGraphicsCurtainItem
*
curtainItemFromSvg
();
UBGraphicsCurtainItem
*
curtainItemFromSvg
();
UBGraphicsRuler
*
rulerFromSvg
();
UBGraphicsRuler
*
rulerFromSvg
();
UBGraphicsCompass
*
compassFromSvg
();
UBGraphicsCompass
*
compassFromSvg
();
UBGraphicsProtractor
*
protractorFromSvg
();
UBGraphicsProtractor
*
protractorFromSvg
();
UBGraphicsTriangle
*
triangleFromSvg
();
UBGraphicsTriangle
*
triangleFromSvg
();
UBGraphicsCache
*
cacheFromSvg
();
UBGraphicsCache
*
cacheFromSvg
();
void
graphicsItemFromSvg
(
QGraphicsItem
*
gItem
);
void
graphicsItemFromSvg
(
QGraphicsItem
*
gItem
);
QXmlStreamReader
mXmlReader
;
QXmlStreamReader
mXmlReader
;
int
mFileVersion
;
int
mFileVersion
;
UBDocumentProxy
*
mProxy
;
UBDocumentProxy
*
mProxy
;
QString
mDocumentPath
;
QString
mDocumentPath
;
QColor
mGroupDarkBackgroundColor
;
QColor
mGroupDarkBackgroundColor
;
QColor
mGroupLightBackgroundColor
;
QColor
mGroupLightBackgroundColor
;
qreal
mGroupZIndex
;
qreal
mGroupZIndex
;
bool
mGroupHasInfo
;
bool
mGroupHasInfo
;
QString
mNamespaceUri
;
QString
mNamespaceUri
;
};
};
class
UBSvgSubsetWriter
class
UBSvgSubsetWriter
{
{
public
:
public
:
UBSvgSubsetWriter
(
UBDocumentProxy
*
proxy
,
UBGraphicsScene
*
pScene
,
const
int
pageIndex
);
UBSvgSubsetWriter
(
UBDocumentProxy
*
proxy
,
UBGraphicsScene
*
pScene
,
const
int
pageIndex
);
bool
persistScene
();
bool
persistScene
();
virtual
~
UBSvgSubsetWriter
(){}
virtual
~
UBSvgSubsetWriter
(){}
private
:
private
:
void
polygonItemToSvgPolygon
(
UBGraphicsPolygonItem
*
polygonItem
,
bool
groupHoldsInfo
);
void
polygonItemToSvgPolygon
(
UBGraphicsPolygonItem
*
polygonItem
,
bool
groupHoldsInfo
);
void
polygonItemToSvgLine
(
UBGraphicsPolygonItem
*
polygonItem
,
bool
groupHoldsInfo
);
void
polygonItemToSvgLine
(
UBGraphicsPolygonItem
*
polygonItem
,
bool
groupHoldsInfo
);
void
strokeToSvgPolyline
(
UBGraphicsStroke
*
stroke
,
bool
groupHoldsInfo
);
void
strokeToSvgPolyline
(
UBGraphicsStroke
*
stroke
,
bool
groupHoldsInfo
);
void
strokeToSvgPolygon
(
UBGraphicsStroke
*
stroke
,
bool
groupHoldsInfo
);
void
strokeToSvgPolygon
(
UBGraphicsStroke
*
stroke
,
bool
groupHoldsInfo
);
inline
QString
pointsToSvgPointsAttribute
(
const
QVector
<
QPointF
>
points
)
inline
QString
pointsToSvgPointsAttribute
(
QVector
<
QPointF
>
points
)
{
{
const
QVector
<
QPointF
>
crashedPoints
=
UBGeometryUtils
::
crashPointList
(
points
);
UBGeometryUtils
::
crashPointList
(
points
);
int
pointsCount
=
crashedPoints
.
size
();
int
pointsCount
=
points
.
size
();
QString
svgPoints
;
QString
svgPoints
;
int
length
=
0
;
int
length
=
0
;
QString
sBuf
;
QString
sBuf
;
for
(
int
j
=
0
;
j
<
pointsCount
;
j
++
)
{
for
(
int
j
=
0
;
j
<
pointsCount
;
j
++
)
const
QPointF
&
point
=
crashedPoints
.
at
(
j
);
{
sBuf
.
sprintf
(
"%.2f,%.2f "
,
point
.
x
(),
point
.
y
());
sBuf
=
"%1,%2 "
;
svgPoints
.
insert
(
length
,
sBuf
);
const
QPointF
&
point
=
points
.
at
(
j
);
length
+=
sBuf
.
length
();
}
QString
temp1
=
"%1"
,
temp2
=
"%2"
;
return
svgPoints
;
}
temp1
=
temp1
.
arg
(
point
.
x
());
temp2
=
temp2
.
arg
(
point
.
y
());
inline
qreal
trickAlpha
(
qreal
alpha
)
{
QLocale
loc
(
QLocale
::
C
);
qreal
trickAlpha
=
alpha
;
sBuf
=
sBuf
.
arg
(
loc
.
toFloat
(
temp1
)).
arg
(
loc
.
toFloat
(
temp2
));
if
(
trickAlpha
>=
0
.
2
&&
trickAlpha
<
0
.
6
){
trickAlpha
/=
5
;
svgPoints
.
insert
(
length
,
sBuf
);
}
else
if
(
trickAlpha
<
0
.
8
)
length
+=
sBuf
.
length
();
trickAlpha
/=
3
;
}
return
svgPoints
;
return
trickAlpha
;
}
}
inline
qreal
trickAlpha
(
qreal
alpha
)
void
pixmapItemToLinkedImage
(
UBGraphicsPixmapItem
*
pixmapItem
);
{
void
svgItemToLinkedSvg
(
UBGraphicsSvgItem
*
svgItem
);
qreal
trickAlpha
=
alpha
;
void
pdfItemToLinkedPDF
(
UBGraphicsPDFItem
*
pdfItem
);
if
(
trickAlpha
>=
0
.
2
&&
trickAlpha
<
0
.
6
){
void
videoItemToLinkedVideo
(
UBGraphicsVideoItem
*
videoItem
);
trickAlpha
/=
5
;
void
audioItemToLinkedAudio
(
UBGraphicsAudioItem
*
audioItem
);
}
else
if
(
trickAlpha
<
0
.
8
)
void
graphicsItemToSvg
(
QGraphicsItem
*
item
);
trickAlpha
/=
3
;
void
graphicsAppleWidgetToSvg
(
UBGraphicsAppleWidgetItem
*
item
);
void
graphicsW3CWidgetToSvg
(
UBGraphicsW3CWidgetItem
*
item
);
return
trickAlpha
;
void
graphicsWidgetToSvg
(
UBGraphicsWidgetItem
*
item
);
}
void
textItemToSvg
(
UBGraphicsTextItem
*
item
);
void
curtainItemToSvg
(
UBGraphicsCurtainItem
*
item
);
void
pixmapItemToLinkedImage
(
UBGraphicsPixmapItem
*
pixmapItem
);
void
rulerToSvg
(
UBGraphicsRuler
*
item
);
void
svgItemToLinkedSvg
(
UBGraphicsSvgItem
*
svgItem
);
void
compassToSvg
(
UBGraphicsCompass
*
item
);
void
pdfItemToLinkedPDF
(
UBGraphicsPDFItem
*
pdfItem
);
void
protractorToSvg
(
UBGraphicsProtractor
*
item
);
void
videoItemToLinkedVideo
(
UBGraphicsVideoItem
*
videoItem
);
void
cacheToSvg
(
UBGraphicsCache
*
item
);
void
audioItemToLinkedAudio
(
UBGraphicsAudioItem
*
audioItem
);
void
triangleToSvg
(
UBGraphicsTriangle
*
item
);
void
graphicsItemToSvg
(
QGraphicsItem
*
item
);
void
writeSvgElement
();
void
graphicsAppleWidgetToSvg
(
UBGraphicsAppleWidgetItem
*
item
);
void
graphicsW3CWidgetToSvg
(
UBGraphicsW3CWidgetItem
*
item
);
private
:
void
graphicsWidgetToSvg
(
UBGraphicsWidgetItem
*
item
);
void
textItemToSvg
(
UBGraphicsTextItem
*
item
);
UBGraphicsScene
*
mScene
;
void
curtainItemToSvg
(
UBGraphicsCurtainItem
*
item
);
QXmlStreamWriter
mXmlWriter
;
void
rulerToSvg
(
UBGraphicsRuler
*
item
);
QString
mDocumentPath
;
void
compassToSvg
(
UBGraphicsCompass
*
item
);
int
mPageIndex
;
void
protractorToSvg
(
UBGraphicsProtractor
*
item
);
void
cacheToSvg
(
UBGraphicsCache
*
item
);
};
void
triangleToSvg
(
UBGraphicsTriangle
*
item
);
};
void
writeSvgElement
();
#endif
/* UBSVGSUBSETADAPTOR_H_ */
private
:
UBGraphicsScene
*
mScene
;
QXmlStreamWriter
mXmlWriter
;
QString
mDocumentPath
;
int
mPageIndex
;
};
};
#endif
/* UBSVGSUBSETADAPTOR_H_ */
src/frameworks/UBGeometryUtils.cpp
View file @
9c8a49f8
/*
/*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "UBGeometryUtils.h"
#include "UBGeometryUtils.h"
#include "core/memcheck.h"
#include "core/memcheck.h"
const
double
PI
=
4.0
*
atan
(
1.0
);
const
double
PI
=
4.0
*
atan
(
1.0
);
UBGeometryUtils
::
UBGeometryUtils
()
UBGeometryUtils
::
UBGeometryUtils
()
{
{
// NOOP
// NOOP
}
}
UBGeometryUtils
::~
UBGeometryUtils
()
UBGeometryUtils
::~
UBGeometryUtils
()
{
{
// NOOP
// NOOP
}
}
QPolygonF
UBGeometryUtils
::
lineToPolygon
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
)
QPolygonF
UBGeometryUtils
::
lineToPolygon
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
)
{
{
qreal
x1
=
pLine
.
x1
();
qreal
x1
=
pLine
.
x1
();
qreal
y1
=
pLine
.
y1
();
qreal
y1
=
pLine
.
y1
();
qreal
x2
=
pLine
.
x2
();
qreal
x2
=
pLine
.
x2
();
qreal
y2
=
pLine
.
y2
();
qreal
y2
=
pLine
.
y2
();
qreal
alpha
=
(
90.0
-
pLine
.
angle
())
*
PI
/
180.0
;
qreal
alpha
=
(
90.0
-
pLine
.
angle
())
*
PI
/
180.0
;
qreal
hypothenuse
=
pWidth
/
2
;
qreal
hypothenuse
=
pWidth
/
2
;
// TODO UB 4.x PERF cache sin/cos table
// TODO UB 4.x PERF cache sin/cos table
qreal
opposite
=
sin
(
alpha
)
*
hypothenuse
;
qreal
opposite
=
sin
(
alpha
)
*
hypothenuse
;
qreal
adjacent
=
cos
(
alpha
)
*
hypothenuse
;
qreal
adjacent
=
cos
(
alpha
)
*
hypothenuse
;
QPointF
p1a
(
x1
-
adjacent
,
y1
-
opposite
);
QPointF
p1a
(
x1
-
adjacent
,
y1
-
opposite
);
QPointF
p1b
(
x1
+
adjacent
,
y1
+
opposite
);
QPointF
p1b
(
x1
+
adjacent
,
y1
+
opposite
);
QPointF
p2a
(
x2
-
adjacent
,
y2
-
opposite
);
QPointF
p2a
(
x2
-
adjacent
,
y2
-
opposite
);
QPointF
p2b
(
x2
+
adjacent
,
y2
+
opposite
);
QPointF
p2b
(
x2
+
adjacent
,
y2
+
opposite
);
QPainterPath
painterPath
;
QPainterPath
painterPath
;
painterPath
.
moveTo
(
p1a
);
painterPath
.
moveTo
(
p1a
);
painterPath
.
lineTo
(
p2a
);
painterPath
.
lineTo
(
p2a
);
painterPath
.
arcTo
(
x2
-
hypothenuse
,
y2
-
hypothenuse
,
pWidth
,
pWidth
,
(
90.0
+
pLine
.
angle
()),
-
180.0
);
painterPath
.
arcTo
(
x2
-
hypothenuse
,
y2
-
hypothenuse
,
pWidth
,
pWidth
,
(
90.0
+
pLine
.
angle
()),
-
180.0
);
//painterPath.lineTo(p2b);
//painterPath.lineTo(p2b);
painterPath
.
lineTo
(
p1b
);
painterPath
.
lineTo
(
p1b
);
painterPath
.
arcTo
(
x1
-
hypothenuse
,
y1
-
hypothenuse
,
pWidth
,
pWidth
,
-
1
*
(
90.0
-
pLine
.
angle
()),
-
180.0
);
painterPath
.
arcTo
(
x1
-
hypothenuse
,
y1
-
hypothenuse
,
pWidth
,
pWidth
,
-
1
*
(
90.0
-
pLine
.
angle
()),
-
180.0
);
painterPath
.
closeSubpath
();
painterPath
.
closeSubpath
();
return
painterPath
.
toFillPolygon
();
return
painterPath
.
toFillPolygon
();
}
}
QPolygonF
UBGeometryUtils
::
lineToPolygon
(
const
QPointF
&
pStart
,
const
QPointF
&
pEnd
,
QPolygonF
UBGeometryUtils
::
lineToPolygon
(
const
QPointF
&
pStart
,
const
QPointF
&
pEnd
,
const
qreal
&
pStartWidth
,
const
qreal
&
pEndWidth
)
const
qreal
&
pStartWidth
,
const
qreal
&
pEndWidth
)
{
{
qreal
x1
=
pStart
.
x
();
qreal
x1
=
pStart
.
x
();
qreal
y1
=
pStart
.
y
();
qreal
y1
=
pStart
.
y
();
qreal
x2
=
pEnd
.
x
();
qreal
x2
=
pEnd
.
x
();
qreal
y2
=
pEnd
.
y
();
qreal
y2
=
pEnd
.
y
();
QLineF
line
(
pStart
,
pEnd
);
QLineF
line
(
pStart
,
pEnd
);
qreal
alpha
=
(
90.0
-
line
.
angle
())
*
PI
/
180.0
;
qreal
alpha
=
(
90.0
-
line
.
angle
())
*
PI
/
180.0
;
qreal
hypothenuseStart
=
pStartWidth
/
2
;
qreal
hypothenuseStart
=
pStartWidth
/
2
;
qreal
hypothenuseEnd
=
pEndWidth
/
2
;
qreal
hypothenuseEnd
=
pEndWidth
/
2
;
qreal
sinAlpha
=
sin
(
alpha
);
qreal
sinAlpha
=
sin
(
alpha
);
qreal
cosAlpha
=
cos
(
alpha
);
qreal
cosAlpha
=
cos
(
alpha
);
// TODO UB 4.x PERF cache sin/cos table
// TODO UB 4.x PERF cache sin/cos table
qreal
oppositeStart
=
sinAlpha
*
hypothenuseStart
;
qreal
oppositeStart
=
sinAlpha
*
hypothenuseStart
;
qreal
adjacentStart
=
cosAlpha
*
hypothenuseStart
;
qreal
adjacentStart
=
cosAlpha
*
hypothenuseStart
;
QPointF
p1a
(
x1
-
adjacentStart
,
y1
-
oppositeStart
);
QPointF
p1a
(
x1
-
adjacentStart
,
y1
-
oppositeStart
);
QPointF
p1b
(
x1
+
adjacentStart
,
y1
+
oppositeStart
);
QPointF
p1b
(
x1
+
adjacentStart
,
y1
+
oppositeStart
);
qreal
oppositeEnd
=
sinAlpha
*
hypothenuseEnd
;
qreal
oppositeEnd
=
sinAlpha
*
hypothenuseEnd
;
qreal
adjacentEnd
=
cosAlpha
*
hypothenuseEnd
;
qreal
adjacentEnd
=
cosAlpha
*
hypothenuseEnd
;
QPointF
p2a
(
x2
-
adjacentEnd
,
y2
-
oppositeEnd
);
QPointF
p2a
(
x2
-
adjacentEnd
,
y2
-
oppositeEnd
);
QPainterPath
painterPath
;
QPainterPath
painterPath
;
painterPath
.
moveTo
(
p1a
);
painterPath
.
moveTo
(
p1a
);
painterPath
.
lineTo
(
p2a
);
painterPath
.
lineTo
(
p2a
);
painterPath
.
arcTo
(
x2
-
hypothenuseEnd
,
y2
-
hypothenuseEnd
,
pEndWidth
,
pEndWidth
,
(
90.0
+
line
.
angle
()),
-
180.0
);
painterPath
.
arcTo
(
x2
-
hypothenuseEnd
,
y2
-
hypothenuseEnd
,
pEndWidth
,
pEndWidth
,
(
90.0
+
line
.
angle
()),
-
180.0
);
painterPath
.
lineTo
(
p1b
);
painterPath
.
lineTo
(
p1b
);
painterPath
.
arcTo
(
x1
-
hypothenuseStart
,
y1
-
hypothenuseStart
,
pStartWidth
,
pStartWidth
,
-
1
*
(
90.0
-
line
.
angle
()),
-
180.0
);
painterPath
.
arcTo
(
x1
-
hypothenuseStart
,
y1
-
hypothenuseStart
,
pStartWidth
,
pStartWidth
,
-
1
*
(
90.0
-
line
.
angle
()),
-
180.0
);
painterPath
.
closeSubpath
();
painterPath
.
closeSubpath
();
return
painterPath
.
toFillPolygon
();
return
painterPath
.
toFillPolygon
();
}
}
QPolygonF
UBGeometryUtils
::
arcToPolygon
(
const
QLineF
&
startRadius
,
qreal
spanAngleInDegrees
,
qreal
width
)
QPolygonF
UBGeometryUtils
::
arcToPolygon
(
const
QLineF
&
startRadius
,
qreal
spanAngleInDegrees
,
qreal
width
)
{
{
qreal
startAngleInDegrees
=
-
startRadius
.
angle
();
qreal
startAngleInDegrees
=
-
startRadius
.
angle
();
if
(
startAngleInDegrees
>
180
)
if
(
startAngleInDegrees
>
180
)
startAngleInDegrees
-=
360
;
startAngleInDegrees
-=
360
;
else
if
(
startAngleInDegrees
<
-
180
)
else
if
(
startAngleInDegrees
<
-
180
)
startAngleInDegrees
+=
360
;
startAngleInDegrees
+=
360
;
qreal
radiusLength
=
startRadius
.
length
();
qreal
radiusLength
=
startRadius
.
length
();
qreal
angle
=
2
*
asin
(
width
/
(
2
*
radiusLength
))
*
180
/
PI
;
qreal
angle
=
2
*
asin
(
width
/
(
2
*
radiusLength
))
*
180
/
PI
;
bool
overlap
=
abs
(
spanAngleInDegrees
)
>
360
-
angle
;
bool
overlap
=
abs
(
spanAngleInDegrees
)
>
360
-
angle
;
if
(
overlap
)
if
(
overlap
)
spanAngleInDegrees
=
spanAngleInDegrees
<
0
?
-
360
:
360
;
spanAngleInDegrees
=
spanAngleInDegrees
<
0
?
-
360
:
360
;
qreal
endAngleInDegrees
=
startAngleInDegrees
+
spanAngleInDegrees
;
qreal
endAngleInDegrees
=
startAngleInDegrees
+
spanAngleInDegrees
;
qreal
innerRadius
=
radiusLength
-
width
/
2
;
qreal
innerRadius
=
radiusLength
-
width
/
2
;
QRectF
innerSquare
(
QRectF
innerSquare
(
startRadius
.
p1
().
x
()
-
innerRadius
,
startRadius
.
p1
().
x
()
-
innerRadius
,
startRadius
.
p1
().
y
()
-
innerRadius
,
startRadius
.
p1
().
y
()
-
innerRadius
,
2
*
innerRadius
,
2
*
innerRadius
,
2
*
innerRadius
);
2
*
innerRadius
);
qreal
outerRadius
=
radiusLength
+
width
/
2
;
qreal
outerRadius
=
radiusLength
+
width
/
2
;
QRectF
outerSquare
(
QRectF
outerSquare
(
startRadius
.
p1
().
x
()
-
outerRadius
,
startRadius
.
p1
().
x
()
-
outerRadius
,
startRadius
.
p1
().
y
()
-
outerRadius
,
startRadius
.
p1
().
y
()
-
outerRadius
,
2
*
outerRadius
,
2
*
outerRadius
,
2
*
outerRadius
);
2
*
outerRadius
);
QRectF
startSquare
(
QRectF
startSquare
(
startRadius
.
p2
().
x
()
-
width
/
2
,
startRadius
.
p2
().
x
()
-
width
/
2
,
startRadius
.
p2
().
y
()
-
width
/
2
,
startRadius
.
p2
().
y
()
-
width
/
2
,
width
,
width
,
width
);
width
);
QRectF
endSquare
(
QRectF
endSquare
(
startRadius
.
p1
().
x
()
+
radiusLength
*
cos
(
endAngleInDegrees
*
PI
/
180.0
)
-
width
/
2
,
startRadius
.
p1
().
x
()
+
radiusLength
*
cos
(
endAngleInDegrees
*
PI
/
180.0
)
-
width
/
2
,
startRadius
.
p1
().
y
()
+
radiusLength
*
sin
(
endAngleInDegrees
*
PI
/
180.0
)
-
width
/
2
,
startRadius
.
p1
().
y
()
+
radiusLength
*
sin
(
endAngleInDegrees
*
PI
/
180.0
)
-
width
/
2
,
width
,
width
,
width
);
width
);
QPainterPath
painterPath
(
QPainterPath
painterPath
(
QPointF
(
QPointF
(
startRadius
.
p1
().
x
()
+
innerRadius
*
cos
(
startAngleInDegrees
*
PI
/
180.0
),
startRadius
.
p1
().
x
()
+
innerRadius
*
cos
(
startAngleInDegrees
*
PI
/
180.0
),
startRadius
.
p1
().
y
()
+
innerRadius
*
sin
(
startAngleInDegrees
*
PI
/
180.0
)));
startRadius
.
p1
().
y
()
+
innerRadius
*
sin
(
startAngleInDegrees
*
PI
/
180.0
)));
startAngleInDegrees
=
-
startAngleInDegrees
;
startAngleInDegrees
=
-
startAngleInDegrees
;
endAngleInDegrees
=
-
endAngleInDegrees
;
endAngleInDegrees
=
-
endAngleInDegrees
;
spanAngleInDegrees
=
-
spanAngleInDegrees
;
spanAngleInDegrees
=
-
spanAngleInDegrees
;
if
(
overlap
)
if
(
overlap
)
{
{
painterPath
.
addEllipse
(
outerSquare
);
painterPath
.
addEllipse
(
outerSquare
);
QPainterPath
innerPainterPath
;
QPainterPath
innerPainterPath
;
innerPainterPath
.
addEllipse
(
innerSquare
);
innerPainterPath
.
addEllipse
(
innerSquare
);
painterPath
=
painterPath
.
subtracted
(
innerPainterPath
);
painterPath
=
painterPath
.
subtracted
(
innerPainterPath
);
}
}
else
else
{
{
painterPath
.
arcTo
(
innerSquare
,
startAngleInDegrees
,
spanAngleInDegrees
);
painterPath
.
arcTo
(
innerSquare
,
startAngleInDegrees
,
spanAngleInDegrees
);
painterPath
.
arcTo
(
endSquare
,
180.0
+
endAngleInDegrees
,
spanAngleInDegrees
>
0
?
-
180.0
:
180.0
);
painterPath
.
arcTo
(
endSquare
,
180.0
+
endAngleInDegrees
,
spanAngleInDegrees
>
0
?
-
180.0
:
180.0
);
painterPath
.
arcTo
(
outerSquare
,
endAngleInDegrees
,
-
spanAngleInDegrees
);
painterPath
.
arcTo
(
outerSquare
,
endAngleInDegrees
,
-
spanAngleInDegrees
);
painterPath
.
arcTo
(
startSquare
,
startAngleInDegrees
,
spanAngleInDegrees
>
0
?
-
180.0
:
180.0
);
painterPath
.
arcTo
(
startSquare
,
startAngleInDegrees
,
spanAngleInDegrees
>
0
?
-
180.0
:
180.0
);
painterPath
.
closeSubpath
();
painterPath
.
closeSubpath
();
}
}
return
painterPath
.
toFillPolygon
();
return
painterPath
.
toFillPolygon
();
}
}
QPointF
UBGeometryUtils
::
pointConstrainedInRect
(
QPointF
point
,
QRectF
rect
)
QPointF
UBGeometryUtils
::
pointConstrainedInRect
(
QPointF
point
,
QRectF
rect
)
{
{
return
QPointF
(
qMax
(
rect
.
x
(),
qMin
(
rect
.
x
()
+
rect
.
width
(),
point
.
x
())),
qMax
(
rect
.
y
(),
qMin
(
rect
.
y
()
+
rect
.
height
(),
point
.
y
())));
return
QPointF
(
qMax
(
rect
.
x
(),
qMin
(
rect
.
x
()
+
rect
.
width
(),
point
.
x
())),
qMax
(
rect
.
y
(),
qMin
(
rect
.
y
()
+
rect
.
height
(),
point
.
y
())));
}
}
QPoint
UBGeometryUtils
::
pointConstrainedInRect
(
QPoint
point
,
QRect
rect
)
QPoint
UBGeometryUtils
::
pointConstrainedInRect
(
QPoint
point
,
QRect
rect
)
{
{
return
QPoint
(
qMax
(
rect
.
x
(),
qMin
(
rect
.
x
()
+
rect
.
width
(),
point
.
x
())),
qMax
(
rect
.
y
(),
qMin
(
rect
.
y
()
+
rect
.
height
(),
point
.
y
())));
return
QPoint
(
qMax
(
rect
.
x
(),
qMin
(
rect
.
x
()
+
rect
.
width
(),
point
.
x
())),
qMax
(
rect
.
y
(),
qMin
(
rect
.
y
()
+
rect
.
height
(),
point
.
y
())));
}
}
QRectF
UBGeometryUtils
::
lineToInnerRect
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
)
QRectF
UBGeometryUtils
::
lineToInnerRect
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
)
{
{
qreal
centerX
=
(
pLine
.
x1
()
+
pLine
.
x2
())
/
2
;
qreal
centerX
=
(
pLine
.
x1
()
+
pLine
.
x2
())
/
2
;
qreal
centerY
=
(
pLine
.
y1
()
+
pLine
.
y2
())
/
2
;
qreal
centerY
=
(
pLine
.
y1
()
+
pLine
.
y2
())
/
2
;
qreal
side
=
sqrt
((
pWidth
*
pWidth
)
/
2
);
qreal
side
=
sqrt
((
pWidth
*
pWidth
)
/
2
);
qreal
halfSide
=
side
/
2
;
qreal
halfSide
=
side
/
2
;
return
QRectF
(
centerX
-
halfSide
,
centerY
-
halfSide
,
side
,
side
);
return
QRectF
(
centerX
-
halfSide
,
centerY
-
halfSide
,
side
,
side
);
}
}
QVector
<
QPointF
>
UBGeometryUtils
::
crashPointList
(
const
QVector
<
QPointF
>
points
)
void
UBGeometryUtils
::
crashPointList
(
QVector
<
QPointF
>
&
points
)
{
{
QVector
<
QPointF
>
result
(
points
);
// QVector<QPointF> result(points);
int
position
=
1
;
int
position
=
1
;
while
(
position
<
result
.
size
())
while
(
position
<
points
.
size
())
{
{
if
(
result
.
at
(
position
)
==
result
.
at
(
position
-
1
))
if
(
points
.
at
(
position
)
==
points
.
at
(
position
-
1
))
{
{
result
.
remove
(
position
);
points
.
remove
(
position
);
}
}
else
else
{
{
++
position
;
++
position
;
}
}
}
}
}
return
result
;
}
src/frameworks/UBGeometryUtils.h
View file @
9c8a49f8
/*
/*
* This program is free software: you can redistribute it and/or modify
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef UBGEOMETRYUTILS_H_
#ifndef UBGEOMETRYUTILS_H_
#define UBGEOMETRYUTILS_H_
#define UBGEOMETRYUTILS_H_
#include <QtGui>
#include <QtGui>
class
UBGeometryUtils
class
UBGeometryUtils
{
{
private
:
private
:
UBGeometryUtils
();
UBGeometryUtils
();
virtual
~
UBGeometryUtils
();
virtual
~
UBGeometryUtils
();
public
:
public
:
static
QPolygonF
lineToPolygon
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
);
static
QPolygonF
lineToPolygon
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
);
static
QRectF
lineToInnerRect
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
);
static
QRectF
lineToInnerRect
(
const
QLineF
&
pLine
,
const
qreal
&
pWidth
);
static
QPolygonF
arcToPolygon
(
const
QLineF
&
startRadius
,
qreal
spanAngle
,
qreal
width
);
static
QPolygonF
arcToPolygon
(
const
QLineF
&
startRadius
,
qreal
spanAngle
,
qreal
width
);
static
QPolygonF
lineToPolygon
(
const
QPointF
&
pStart
,
const
QPointF
&
pEnd
,
static
QPolygonF
lineToPolygon
(
const
QPointF
&
pStart
,
const
QPointF
&
pEnd
,
const
qreal
&
pStartWidth
,
const
qreal
&
pEndWidth
);
const
qreal
&
pStartWidth
,
const
qreal
&
pEndWidth
);
static
QPointF
pointConstrainedInRect
(
QPointF
point
,
QRectF
rect
);
static
QPointF
pointConstrainedInRect
(
QPointF
point
,
QRectF
rect
);
static
QPoint
pointConstrainedInRect
(
QPoint
point
,
QRect
rect
);
static
QPoint
pointConstrainedInRect
(
QPoint
point
,
QRect
rect
);
static
QVector
<
QPointF
>
crashPointList
(
const
QVector
<
QPointF
>
points
);
static
void
crashPointList
(
QVector
<
QPointF
>
&
points
);
};
};
#endif
/* UBGEOMETRYUTILS_H_ */
#endif
/* UBGEOMETRYUTILS_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