mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Fix drag and drop of semi-transparent images onto the book details panel giving them a black background instead of a white background
This commit is contained in:
parent
5088a023c7
commit
a8f7c27e40
@ -23,6 +23,7 @@ from calibre.ebooks.metadata.book.base import (field_metadata, Metadata)
|
||||
from calibre.ebooks.metadata.book.render import mi_to_html
|
||||
from calibre.gui2 import (config, open_url, pixmap_to_data, gprefs, rating_font, NO_URL_FORMATTING)
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.utils.img import image_from_x, blend_image
|
||||
from calibre.utils.localization import is_rtl
|
||||
|
||||
_css = None
|
||||
@ -368,6 +369,8 @@ class CoverView(QWidget): # {{{
|
||||
pmap.loadFromData(cdata)
|
||||
if pmap.isNull():
|
||||
return
|
||||
if pmap.hasAlphaChannel():
|
||||
pmap = QPixmap.fromImage(blend_image(image_from_x(pmap)))
|
||||
self.pixmap = pmap
|
||||
self.do_layout()
|
||||
self.update()
|
||||
@ -665,7 +668,7 @@ class BookDetails(QWidget): # {{{
|
||||
return
|
||||
|
||||
# Now look for ebook files
|
||||
urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True)
|
||||
urls, filenames = dnd_get_files(md, BOOK_EXTENSIONS, allow_all_extensions=True, filter_exts=image_extensions())
|
||||
if not urls:
|
||||
# Nothing found
|
||||
return
|
||||
|
@ -246,7 +246,7 @@ def dnd_get_image(md, image_exts=None):
|
||||
|
||||
return None, None
|
||||
|
||||
def dnd_get_files(md, exts, allow_all_extensions=False):
|
||||
def dnd_get_files(md, exts, allow_all_extensions=False, filter_exts=()):
|
||||
'''
|
||||
Get the file in the QMimeData object md with an extension that is one of
|
||||
the extensions in exts.
|
||||
@ -261,9 +261,9 @@ def dnd_get_files(md, exts, allow_all_extensions=False):
|
||||
local_files = [path_from_qurl(x) for x in urls]
|
||||
def is_ok(path):
|
||||
ext = posixpath.splitext(path)[1][1:].lower()
|
||||
if allow_all_extensions and ext:
|
||||
if allow_all_extensions and ext and ext not in filter_exts:
|
||||
return True
|
||||
return ext in exts
|
||||
return ext in exts and ext not in filter_exts
|
||||
local_files = [p for p in local_files if is_ok(urllib.unquote(p))]
|
||||
local_files = [x for x in local_files if os.path.exists(x)]
|
||||
if local_files:
|
||||
|
@ -8,7 +8,7 @@ import os, subprocess, errno, shutil, tempfile, sys
|
||||
from io import BytesIO
|
||||
from threading import Thread
|
||||
|
||||
from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter, QTransform
|
||||
from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter, QTransform, QPixmap
|
||||
from calibre import fit_image, force_unicode
|
||||
from calibre.constants import iswindows, plugins, get_version
|
||||
from calibre.utils.config_base import tweaks
|
||||
@ -71,6 +71,8 @@ def image_from_x(x):
|
||||
return image_from_data(x)
|
||||
if isinstance(x, bytearray):
|
||||
return image_from_data(bytes(x))
|
||||
if isinstance(x, QPixmap):
|
||||
return x.toImage()
|
||||
raise TypeError('Unknown image src type: %s' % type(x))
|
||||
|
||||
def image_and_format_from_data(data):
|
||||
|
Loading…
x
Reference in New Issue
Block a user