mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
IGN:Make locations view a little prettier
This commit is contained in:
parent
a06522c486
commit
e90cb0954b
@ -46,8 +46,8 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="maximumSize" >
|
<property name="maximumSize" >
|
||||||
<size>
|
<size>
|
||||||
<width>10000</width>
|
<width>16777215</width>
|
||||||
<height>110</height>
|
<height>100</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="verticalScrollBarPolicy" >
|
<property name="verticalScrollBarPolicy" >
|
||||||
@ -74,14 +74,17 @@
|
|||||||
<property name="flow" >
|
<property name="flow" >
|
||||||
<enum>QListView::LeftToRight</enum>
|
<enum>QListView::LeftToRight</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="isWrapping" stdset="0" >
|
<property name="gridSize" >
|
||||||
<bool>false</bool>
|
<size>
|
||||||
</property>
|
<width>175</width>
|
||||||
<property name="spacing" >
|
<height>90</height>
|
||||||
<number>10</number>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="viewMode" >
|
<property name="viewMode" >
|
||||||
<enum>QListView::IconMode</enum>
|
<enum>QListView::ListMode</enum>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -7,9 +7,9 @@ import re, os, traceback
|
|||||||
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
||||||
QListWidgetItem, QTextCharFormat, QApplication, \
|
QListWidgetItem, QTextCharFormat, QApplication, \
|
||||||
QSyntaxHighlighter, QCursor, QColor, QWidget, QDialog, \
|
QSyntaxHighlighter, QCursor, QColor, QWidget, QDialog, \
|
||||||
QAbstractItemDelegate, QPixmap, QStyle, QFontMetrics
|
QPixmap
|
||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, SIGNAL, \
|
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, SIGNAL, \
|
||||||
QObject, QRegExp, QString, QSettings
|
QObject, QRegExp, QString, QSettings, QSize
|
||||||
|
|
||||||
from calibre.gui2.jobs2 import DetailView
|
from calibre.gui2.jobs2 import DetailView
|
||||||
from calibre.gui2 import human_readable, NONE, TableView, \
|
from calibre.gui2 import human_readable, NONE, TableView, \
|
||||||
@ -128,56 +128,17 @@ class ImageView(QLabel):
|
|||||||
self.setMaximumWidth(width)
|
self.setMaximumWidth(width)
|
||||||
self.setMaximumHeight(height)
|
self.setMaximumHeight(height)
|
||||||
|
|
||||||
class LocationDelegate(QAbstractItemDelegate):
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
QAbstractItemDelegate.__init__(self)
|
|
||||||
self.pixmap = QPixmap(40, 40)
|
|
||||||
self.text = QString('Reader\n999.9 MB Available202')
|
|
||||||
|
|
||||||
def rects(self, option):
|
|
||||||
style = QApplication.style()
|
|
||||||
font = QFont(option.font)
|
|
||||||
font.setBold(True)
|
|
||||||
irect = style.itemPixmapRect(option.rect, Qt.AlignHCenter|Qt.AlignTop, self.pixmap)
|
|
||||||
trect = style.itemTextRect(QFontMetrics(font), option.rect,
|
|
||||||
Qt.AlignHCenter|Qt.AlignTop, True, self.text)
|
|
||||||
trect.moveTop(irect.bottom())
|
|
||||||
return irect, trect
|
|
||||||
|
|
||||||
def sizeHint(self, option, index):
|
|
||||||
irect, trect = self.rects(option)
|
|
||||||
return irect.united(trect).size()
|
|
||||||
|
|
||||||
def paint(self, painter, option, index):
|
|
||||||
style = QApplication.style()
|
|
||||||
painter.save()
|
|
||||||
if hasattr(QStyle, 'CE_ItemViewItem'):
|
|
||||||
QApplication.style().drawControl(QStyle.CE_ItemViewItem, option, painter)
|
|
||||||
highlight = getattr(index.model(), 'highlight_row', -1) == index.row()
|
|
||||||
mode = QIcon.Active if highlight else QIcon.Normal
|
|
||||||
pixmap = QIcon(index.model().data(index, Qt.DecorationRole)).pixmap(self.pixmap.size())
|
|
||||||
pixmap = style.generatedIconPixmap(mode, pixmap, option)
|
|
||||||
text = index.model().data(index, Qt.DisplayRole).toString()
|
|
||||||
irect, trect = self.rects(option)
|
|
||||||
style.drawItemPixmap(painter, irect, Qt.AlignHCenter|Qt.AlignTop, pixmap)
|
|
||||||
font = QFont(option.font)
|
|
||||||
font.setBold(highlight)
|
|
||||||
painter.setFont(font)
|
|
||||||
style.drawItemText(painter, trect, Qt.AlignHCenter|Qt.AlignBottom,
|
|
||||||
option.palette, True, text)
|
|
||||||
painter.restore()
|
|
||||||
|
|
||||||
|
|
||||||
class LocationModel(QAbstractListModel):
|
class LocationModel(QAbstractListModel):
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
QAbstractListModel.__init__(self, parent)
|
QAbstractListModel.__init__(self, parent)
|
||||||
self.icons = [QVariant(QIcon(':/library')),
|
self.icons = [QVariant(QIcon(':/library')),
|
||||||
QVariant(QIcon(':/images/reader.svg')),
|
QVariant(QIcon(':/images/reader.svg')),
|
||||||
QVariant(QIcon(':/images/sd.svg'))]
|
QVariant(QIcon(':/images/sd.svg'))]
|
||||||
self.text = [_('Library'),
|
self.text = [_('Library'),
|
||||||
_('Reader\n%s available'),
|
_('Reader\n%s\navailable'),
|
||||||
_('Card\n%s available')]
|
_('Card\n%s\navailable')]
|
||||||
self.free = [-1, -1]
|
self.free = [-1, -1]
|
||||||
self.highlight_row = 0
|
self.highlight_row = 0
|
||||||
self.tooltips = [
|
self.tooltips = [
|
||||||
@ -199,7 +160,13 @@ class LocationModel(QAbstractListModel):
|
|||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
data = self.icons[row]
|
data = self.icons[row]
|
||||||
elif role == Qt.ToolTipRole:
|
elif role == Qt.ToolTipRole:
|
||||||
return QVariant(self.tooltips[row])
|
data = QVariant(self.tooltips[row])
|
||||||
|
elif role == Qt.SizeHintRole:
|
||||||
|
data = QVariant(QSize(155, 90))
|
||||||
|
elif role == Qt.FontRole:
|
||||||
|
font = QFont('monospace')
|
||||||
|
font.setBold(row == self.highlight_row)
|
||||||
|
data = QVariant(font)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
@ -223,8 +190,6 @@ class LocationView(QListView):
|
|||||||
self.setModel(LocationModel(self))
|
self.setModel(LocationModel(self))
|
||||||
self.reset()
|
self.reset()
|
||||||
QObject.connect(self.selectionModel(), SIGNAL('currentChanged(QModelIndex, QModelIndex)'), self.current_changed)
|
QObject.connect(self.selectionModel(), SIGNAL('currentChanged(QModelIndex, QModelIndex)'), self.current_changed)
|
||||||
self.delegate = LocationDelegate()
|
|
||||||
self.setItemDelegate(self.delegate)
|
|
||||||
self.setCursor(Qt.PointingHandCursor)
|
self.setCursor(Qt.PointingHandCursor)
|
||||||
|
|
||||||
def current_changed(self, current, previous):
|
def current_changed(self, current, previous):
|
||||||
@ -270,7 +235,6 @@ class FontFamilyModel(QAbstractListModel):
|
|||||||
try:
|
try:
|
||||||
family = self.families[index.row()]
|
family = self.families[index.row()]
|
||||||
except:
|
except:
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return NONE
|
return NONE
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user