mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix ratings deleegate to use model supplied color
This commit is contained in:
parent
b0db493968
commit
8a4ceb206d
@ -40,10 +40,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
|
|||||||
50 + 40 * sin(0.8 * i * pi))
|
50 + 40 * sin(0.8 * i * pi))
|
||||||
self.star_path.closeSubpath()
|
self.star_path.closeSubpath()
|
||||||
self.star_path.setFillRule(Qt.WindingFill)
|
self.star_path.setFillRule(Qt.WindingFill)
|
||||||
gradient = QLinearGradient(0, 0, 0, 100)
|
self.gradient = QLinearGradient(0, 0, 0, 100)
|
||||||
gradient.setColorAt(0.0, self.COLOR)
|
|
||||||
gradient.setColorAt(1.0, self.COLOR)
|
|
||||||
self.brush = QBrush(gradient)
|
|
||||||
self.factor = self.SIZE/100.
|
self.factor = self.SIZE/100.
|
||||||
|
|
||||||
def sizeHint(self, option, index):
|
def sizeHint(self, option, index):
|
||||||
@ -53,7 +50,8 @@ class RatingDelegate(QStyledItemDelegate): # {{{
|
|||||||
def paint(self, painter, option, index):
|
def paint(self, painter, option, index):
|
||||||
style = self._parent.style()
|
style = self._parent.style()
|
||||||
option = QStyleOptionViewItemV4(option)
|
option = QStyleOptionViewItemV4(option)
|
||||||
self.initStyleOption(option, self.dummy)
|
self.initStyleOption(option, index)
|
||||||
|
option.text = u''
|
||||||
num = index.model().data(index, Qt.DisplayRole).toInt()[0]
|
num = index.model().data(index, Qt.DisplayRole).toInt()[0]
|
||||||
def draw_star():
|
def draw_star():
|
||||||
painter.save()
|
painter.save()
|
||||||
@ -65,6 +63,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{
|
|||||||
painter.restore()
|
painter.restore()
|
||||||
|
|
||||||
painter.save()
|
painter.save()
|
||||||
|
|
||||||
if hasattr(QStyle, 'CE_ItemViewItem'):
|
if hasattr(QStyle, 'CE_ItemViewItem'):
|
||||||
style.drawControl(QStyle.CE_ItemViewItem, option,
|
style.drawControl(QStyle.CE_ItemViewItem, option,
|
||||||
painter, self._parent)
|
painter, self._parent)
|
||||||
@ -75,8 +74,15 @@ class RatingDelegate(QStyledItemDelegate): # {{{
|
|||||||
painter.setClipRect(option.rect)
|
painter.setClipRect(option.rect)
|
||||||
y = option.rect.center().y()-self.SIZE/2.
|
y = option.rect.center().y()-self.SIZE/2.
|
||||||
x = option.rect.left()
|
x = option.rect.left()
|
||||||
painter.setPen(self.PEN)
|
color = index.data(Qt.ForegroundRole)
|
||||||
painter.setBrush(self.brush)
|
if color.isNull() or not color.isValid():
|
||||||
|
color = self.COLOR
|
||||||
|
else:
|
||||||
|
color = QColor(color)
|
||||||
|
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
|
||||||
|
self.gradient.setColorAt(0.0, color)
|
||||||
|
self.gradient.setColorAt(1.0, color)
|
||||||
|
painter.setBrush(QBrush(self.gradient))
|
||||||
painter.translate(x, y)
|
painter.translate(x, y)
|
||||||
i = 0
|
i = 0
|
||||||
while i < num:
|
while i < num:
|
||||||
|
@ -693,9 +693,9 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
return NONE
|
return NONE
|
||||||
if role in (Qt.DisplayRole, Qt.EditRole):
|
if role in (Qt.DisplayRole, Qt.EditRole):
|
||||||
return self.column_to_dc_map[col](index.row())
|
return self.column_to_dc_map[col](index.row())
|
||||||
elif role == Qt.BackgroundColorRole:
|
elif role == Qt.BackgroundRole:
|
||||||
if self.id(index) in self.ids_to_highlight_set:
|
if self.id(index) in self.ids_to_highlight_set:
|
||||||
return QColor('lightgreen')
|
return QVariant(QColor('lightgreen'))
|
||||||
elif role == Qt.DecorationRole:
|
elif role == Qt.DecorationRole:
|
||||||
if self.column_to_dc_decorator_map[col] is not None:
|
if self.column_to_dc_decorator_map[col] is not None:
|
||||||
return self.column_to_dc_decorator_map[index.column()](index.row())
|
return self.column_to_dc_decorator_map[index.column()](index.row())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user