Fix rendering artifacts caused by changes in Qt 4.4

This commit is contained in:
Kovid Goyal 2008-05-16 10:40:17 -07:00
parent f7b1d8d0d7
commit d32f4fb855
4 changed files with 63 additions and 19 deletions

View File

@ -1,6 +1,6 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import os, textwrap, traceback, time, re, sre_constants, locale, codecs import os, textwrap, traceback, time, re, sre_constants
from datetime import timedelta, datetime from datetime import timedelta, datetime
from operator import attrgetter from operator import attrgetter
from math import cos, sin, pi from math import cos, sin, pi
@ -17,7 +17,7 @@ from calibre.library.database import LibraryDatabase, SearchToken
from calibre.gui2 import NONE, TableView, qstring_to_unicode from calibre.gui2 import NONE, TableView, qstring_to_unicode
class LibraryDelegate(QItemDelegate): class LibraryDelegate(QItemDelegate):
COLOR = QColor("blue") COLOR = QColor("blue")
SIZE = 16 SIZE = 16
PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)

View File

@ -828,11 +828,12 @@ class Main(MainWindow, Ui_MainWindow):
self.view_format(row, format) self.view_format(row, format)
else: else:
paths = self.current_view().model().paths(rows) paths = self.current_view().model().paths(rows)
pt = PersistentTemporaryFile('_viewer_'+os.path.splitext(paths[0])[1]) if paths:
self.persistent_files.append(pt) pt = PersistentTemporaryFile('_viewer_'+os.path.splitext(paths[0])[1])
pt.close() self.persistent_files.append(pt)
self.job_manager.run_device_job(self.book_downloaded_for_viewing, pt.close()
self.device_manager.view_book_func(), paths[0], pt.name) self.job_manager.run_device_job(self.book_downloaded_for_viewing,
self.device_manager.view_book_func(), paths[0], pt.name)

View File

@ -44,7 +44,7 @@
<item> <item>
<widget class="LocationView" name="location_view" > <widget class="LocationView" name="location_view" >
<property name="sizePolicy" > <property name="sizePolicy" >
<sizepolicy vsizetype="Minimum" hsizetype="Preferred" > <sizepolicy vsizetype="Minimum" hsizetype="Expanding" >
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>

View File

@ -6,9 +6,10 @@ Miscellaneous widgets used in the GUI
import re import re
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 QSyntaxHighlighter, QCursor, QColor, QWidget, \
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QSize, SIGNAL, \ QAbstractItemDelegate, QStyle
QObject, QRegExp from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, QRect, SIGNAL, \
QObject, QRegExp, QSize, QRectF
from calibre.gui2.jobs import DetailView from calibre.gui2.jobs import DetailView
from calibre.gui2 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog from calibre.gui2 import human_readable, NONE, TableView, qstring_to_unicode, error_dialog
@ -77,6 +78,53 @@ 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.icon_rect = QRect(0, 10, 150, 45)
self.buffer = 0
def get_rects(self, index, option):
row = index.row()
irect = QRect(self.icon_rect)
irect.translate(row*(irect.width()+self.buffer), 0)
trect = irect.translated(0, irect.height())
trect.adjust(0, 7, 0, 0)
return irect.adjusted(50, 0, -50, 0), trect
def sizeHint(self, option, index):
irect, trect = self.get_rects(index, option)
return irect.united(trect).size()
def paint(self, painter, option, index):
selected = bool(option.state & QStyle.State_Selected)
active = bool(option.state & QStyle.State_Active)
font = QFont()
font.setBold(True)
font.setPointSize(8)
mode = QIcon.Active if active else QIcon.Selected if selected else QIcon.Normal
icon = QIcon(index.model().data(index, Qt.DecorationRole))
text = index.model().data(index, Qt.DisplayRole).toString()
painter.save()
irect, trect = self.get_rects(index, option)
painter.setFont(font)
icon.paint(painter, irect, Qt.AlignHCenter|Qt.AlignTop, mode, QIcon.On)
if selected:
brect = painter.drawText(QRectF(trect), Qt.AlignTop|Qt.AlignHCenter, text)
brect.adjust(-3, -0, 3, 0)
painter.fillRect(brect, option.palette.highlight())
painter.save()
painter.setPen(Qt.DotLine)
painter.drawRect(brect)
painter.restore()
painter.setBrush(option.palette.highlightedText())
else:
painter.setBrush(option.palette.text())
painter.drawText(QRectF(trect), Qt.AlignTop|Qt.AlignHCenter, 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)
@ -101,13 +149,6 @@ class LocationModel(QAbstractListModel):
data = QVariant(text) data = QVariant(text)
elif role == Qt.DecorationRole: elif role == Qt.DecorationRole:
data = self.icons[row] data = self.icons[row]
elif role == Qt.SizeHintRole:
if row == 1:
return QVariant(QSize(150, 65))
elif role == Qt.FontRole and row == self.highlight_row:
font = QFont()
font.setBold(True)
data = QVariant(font)
return data return data
def headerData(self, section, orientation, role): def headerData(self, section, orientation, role):
@ -130,7 +171,9 @@ class LocationView(QListView):
QListView.__init__(self, parent) QListView.__init__(self, parent)
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)
def current_changed(self, current, previous): def current_changed(self, current, previous):
i = current.row() i = current.row()