def gen_dim(self, idx: int, always_above: bool = True) -> 'npt.NDArray[numpy.float64]': """ Generate rendering data for the dimension-lines :param idx: :return: """ a = self.im2V(self.model.dim_handles[0 + idx]) b = self.im2V(self.model.dim_handles[1 + idx]) d = b - a delta = (b - a).norm() normal = Vec2.from_mat(rotate(math.pi / 2)[:2, :2].dot(delta)) if always_above: if numpy.cross(Vec2(1, 0), normal) > 0: normal = -normal res = numpy.array([ a + normal * 8, a + normal * 20, a + normal * 15, b + normal * 15, b + normal * 8, b + normal * 20, ], dtype=numpy.float64) return res
def keyPressEvent(self, evt: QtGui.QKeyEvent) -> bool: if self.disabled: return False if evt.key() == QtCore.Qt.Key_Escape: self.__idx_handle_sel = None elif self.__idx_handle_sel is not None: if evt.key() in (QtCore.Qt.Key_Delete, QtCore.Qt.Key_Backspace) and IDX_IS_LINE(self.__idx_handle_sel): cmd = cmd_set_handle_position(self.model, self.__idx_handle_sel, None) self._parent.undoStack.push(cmd) # self.model.set_handle(self.__idx_handle_sel, None) self.__idx_handle_sel = None # Basic 1-px nudging elif evt.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right, QtCore.Qt.Key_Up, QtCore.Qt.Key_Down): _nudgetab: Dict[int,Tuple[int, int]] = { QtCore.Qt.Key_Left: (-1, 0), QtCore.Qt.Key_Right: (1, 0), QtCore.Qt.Key_Up: (0, -1), QtCore.Qt.Key_Down: (0, 1), } nudge = _nudgetab[evt.key()] current = self.im2V(self.model.align_handles[self.__idx_handle_sel]) viewspace = self.V2im(current + Vec2.from_mat(nudge)) cmd = cmd_set_handle_position(self.model, self.__idx_handle_sel, viewspace) self._parent.undoStack.push(cmd) # self.model.set_handle(self.__idx_handle_sel, viewspace) self.__ghost_handle = None
def keyPressEvent(self, evt: QtGui.QKeyEvent) -> None: if evt.key() == QtCore.Qt.Key_Escape: self.model.kp.selected_idx = None elif self.model.kp.selected_idx is not None: if evt.key() in (QtCore.Qt.Key_Delete, QtCore.Qt.Key_Backspace): cmd = cmd_del_keypoint(self.model.kp, self.model.kp.selected_idx) self._parent.undoStack.push(cmd) self.model.kp.selected_idx = None # Basic 1-px nudging elif evt.key() in (QtCore.Qt.Key_Left, QtCore.Qt.Key_Right, QtCore.Qt.Key_Up, QtCore.Qt.Key_Down): kp_lut: Dict[int, Tuple[int, int]] = { QtCore.Qt.Key_Left: (-1, 0), QtCore.Qt.Key_Right: (1, 0), QtCore.Qt.Key_Up: (0, -1), QtCore.Qt.Key_Down: (0, 1), } nudge = Vec2.from_mat(kp_lut[evt.key()]) current = self.get_keypoint_viewport_center( self.model.kp.keypoints[self.model.kp.selected_idx]) self.do_set_cmd(current + nudge, True)