Browse Source

SO CLOSE

tb-init-ui-render
Taylor Bockman 5 years ago
parent
commit
0fc793e68d
  1. 120
      clusterview/mode_handlers.py

120
clusterview/mode_handlers.py

@ -112,61 +112,101 @@ def __handle_edit_point(ctx, event):
def __handle_move_points(ctx, event): def __handle_move_points(ctx, event):
"""
A relatively complicated state machine that handles the process of
selection, clicking, and dragging.
@param ctx The context to the window.
@param event The event.
"""
global __left_click_flag global __left_click_flag
global __mouse_start global __mouse_start
global __point_set global __point_set
set_drawing_event(event) set_drawing_event(event)
if event.button() == Qt.LeftButton: print(event.type())
# This if statement block is used to set the bounding box for
# drawing and call the selection procedure.
if (__left_click_flag is __ClickFlag.SELECTION_BOX and
event.type() == QEvent.MouseButtonPress):
if __left_click_flag is __ClickFlag.NONE: # This if statement block is used to set the bounding box for
__left_click_flag = __ClickFlag.SELECTION_BOX # drawing and call the selection procedure.
if (event.button() == Qt.LeftButton and
elif __left_click_flag is __ClickFlag.SELECTION_BOX: event.type() == QEvent.MouseButtonPress):
# We are now in the click-and-hold to signal move
# tracking and translation
__left_click_flag = __ClickFlag.SELECTION_MOVE
else:
__left_click_flag = ClickFlag.NONE
if __left_click_flag is __ClickFlag.SELECTION_BOX:
set_move_bb_top_left(event.x(), event.y())
elif __left_click_flag is __ClickFlag.SELECTION_MOVE:
__mouse_start = (event.x(), event.y())
elif (__left_click_flag is __ClickFlag.SELECTION_BOX
and event.type() == QEvent.MouseMove):
if __left_click_flag is __ClickFlag.NONE:
__left_click_flag = __ClickFlag.SELECTION_BOX
set_move_bb_top_left(event.x(), event.y())
elif __left_click_flag is __ClickFlag.SELECTION_BOX:
# We are now in the click-and-hold to signal move
# tracking and translation
__left_click_flag = __ClickFlag.SELECTION_MOVE
__mouse_start = (event.x(), event.y())
else:
__left_click_flag = __ClickFlag.NONE
elif (__left_click_flag is __ClickFlag.SELECTION_BOX
and event.type() == QEvent.MouseMove):
set_move_bb_bottom_right(event.x(), event.y())
elif (__left_click_flag is __ClickFlag.SELECTION_MOVE
and __mouse_start is not None
and event.type() == QEvent.MouseMove):
dx = __mouse_start[0] - event.x()
dy = __mouse_start[1] - event.y()
for p in __point_set.points:
if p.selected:
# Use the deltas to decide what direction to move.
# We only want to move in small unit increments.
# If we used the deltas directly the points would
# fly off screen quickly as we got farther from our
# start.
# TODO: THIS IS NUTS RIGHT NOW
# WE SHOULD NOT ALLOW ANY POINT TO EXCEED
# THE MAXIMUM SIZE OF THE SCREEN.
if dx > 0 and dy > 0:
p.move(10, 10)
elif dx > 0 and dy == 0:
p.move(10, 0)
elif dx < 0 and dy == 0:
p.move(-10, 0)
elif dx == 0 and dy > 0:
p.move(0, 10)
elif dx == 0 and dy < 0:
p.move(0, -10)
elif (__left_click_flag is not __ClickFlag.NONE and
event.type() == QEvent.MouseButtonRelease):
# Final bottom right corner point
if __left_click_flag is __ClickFlag.SELECTION_BOX:
set_move_bb_bottom_right(event.x(), event.y()) set_move_bb_bottom_right(event.x(), event.y())
elif (__left_click_flag is __ClickFlag.SELECTION_MOVE # Satisfy the post condition by resetting the bounding box
and event.type() == QEvent.MouseMove): reset_move_bbs()
for p in __point_set:
if p.selected:
p.move_point(__mouse_start[0] - event.x(),
__mouse_start[1] - event.y())
elif (__left_click_flag is not __ClickFlag.NONE
and event.type() == QEvent.KeyPress
and event.key() == Qt.Key_Escape):
elif (__left_click_flag is not __ClickFlag.NONE and # TODO: THIS KEY PRESS IS BROKEN AND THE CLICK TO CANCEL BEHAVIOR
event.type() == QEvent.MouseButtonRelease): # NEED TO BE REMOVED. YOU NEED TO OVERWRITE THE KEY PRESS
# EVENT ON THE OPENGL WIDGET. IF MODE IS MOVE AND ESCAPE IS
# PRESSED CANCEL ALL SELECTIONS!!
# Final bottom right corner point if __left_click_flag is __ClickFlag.SELECTION_MOVE:
set_move_bb_bottom_right(event.x(), event.y()) __mouse_start = None
# Satisfy the post condition by resetting the bounding box __left_click_flag = __ClickFlag.NONE
reset_move_bbs() __point_set.clear_selection()
if __left_click_flag is __ClickFlag.SELECTION_MOVE:
__mouse_start = None
ctx.point_list_widget.update()
ctx.opengl_widget.update() ctx.opengl_widget.update()
def __handle_delete_point(ctx, event): def __handle_delete_point(ctx, event):

Loading…
Cancel
Save