mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use keypresses for fine adjustment of selection rect
This commit is contained in:
parent
a83476cea8
commit
543a33bc63
@ -108,6 +108,7 @@ class Canvas(QWidget):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.setMouseTracking(True)
|
self.setMouseTracking(True)
|
||||||
|
self.setFocusPolicy(Qt.ClickFocus)
|
||||||
self.selection_state = SelectionState()
|
self.selection_state = SelectionState()
|
||||||
self.undo_stack = QUndoStack()
|
self.undo_stack = QUndoStack()
|
||||||
self.undo_stack.setUndoLimit(10)
|
self.undo_stack.setUndoLimit(10)
|
||||||
@ -212,21 +213,24 @@ class Canvas(QWidget):
|
|||||||
maxv = sr.bottom() - buf if edge == 'top' else self.target.bottom()
|
maxv = sr.bottom() - buf if edge == 'top' else self.target.bottom()
|
||||||
func(max(minv, min(maxv, delta + getattr(sr, edge)())))
|
func(max(minv, min(maxv, delta + getattr(sr, edge)())))
|
||||||
|
|
||||||
def move_selection(self, dp):
|
def move_selection_rect(self, x, y):
|
||||||
sr = self.selection_state.rect
|
sr = self.selection_state.rect
|
||||||
|
half_width = sr.width() / 2.0
|
||||||
|
half_height = sr.height() / 2.0
|
||||||
|
c = sr.center()
|
||||||
|
nx = c.x() + x
|
||||||
|
ny = c.y() + y
|
||||||
|
minx = self.target.left() + half_width
|
||||||
|
maxx = self.target.right() - half_width
|
||||||
|
miny, maxy = self.target.top() + half_height, self.target.bottom() - half_height
|
||||||
|
nx = max(minx, min(maxx, nx))
|
||||||
|
ny = max(miny, min(maxy, ny))
|
||||||
|
sr.moveCenter(QPointF(nx, ny))
|
||||||
|
|
||||||
|
def move_selection(self, dp):
|
||||||
dm = self.selection_state.dragging
|
dm = self.selection_state.dragging
|
||||||
if dm is None:
|
if dm is None:
|
||||||
half_width = sr.width() / 2.0
|
self.move_selection_rect(dp.x(), dp.y())
|
||||||
half_height = sr.height() / 2.0
|
|
||||||
c = sr.center()
|
|
||||||
nx = c.x() + dp.x()
|
|
||||||
ny = c.y() + dp.y()
|
|
||||||
minx = self.target.left() + half_width
|
|
||||||
maxx = self.target.right() - half_width
|
|
||||||
miny, maxy = self.target.top() + half_height, self.target.bottom() - half_height
|
|
||||||
nx = max(minx, min(maxx, nx))
|
|
||||||
ny = max(miny, min(maxy, ny))
|
|
||||||
sr.moveCenter(QPointF(nx, ny))
|
|
||||||
else:
|
else:
|
||||||
for edge in dm:
|
for edge in dm:
|
||||||
if edge is not None:
|
if edge is not None:
|
||||||
@ -302,6 +306,21 @@ class Canvas(QWidget):
|
|||||||
self.update()
|
self.update()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
def keyPressEvent(self, ev):
|
||||||
|
k = ev.key()
|
||||||
|
if k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down) and self.has_selection:
|
||||||
|
ev.accept()
|
||||||
|
delta = 10 if ev.modifiers() & Qt.ShiftModifier else 1
|
||||||
|
x = y = 0
|
||||||
|
if k in (Qt.Key_Left, Qt.Key_Right):
|
||||||
|
x = delta * (-1 if k == Qt.Key_Left else 1)
|
||||||
|
else:
|
||||||
|
y = delta * (-1 if k == Qt.Key_Up else 1)
|
||||||
|
self.move_selection_rect(x, y)
|
||||||
|
self.update()
|
||||||
|
else:
|
||||||
|
return QWidget.keyPressEvent(self, ev)
|
||||||
|
|
||||||
# Painting {{{
|
# Painting {{{
|
||||||
@painter
|
@painter
|
||||||
def draw_background(self, painter):
|
def draw_background(self, painter):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user