diff --git a/clusterview/mode_handlers.py b/clusterview/mode_handlers.py index 52699e2..b5b8028 100644 --- a/clusterview/mode_handlers.py +++ b/clusterview/mode_handlers.py @@ -112,61 +112,101 @@ def __handle_edit_point(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 __mouse_start global __point_set set_drawing_event(event) - if event.button() == Qt.LeftButton: - - # 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): + print(event.type()) - if __left_click_flag is __ClickFlag.NONE: - __left_click_flag = __ClickFlag.SELECTION_BOX - - 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 - 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): + # This if statement block is used to set the bounding box for + # drawing and call the selection procedure. + if (event.button() == Qt.LeftButton and + event.type() == QEvent.MouseButtonPress): + 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()) - elif (__left_click_flag is __ClickFlag.SELECTION_MOVE - and event.type() == QEvent.MouseMove): - - for p in __point_set: - if p.selected: - p.move_point(__mouse_start[0] - event.x(), - __mouse_start[1] - event.y()) + # Satisfy the post condition by resetting the bounding box + reset_move_bbs() + 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 - event.type() == QEvent.MouseButtonRelease): + # TODO: THIS KEY PRESS IS BROKEN AND THE CLICK TO CANCEL BEHAVIOR + # 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 - set_move_bb_bottom_right(event.x(), event.y()) + if __left_click_flag is __ClickFlag.SELECTION_MOVE: + __mouse_start = None - # Satisfy the post condition by resetting the bounding box - reset_move_bbs() - - if __left_click_flag is __ClickFlag.SELECTION_MOVE: - __mouse_start = None + __left_click_flag = __ClickFlag.NONE + __point_set.clear_selection() + ctx.point_list_widget.update() ctx.opengl_widget.update() def __handle_delete_point(ctx, event):