mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add a copy button to the image view popup. Fixes #1966851 [Enhancement Request: Copy image in Image Viewer](https://bugs.launchpad.net/calibre/+bug/1966851)
This commit is contained in:
parent
b5e5f1a10b
commit
19a9346296
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QImage,
|
QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QImage,
|
||||||
QLabel, QPainter, QPalette, QPixmap, QScrollArea, QSize, QSizePolicy,
|
QLabel, QPainter, QPalette, QPixmap, QScrollArea, QSize, QSizePolicy,
|
||||||
QSvgRenderer, Qt, QTransform, QUrl, QVBoxLayout, pyqtSignal
|
QSvgRenderer, Qt, QTransform, QUrl, QVBoxLayout, pyqtSignal, QAction, QKeySequence
|
||||||
)
|
)
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
@ -120,16 +120,23 @@ class ImageView(QDialog):
|
|||||||
self.zi_button = zi = bb.addButton(_('Zoom &in'), QDialogButtonBox.ButtonRole.ActionRole)
|
self.zi_button = zi = bb.addButton(_('Zoom &in'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
self.zo_button = zo = bb.addButton(_('Zoom &out'), QDialogButtonBox.ButtonRole.ActionRole)
|
self.zo_button = zo = bb.addButton(_('Zoom &out'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
self.save_button = so = bb.addButton(_('&Save as'), QDialogButtonBox.ButtonRole.ActionRole)
|
self.save_button = so = bb.addButton(_('&Save as'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
|
self.copy_button = co = bb.addButton(_('&Copy'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
self.rotate_button = ro = bb.addButton(_('&Rotate'), QDialogButtonBox.ButtonRole.ActionRole)
|
self.rotate_button = ro = bb.addButton(_('&Rotate'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
self.fullscreen_button = fo = bb.addButton(_('&Full screen'), QDialogButtonBox.ButtonRole.ActionRole)
|
self.fullscreen_button = fo = bb.addButton(_('&Full screen'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||||
zi.setIcon(QIcon(I('plus.png')))
|
zi.setIcon(QIcon(I('plus.png')))
|
||||||
zo.setIcon(QIcon(I('minus.png')))
|
zo.setIcon(QIcon(I('minus.png')))
|
||||||
so.setIcon(QIcon(I('save.png')))
|
so.setIcon(QIcon(I('save.png')))
|
||||||
|
co.setIcon(QIcon.ic('edit-copy.png'))
|
||||||
ro.setIcon(QIcon(I('rotate-right.png')))
|
ro.setIcon(QIcon(I('rotate-right.png')))
|
||||||
fo.setIcon(QIcon(I('page.png')))
|
fo.setIcon(QIcon(I('page.png')))
|
||||||
zi.clicked.connect(self.zoom_in)
|
zi.clicked.connect(self.zoom_in)
|
||||||
zo.clicked.connect(self.zoom_out)
|
zo.clicked.connect(self.zoom_out)
|
||||||
so.clicked.connect(self.save_image)
|
so.clicked.connect(self.save_image)
|
||||||
|
co.clicked.connect(self.copy_image)
|
||||||
|
self.copy_action = QAction(self)
|
||||||
|
self.addAction(self.copy_action)
|
||||||
|
self.copy_action.triggered.connect(self.copy_button.click)
|
||||||
|
self.copy_action.setShortcut(QKeySequence.StandardKey.Copy)
|
||||||
ro.clicked.connect(self.rotate_image)
|
ro.clicked.connect(self.rotate_image)
|
||||||
fo.setCheckable(True)
|
fo.setCheckable(True)
|
||||||
|
|
||||||
@ -196,6 +203,10 @@ class ImageView(QDialog):
|
|||||||
from calibre.utils.img import save_image
|
from calibre.utils.img import save_image
|
||||||
save_image(self.current_img.toImage(), f)
|
save_image(self.current_img.toImage(), f)
|
||||||
|
|
||||||
|
def copy_image(self):
|
||||||
|
if self.current_img and not self.current_img.isNull():
|
||||||
|
QApplication.instance().clipboard().setPixmap(self.current_img)
|
||||||
|
|
||||||
def fit_changed(self):
|
def fit_changed(self):
|
||||||
fitted = bool(self.fit_image.isChecked())
|
fitted = bool(self.fit_image.isChecked())
|
||||||
self.prefs.set('image_popup_fit_image', fitted)
|
self.prefs.set('image_popup_fit_image', fitted)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user