Add keyboard nudging for selected objects

This commit is contained in:
2026-06-30 15:04:38 +08:00
parent 04f1d901b2
commit 25274a9d95
2 changed files with 44 additions and 6 deletions
+6 -6
View File
@@ -22,10 +22,10 @@
## 注释:旧功能完善
- [ ] 高亮、下划线、删除线保留“输入文字查找后标注”的备用方式。
- [x] 高亮、下划线、删除线保留“输入文字查找后标注”的备用方式。
- [x] 图形注释支持修改颜色、线宽、透明度。
- [x] 自由画笔支持颜色、线宽、透明度。
- [ ] 注释创建后自动刷新右侧注释列表。
- [x] 注释创建后自动刷新右侧注释列表。
- [x] 注释删除后自动刷新右侧注释列表。
- [x] 阅读模式下禁止选中注释对象。
@@ -45,16 +45,16 @@
- [ ] 遮盖后添加文字。
- [ ] 对象复制。
- [ ] 对象粘贴。
- [ ] 方向键微调对象。
- [ ] Shift+方向键大步移动对象。
- [x] 方向键微调对象。
- [x] Shift+方向键大步移动对象。
- [ ] 对象图层顺序:置顶、置底、上移、下移。
- [ ] 页面内对象列表。
## 编辑:旧功能完善
- [ ] 文本、图片、签名、遮盖、图形注释使用统一选择框。
- [ ] Delete 删除选中对象。
- [ ] Esc 取消当前选择。
- [x] Delete 删除选中对象。
- [x] Esc 取消当前选择。
- [ ] 右键菜单支持删除、复制、属性。
- [ ] 保存前正确固化当前会话对象。
- [ ] 所有对象变更触发未保存状态。
+38
View File
@@ -1867,6 +1867,28 @@ class MainWindow(QMainWindow):
QMessageBox.critical(self, "对象更新失败", f"无法更新对象:\n{exc}")
self.viewer.render()
def nudge_selected_object(self, dx: float, dy: float) -> bool:
page_index, rect = self._selected_object_rect()
if page_index is None or rect is None:
return False
x0, y0, x1, y1 = rect
self.update_selected_object_rect(page_index, (x0 + dx, y0 + dy, x1 + dx, y1 + dy))
return True
def _selected_object_rect(self) -> tuple[int | None, tuple[float, float, float, float] | None]:
if self.selected_raster_id is not None:
raster = self._session_raster_by_id(self.selected_raster_id)
if raster:
return int(raster["page_index"]), raster["rect"]
return None, None
if self.selected_annotation:
rect = self.selected_annotation.rect or self.document.annotation_rect(
self.selected_annotation.page_index,
self.selected_annotation.xref,
)
return self.selected_annotation.page_index, rect
return None, None
def delete_selected_object(self) -> None:
if self.selected_raster_id is not None:
raster_id = self.selected_raster_id
@@ -1939,6 +1961,22 @@ class MainWindow(QMainWindow):
self.delete_selected_object()
return
if self.document.is_open and not isinstance(self.focusWidget(), QLineEdit):
has_movable_selection = self.selected_raster_id is not None or (
self.selected_annotation is not None and self.select_object_action.isChecked()
)
if has_movable_selection:
step = 10 if event.modifiers() & Qt.KeyboardModifier.ShiftModifier else 1
offsets = {
Qt.Key.Key_Left: (-step, 0),
Qt.Key.Key_Right: (step, 0),
Qt.Key.Key_Up: (0, -step),
Qt.Key.Key_Down: (0, step),
}
if event.key() in offsets:
dx, dy = offsets[event.key()]
if self.nudge_selected_object(dx, dy):
event.accept()
return
if event.key() == Qt.Key.Key_Left:
self.previous_page()
event.accept()