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
|
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 PyQt4.QtGui import QDialog, QPixmap, QGraphicsScene, QIcon, QDesktopServices
|
||||||
|
|
||||||
from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo
|
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):
|
class BookInfo(QDialog, Ui_BookInfo):
|
||||||
|
|
||||||
@ -18,6 +20,7 @@ class BookInfo(QDialog, Ui_BookInfo):
|
|||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
Ui_BookInfo.__init__(self)
|
Ui_BookInfo.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
self.cover_pixmap = None
|
||||||
desktop = QCoreApplication.instance().desktop()
|
desktop = QCoreApplication.instance().desktop()
|
||||||
screen_height = desktop.availableGeometry().height() - 100
|
screen_height = desktop.availableGeometry().height() - 100
|
||||||
self.resize(self.size().width(), screen_height)
|
self.resize(self.size().width(), screen_height)
|
||||||
@ -25,12 +28,22 @@ class BookInfo(QDialog, Ui_BookInfo):
|
|||||||
|
|
||||||
self.view = view
|
self.view = view
|
||||||
self.current_row = None
|
self.current_row = None
|
||||||
|
self.fit_cover.setChecked(dynamic.get('book_info_dialog_fit_cover',
|
||||||
|
False))
|
||||||
self.refresh(row)
|
self.refresh(row)
|
||||||
self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave)
|
self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave)
|
||||||
self.connect(self.next_button, SIGNAL('clicked()'), self.next)
|
self.connect(self.next_button, SIGNAL('clicked()'), self.next)
|
||||||
self.connect(self.previous_button, SIGNAL('clicked()'), self.previous)
|
self.connect(self.previous_button, SIGNAL('clicked()'), self.previous)
|
||||||
self.connect(self.text, SIGNAL('linkActivated(QString)'), self.open_book_path)
|
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):
|
def slave(self, current, previous):
|
||||||
row = current.row()
|
row = current.row()
|
||||||
self.refresh(row)
|
self.refresh(row)
|
||||||
@ -57,6 +70,22 @@ class BookInfo(QDialog, Ui_BookInfo):
|
|||||||
if ni.isValid():
|
if ni.isValid():
|
||||||
self.view.setCurrentIndex(ni)
|
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):
|
def refresh(self, row):
|
||||||
if isinstance(row, QModelIndex):
|
if isinstance(row, QModelIndex):
|
||||||
row = row.row()
|
row = row.row()
|
||||||
@ -71,12 +100,8 @@ class BookInfo(QDialog, Ui_BookInfo):
|
|||||||
self.comments.setText(info.pop(_('Comments'), ''))
|
self.comments.setText(info.pop(_('Comments'), ''))
|
||||||
|
|
||||||
cdata = info.pop('cover', '')
|
cdata = info.pop('cover', '')
|
||||||
pixmap = QPixmap.fromImage(cdata)
|
self.cover_pixmap = QPixmap.fromImage(cdata)
|
||||||
self.setWindowIcon(QIcon(pixmap))
|
self.resize_cover()
|
||||||
|
|
||||||
self.scene = QGraphicsScene()
|
|
||||||
self.scene.addPixmap(pixmap)
|
|
||||||
self.cover.setScene(self.scene)
|
|
||||||
|
|
||||||
rows = u''
|
rows = u''
|
||||||
self.text.setText('')
|
self.text.setText('')
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
<ui version="4.0" >
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
<class>BookInfo</class>
|
<class>BookInfo</class>
|
||||||
<widget class="QDialog" name="BookInfo" >
|
<widget class="QDialog" name="BookInfo">
|
||||||
<property name="geometry" >
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
@ -9,70 +10,77 @@
|
|||||||
<height>783</height>
|
<height>783</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Dialog</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" >
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2" >
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QLabel" name="title" >
|
<widget class="QLabel" name="title">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>TextLabel</string>
|
<string>TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment" >
|
<property name="alignment">
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" >
|
<item row="1" column="0">
|
||||||
<widget class="QGraphicsView" name="cover" />
|
<widget class="QGraphicsView" name="cover"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1" >
|
<item row="1" column="1">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" >
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="text" >
|
<widget class="QLabel" name="text">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>TextLabel</string>
|
<string>TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment" >
|
<property name="alignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap" >
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox" >
|
<widget class="QGroupBox" name="groupBox">
|
||||||
<property name="title" >
|
<property name="title">
|
||||||
<string>Comments</string>
|
<string>Comments</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" >
|
<layout class="QGridLayout">
|
||||||
<item row="0" column="0" >
|
<item row="0" column="0">
|
||||||
<widget class="QTextBrowser" name="comments" />
|
<widget class="QTextBrowser" name="comments"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" >
|
<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>
|
<item>
|
||||||
<widget class="QPushButton" name="previous_button" >
|
<widget class="QPushButton" name="previous_button">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>&Previous</string>
|
<string>&Previous</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon" >
|
<property name="icon">
|
||||||
<iconset resource="../../../../resources/images.qrc" >
|
<iconset resource="../../../../resources/images.qrc">
|
||||||
<normaloff>:/images/previous.svg</normaloff>:/images/previous.svg</iconset>
|
<normaloff>:/images/previous.svg</normaloff>:/images/previous.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="next_button" >
|
<widget class="QPushButton" name="next_button">
|
||||||
<property name="text" >
|
<property name="text">
|
||||||
<string>&Next</string>
|
<string>&Next</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon" >
|
<property name="icon">
|
||||||
<iconset resource="../../../../resources/images.qrc" >
|
<iconset resource="../../../../resources/images.qrc">
|
||||||
<normaloff>:/images/next.svg</normaloff>:/images/next.svg</iconset>
|
<normaloff>:/images/next.svg</normaloff>:/images/next.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -84,7 +92,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../../../resources/images.qrc" />
|
<include location="../../../../resources/images.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user