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
881a1d50
Commit
881a1d50
authored
Apr 30, 2017
by
Craig Watson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to undo/redo setting image as background
parent
aedebaf2
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
52 additions
and
2 deletions
+52
-2
UBGraphicsItemDelegate.cpp
src/domain/UBGraphicsItemDelegate.cpp
+14
-0
UBGraphicsItemTransformUndoCommand.cpp
src/domain/UBGraphicsItemTransformUndoCommand.cpp
+18
-1
UBGraphicsItemTransformUndoCommand.h
src/domain/UBGraphicsItemTransformUndoCommand.h
+4
-1
UBGraphicsScene.cpp
src/domain/UBGraphicsScene.cpp
+15
-0
UBGraphicsScene.h
src/domain/UBGraphicsScene.h
+1
-0
No files found.
src/domain/UBGraphicsItemDelegate.cpp
View file @
881a1d50
...
...
@@ -596,16 +596,30 @@ void UBGraphicsItemDelegate::showHide(bool show)
emit
showOnDisplayChanged
(
show
);
}
/**
* @brief Set delegate as background for the scene, replacing any existing background.
*/
void
UBGraphicsItemDelegate
::
setAsBackground
()
{
UBGraphicsScene
*
scene
=
castUBGraphicsScene
();
QGraphicsItem
*
item
=
delegated
();
if
(
scene
&&
item
)
{
startUndoStep
();
item
->
resetTransform
();
item
->
setPos
(
item
->
sceneBoundingRect
().
width
()
/-
2.
,
item
->
sceneBoundingRect
().
height
()
/-
2.
);
scene
->
setAsBackgroundObject
(
item
);
UBGraphicsItemTransformUndoCommand
*
uc
=
new
UBGraphicsItemTransformUndoCommand
(
mDelegated
,
mPreviousPosition
,
mPreviousTransform
,
mPreviousZValue
,
mPreviousSize
,
true
);
UBApplication
::
undoStack
->
push
(
uc
);
}
}
...
...
src/domain/UBGraphicsItemTransformUndoCommand.cpp
View file @
881a1d50
...
...
@@ -30,12 +30,14 @@
#include "UBGraphicsItemTransformUndoCommand.h"
#include "UBResizableGraphicsItem.h"
#include "domain/UBItem.h"
#include "domain/UBGraphicsScene.h"
#include "core/memcheck.h"
UBGraphicsItemTransformUndoCommand
::
UBGraphicsItemTransformUndoCommand
(
QGraphicsItem
*
pItem
,
const
QPointF
&
prevPos
,
const
QTransform
&
prevTransform
,
const
qreal
&
prevZValue
,
const
QSizeF
&
prevSize
)
:
UBUndoCommand
()
const
QSizeF
&
prevSize
,
bool
setToBackground
)
:
UBUndoCommand
()
{
mItem
=
pItem
;
mPreviousTransform
=
prevTransform
;
...
...
@@ -52,6 +54,8 @@ UBGraphicsItemTransformUndoCommand::UBGraphicsItemTransformUndoCommand(QGraphics
if
(
resizableItem
)
mCurrentSize
=
resizableItem
->
size
();
mSetToBackground
=
setToBackground
;
}
UBGraphicsItemTransformUndoCommand
::~
UBGraphicsItemTransformUndoCommand
()
...
...
@@ -61,6 +65,13 @@ UBGraphicsItemTransformUndoCommand::~UBGraphicsItemTransformUndoCommand()
void
UBGraphicsItemTransformUndoCommand
::
undo
()
{
if
(
mSetToBackground
)
{
UBGraphicsScene
*
scene
=
dynamic_cast
<
UBGraphicsScene
*>
(
mItem
->
scene
());
if
(
scene
&&
scene
->
isBackgroundObject
(
mItem
))
{
scene
->
unsetBackgroundObject
();
}
}
mItem
->
setPos
(
mPreviousPosition
);
mItem
->
setTransform
(
mPreviousTransform
);
mItem
->
setZValue
(
mPreviousZValue
);
...
...
@@ -73,6 +84,12 @@ void UBGraphicsItemTransformUndoCommand::undo()
void
UBGraphicsItemTransformUndoCommand
::
redo
()
{
if
(
mSetToBackground
)
{
UBGraphicsScene
*
scene
=
dynamic_cast
<
UBGraphicsScene
*>
(
mItem
->
scene
());
if
(
scene
)
scene
->
setAsBackgroundObject
(
mItem
);
}
mItem
->
setPos
(
mCurrentPosition
);
mItem
->
setTransform
(
mCurrentTransform
);
mItem
->
setZValue
(
mCurrentZValue
);
...
...
src/domain/UBGraphicsItemTransformUndoCommand.h
View file @
881a1d50
...
...
@@ -42,7 +42,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand
const
QPointF
&
prevPos
,
const
QTransform
&
prevTransform
,
const
qreal
&
prevZValue
,
const
QSizeF
&
prevSize
=
QSizeF
());
const
QSizeF
&
prevSize
=
QSizeF
(),
bool
setToBackground
=
false
);
virtual
~
UBGraphicsItemTransformUndoCommand
();
virtual
int
getType
()
const
{
return
UBUndoType
::
undotype_GRAPHICITEMTRANSFORM
;
}
...
...
@@ -63,6 +64,8 @@ class UBGraphicsItemTransformUndoCommand : public UBUndoCommand
qreal
mPreviousZValue
;
qreal
mCurrentZValue
;
bool
mSetToBackground
;
};
#endif
/* UBGRAPHICSITEMTRANSFORMUNDOCOMMAND_H_ */
src/domain/UBGraphicsScene.cpp
View file @
881a1d50
...
...
@@ -1983,6 +1983,21 @@ QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool
return
item
;
}
void
UBGraphicsScene
::
unsetBackgroundObject
()
{
if
(
!
mBackgroundObject
)
return
;
mBackgroundObject
->
setFlag
(
QGraphicsItem
::
ItemIsSelectable
,
true
);
mBackgroundObject
->
setFlag
(
QGraphicsItem
::
ItemIsMovable
,
true
);
mBackgroundObject
->
setAcceptedMouseButtons
(
Qt
::
LeftButton
);
// Item zLayer and Layer Type should be set by the caller of this function, as
// it may depend on the object type, where it was before, etc.
mBackgroundObject
=
0
;
}
QRectF
UBGraphicsScene
::
normalizedSceneRect
(
qreal
ratio
)
{
...
...
src/domain/UBGraphicsScene.h
View file @
881a1d50
...
...
@@ -174,6 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem
void
addGroup
(
UBGraphicsGroupContainerItem
*
groupItem
);
QGraphicsItem
*
setAsBackgroundObject
(
QGraphicsItem
*
item
,
bool
pAdaptTransformation
=
false
,
bool
expand
=
false
);
void
unsetBackgroundObject
();
QGraphicsItem
*
backgroundObject
()
const
{
...
...
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