mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Work on the new wide layout
This commit is contained in:
parent
320522b5c9
commit
c824130633
@ -8,71 +8,14 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os, collections
|
import os, collections
|
||||||
|
|
||||||
from PyQt4.Qt import QLabel, QPixmap, QSize, QWidget, Qt, pyqtSignal, \
|
from PyQt4.Qt import QLabel, QPixmap, QSize, QWidget, Qt, pyqtSignal, \
|
||||||
QVBoxLayout, QScrollArea
|
QVBoxLayout, QScrollArea, QPropertyAnimation, QEasingCurve
|
||||||
|
|
||||||
from calibre import fit_image, prepare_string_for_xml
|
from calibre import fit_image, prepare_string_for_xml
|
||||||
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
from calibre.gui2.widgets import IMAGE_EXTENSIONS
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS
|
from calibre.ebooks import BOOK_EXTENSIONS
|
||||||
from calibre.constants import preferred_encoding
|
from calibre.constants import preferred_encoding
|
||||||
|
|
||||||
class CoverView(QLabel):
|
# render_rows(data) {{{
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
QLabel.__init__(self, parent)
|
|
||||||
self.default_pixmap = QPixmap(I('book.svg'))
|
|
||||||
self.max_width, self.max_height = 120, 120
|
|
||||||
self.setScaledContents(True)
|
|
||||||
self.setPixmap(self.default_pixmap)
|
|
||||||
|
|
||||||
def do_layout(self):
|
|
||||||
pixmap = self.pixmap()
|
|
||||||
pwidth, pheight = pixmap.width(), pixmap.height()
|
|
||||||
width, height = fit_image(pwidth, pheight,
|
|
||||||
self.max_width, self.max_height)[1:]
|
|
||||||
self.setMaximumWidth(width)
|
|
||||||
try:
|
|
||||||
aspect_ratio = pwidth/float(pheight)
|
|
||||||
except ZeroDivisionError:
|
|
||||||
aspect_ratio = 1
|
|
||||||
mh = min(self.max_height, int(width/aspect_ratio))
|
|
||||||
self.setMaximumHeight(mh)
|
|
||||||
|
|
||||||
def setPixmap(self, pixmap):
|
|
||||||
QLabel.setPixmap(self, pixmap)
|
|
||||||
self.do_layout()
|
|
||||||
|
|
||||||
|
|
||||||
def sizeHint(self):
|
|
||||||
return QSize(self.maximumWidth(), self.maximumHeight())
|
|
||||||
|
|
||||||
def relayout(self, parent_size):
|
|
||||||
self.max_height = int(parent_size.height()/3.)
|
|
||||||
self.max_width = parent_size.width()
|
|
||||||
self.do_layout()
|
|
||||||
|
|
||||||
def show_data(self, data):
|
|
||||||
if data.has_key('cover'):
|
|
||||||
self.setPixmap(QPixmap.fromImage(data.pop('cover')))
|
|
||||||
else:
|
|
||||||
self.setPixmap(self.default_pixmap)
|
|
||||||
|
|
||||||
class BookInfo(QScrollArea):
|
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
|
||||||
QScrollArea.__init__(self, parent)
|
|
||||||
self.setWidgetResizable(True)
|
|
||||||
self.label = QLabel()
|
|
||||||
self.label.setWordWrap(True)
|
|
||||||
self.setWidget(self.label)
|
|
||||||
|
|
||||||
def show_data(self, data):
|
|
||||||
self.label.setText('')
|
|
||||||
self.data = data.copy()
|
|
||||||
rows = render_rows(self.data)
|
|
||||||
rows = u'\n'.join([u'<tr><td valign="top"><b>%s:</b></td><td valign="top">%s</td></tr>'%(k,t) for
|
|
||||||
k, t in rows])
|
|
||||||
self.label.setText(u'<table>%s</table>'%rows)
|
|
||||||
|
|
||||||
WEIGHTS = collections.defaultdict(lambda : 100)
|
WEIGHTS = collections.defaultdict(lambda : 100)
|
||||||
WEIGHTS[_('Path')] = 0
|
WEIGHTS[_('Path')] = 0
|
||||||
WEIGHTS[_('Formats')] = 1
|
WEIGHTS[_('Formats')] = 1
|
||||||
@ -107,10 +50,104 @@ def render_rows(data):
|
|||||||
rows.append((key, txt))
|
rows.append((key, txt))
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class CoverView(QLabel): # {{{
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QLabel.__init__(self, parent)
|
||||||
|
self.animation = QPropertyAnimation(self, 'size', self)
|
||||||
|
self.animation.setEasingCurve(QEasingCurve(QEasingCurve.OutExpo))
|
||||||
|
self.animation.setDuration(1000)
|
||||||
|
self.animation.setStartValue(QSize(0, 0))
|
||||||
|
|
||||||
|
self.default_pixmap = QPixmap(I('book.svg'))
|
||||||
|
self.max_width, self.max_height = 120, 120
|
||||||
|
self.setScaledContents(True)
|
||||||
|
self.setPixmap(self.default_pixmap)
|
||||||
|
|
||||||
|
def do_layout(self):
|
||||||
|
pixmap = self.pixmap()
|
||||||
|
pwidth, pheight = pixmap.width(), pixmap.height()
|
||||||
|
width, height = fit_image(pwidth, pheight,
|
||||||
|
self.max_width, self.max_height)[1:]
|
||||||
|
self.setMaximumWidth(width)
|
||||||
|
try:
|
||||||
|
aspect_ratio = pwidth/float(pheight)
|
||||||
|
except ZeroDivisionError:
|
||||||
|
aspect_ratio = 1
|
||||||
|
mh = min(self.max_height, int(width/aspect_ratio))
|
||||||
|
self.setMaximumHeight(mh)
|
||||||
|
self.animation.setEndValue(self.maximumSize())
|
||||||
|
|
||||||
|
def setPixmap(self, pixmap):
|
||||||
|
QLabel.setPixmap(self, pixmap)
|
||||||
|
self.do_layout()
|
||||||
|
self.animation.start()
|
||||||
|
|
||||||
|
|
||||||
|
def sizeHint(self):
|
||||||
|
return QSize(self.maximumWidth(), self.maximumHeight())
|
||||||
|
|
||||||
|
def relayout(self, parent_size):
|
||||||
|
self.max_height = int(parent_size.height()/3.)
|
||||||
|
self.max_width = parent_size.width()
|
||||||
|
self.do_layout()
|
||||||
|
|
||||||
|
def show_data(self, data):
|
||||||
|
if data.has_key('cover'):
|
||||||
|
self.setPixmap(QPixmap.fromImage(data.pop('cover')))
|
||||||
|
else:
|
||||||
|
self.setPixmap(self.default_pixmap)
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
|
class Label(QLabel):
|
||||||
|
|
||||||
|
mr = pyqtSignal(object)
|
||||||
|
link_clicked = pyqtSignal(object)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.setText('')
|
||||||
|
self.setWordWrap(True)
|
||||||
|
self.linkActivated.connect(self.link_activated)
|
||||||
|
self._link_clicked = False
|
||||||
|
|
||||||
|
def link_activated(self, link):
|
||||||
|
self._link_clicked = True
|
||||||
|
link = unicode(link)
|
||||||
|
self.link_clicked.emit(link)
|
||||||
|
|
||||||
|
def mouseReleaseEvent(self, ev):
|
||||||
|
QLabel.mouseReleaseEvent(self, ev)
|
||||||
|
if not self._link_clicked:
|
||||||
|
self.mr.emit(ev)
|
||||||
|
self._link_clicked = False
|
||||||
|
|
||||||
|
class BookInfo(QScrollArea):
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QScrollArea.__init__(self, parent)
|
||||||
|
self.setWidgetResizable(True)
|
||||||
|
self.label = Label()
|
||||||
|
self.setWidget(self.label)
|
||||||
|
self.link_clicked = self.label.link_clicked
|
||||||
|
self.mr = self.label.mr
|
||||||
|
|
||||||
|
def show_data(self, data):
|
||||||
|
self.label.setText('')
|
||||||
|
self.data = data.copy()
|
||||||
|
rows = render_rows(self.data)
|
||||||
|
rows = u'\n'.join([u'<tr><td valign="top"><b>%s:</b></td><td valign="top">%s</td></tr>'%(k,t) for
|
||||||
|
k, t in rows])
|
||||||
|
self.label.setText(u'<table>%s</table>'%rows)
|
||||||
|
|
||||||
class BookDetails(QWidget):
|
class BookDetails(QWidget):
|
||||||
|
|
||||||
resized = pyqtSignal(object)
|
resized = pyqtSignal(object)
|
||||||
show_book_info = pyqtSignal()
|
show_book_info = pyqtSignal()
|
||||||
|
open_containing_folder = pyqtSignal(int)
|
||||||
|
view_specific_format = pyqtSignal(int, object)
|
||||||
|
|
||||||
# Drag 'n drop {{{
|
# Drag 'n drop {{{
|
||||||
DROPABBLE_EXTENSIONS = IMAGE_EXTENSIONS+BOOK_EXTENSIONS
|
DROPABBLE_EXTENSIONS = IMAGE_EXTENSIONS+BOOK_EXTENSIONS
|
||||||
@ -154,18 +191,31 @@ class BookDetails(QWidget):
|
|||||||
self.cover_view.relayout()
|
self.cover_view.relayout()
|
||||||
self.resized.connect(self.cover_view.relayout, type=Qt.QueuedConnection)
|
self.resized.connect(self.cover_view.relayout, type=Qt.QueuedConnection)
|
||||||
self._layout.addWidget(self.cover_view)
|
self._layout.addWidget(self.cover_view)
|
||||||
|
self.book_info = BookInfo(self)
|
||||||
|
self._layout.addWidget(self.book_info)
|
||||||
|
self.book_info.link_clicked.connect(self._link_clicked)
|
||||||
|
self.book_info.mr.connect(self.mouseReleaseEvent)
|
||||||
|
|
||||||
|
def _link_clicked(self, link):
|
||||||
|
typ, _, val = link.partition(':')
|
||||||
|
if typ == 'path':
|
||||||
|
self.open_containing_folder.emit(int(val))
|
||||||
|
if typ == 'format':
|
||||||
|
id_, fmt = val.split(':')
|
||||||
|
self.view_specific_format.emit(int(id_), fmt)
|
||||||
|
|
||||||
|
def mouseReleaseEvent(self, ev):
|
||||||
|
ev.accept()
|
||||||
|
self.show_book_info.emit()
|
||||||
|
|
||||||
def resizeEvent(self, ev):
|
def resizeEvent(self, ev):
|
||||||
self.resized.emit(self.size())
|
self.resized.emit(self.size())
|
||||||
|
|
||||||
def show_data(self, data):
|
def show_data(self, data):
|
||||||
self.cover_view.show_data(data)
|
self.cover_view.show_data(data)
|
||||||
|
self.book_info.show_data(data)
|
||||||
|
|
||||||
def reset_info(self):
|
def reset_info(self):
|
||||||
self.show_data({})
|
self.show_data({})
|
||||||
|
|
||||||
def mouseReleaseEvent(self, ev):
|
|
||||||
self.show_book_info.emit()
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ class BookInfoDisplay(QWidget):
|
|||||||
event.acceptProposedAction()
|
event.acceptProposedAction()
|
||||||
|
|
||||||
|
|
||||||
class BookCoverDisplay(QLabel):
|
class BookCoverDisplay(QLabel): # {{{
|
||||||
|
|
||||||
def __init__(self, coverpath=I('book.svg')):
|
def __init__(self, coverpath=I('book.svg')):
|
||||||
QLabel.__init__(self)
|
QLabel.__init__(self)
|
||||||
@ -90,6 +90,7 @@ class BookInfoDisplay(QWidget):
|
|||||||
self.statusbar_height = statusbar_size.height()
|
self.statusbar_height = statusbar_size.height()
|
||||||
self.do_layout()
|
self.do_layout()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class BookDataDisplay(QLabel):
|
class BookDataDisplay(QLabel):
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user