mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enforce a maximum size for cover display widgets.
This commit is contained in:
parent
c4d75650c8
commit
8f7335ff56
@ -20,6 +20,7 @@ __appname__ = 'libprs500'
|
|||||||
|
|
||||||
import sys, os, logging, mechanize, locale, cStringIO
|
import sys, os, logging, mechanize, locale, cStringIO
|
||||||
from gettext import GNUTranslations
|
from gettext import GNUTranslations
|
||||||
|
from math import floor
|
||||||
|
|
||||||
iswindows = 'win32' in sys.platform.lower()
|
iswindows = 'win32' in sys.platform.lower()
|
||||||
isosx = 'darwin' in sys.platform.lower()
|
isosx = 'darwin' in sys.platform.lower()
|
||||||
@ -84,6 +85,28 @@ def browser():
|
|||||||
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; i686 Linux; en_US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4')]
|
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; i686 Linux; en_US; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4')]
|
||||||
return opener
|
return opener
|
||||||
|
|
||||||
|
def fit_image(width, height, pwidth, pheight):
|
||||||
|
'''
|
||||||
|
Fit image in box of width pwidth and height pheight.
|
||||||
|
@param width: Width of image
|
||||||
|
@param height: Height of image
|
||||||
|
@param pwidth: Width of box
|
||||||
|
@param pheight: Height of box
|
||||||
|
@return: scaled, new_width, new_height. scaled is True iff new_widdth and/or new_height is different from width or height.
|
||||||
|
'''
|
||||||
|
scaled = height > pheight or width > pwidth
|
||||||
|
if height > pheight:
|
||||||
|
corrf = pheight/float(height)
|
||||||
|
width, height = floor(corrf*width), pheight
|
||||||
|
if width > pwidth:
|
||||||
|
corrf = pwidth/float(width)
|
||||||
|
width, height = pwidth, floor(corrf*height)
|
||||||
|
if height > pheight:
|
||||||
|
corrf = pheight/float(height)
|
||||||
|
width, height = floor(corrf*width), pheight
|
||||||
|
|
||||||
|
return scaled, int(width), int(height)
|
||||||
|
|
||||||
def set_translator():
|
def set_translator():
|
||||||
# To test different translations invoke as
|
# To test different translations invoke as
|
||||||
# LC_ALL=de_DE.utf8 program
|
# LC_ALL=de_DE.utf8 program
|
||||||
|
@ -42,7 +42,7 @@ from libprs500.ebooks.lrf import Book
|
|||||||
from libprs500.ebooks.lrf import option_parser as lrf_option_parser
|
from libprs500.ebooks.lrf import option_parser as lrf_option_parser
|
||||||
from libprs500.ebooks import ConversionError
|
from libprs500.ebooks import ConversionError
|
||||||
from libprs500.ebooks.lrf.html.table import Table
|
from libprs500.ebooks.lrf.html.table import Table
|
||||||
from libprs500 import filename_to_utf8, setup_cli_handlers, __appname__
|
from libprs500 import filename_to_utf8, setup_cli_handlers, __appname__, fit_image
|
||||||
from libprs500.ptempfile import PersistentTemporaryFile
|
from libprs500.ptempfile import PersistentTemporaryFile
|
||||||
from libprs500.ebooks.metadata.opf import OPFReader
|
from libprs500.ebooks.metadata.opf import OPFReader
|
||||||
from libprs500.devices.interface import Device
|
from libprs500.devices.interface import Device
|
||||||
@ -64,19 +64,7 @@ def munge_paths(basepath, url):
|
|||||||
path = os.path.join(os.path.dirname(basepath), path)
|
path = os.path.join(os.path.dirname(basepath), path)
|
||||||
return os.path.normpath(path), fragment
|
return os.path.normpath(path), fragment
|
||||||
|
|
||||||
def fit_image(width, height, pwidth, pheight):
|
|
||||||
scaled = height > pheight or width > pwidth
|
|
||||||
if height > pheight:
|
|
||||||
corrf = pheight/float(height)
|
|
||||||
width, height = floor(corrf*width), pheight
|
|
||||||
if width > pwidth:
|
|
||||||
corrf = pwidth/float(width)
|
|
||||||
width, height = pwidth, floor(corrf*height)
|
|
||||||
if height > pheight:
|
|
||||||
corrf = pheight/float(height)
|
|
||||||
width, height = floor(corrf*width), pheight
|
|
||||||
|
|
||||||
return scaled, int(width), int(height)
|
|
||||||
|
|
||||||
|
|
||||||
class HTMLConverter(object):
|
class HTMLConverter(object):
|
||||||
|
@ -17,6 +17,7 @@ import textwrap
|
|||||||
from PyQt4.QtGui import QStatusBar, QMovie, QLabel, QFrame, QHBoxLayout, QPixmap, \
|
from PyQt4.QtGui import QStatusBar, QMovie, QLabel, QFrame, QHBoxLayout, QPixmap, \
|
||||||
QVBoxLayout, QSizePolicy
|
QVBoxLayout, QSizePolicy
|
||||||
from PyQt4.QtCore import Qt, QSize
|
from PyQt4.QtCore import Qt, QSize
|
||||||
|
from libprs500 import fit_image
|
||||||
from libprs500.gui2 import qstring_to_unicode
|
from libprs500.gui2 import qstring_to_unicode
|
||||||
|
|
||||||
class BookInfoDisplay(QFrame):
|
class BookInfoDisplay(QFrame):
|
||||||
@ -29,13 +30,17 @@ class BookInfoDisplay(QFrame):
|
|||||||
self.__class__.HEIGHT,
|
self.__class__.HEIGHT,
|
||||||
Qt.IgnoreAspectRatio,
|
Qt.IgnoreAspectRatio,
|
||||||
Qt.SmoothTransformation)
|
Qt.SmoothTransformation)
|
||||||
self.setPixmap(self.default_pixmap)
|
|
||||||
self.setMaximumHeight(self.HEIGHT)
|
|
||||||
self.setMaximumWidth(self.WIDTH)
|
|
||||||
self.setScaledContents(True)
|
self.setScaledContents(True)
|
||||||
|
self.setPixmap(self.default_pixmap)
|
||||||
|
|
||||||
|
|
||||||
def setPixmap(self, pixmap):
|
def setPixmap(self, pixmap):
|
||||||
|
width, height = fit_image(pixmap.width(), pixmap.height(),
|
||||||
|
self.WIDTH, self.HEIGHT)[1:]
|
||||||
|
self.setMaximumHeight(height)
|
||||||
|
self.setMaximumWidth(width)
|
||||||
QLabel.setPixmap(self, pixmap)
|
QLabel.setPixmap(self, pixmap)
|
||||||
|
|
||||||
aspect_ratio = pixmap.width()/float(pixmap.height())
|
aspect_ratio = pixmap.width()/float(pixmap.height())
|
||||||
self.setMaximumWidth(int(aspect_ratio*self.HEIGHT))
|
self.setMaximumWidth(int(aspect_ratio*self.HEIGHT))
|
||||||
|
|
||||||
|
@ -19,13 +19,18 @@ from PyQt4.QtGui import QListView, QIcon, QFont, QLabel
|
|||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject
|
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, QObject
|
||||||
|
|
||||||
from libprs500.gui2 import human_readable, NONE
|
from libprs500.gui2 import human_readable, NONE
|
||||||
|
from libprs500 import fit_image
|
||||||
|
|
||||||
class ImageView(QLabel):
|
class ImageView(QLabel):
|
||||||
|
|
||||||
|
MAX_WIDTH = 400
|
||||||
|
MAX_HEIGHT = 300
|
||||||
|
|
||||||
def setPixmap(self, pixmap):
|
def setPixmap(self, pixmap):
|
||||||
QLabel.setPixmap(self, pixmap)
|
QLabel.setPixmap(self, pixmap)
|
||||||
self.setMaximumWidth(pixmap.width())
|
width, height = fit_image(pixmap.width(), pixmap.height(), self.MAX_WIDTH, self.MAX_HEIGHT)[1:]
|
||||||
self.setMaximumHeight(pixmap.height())
|
self.setMaximumWidth(width)
|
||||||
|
self.setMaximumHeight(height)
|
||||||
|
|
||||||
class LocationModel(QAbstractListModel):
|
class LocationModel(QAbstractListModel):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user