mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Fix #1959893 [Trim Image - Size of selected area is incorrect](https://bugs.launchpad.net/calibre/+bug/1959893)
This commit is contained in:
parent
57d24f0538
commit
ed209b9374
@ -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)
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user