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
de18bf79
Commit
de18bf79
authored
Jun 22, 2012
by
Aleksei Kanash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RubberBand is moveble and resizable by PlayTool.
Items can be moved by RubberBand.
parent
6b85418a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
269 additions
and
16 deletions
+269
-16
UBBoardView.cpp
src/board/UBBoardView.cpp
+40
-16
UBBoardView.h
src/board/UBBoardView.h
+6
-0
UBRubberBand.cpp
src/gui/UBRubberBand.cpp
+199
-0
UBRubberBand.h
src/gui/UBRubberBand.h
+24
-0
No files found.
src/board/UBBoardView.cpp
View file @
de18bf79
...
...
@@ -613,6 +613,37 @@ void UBBoardView::handleItemMouseMove(QMouseEvent *event)
}
}
void
UBBoardView
::
rubberItems
()
{
if
(
mUBRubberBand
)
mRubberedItems
=
items
(
mUBRubberBand
->
geometry
());
}
void
UBBoardView
::
moveRubberedItems
(
QPointF
movingVector
)
{
// QRect bandRect = mUBRubberBand->geometry();
//
QRectF
invalidateRect
=
scene
()
->
itemsBoundingRect
();
// QList<QGraphicsItem *> rubberItems = items(bandRect);
foreach
(
QGraphicsItem
*
item
,
mRubberedItems
)
{
if
(
item
->
type
()
==
UBGraphicsW3CWidgetItem
::
Type
||
item
->
type
()
==
UBGraphicsPixmapItem
::
Type
||
item
->
type
()
==
UBGraphicsMediaItem
::
Type
||
item
->
type
()
==
UBGraphicsSvgItem
::
Type
||
item
->
type
()
==
UBGraphicsTextItem
::
Type
||
item
->
type
()
==
UBGraphicsStrokesGroup
::
Type
||
item
->
type
()
==
UBGraphicsGroupContainerItem
::
Type
)
{
item
->
setPos
(
item
->
pos
()
+
movingVector
);
}
}
scene
()
->
invalidate
(
invalidateRect
);
}
void
UBBoardView
::
mousePressEvent
(
QMouseEvent
*
event
)
{
if
(
isAbsurdPoint
(
event
->
pos
()))
...
...
@@ -649,7 +680,7 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
mPreviousPoint
=
event
->
posF
();
event
->
accept
();
}
else
if
(
currentTool
==
UBStylusTool
::
Selector
)
else
if
(
currentTool
==
UBStylusTool
::
Selector
||
currentTool
==
UBStylusTool
::
Play
)
{
movingItem
=
scene
()
->
itemAt
(
this
->
mapToScene
(
event
->
posF
().
toPoint
()));
...
...
@@ -662,14 +693,6 @@ void UBBoardView::mousePressEvent (QMouseEvent *event)
mUBRubberBand
->
show
();
}
handleItemMousePress
(
event
);
event
->
accept
();
}
else
if
(
currentTool
==
UBStylusTool
::
Play
)
{
movingItem
=
scene
()
->
itemAt
(
this
->
mapToScene
(
event
->
posF
().
toPoint
()));
handleItemMousePress
(
event
);
event
->
accept
();
}
...
...
@@ -754,14 +777,16 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
mPreviousPoint
=
eventPosition
;
event
->
accept
();
}
else
if
(
currentTool
==
UBStylusTool
::
Selector
)
else
if
(
currentTool
==
UBStylusTool
::
Selector
||
currentTool
==
UBStylusTool
::
Play
)
{
if
((
event
->
pos
()
-
mLastPressedMousePos
).
manhattanLength
()
<
QApplication
::
startDragDistance
())
{
return
;
}
if
(
mUBRubberBand
&&
mUBRubberBand
->
isVisible
())
{
if
(
!
movingItem
&&
(
mMouseButtonIsPressed
||
mTabletStylusIsPressed
)
&&
mUBRubberBand
&&
mUBRubberBand
->
isVisible
())
{
QRect
bandRect
(
mMouseDownPos
,
event
->
pos
());
bandRect
=
bandRect
.
normalized
();
mUBRubberBand
->
setGeometry
(
bandRect
);
...
...
@@ -773,6 +798,8 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
mJustSelectedItems
.
remove
(
item
);
}
}
if
(
currentTool
==
UBStylusTool
::
Selector
)
foreach
(
QGraphicsItem
*
item
,
items
(
bandRect
))
{
if
(
item
->
type
()
==
UBGraphicsW3CWidgetItem
::
Type
...
...
@@ -793,10 +820,6 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event)
handleItemMouseMove
(
event
);
}
else
if
(
currentTool
==
UBStylusTool
::
Play
)
{
handleItemMouseMove
(
event
);
}
else
if
((
UBDrawingController
::
drawingController
()
->
isDrawingTool
())
&&
!
mMouseButtonIsPressed
)
{
...
...
@@ -859,6 +882,7 @@ UBBoardView::mouseReleaseEvent (QMouseEvent *event)
if
(
mUBRubberBand
&&
mUBRubberBand
->
isVisible
())
{
mUBRubberBand
->
hide
();
}
QGraphicsView
::
mouseReleaseEvent
(
event
);
}
else
if
(
currentTool
==
UBStylusTool
::
Play
)
...
...
src/board/UBBoardView.h
View file @
de18bf79
...
...
@@ -42,6 +42,9 @@ class UBBoardView : public QGraphicsView
void
setToolCursor
(
int
tool
);
void
rubberItems
();
void
moveRubberedItems
(
QPointF
movingVector
);
signals
:
void
resized
(
QResizeEvent
*
event
);
...
...
@@ -133,7 +136,10 @@ class UBBoardView : public QGraphicsView
QGraphicsItem
*
movingItem
;
QMouseEvent
*
suspendedMousePressEvent
;
bool
moveRubberBand
;
UBRubberBand
*
mUBRubberBand
;
QList
<
QGraphicsItem
*>
mRubberedItems
;
QSet
<
QGraphicsItem
*>
mJustSelectedItems
;
private
slots
:
...
...
src/gui/UBRubberBand.cpp
View file @
de18bf79
...
...
@@ -23,10 +23,18 @@
#include <QtGui/QMacStyle>
#endif
#include "core/UBApplication.h"
#include "board/UBBoardController.h"
#include "board/UBBoardView.h"
#include "core/memcheck.h"
UBRubberBand
::
UBRubberBand
(
Shape
s
,
QWidget
*
p
)
:
QRubberBand
(
s
,
p
)
,
mResizingMode
(
None
)
,
mMouseIsPressed
(
false
)
,
mLastPressedPoint
(
QPoint
())
,
mResizingBorderHeight
(
20
)
{
customStyle
=
NULL
;
...
...
@@ -41,6 +49,8 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p)
if
(
customStyle
)
QRubberBand
::
setStyle
(
customStyle
);
setAttribute
(
Qt
::
WA_TransparentForMouseEvents
,
false
);
setMouseTracking
(
true
);
}
UBRubberBand
::~
UBRubberBand
()
...
...
@@ -48,3 +58,192 @@ UBRubberBand::~UBRubberBand()
if
(
customStyle
)
delete
customStyle
;
}
UBRubberBand
::
enm_resizingMode
UBRubberBand
::
determineResizingMode
(
QPoint
pos
)
{
if
(
mMouseIsPressed
)
return
mResizingMode
;
QRect
resizerTop
(
mResizingBorderHeight
,
0
,
rect
().
width
()
-
2
*
mResizingBorderHeight
,
mResizingBorderHeight
);
QRect
resizerBottom
(
mResizingBorderHeight
,
rect
().
height
()
-
mResizingBorderHeight
,
rect
().
width
()
-
2
*
mResizingBorderHeight
,
mResizingBorderHeight
);
QRect
resizerLeft
(
0
,
mResizingBorderHeight
,
mResizingBorderHeight
,
rect
().
height
()
-
2
*
mResizingBorderHeight
);
QRect
resizerRight
(
rect
().
width
()
-
mResizingBorderHeight
,
mResizingBorderHeight
,
mResizingBorderHeight
,
rect
().
height
()
-
2
*
mResizingBorderHeight
);
QRect
resizerTopLeft
(
0
,
0
,
mResizingBorderHeight
,
mResizingBorderHeight
);
QRect
resizerTopRight
(
rect
().
width
()
-
mResizingBorderHeight
,
0
,
mResizingBorderHeight
,
mResizingBorderHeight
);
QRect
resizerBottomLeft
(
0
,
rect
().
height
()
-
mResizingBorderHeight
,
mResizingBorderHeight
,
mResizingBorderHeight
);
QRect
resizerBottomRight
(
rect
().
width
()
-
mResizingBorderHeight
,
rect
().
height
()
-
mResizingBorderHeight
,
mResizingBorderHeight
,
mResizingBorderHeight
);
enm_resizingMode
resizingMode
;
QTransform
cursorTransrofm
;
if
(
resizerTop
.
contains
(
pos
))
{
resizingMode
=
Top
;
cursorTransrofm
.
rotate
(
90
);
}
else
if
(
resizerBottom
.
contains
(
pos
))
{
resizingMode
=
Bottom
;
cursorTransrofm
.
rotate
(
90
);
}
else
if
(
resizerLeft
.
contains
(
pos
))
{
resizingMode
=
Left
;
}
else
if
(
resizerRight
.
contains
(
pos
))
{
resizingMode
=
Right
;
}
else
if
(
resizerTopLeft
.
contains
(
pos
))
{
resizingMode
=
TopLeft
;
cursorTransrofm
.
rotate
(
45
);
}
else
if
(
resizerTopRight
.
contains
(
pos
))
{
resizingMode
=
TopRight
;
cursorTransrofm
.
rotate
(
-
45
);
}
else
if
(
resizerBottomLeft
.
contains
(
pos
))
{
resizingMode
=
BottomLeft
;
cursorTransrofm
.
rotate
(
-
45
);
}
else
if
(
resizerBottomRight
.
contains
(
pos
))
{
resizingMode
=
BottomRight
;
cursorTransrofm
.
rotate
(
45
);
}
else
resizingMode
=
None
;
if
(
None
!=
resizingMode
)
{
QPixmap
pix
(
":/images/cursors/resize.png"
);
QCursor
resizeCursor
=
QCursor
(
pix
.
transformed
(
cursorTransrofm
,
Qt
::
SmoothTransformation
),
pix
.
width
()
/
2
,
pix
.
height
()
/
2
);
setCursor
(
resizeCursor
);
}
else
unsetCursor
();
return
resizingMode
;
}
void
UBRubberBand
::
mousePressEvent
(
QMouseEvent
*
event
)
{
mResizingMode
=
determineResizingMode
(
event
->
pos
());
mMouseIsPressed
=
true
;
mLastPressedPoint
=
event
->
pos
();
mLastMousePos
=
event
->
pos
();
if
(
None
==
mResizingMode
)
{
UBApplication
::
boardController
->
controlView
()
->
rubberItems
();
setCursor
(
QCursor
(
Qt
::
SizeAllCursor
));
}
}
void
UBRubberBand
::
mouseMoveEvent
(
QMouseEvent
*
event
)
{
determineResizingMode
(
event
->
pos
());
if
(
mMouseIsPressed
)
{
UBBoardView
*
view
=
UBApplication
::
boardController
->
controlView
();
QRect
currentGeometry
=
geometry
();
QPoint
pressPoint
(
event
->
pos
());
QPoint
pressPointGlobal
(
view
->
mapToGlobal
(
pressPoint
));
QPoint
prevPressPointGlobal
(
view
->
mapToGlobal
(
mLastPressedPoint
));
QPoint
movePointGlogal
=
(
view
->
mapToGlobal
(
mLastMousePos
));
QPoint
topLeftResizeVector
(
pressPointGlobal
-
prevPressPointGlobal
);
QPoint
rightBottomResizeVector
(
pressPointGlobal
-
movePointGlogal
);
bool
bGeometryChange
=
true
;
switch
(
mResizingMode
)
{
case
None
:
{
QPointF
itemsMoveVector
(
view
->
mapToScene
(
pressPointGlobal
)
-
view
->
mapToScene
(
prevPressPointGlobal
));
move
(
pos
()
+
pressPointGlobal
-
prevPressPointGlobal
);
view
->
moveRubberedItems
(
itemsMoveVector
);
bGeometryChange
=
false
;
break
;
}
case
Top
:
{
currentGeometry
.
setY
(
currentGeometry
.
y
()
+
topLeftResizeVector
.
y
());
}
break
;
case
Bottom
:
{
currentGeometry
.
setHeight
(
currentGeometry
.
height
()
+
rightBottomResizeVector
.
y
());
}
break
;
case
Left
:
{
currentGeometry
.
setX
(
currentGeometry
.
x
()
+
topLeftResizeVector
.
x
());
}
break
;
case
Right
:
{
currentGeometry
.
setWidth
(
currentGeometry
.
width
()
+
rightBottomResizeVector
.
x
());
}
break
;
case
TopLeft
:
{
currentGeometry
.
setX
(
currentGeometry
.
x
()
+
topLeftResizeVector
.
x
());
currentGeometry
.
setY
(
currentGeometry
.
y
()
+
topLeftResizeVector
.
y
());
}
break
;
case
TopRight
:
{
currentGeometry
.
setY
(
currentGeometry
.
y
()
+
topLeftResizeVector
.
y
());
currentGeometry
.
setWidth
(
currentGeometry
.
width
()
+
rightBottomResizeVector
.
x
());
}
break
;
case
BottomLeft
:
{
currentGeometry
.
setX
(
currentGeometry
.
x
()
+
topLeftResizeVector
.
x
());
currentGeometry
.
setHeight
(
currentGeometry
.
height
()
+
rightBottomResizeVector
.
y
());
}
break
;
case
BottomRight
:
{
currentGeometry
.
setWidth
(
currentGeometry
.
width
()
+
rightBottomResizeVector
.
x
());
currentGeometry
.
setHeight
(
currentGeometry
.
height
()
+
rightBottomResizeVector
.
y
());
}
break
;
}
if
(
bGeometryChange
)
{
setGeometry
(
currentGeometry
);
}
mLastMousePos
=
event
->
pos
();
}
QRubberBand
::
mouseMoveEvent
(
event
);
}
void
UBRubberBand
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
{
Q_UNUSED
(
event
);
mMouseIsPressed
=
false
;
unsetCursor
();
}
\ No newline at end of file
src/gui/UBRubberBand.h
View file @
de18bf79
...
...
@@ -26,8 +26,32 @@ class UBRubberBand : public QRubberBand
UBRubberBand
(
Shape
s
,
QWidget
*
p
=
0
);
virtual
~
UBRubberBand
();
private
:
enum
enm_resizingMode
{
None
,
Top
,
TopLeft
,
TopRight
,
Bottom
,
BottomLeft
,
BottomRight
,
Left
,
Right
};
enm_resizingMode
determineResizingMode
(
QPoint
pos
);
virtual
void
mousePressEvent
(
QMouseEvent
*
event
);
virtual
void
mouseMoveEvent
(
QMouseEvent
*
event
);
virtual
void
mouseReleaseEvent
(
QMouseEvent
*
event
);
private
:
QStyle
*
customStyle
;
enm_resizingMode
mResizingMode
;
int
mResizingBorderHeight
;
bool
mMouseIsPressed
;
QPoint
mLastPressedPoint
;
QPoint
mLastMousePos
;
};
#endif
/* UBRUBBERBAND_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