Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Graphics
Okular
Commits
55e074c8
Commit
55e074c8
authored
Aug 01, 2022
by
Nikola Nikolic
Committed by
Albert Astals Cid
Aug 05, 2022
Browse files
Prevent popup note from being dragged outside the viewport
BUG: 423363
parent
915e8230
Pipeline
#213702
passed with stage
in 8 minutes and 12 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
part/annotwindow.cpp
View file @
55e074c8
...
...
@@ -139,10 +139,36 @@ public:
case
QEvent
::
MouseButtonRelease
:
mousePressPos
=
QPoint
();
break
;
case
QEvent
::
MouseMove
:
case
QEvent
::
MouseMove
:
{
me
=
(
QMouseEvent
*
)
e
;
parentWidget
()
->
move
(
me
->
pos
()
-
mousePressPos
+
parentWidget
()
->
pos
());
// viewport info
const
QPoint
topLeftPoint
=
parentWidget
()
->
parentWidget
()
->
pos
();
const
int
viewportHeight
=
parentWidget
()
->
parentWidget
()
->
height
();
const
int
viewportWidth
=
parentWidget
()
->
parentWidget
()
->
width
();
// annotation's popup window info
QPoint
newPositionPoint
=
me
->
pos
()
-
mousePressPos
+
parentWidget
()
->
pos
();
const
int
annotHeight
=
parentWidget
()
->
height
();
const
int
annotWidth
=
parentWidget
()
->
width
();
// make sure x is in range
if
(
newPositionPoint
.
x
()
<
topLeftPoint
.
x
())
{
newPositionPoint
.
setX
(
topLeftPoint
.
x
());
}
else
if
(
newPositionPoint
.
x
()
+
annotWidth
>
topLeftPoint
.
x
()
+
viewportWidth
)
{
newPositionPoint
.
setX
(
topLeftPoint
.
x
()
+
viewportWidth
-
annotWidth
);
}
// make sure y is in range
if
(
newPositionPoint
.
y
()
<
topLeftPoint
.
y
())
{
newPositionPoint
.
setY
(
topLeftPoint
.
y
());
}
else
if
(
newPositionPoint
.
y
()
+
annotHeight
>
topLeftPoint
.
y
()
+
viewportHeight
)
{
newPositionPoint
.
setY
(
topLeftPoint
.
y
()
+
viewportHeight
-
annotHeight
);
}
parentWidget
()
->
move
(
newPositionPoint
);
break
;
}
default:
return
false
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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