Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pt2d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
pt2d
Commits
76afb30a
Commit
76afb30a
authored
2 months ago
by
Christian
Browse files
Options
Downloads
Patches
Plain Diff
Added mouse cursor changes disk size functionality
parent
98a35b34
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GUI_draft_live.py
+54
-4
54 additions, 4 deletions
GUI_draft_live.py
with
54 additions
and
4 deletions
GUI_draft_live.py
+
54
−
4
View file @
76afb30a
...
@@ -72,25 +72,66 @@ class PanZoomGraphicsView(QGraphicsView):
...
@@ -72,25 +72,66 @@ class PanZoomGraphicsView(QGraphicsView):
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# A specialized PanZoomGraphicsView for the circle editor
# A specialized PanZoomGraphicsView for the circle editor
# Only pan if user did NOT click on the draggable circle
# - Only pan if user did NOT click on the draggable circle
# - If the mouse is over the circle item, scrolling changes radius
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
class
CircleEditorGraphicsView
(
PanZoomGraphicsView
):
class
CircleEditorGraphicsView
(
PanZoomGraphicsView
):
def
__init__
(
self
,
circle_editor_widget
,
parent
=
None
):
"""
:param circle_editor_widget: Reference to the parent CircleEditorWidget
so we can communicate (e.g. update slider).
"""
super
().
__init__
(
parent
)
self
.
_circle_editor_widget
=
circle_editor_widget
def
mousePressEvent
(
self
,
event
):
def
mousePressEvent
(
self
,
event
):
if
event
.
button
()
==
Qt
.
LeftButton
:
if
event
.
button
()
==
Qt
.
LeftButton
:
# Check if the user clicked on the circle item
# Check if the user clicked on the circle item
clicked_item
=
self
.
itemAt
(
event
.
pos
()
.
x
(),
event
.
pos
().
y
()
)
clicked_item
=
self
.
itemAt
(
event
.
pos
())
if
clicked_item
is
not
None
:
if
clicked_item
is
not
None
:
# Walk up parent chain to see if it is our DraggableCircleItem
# Walk up parent chain to see if it is our DraggableCircleItem
it
=
clicked_item
it
=
clicked_item
while
it
is
not
None
and
not
hasattr
(
it
,
"
boundingRect
"
):
while
it
is
not
None
and
not
hasattr
(
it
,
"
boundingRect
"
):
it
=
it
.
parentItem
()
it
=
it
.
parentItem
()
from
PyQt5.QtWidgets
import
QGraphicsEllipseItem
if
isinstance
(
it
,
DraggableCircleItem
):
if
isinstance
(
it
,
DraggableCircleItem
):
# Let normal item-dragging occur, don't initiate panning
# Let normal item-dragging occur, don't initiate panning
return
QGraphicsView
.
mousePressEvent
(
self
,
event
)
return
QGraphicsView
.
mousePressEvent
(
self
,
event
)
# Otherwise proceed with normal panning logic
# Otherwise proceed with normal panning logic
super
().
mousePressEvent
(
event
)
super
().
mousePressEvent
(
event
)
def
wheelEvent
(
self
,
event
):
"""
Overridden so that if the mouse is hovering over the circle,
we adjust the circle
'
s radius instead of zooming the image.
"""
pos_in_widget
=
event
.
pos
()
item_under
=
self
.
itemAt
(
pos_in_widget
)
if
item_under
is
not
None
:
# climb up the chain to find if it's our DraggableCircleItem
it
=
item_under
while
it
is
not
None
and
not
hasattr
(
it
,
"
boundingRect
"
):
it
=
it
.
parentItem
()
if
isinstance
(
it
,
DraggableCircleItem
):
# Scroll up -> increase radius, scroll down -> decrease
delta
=
event
.
angleDelta
().
y
()
# each wheel "notch" is typically 120, so let's do small steps
step
=
1
if
delta
>
0
else
-
1
old_r
=
it
.
radius
()
new_r
=
max
(
1
,
old_r
+
step
)
it
.
set_radius
(
new_r
)
# Also update the slider in the parent CircleEditorWidget
self
.
_circle_editor_widget
.
update_slider_value
(
new_r
)
event
.
accept
()
return
# else do normal pan/zoom
super
().
wheelEvent
(
event
)
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# Draggable circle item (centered at (x, y) with radius)
# Draggable circle item (centered at (x, y) with radius)
...
@@ -141,7 +182,7 @@ class CircleEditorWidget(QWidget):
...
@@ -141,7 +182,7 @@ class CircleEditorWidget(QWidget):
self
.
setLayout
(
layout
)
self
.
setLayout
(
layout
)
# Use specialized CircleEditorGraphicsView
# Use specialized CircleEditorGraphicsView
self
.
_graphics_view
=
CircleEditorGraphicsView
()
self
.
_graphics_view
=
CircleEditorGraphicsView
(
circle_editor_widget
=
self
)
self
.
_scene
=
QGraphicsScene
(
self
)
self
.
_scene
=
QGraphicsScene
(
self
)
self
.
_graphics_view
.
setScene
(
self
.
_scene
)
self
.
_graphics_view
.
setScene
(
self
.
_scene
)
layout
.
addWidget
(
self
.
_graphics_view
)
layout
.
addWidget
(
self
.
_graphics_view
)
...
@@ -186,6 +227,15 @@ class CircleEditorWidget(QWidget):
...
@@ -186,6 +227,15 @@ class CircleEditorWidget(QWidget):
if
self
.
_done_callback
is
not
None
:
if
self
.
_done_callback
is
not
None
:
self
.
_done_callback
(
final_radius
)
self
.
_done_callback
(
final_radius
)
def
update_slider_value
(
self
,
new_radius
):
"""
Called by CircleEditorGraphicsView when the user scrolls on the circle item.
We sync the slider to the new radius.
"""
self
.
_slider
.
blockSignals
(
True
)
# to avoid recursively calling set_radius
self
.
_slider
.
setValue
(
new_radius
)
self
.
_slider
.
blockSignals
(
False
)
def
sizeHint
(
self
):
def
sizeHint
(
self
):
return
QSize
(
800
,
600
)
return
QSize
(
800
,
600
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment