mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Edit Book: When inserting images, add an option to insert the image as a full page image
This commit is contained in:
parent
b090f18d81
commit
12df3ac3c4
@ -71,6 +71,8 @@ d['auto_close_tags'] = True
|
|||||||
d['restore_book_state'] = True
|
d['restore_book_state'] = True
|
||||||
d['editor_accepts_drops'] = True
|
d['editor_accepts_drops'] = True
|
||||||
d['toolbar_icon_size'] = 24
|
d['toolbar_icon_size'] = 24
|
||||||
|
d['insert_full_screen_image'] = False
|
||||||
|
d['preserve_aspect_ratio_when_inserting_image'] = False
|
||||||
del d
|
del d
|
||||||
|
|
||||||
ucase_map = {l:string.ascii_uppercase[i] for i, l in enumerate(string.ascii_lowercase)}
|
ucase_map = {l:string.ascii_uppercase[i] for i, l in enumerate(string.ascii_lowercase)}
|
||||||
|
@ -776,14 +776,14 @@ class Boss(QObject):
|
|||||||
if rdata is None:
|
if rdata is None:
|
||||||
return
|
return
|
||||||
if rtype == 'image':
|
if rtype == 'image':
|
||||||
chosen_name, chosen_image_is_external = rdata
|
chosen_name, chosen_image_is_external, fullpage, preserve_ar = rdata
|
||||||
if chosen_image_is_external:
|
if chosen_image_is_external:
|
||||||
with open(chosen_image_is_external[1], 'rb') as f:
|
with open(chosen_image_is_external[1], 'rb') as f:
|
||||||
current_container().add_file(chosen_image_is_external[0], f.read())
|
current_container().add_file(chosen_image_is_external[0], f.read())
|
||||||
self.refresh_file_list()
|
self.refresh_file_list()
|
||||||
chosen_name = chosen_image_is_external[0]
|
chosen_name = chosen_image_is_external[0]
|
||||||
href = current_container().name_to_href(chosen_name, edname)
|
href = current_container().name_to_href(chosen_name, edname)
|
||||||
ed.insert_image(href)
|
ed.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_ar)
|
||||||
elif action[0] == 'insert_hyperlink':
|
elif action[0] == 'insert_hyperlink':
|
||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
||||||
|
@ -11,10 +11,10 @@ from functools import partial
|
|||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QGridLayout, QSize, QListView, QStyledItemDelegate, QLabel, QPixmap,
|
QGridLayout, QSize, QListView, QStyledItemDelegate, QLabel, QPixmap,
|
||||||
QApplication, QSizePolicy, QAbstractListModel, Qt, QRect,
|
QApplication, QSizePolicy, QAbstractListModel, Qt, QRect, QCheckBox,
|
||||||
QPainter, QModelIndex, QSortFilterProxyModel, QLineEdit, QToolButton,
|
QPainter, QModelIndex, QSortFilterProxyModel, QLineEdit, QToolButton,
|
||||||
QIcon, QFormLayout, pyqtSignal, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
|
QIcon, QFormLayout, pyqtSignal, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
|
||||||
QMenu, QInputDialog)
|
QMenu, QInputDialog, QHBoxLayout)
|
||||||
|
|
||||||
from calibre import fit_image
|
from calibre import fit_image
|
||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
@ -226,7 +226,6 @@ class InsertImage(Dialog):
|
|||||||
l.addWidget(b, 2, 1)
|
l.addWidget(b, 2, 1)
|
||||||
f.textChanged.connect(self.filter_changed)
|
f.textChanged.connect(self.filter_changed)
|
||||||
|
|
||||||
l.addWidget(self.bb, 3, 0, 1, 2)
|
|
||||||
if self.for_browsing:
|
if self.for_browsing:
|
||||||
self.bb.clear()
|
self.bb.clear()
|
||||||
self.bb.addButton(self.bb.Close)
|
self.bb.addButton(self.bb.Close)
|
||||||
@ -244,6 +243,19 @@ class InsertImage(Dialog):
|
|||||||
b.clicked.connect(self.paste_image)
|
b.clicked.connect(self.paste_image)
|
||||||
b.setIcon(QIcon(I('edit-paste.png')))
|
b.setIcon(QIcon(I('edit-paste.png')))
|
||||||
b.setToolTip(_('Paste an image from the clipboard'))
|
b.setToolTip(_('Paste an image from the clipboard'))
|
||||||
|
self.fullpage = f = QCheckBox(_('Full page image'), self)
|
||||||
|
f.setToolTip(_('Insert the image so that it takes up an entire page when viewed in a reader'))
|
||||||
|
f.setChecked(tprefs['insert_full_screen_image'])
|
||||||
|
self.preserve_aspect_ratio = a = QCheckBox(_('Preserve aspect ratio'))
|
||||||
|
a.setToolTip(_('Preserve the aspect ratio of the inserted image when rendering it full paged'))
|
||||||
|
a.setChecked(tprefs['preserve_aspect_ratio_when_inserting_image'])
|
||||||
|
f.toggled.connect(lambda : (tprefs.set('insert_full_screen_image', f.isChecked()), a.setVisible(f.isChecked())))
|
||||||
|
a.toggled.connect(lambda : tprefs.set('preserve_aspect_ratio_when_inserting_image', a.isChecked()))
|
||||||
|
a.setVisible(f.isChecked())
|
||||||
|
h = QHBoxLayout()
|
||||||
|
l.addLayout(h, 3, 0, 1, -1)
|
||||||
|
h.addWidget(f), h.addStretch(10), h.addWidget(a)
|
||||||
|
l.addWidget(self.bb, 4, 0, 1, 2)
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.d.cover_cache.clear()
|
self.d.cover_cache.clear()
|
||||||
@ -305,7 +317,7 @@ def get_resource_data(rtype, parent):
|
|||||||
if rtype == 'image':
|
if rtype == 'image':
|
||||||
d = InsertImage(parent)
|
d = InsertImage(parent)
|
||||||
if d.exec_() == d.Accepted:
|
if d.exec_() == d.Accepted:
|
||||||
return d.chosen_image, d.chosen_image_is_external
|
return d.chosen_image, d.chosen_image_is_external, d.fullpage.isChecked(), d.preserve_aspect_ratio.isChecked()
|
||||||
|
|
||||||
def create_folder_tree(container):
|
def create_folder_tree(container):
|
||||||
root = {}
|
root = {}
|
||||||
|
@ -682,7 +682,7 @@ class TextEdit(PlainTextEdit):
|
|||||||
c.setPosition(c.position() - len(suffix))
|
c.setPosition(c.position() - len(suffix))
|
||||||
self.setTextCursor(c)
|
self.setTextCursor(c)
|
||||||
|
|
||||||
def insert_image(self, href):
|
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False):
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
template, alt = 'url(%s)', ''
|
template, alt = 'url(%s)', ''
|
||||||
left = min(c.position(), c.anchor)
|
left = min(c.position(), c.anchor)
|
||||||
@ -690,12 +690,19 @@ class TextEdit(PlainTextEdit):
|
|||||||
left, right = self.get_range_inside_tag()
|
left, right = self.get_range_inside_tag()
|
||||||
c.setPosition(left)
|
c.setPosition(left)
|
||||||
c.setPosition(right, c.KeepAnchor)
|
c.setPosition(right, c.KeepAnchor)
|
||||||
alt = _('Image')
|
|
||||||
template = '<img alt="{0}" src="%s" />'.format(alt)
|
|
||||||
href = prepare_string_for_xml(href, True)
|
href = prepare_string_for_xml(href, True)
|
||||||
|
if fullpage:
|
||||||
|
template = '''\
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \
|
||||||
|
version="1.1" width="100%%" height="100%%" viewBox="0 0 1200 1600" preserveAspectRatio="{}">\
|
||||||
|
<image width="1200" height="1600" xlink:href="%s"/>\
|
||||||
|
</svg>'''.format('xMidYMid meet' if preserve_aspect_ratio else 'none')
|
||||||
|
else:
|
||||||
|
alt = _('Image')
|
||||||
|
template = '<img alt="{0}" src="%s" />'.format(alt)
|
||||||
text = template % href
|
text = template % href
|
||||||
c.insertText(text)
|
c.insertText(text)
|
||||||
if self.syntax == 'html':
|
if self.syntax == 'html' and not fullpage:
|
||||||
c.setPosition(left + 10)
|
c.setPosition(left + 10)
|
||||||
c.setPosition(c.position() + len(alt), c.KeepAnchor)
|
c.setPosition(c.position() + len(alt), c.KeepAnchor)
|
||||||
else:
|
else:
|
||||||
|
@ -221,8 +221,8 @@ class Editor(QMainWindow):
|
|||||||
func = getattr(self.editor, action)
|
func = getattr(self.editor, action)
|
||||||
func(*args)
|
func(*args)
|
||||||
|
|
||||||
def insert_image(self, href):
|
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False):
|
||||||
self.editor.insert_image(href)
|
self.editor.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_aspect_ratio)
|
||||||
|
|
||||||
def insert_hyperlink(self, href, text):
|
def insert_hyperlink(self, href, text):
|
||||||
self.editor.insert_hyperlink(href, text)
|
self.editor.insert_hyperlink(href, text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user