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
e60416f3
Commit
e60416f3
authored
Jul 01, 2019
by
Clément Fauconnier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved click handling on thumbnails view
parent
9e4dfba3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
81 deletions
+131
-81
UBDocumentNavigator.cpp
src/gui/UBDocumentNavigator.cpp
+48
-32
UBDocumentNavigator.h
src/gui/UBDocumentNavigator.h
+2
-1
UBThumbnailWidget.cpp
src/gui/UBThumbnailWidget.cpp
+45
-44
UBThumbnailWidget.h
src/gui/UBThumbnailWidget.h
+36
-4
No files found.
src/gui/UBDocumentNavigator.cpp
View file @
e60416f3
...
...
@@ -59,6 +59,7 @@ UBDocumentNavigator::UBDocumentNavigator(QWidget *parent, const char *name):QGra
,
mThumbnailWidth
(
0
)
,
mThumbnailMinWidth
(
100
)
,
mSelectedThumbnail
(
NULL
)
,
mLastClickedThumbnail
(
NULL
)
,
mDropSource
(
NULL
)
,
mDropTarget
(
NULL
)
,
mDropBar
(
new
QGraphicsRectItem
())
...
...
@@ -285,50 +286,65 @@ void UBDocumentNavigator::resizeEvent(QResizeEvent *event)
*/
void
UBDocumentNavigator
::
mousePressEvent
(
QMouseEvent
*
event
)
{
mLongPressTimer
.
start
();
mLastPressedMousePos
=
event
->
pos
();
QGraphicsView
::
mousePressEvent
(
event
);
QGraphicsItem
*
pClickedItem
=
itemAt
(
event
->
pos
());
if
(
NULL
!=
pClickedItem
)
if
(
!
event
->
isAccepted
())
{
mLongPressTimer
.
start
();
mLastPressedMousePos
=
event
->
pos
();
// First, select the clicked item
UBSceneThumbnailNavigPixmap
*
pCrntItem
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
pClickedItem
);
mLastClickedThumbnail
=
clickedThumbnail
(
mLastPressedMousePos
);
if
(
NULL
==
pCrntItem
)
if
(
mLastClickedThumbnail
)
{
int
index
=
0
;
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
{
if
(
mThumbsWithLabels
.
at
(
i
).
getThumbnail
()
==
mLastClickedThumbnail
)
{
mSelectedThumbnail
=
mLastClickedThumbnail
;
index
=
i
;
break
;
}
}
UBApplication
::
boardController
->
persistViewPositionOnCurrentScene
();
UBApplication
::
boardController
->
persistCurrentScene
();
UBApplication
::
boardController
->
setActiveDocumentScene
(
index
);
UBApplication
::
boardController
->
centerOn
(
UBApplication
::
boardController
->
activeScene
()
->
lastCenter
());
}
}
}
UBSceneThumbnailNavigPixmap
*
UBDocumentNavigator
::
clickedThumbnail
(
const
QPoint
pos
)
const
{
UBSceneThumbnailNavigPixmap
*
clickedThumbnail
=
NULL
;
QGraphicsItem
*
clickedItem
=
itemAt
(
pos
);
if
(
clickedItem
)
{
clickedThumbnail
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
clickedItem
);
if
(
!
clickedThumbnail
)
{
// If we fall here we may have clicked on the label instead of the thumbnail
UBThumbnailTextItem
*
pTextItem
=
dynamic_cast
<
UBThumbnailTextItem
*>
(
pC
lickedItem
);
if
(
NULL
!=
p
TextItem
)
UBThumbnailTextItem
*
clickedTextItem
=
dynamic_cast
<
UBThumbnailTextItem
*>
(
c
lickedItem
);
if
(
clicked
TextItem
)
{
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
{
const
UBImgTextThumbnailElement
&
el
=
mThumbsWithLabels
.
at
(
i
);
if
(
el
.
getCaption
()
==
p
TextItem
)
if
(
el
.
getCaption
()
==
clicked
TextItem
)
{
pCrntItem
=
el
.
getThumbnail
();
clickedThumbnail
=
el
.
getThumbnail
();
break
;
}
}
}
}
int
index
=
0
;
for
(
int
i
=
0
;
i
<
mThumbsWithLabels
.
size
();
i
++
)
{
if
(
mThumbsWithLabels
.
at
(
i
).
getThumbnail
()
==
pCrntItem
)
{
mSelectedThumbnail
=
pCrntItem
;
index
=
i
;
break
;
}
}
UBApplication
::
boardController
->
persistViewPositionOnCurrentScene
();
UBApplication
::
boardController
->
persistCurrentScene
();
UBApplication
::
boardController
->
setActiveDocumentScene
(
index
);
UBApplication
::
boardController
->
centerOn
(
UBApplication
::
boardController
->
activeScene
()
->
lastCenter
());
}
QGraphicsView
::
mousePressEvent
(
event
);
return
clickedThumbnail
;
}
void
UBDocumentNavigator
::
mouseReleaseEvent
(
QMouseEvent
*
event
)
...
...
@@ -346,13 +362,13 @@ void UBDocumentNavigator::longPressTimeout()
void
UBDocumentNavigator
::
mousePressAndHoldEvent
(
QPoint
pos
)
{
UBSceneThumbnailNavigPixmap
*
item
=
dynamic_cast
<
UBSceneThumbnailNavigPixmap
*>
(
itemAt
(
pos
));
if
(
item
)
//
UBSceneThumbnailNavigPixmap* item = dynamic_cast<UBSceneThumbnailNavigPixmap*>(itemAt(pos));
if
(
mLastClickedThumbnail
)
{
mDropSource
=
item
;
mDropTarget
=
item
;
mDropSource
=
mLastClickedThumbnail
;
mDropTarget
=
mLastClickedThumbnail
;
QPixmap
pixmap
=
item
->
pixmap
().
scaledToWidth
(
mThumbnailWidth
/
2
);
QPixmap
pixmap
=
mLastClickedThumbnail
->
pixmap
().
scaledToWidth
(
mThumbnailWidth
/
2
);
QDrag
*
drag
=
new
QDrag
(
this
);
drag
->
setMimeData
(
new
QMimeData
());
...
...
src/gui/UBDocumentNavigator.h
View file @
e60416f3
...
...
@@ -53,6 +53,7 @@ public:
int
nbColumns
();
void
setThumbnailMinWidth
(
int
width
);
int
thumbnailMinWidth
();
UBSceneThumbnailNavigPixmap
*
clickedThumbnail
(
const
QPoint
pos
)
const
;
public
slots
:
void
onScrollToSelectedPage
(
int
index
);
// { if (mCrntItem) centerOn(mCrntItem); }
...
...
@@ -94,7 +95,7 @@ private:
int
mThumbnailMinWidth
;
/** The selected thumbnail */
UBSceneThumbnailNavigPixmap
*
mSelectedThumbnail
;
UBSceneThumbnailNavigPixmap
*
mLastClickedThumbnail
;
UBSceneThumbnailNavigPixmap
*
mDropSource
;
UBSceneThumbnailNavigPixmap
*
mDropTarget
;
QGraphicsRectItem
*
mDropBar
;
...
...
src/gui/UBThumbnailWidget.cpp
View file @
e60416f3
...
...
@@ -773,10 +773,7 @@ UBThumbnail::~UBThumbnail()
UBSceneThumbnailNavigPixmap
::
UBSceneThumbnailNavigPixmap
(
const
QPixmap
&
pix
,
UBDocumentProxy
*
proxy
,
int
pSceneIndex
)
:
UBSceneThumbnailPixmap
(
pix
,
proxy
,
pSceneIndex
)
,
bButtonsVisible
(
false
)
,
bCanDelete
(
false
)
,
bCanMoveUp
(
false
)
,
bCanMoveDown
(
false
)
,
mEditable
(
false
)
{
if
(
0
<=
UBDocumentContainer
::
pageFromSceneIndex
(
pSceneIndex
)){
setAcceptHoverEvents
(
true
);
...
...
@@ -792,49 +789,30 @@ UBSceneThumbnailNavigPixmap::~UBSceneThumbnailNavigPixmap()
void
UBSceneThumbnailNavigPixmap
::
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
event
->
accept
();
bButtonsVisible
=
true
;
bCanDelete
=
true
;
bCanMoveDown
=
false
;
bCanMoveUp
=
false
;
if
(
sceneIndex
()
<
proxy
()
->
pageCount
()
-
1
)
bCanMoveDown
=
true
;
if
(
sceneIndex
()
>
0
)
bCanMoveUp
=
true
;
if
(
proxy
()
->
pageCount
()
==
1
)
bCanDelete
=
false
;
showUI
();
update
();
}
void
UBSceneThumbnailNavigPixmap
::
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
)
{
event
->
accept
();
bButtonsVisible
=
false
;
hideUI
()
;
update
();
}
void
UBSceneThumbnailNavigPixmap
::
paint
(
QPainter
*
painter
,
const
QStyleOptionGraphicsItem
*
option
,
QWidget
*
widget
)
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
UBSceneThumbnailPixmap
::
paint
(
painter
,
option
,
widget
);
if
(
bButtonsVisible
)
using
namespace
UBThumbnailUI
;
if
(
editable
())
{
if
(
bCanDelete
)
painter
->
drawPixmap
(
0
,
0
,
BUTTONSIZE
,
BUTTONSIZE
,
QPixmap
(
":images/close.svg
"
));
if
(
deletable
()
)
draw
(
painter
,
*
getIcon
(
"close
"
));
else
painter
->
drawPixmap
(
0
,
0
,
BUTTONSIZE
,
BUTTONSIZE
,
QPixmap
(
":images/closeDisabled.svg"
));
painter
->
drawPixmap
(
BUTTONSIZE
+
BUTTONSPACING
,
0
,
BUTTONSIZE
,
BUTTONSIZE
,
QPixmap
(
":images/duplicate.svg"
));
// if(bCanMoveUp)
// painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUp.svg"));
// else
// painter->drawPixmap(2*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/moveUpDisabled.svg"));
// if(bCanMoveDown)
// painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menu.svg"));
// else
// painter->drawPixmap(3*(BUTTONSIZE + BUTTONSPACING), 0, BUTTONSIZE, BUTTONSIZE, QPixmap(":images/menuDisabled.svg"));
draw
(
painter
,
*
getIcon
(
"closeDisabled"
));
draw
(
painter
,
*
getIcon
(
"duplicate"
));
}
}
...
...
@@ -842,18 +820,41 @@ void UBSceneThumbnailNavigPixmap::mousePressEvent(QGraphicsSceneMouseEvent *even
{
QPointF
p
=
event
->
pos
();
// Here we check the position of the click and verify if it has to trig an action or not.
if
(
bCanDelete
&&
p
.
x
()
>=
0
&&
p
.
x
()
<=
BUTTONSIZE
&&
p
.
y
()
>=
0
&&
p
.
y
()
<=
BUTTONSIZE
)
deletePage
();
if
(
p
.
x
()
>=
BUTTONSIZE
+
BUTTONSPACING
&&
p
.
x
()
<=
2
*
BUTTONSIZE
+
BUTTONSPACING
&&
p
.
y
()
>=
0
&&
p
.
y
()
<=
BUTTONSIZE
)
duplicatePage
();
// if(bCanMoveUp && p.x() >= 2*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 3*BUTTONSIZE + 2*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
// moveUpPage();
// if(bCanMoveDown && p.x() >= 3*(BUTTONSIZE + BUTTONSPACING) && p.x() <= 4*BUTTONSIZE + 3*BUTTONSPACING && p.y() >= 0 && p.y() <= BUTTONSIZE)
// moveDownPage();
using
namespace
UBThumbnailUI
;
event
->
accept
();
if
(
triggered
(
p
.
y
()))
{
if
(
deletable
()
&&
getIcon
(
"close"
)
->
triggered
(
p
.
x
()))
{
event
->
accept
();
deletePage
();
}
else
if
(
getIcon
(
"duplicate"
)
->
triggered
(
p
.
x
()))
{
event
->
accept
();
duplicatePage
();
}
else
{
event
->
ignore
();
}
/*
else if(movableUp() && getIcon("moveUp")->triggered(p.x()))
{
event->accept();
moveUpPage();
}
else if (movableDown() && getIcon("moveDown")->triggered(p.x()))
{
event->accept();
moveDownPage();
}
*/
}
else
{
event
->
ignore
();
}
}
void
UBSceneThumbnailNavigPixmap
::
deletePage
()
...
...
src/gui/UBThumbnailWidget.h
View file @
e60416f3
...
...
@@ -355,6 +355,41 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
UBSceneThumbnailNavigPixmap
(
const
QPixmap
&
pix
,
UBDocumentProxy
*
proxy
,
int
pSceneIndex
);
~
UBSceneThumbnailNavigPixmap
();
bool
editable
()
{
return
mEditable
;
}
bool
deletable
()
{
return
proxy
()
->
pageCount
()
>
1
;
}
bool
movableUp
()
{
return
sceneIndex
()
>
0
;
}
bool
movableDown
()
{
return
sceneIndex
()
<
(
proxy
()
->
pageCount
()
-
1
);
}
void
showUI
()
{
setEditable
(
true
);
}
void
hideUI
()
{
setEditable
(
false
);
}
void
setEditable
(
bool
editable
)
{
mEditable
=
editable
;
}
protected
:
void
hoverEnterEvent
(
QGraphicsSceneHoverEvent
*
event
);
void
hoverLeaveEvent
(
QGraphicsSceneHoverEvent
*
event
);
...
...
@@ -367,10 +402,7 @@ class UBSceneThumbnailNavigPixmap : public UBSceneThumbnailPixmap
void
moveUpPage
();
void
moveDownPage
();
bool
bButtonsVisible
;
bool
bCanDelete
;
bool
bCanMoveUp
;
bool
bCanMoveDown
;
bool
mEditable
;
};
class
UBImgTextThumbnailElement
...
...
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