Fix #1959893 [Trim Image - Size of selected area is incorrect](https://bugs.launchpad.net/calibre/+bug/1959893)

This commit is contained in:
Kovid Goyal 2022-02-03 19:14:05 +05:30
parent 57d24f0538
commit ed209b9374
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 7 deletions

View File

@ -83,10 +83,9 @@ class TrimImage(QDialog):
def selection_area_changed(self, rect): def selection_area_changed(self, rect):
if rect: if rect:
w = rect.width() x, y, w, h = map(int, self.canvas.rect_for_trim())
h = rect.height()
text = f'{int(w)}x{int(h)}' text = f'{int(w)}x{int(h)}'
text = _('Size: {0}px Aspect ratio: {1:.2g}').format(text, w / h) text = _('Size: {0}px Aspect ratio: {1:.3g}').format(text, w / h)
else: else:
text = '' text = ''
self.tr_sz.setText(text) self.tr_sz.setText(text)

View File

@ -93,10 +93,7 @@ class Trim(Command):
TEXT = _('Trim image') TEXT = _('Trim image')
def __call__(self, canvas): def __call__(self, canvas):
img = canvas.current_image return canvas.current_image.copy(*map(int, canvas.rect_for_trim()))
target = canvas.target
sr = canvas.selection_state.rect
return img.copy(*map(int, get_selection_rect(img, sr, target)))
class AutoTrim(Trim): class AutoTrim(Trim):
@ -502,6 +499,12 @@ class Canvas(QWidget):
if edge is not None: if edge is not None:
self.move_edge(edge, dp) self.move_edge(edge, dp)
def rect_for_trim(self):
img = self.current_image
target = self.target
sr = self.selection_state.rect
return get_selection_rect(img, sr, target)
def mousePressEvent(self, ev): def mousePressEvent(self, ev):
if ev.button() == Qt.MouseButton.LeftButton and self.target.contains(ev.pos()): if ev.button() == Qt.MouseButton.LeftButton and self.target.contains(ev.pos()):
pos = ev.pos() pos = ev.pos()