|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
from enum import Enum |
|
|
|
|
|
|
|
|
|
from PyQt5.QtCore import QEvent, Qt |
|
|
|
|
|
|
|
|
|
from .mode import Mode |
|
|
|
@ -7,6 +9,25 @@ from .opengl_widget import (get_bb_bottom_right, get_bb_top_left,
|
|
|
|
|
reset_move_bbs) |
|
|
|
|
from .points import PointSet |
|
|
|
|
|
|
|
|
|
class __ClickFlag: |
|
|
|
|
|
|
|
|
|
# This is the first stage. On mouse release it goes to |
|
|
|
|
# SELECTION_MOVE. |
|
|
|
|
NONE = 0 |
|
|
|
|
|
|
|
|
|
# We are now in selection box mode. |
|
|
|
|
SELECTION_BOX = 1 |
|
|
|
|
|
|
|
|
|
# Second stage - we have selected a number of points |
|
|
|
|
# and now we are going to track the left mouse button |
|
|
|
|
# to translate those points. After a left click |
|
|
|
|
# this moves to SELECTED_MOVED. |
|
|
|
|
SELECTION_MOVE = 2 |
|
|
|
|
|
|
|
|
|
# Any subsequent click in this mode will send it back |
|
|
|
|
# to NONE - we are done. |
|
|
|
|
SELECTED_MOVED = 3 |
|
|
|
|
|
|
|
|
|
# Size of point for drawing |
|
|
|
|
__POINT_SIZE = 8 |
|
|
|
|
|
|
|
|
@ -16,7 +37,10 @@ __point_set = PointSet(__POINT_SIZE)
|
|
|
|
|
|
|
|
|
|
# Module level flag for left click events (used to detect a left |
|
|
|
|
# click hold drag) |
|
|
|
|
__left_click_flag = False |
|
|
|
|
__left_click_flag = __ClickFlag.NONE |
|
|
|
|
|
|
|
|
|
# Variable to track the mouse state during selection movement |
|
|
|
|
__mouse_start = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __refresh_point_list(ctx): |
|
|
|
@ -50,6 +74,9 @@ def __handle_add_point(ctx, event):
|
|
|
|
|
if (event.button() == Qt.LeftButton and |
|
|
|
|
event.type() == QEvent.MouseButtonPress): |
|
|
|
|
|
|
|
|
|
# Clear any existing selections |
|
|
|
|
__point_set.clear_selection() |
|
|
|
|
|
|
|
|
|
# No attribute at the moment. |
|
|
|
|
__point_set.add_point(event.x(), event.y()) |
|
|
|
|
|
|
|
|
@ -74,6 +101,9 @@ def __handle_edit_point(ctx, event):
|
|
|
|
|
# |
|
|
|
|
# Should move the associated point in the list to the new location if |
|
|
|
|
# applicable. |
|
|
|
|
global __point_set |
|
|
|
|
|
|
|
|
|
__point_set.clear_selection() |
|
|
|
|
|
|
|
|
|
# Store old x, y from event |
|
|
|
|
set_drawing_event(event) |
|
|
|
@ -83,25 +113,50 @@ def __handle_edit_point(ctx, event):
|
|
|
|
|
|
|
|
|
|
def __handle_move_points(ctx, event): |
|
|
|
|
global __left_click_flag |
|
|
|
|
global __mouse_start |
|
|
|
|
global __point_set |
|
|
|
|
|
|
|
|
|
set_drawing_event(event) |
|
|
|
|
|
|
|
|
|
if event.button() == Qt.LeftButton: |
|
|
|
|
__left_click_flag = True |
|
|
|
|
|
|
|
|
|
# This if statement block is used to set the bounding box for |
|
|
|
|
# drawing and call the selection procedure. |
|
|
|
|
if __left_click_flag and event.type() == QEvent.MouseButtonPress: |
|
|
|
|
if (__left_click_flag is __ClickFlag.SELECTION_BOX and |
|
|
|
|
event.type() == QEvent.MouseButtonPress): |
|
|
|
|
|
|
|
|
|
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 and event.type() == QEvent.MouseMove: |
|
|
|
|
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): |
|
|
|
|
|
|
|
|
|
set_move_bb_bottom_right(event.x(), event.y()) |
|
|
|
|
|
|
|
|
|
elif __left_click_flag and event.type() == QEvent.MouseButtonRelease: |
|
|
|
|
elif (__left_click_flag is __ClickFlag.SELECTION_MOVE |
|
|
|
|
and event.type() == QEvent.MouseMove): |
|
|
|
|
|
|
|
|
|
__left_click_flag = False |
|
|
|
|
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.MouseButtonRelease): |
|
|
|
|
|
|
|
|
|
# Final bottom right corner point |
|
|
|
|
set_move_bb_bottom_right(event.x(), event.y()) |
|
|
|
@ -109,14 +164,11 @@ def __handle_move_points(ctx, event):
|
|
|
|
|
# Satisfy the post condition by resetting the bounding box |
|
|
|
|
reset_move_bbs() |
|
|
|
|
|
|
|
|
|
# Fix the highlighted pointed into a set (separate from point_set) and |
|
|
|
|
# prepare to move. |
|
|
|
|
if __left_click_flag is __ClickFlag.SELECTION_MOVE: |
|
|
|
|
__mouse_start = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Find and move all points from the old list to their new locations |
|
|
|
|
ctx.opengl_widget.update() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __handle_delete_point(ctx, event): |
|
|
|
|
if (event.button() == Qt.LeftButton and |
|
|
|
|
event.type() == QEvent.MouseButtonPress): |
|
|
|
|