mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #4536 (Auto fit-to-view of cover display in details view)
This commit is contained in:
parent
8477c4313e
commit
edf38c51f1
@ -7,10 +7,12 @@ __docformat__ = 'restructuredtext en'
|
||||
'''
|
||||
import textwrap, os
|
||||
|
||||
from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl
|
||||
from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl, QTimer, Qt
|
||||
from PyQt4.QtGui import QDialog, QPixmap, QGraphicsScene, QIcon, QDesktopServices
|
||||
|
||||
from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo
|
||||
from calibre.gui2 import dynamic
|
||||
from calibre import fit_image
|
||||
|
||||
class BookInfo(QDialog, Ui_BookInfo):
|
||||
|
||||
@ -18,6 +20,7 @@ class BookInfo(QDialog, Ui_BookInfo):
|
||||
QDialog.__init__(self, parent)
|
||||
Ui_BookInfo.__init__(self)
|
||||
self.setupUi(self)
|
||||
self.cover_pixmap = None
|
||||
desktop = QCoreApplication.instance().desktop()
|
||||
screen_height = desktop.availableGeometry().height() - 100
|
||||
self.resize(self.size().width(), screen_height)
|
||||
@ -25,12 +28,22 @@ class BookInfo(QDialog, Ui_BookInfo):
|
||||
|
||||
self.view = view
|
||||
self.current_row = None
|
||||
self.fit_cover.setChecked(dynamic.get('book_info_dialog_fit_cover',
|
||||
False))
|
||||
self.refresh(row)
|
||||
self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave)
|
||||
self.connect(self.next_button, SIGNAL('clicked()'), self.next)
|
||||
self.connect(self.previous_button, SIGNAL('clicked()'), self.previous)
|
||||
self.connect(self.text, SIGNAL('linkActivated(QString)'), self.open_book_path)
|
||||
self.fit_cover.stateChanged.connect(self.toggle_cover_fit)
|
||||
self.cover.resizeEvent = self.cover_view_resized
|
||||
|
||||
def toggle_cover_fit(self, state):
|
||||
dynamic.set('book_info_dialog_fit_cover', self.fit_cover.isChecked())
|
||||
self.resize_cover()
|
||||
|
||||
def cover_view_resized(self, event):
|
||||
QTimer.singleShot(1, self.resize_cover)
|
||||
def slave(self, current, previous):
|
||||
row = current.row()
|
||||
self.refresh(row)
|
||||
@ -57,6 +70,22 @@ class BookInfo(QDialog, Ui_BookInfo):
|
||||
if ni.isValid():
|
||||
self.view.setCurrentIndex(ni)
|
||||
|
||||
def resize_cover(self):
|
||||
if self.cover_pixmap is None:
|
||||
return
|
||||
self.setWindowIcon(QIcon(self.cover_pixmap))
|
||||
self.scene = QGraphicsScene()
|
||||
pixmap = self.cover_pixmap
|
||||
if self.fit_cover.isChecked():
|
||||
scaled, new_width, new_height = fit_image(pixmap.width(),
|
||||
pixmap.height(), self.cover.size().width()-10,
|
||||
self.cover.size().height()-10)
|
||||
if scaled:
|
||||
pixmap = pixmap.scaled(new_width, new_height,
|
||||
Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
||||
self.scene.addPixmap(pixmap)
|
||||
self.cover.setScene(self.scene)
|
||||
|
||||
def refresh(self, row):
|
||||
if isinstance(row, QModelIndex):
|
||||
row = row.row()
|
||||
@ -71,12 +100,8 @@ class BookInfo(QDialog, Ui_BookInfo):
|
||||
self.comments.setText(info.pop(_('Comments'), ''))
|
||||
|
||||
cdata = info.pop('cover', '')
|
||||
pixmap = QPixmap.fromImage(cdata)
|
||||
self.setWindowIcon(QIcon(pixmap))
|
||||
|
||||
self.scene = QGraphicsScene()
|
||||
self.scene.addPixmap(pixmap)
|
||||
self.cover.setScene(self.scene)
|
||||
self.cover_pixmap = QPixmap.fromImage(cdata)
|
||||
self.resize_cover()
|
||||
|
||||
rows = u''
|
||||
self.text.setText('')
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BookInfo</class>
|
||||
<widget class="QDialog" name="BookInfo">
|
||||
@ -53,6 +54,13 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="fit_cover">
|
||||
<property name="text">
|
||||
<string>Fit &cover to view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user