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
7b40574a
Commit
7b40574a
authored
May 09, 2012
by
shibakaneki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backup of the strokes as object
parent
a909eafd
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
159 additions
and
78 deletions
+159
-78
UBBoardView.cpp
src/board/UBBoardView.cpp
+3
-1
UBDrawingController.cpp
src/board/UBDrawingController.cpp
+8
-2
UBDrawingController.h
src/board/UBDrawingController.h
+2
-0
UBGraphicsPolygonItem.cpp
src/domain/UBGraphicsPolygonItem.cpp
+6
-1
UBGraphicsPolygonItem.h
src/domain/UBGraphicsPolygonItem.h
+4
-0
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+129
-73
UBGraphicsStrokesGroup.h
src/domain/UBGraphicsStrokesGroup.h
+5
-0
UBGeometryUtils.cpp
src/frameworks/UBGeometryUtils.cpp
+2
-1
No files found.
src/board/UBBoardView.cpp
View file @
7b40574a
...
@@ -50,6 +50,7 @@
...
@@ -50,6 +50,7 @@
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsVideoItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsAudioItem.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsSvgItem.h"
#include "domain/UBGraphicsStrokesGroup.h"
#include "document/UBDocumentProxy.h"
#include "document/UBDocumentProxy.h"
...
@@ -563,7 +564,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
...
@@ -563,7 +564,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
||
item
->
type
()
==
UBGraphicsPixmapItem
::
Type
||
item
->
type
()
==
UBGraphicsPixmapItem
::
Type
||
item
->
type
()
==
UBGraphicsVideoItem
::
Type
||
item
->
type
()
==
UBGraphicsVideoItem
::
Type
||
item
->
type
()
==
UBGraphicsAudioItem
::
Type
||
item
->
type
()
==
UBGraphicsAudioItem
::
Type
||
item
->
type
()
==
UBGraphicsSvgItem
::
Type
)
{
||
item
->
type
()
==
UBGraphicsSvgItem
::
Type
||
item
->
type
()
==
UBGraphicsStrokesGroup
::
Type
)
{
if
(
!
mJustSelectedItems
.
contains
(
item
))
{
if
(
!
mJustSelectedItems
.
contains
(
item
))
{
item
->
setSelected
(
true
);
item
->
setSelected
(
true
);
...
...
src/board/UBDrawingController.cpp
View file @
7b40574a
...
@@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
...
@@ -45,7 +45,7 @@ UBDrawingController::UBDrawingController(QObject * parent)
,
mActiveRuler
(
NULL
)
,
mActiveRuler
(
NULL
)
,
mStylusTool
((
UBStylusTool
::
Enum
)
-
1
)
,
mStylusTool
((
UBStylusTool
::
Enum
)
-
1
)
,
mLatestDrawingTool
((
UBStylusTool
::
Enum
)
-
1
)
,
mLatestDrawingTool
((
UBStylusTool
::
Enum
)
-
1
)
//, mDrawingMode(eDrawingMode_Vector
)
,
mDrawingMode
(
DRAWING_MODE
)
{
{
connect
(
UBSettings
::
settings
(),
SIGNAL
(
colorContextChanged
()),
this
,
SIGNAL
(
colorPaletteChanged
()));
connect
(
UBSettings
::
settings
(),
SIGNAL
(
colorContextChanged
()),
this
,
SIGNAL
(
colorPaletteChanged
()));
...
@@ -106,10 +106,16 @@ void UBDrawingController::setStylusTool(int tool)
...
@@ -106,10 +106,16 @@ void UBDrawingController::setStylusTool(int tool)
mStylusTool
=
(
UBStylusTool
::
Enum
)
tool
;
mStylusTool
=
(
UBStylusTool
::
Enum
)
tool
;
if
(
eDrawingMode_Vector
==
DRAWING_MODE
){
mDrawingMode
=
eDrawingMode_Vector
;
}
if
(
mStylusTool
==
UBStylusTool
::
Pen
)
if
(
mStylusTool
==
UBStylusTool
::
Pen
)
UBApplication
::
mainWindow
->
actionPen
->
setChecked
(
true
);
UBApplication
::
mainWindow
->
actionPen
->
setChecked
(
true
);
else
if
(
mStylusTool
==
UBStylusTool
::
Eraser
)
else
if
(
mStylusTool
==
UBStylusTool
::
Eraser
)
{
UBApplication
::
mainWindow
->
actionEraser
->
setChecked
(
true
);
UBApplication
::
mainWindow
->
actionEraser
->
setChecked
(
true
);
mDrawingMode
=
eDrawingMode_Artistic
;
}
else
if
(
mStylusTool
==
UBStylusTool
::
Marker
)
else
if
(
mStylusTool
==
UBStylusTool
::
Marker
)
UBApplication
::
mainWindow
->
actionMarker
->
setChecked
(
true
);
UBApplication
::
mainWindow
->
actionMarker
->
setChecked
(
true
);
else
if
(
mStylusTool
==
UBStylusTool
::
Selector
)
else
if
(
mStylusTool
==
UBStylusTool
::
Selector
)
...
...
src/board/UBDrawingController.h
View file @
7b40574a
...
@@ -27,6 +27,8 @@ typedef enum{
...
@@ -27,6 +27,8 @@ typedef enum{
eDrawingMode_Vector
eDrawingMode_Vector
}
eDrawingMode
;
}
eDrawingMode
;
#define DRAWING_MODE eDrawingMode_Artistic
class
UBDrawingController
:
public
QObject
class
UBDrawingController
:
public
QObject
{
{
Q_OBJECT
;
Q_OBJECT
;
...
...
src/domain/UBGraphicsPolygonItem.cpp
View file @
7b40574a
...
@@ -39,6 +39,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi
...
@@ -39,6 +39,7 @@ UBGraphicsPolygonItem::UBGraphicsPolygonItem (const QPolygonF & polygon, QGraphi
,
mOriginalWidth
(
-
1
)
,
mOriginalWidth
(
-
1
)
,
mIsNominalLine
(
false
)
,
mIsNominalLine
(
false
)
,
mStroke
(
0
)
,
mStroke
(
0
)
,
mpGroup
(
NULL
)
{
{
// NOOP
// NOOP
initialize
();
initialize
();
...
@@ -77,6 +78,10 @@ UBGraphicsPolygonItem::~UBGraphicsPolygonItem()
...
@@ -77,6 +78,10 @@ UBGraphicsPolygonItem::~UBGraphicsPolygonItem()
clearStroke
();
clearStroke
();
}
}
void
UBGraphicsPolygonItem
::
setStrokesGroup
(
UBGraphicsStrokesGroup
*
group
)
{
mpGroup
=
group
;
}
void
UBGraphicsPolygonItem
::
setStroke
(
UBGraphicsStroke
*
stroke
)
void
UBGraphicsPolygonItem
::
setStroke
(
UBGraphicsStroke
*
stroke
)
{
{
...
@@ -156,7 +161,7 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con
...
@@ -156,7 +161,7 @@ UBGraphicsPolygonItem* UBGraphicsPolygonItem::deepCopy(const QPolygonF& pol) con
copy
->
mIsNominalLine
=
false
;
copy
->
mIsNominalLine
=
false
;
copy
->
setStroke
(
this
->
stroke
());
copy
->
setStroke
(
this
->
stroke
());
copy
->
set
Group
(
this
->
g
roup
());
copy
->
set
StrokesGroup
(
this
->
strokesG
roup
());
copy
->
setBrush
(
this
->
brush
());
copy
->
setBrush
(
this
->
brush
());
copy
->
setPen
(
this
->
pen
());
copy
->
setPen
(
this
->
pen
());
copy
->
mHasAlpha
=
this
->
mHasAlpha
;
copy
->
mHasAlpha
=
this
->
mHasAlpha
;
...
...
src/domain/UBGraphicsPolygonItem.h
View file @
7b40574a
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include "core/UB.h"
#include "core/UB.h"
#include "UBItem.h"
#include "UBItem.h"
#include "UBGraphicsStrokesGroup.h"
class
UBItem
;
class
UBItem
;
class
UBGraphicsScene
;
class
UBGraphicsScene
;
...
@@ -37,6 +38,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
...
@@ -37,6 +38,8 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
void
initialize
();
void
initialize
();
void
setStrokesGroup
(
UBGraphicsStrokesGroup
*
group
);
UBGraphicsStrokesGroup
*
strokesGroup
()
const
{
return
mpGroup
;}
void
setColor
(
const
QColor
&
color
);
void
setColor
(
const
QColor
&
color
);
QColor
color
()
const
;
QColor
color
()
const
;
...
@@ -132,6 +135,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
...
@@ -132,6 +135,7 @@ class UBGraphicsPolygonItem : public QGraphicsPolygonItem, public UBItem
QColor
mColorOnLightBackground
;
QColor
mColorOnLightBackground
;
UBGraphicsStroke
*
mStroke
;
UBGraphicsStroke
*
mStroke
;
UBGraphicsStrokesGroup
*
mpGroup
;
};
};
...
...
src/domain/UBGraphicsScene.cpp
View file @
7b40574a
...
@@ -567,7 +567,7 @@ bool UBGraphicsScene::inputDeviceRelease()
...
@@ -567,7 +567,7 @@ bool UBGraphicsScene::inputDeviceRelease()
}
}
}
else
if
(
mCurrentStroke
)
}
else
if
(
mCurrentStroke
)
{
{
if
(
eDrawingMode_Vector
==
dc
->
drawingMode
()
){
if
(
eDrawingMode_Vector
==
DRAWING_MODE
){
UBGraphicsStrokesGroup
*
pStrokes
=
new
UBGraphicsStrokesGroup
();
UBGraphicsStrokesGroup
*
pStrokes
=
new
UBGraphicsStrokesGroup
();
// Remove the strokes that were just drawn here and replace them by a stroke item
// Remove the strokes that were just drawn here and replace them by a stroke item
...
@@ -575,6 +575,7 @@ bool UBGraphicsScene::inputDeviceRelease()
...
@@ -575,6 +575,7 @@ bool UBGraphicsScene::inputDeviceRelease()
mPreviousPolygonItems
.
removeAll
(
poly
);
mPreviousPolygonItems
.
removeAll
(
poly
);
removeItem
(
poly
);
removeItem
(
poly
);
UBCoreGraphicsScene
::
removeItemFromDeletion
(
poly
);
UBCoreGraphicsScene
::
removeItemFromDeletion
(
poly
);
poly
->
setStrokesGroup
(
pStrokes
);
pStrokes
->
addToGroup
(
poly
);
pStrokes
->
addToGroup
(
poly
);
}
}
...
@@ -756,37 +757,65 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
...
@@ -756,37 +757,65 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
eraserPathVar
.
addPolygon
(
eraserPolygon
);
eraserPathVar
.
addPolygon
(
eraserPolygon
);
const
QPainterPath
eraserPath
=
eraserPathVar
;
const
QPainterPath
eraserPath
=
eraserPathVar
;
// Get all the items that are intersecting with the eraser path
QList
<
QGraphicsItem
*>
collidItems
=
items
(
eraserBoundingRect
,
Qt
::
IntersectsItemBoundingRect
);
QList
<
QGraphicsItem
*>
collidItems
=
items
(
eraserBoundingRect
,
Qt
::
IntersectsItemBoundingRect
);
if
(
eDrawingMode_Vector
==
UBDrawingController
::
drawingController
()
->
drawingMode
()){
// NOTE: I decided to reuse the 'artistic' eraser all the time in order to have a better eraser
// For this reason, the following code is not used but we will keep it for now, in case of
// futur requirements.
foreach
(
QGraphicsItem
*
poly
,
collidItems
){
UBGraphicsStrokesGroup
*
pGroup
=
dynamic_cast
<
UBGraphicsStrokesGroup
*>
(
poly
);
if
(
NULL
!=
pGroup
){
// TODO: Ungroup the item, put back the polygons on the scene, deal with the
// eraser's bounding rect, remove the polygons that must be removed
// then create new groups.
// Get all substrokes and verify if they are part of the eraserpath then deal with it
foreach
(
QGraphicsItem
*
item
,
poly
->
childItems
()){
UBGraphicsPolygonItem
*
polygon
=
dynamic_cast
<
UBGraphicsPolygonItem
*>
(
item
);
if
(
NULL
!=
polygon
){
if
(
eraserBoundingRect
.
intersects
(
polygon
->
boundingRect
())){
pGroup
->
removeFromGroup
(
polygon
);
removeItem
(
polygon
);
}
}
}
}
}
}
else
{
QSet
<
QGraphicsItem
*>
toBeAddedItems
;
QSet
<
QGraphicsItem
*>
toBeAddedItems
;
QSet
<
QGraphicsItem
*>
toBeRemovedItems
;
QSet
<
QGraphicsItem
*>
toBeRemovedItems
;
int
collidItemsSize
=
collidItems
.
size
();
int
collidItemsSize
=
collidItems
.
size
();
toBeAddedItems
.
reserve
(
collidItemsSize
);
toBeAddedItems
.
reserve
(
collidItemsSize
);
toBeRemovedItems
.
reserve
(
collidItemsSize
);
toBeRemovedItems
.
reserve
(
collidItemsSize
);
if
(
mShouldUseOMP
)
if
(
mShouldUseOMP
)
{
{
#pragma omp parallel for
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
collidItemsSize
;
i
++
)
for
(
int
i
=
0
;
i
<
collidItemsSize
;
i
++
)
{
{
UBGraphicsPolygonItem
*
collidingPolygonItem
UBGraphicsPolygonItem
*
collidingPolygonItem
=
dynamic_cast
<
UBGraphicsPolygonItem
*>
(
collidItems
.
at
(
i
));
=
qgraphicsitem_cast
<
UBGraphicsPolygonItem
*>
(
collidItems
.
at
(
i
));
if
(
collidingPolygonItem
)
if
(
NULL
!=
collidingPolygonItem
)
{
{
UBGraphicsStrokesGroup
*
pGroup
=
collidingPolygonItem
->
strokesGroup
();
if
(
eraserInnerRect
.
contains
(
collidingPolygonItem
->
boundingRect
()))
if
(
eraserInnerRect
.
contains
(
collidingPolygonItem
->
boundingRect
()))
{
{
#pragma omp critical
#pragma omp critical
// Put the entire polygon into the remove list
toBeRemovedItems
<<
collidingPolygonItem
;
toBeRemovedItems
<<
collidingPolygonItem
;
}
}
else
else
{
{
// Here we get the polygon of the colliding item
QPolygonF
collidingPolygon
=
collidingPolygonItem
->
polygon
();
QPolygonF
collidingPolygon
=
collidingPolygonItem
->
polygon
();
QPainterPath
collidingPath
;
QPainterPath
collidingPath
;
collidingPath
.
addPolygon
(
collidingPolygon
);
collidingPath
.
addPolygon
(
collidingPolygon
);
// Then we substract the eraser path to the polygon and we simplify it
QPainterPath
croppedPath
=
collidingPath
.
subtracted
(
eraserPath
);
QPainterPath
croppedPath
=
collidingPath
.
subtracted
(
eraserPath
);
QPainterPath
croppedPathSimplified
=
croppedPath
.
simplified
();
QPainterPath
croppedPathSimplified
=
croppedPath
.
simplified
();
...
@@ -796,18 +825,26 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
...
@@ -796,18 +825,26 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
}
}
else
if
(
croppedPathSimplified
.
isEmpty
())
else
if
(
croppedPathSimplified
.
isEmpty
())
{
{
#pragma omp critical
#pragma omp critical
// Put the entire polygon into the remove list if the eraser removes all its visible content
toBeRemovedItems
<<
collidingPolygonItem
;
toBeRemovedItems
<<
collidingPolygonItem
;
}
}
else
else
{
{
// Then we convert the remaining path to a list of polygons that will be converted in
// UBGraphicsPolygonItems and added to the scene
foreach
(
const
QPolygonF
&
pol
,
croppedPathSimplified
.
toFillPolygons
())
foreach
(
const
QPolygonF
&
pol
,
croppedPathSimplified
.
toFillPolygons
())
{
{
UBGraphicsPolygonItem
*
croppedPolygonItem
=
collidingPolygonItem
->
deepCopy
(
pol
);
UBGraphicsPolygonItem
*
croppedPolygonItem
=
collidingPolygonItem
->
deepCopy
(
pol
);
#pragma omp critical
#pragma omp critical
// Add this new polygon to the 'added' list
toBeAddedItems
<<
croppedPolygonItem
;
toBeAddedItems
<<
croppedPolygonItem
;
if
(
NULL
!=
pGroup
){
croppedPolygonItem
->
setStrokesGroup
(
pGroup
);
}
}
}
#pragma omp critical
#pragma omp critical
// Remove the original polygonitem because it has been replaced by many smaller polygons
toBeRemovedItems
<<
collidingPolygonItem
;
toBeRemovedItems
<<
collidingPolygonItem
;
}
}
}
}
...
@@ -862,9 +899,28 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
...
@@ -862,9 +899,28 @@ void UBGraphicsScene::eraseLineTo(const QPointF &pEndPoint, const qreal &pWidth)
addItems
(
toBeAddedItems
);
addItems
(
toBeAddedItems
);
mAddedItems
+=
toBeAddedItems
;
mAddedItems
+=
toBeAddedItems
;
if
(
eDrawingMode_Vector
==
DRAWING_MODE
){
foreach
(
QGraphicsItem
*
item
,
toBeAddedItems
){
UBGraphicsPolygonItem
*
poly
=
dynamic_cast
<
UBGraphicsPolygonItem
*>
(
item
);
if
(
NULL
!=
poly
&&
NULL
!=
poly
->
strokesGroup
()){
poly
->
strokesGroup
()
->
addToGroup
(
poly
);
}
}
}
removeItems
(
toBeRemovedItems
);
removeItems
(
toBeRemovedItems
);
mRemovedItems
+=
toBeRemovedItems
;
mRemovedItems
+=
toBeRemovedItems
;
if
(
eDrawingMode_Vector
==
DRAWING_MODE
){
foreach
(
QGraphicsItem
*
item
,
toBeRemovedItems
){
UBGraphicsPolygonItem
*
poly
=
dynamic_cast
<
UBGraphicsPolygonItem
*>
(
item
);
if
(
NULL
!=
poly
&&
NULL
!=
poly
->
strokesGroup
()){
poly
->
strokesGroup
()
->
removeFromGroup
(
poly
);
}
}
}
}
mPreviousPoint
=
pEndPoint
;
mPreviousPoint
=
pEndPoint
;
}
}
...
...
src/domain/UBGraphicsStrokesGroup.h
View file @
7b40574a
...
@@ -16,6 +16,11 @@ public:
...
@@ -16,6 +16,11 @@ public:
virtual
UBItem
*
deepCopy
()
const
;
virtual
UBItem
*
deepCopy
()
const
;
virtual
void
remove
();
virtual
void
remove
();
virtual
UBGraphicsItemDelegate
*
Delegate
()
const
{
return
mDelegate
;}
virtual
UBGraphicsItemDelegate
*
Delegate
()
const
{
return
mDelegate
;}
enum
{
Type
=
UBGraphicsItemType
::
StrokeItemType
};
virtual
int
type
()
const
{
return
Type
;
}
protected
:
protected
:
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
virtual
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
);
...
...
src/frameworks/UBGeometryUtils.cpp
View file @
7b40574a
...
@@ -198,6 +198,7 @@ QRectF UBGeometryUtils::lineToInnerRect(const QLineF& pLine, const qreal& pWidth
...
@@ -198,6 +198,7 @@ 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
;
// Please put a fucking comment here
qreal
side
=
sqrt
((
pWidth
*
pWidth
)
/
2
);
qreal
side
=
sqrt
((
pWidth
*
pWidth
)
/
2
);
qreal
halfSide
=
side
/
2
;
qreal
halfSide
=
side
/
2
;
...
...
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