Package Camelot :: Package camelot :: Package view :: Package controls :: Package delegates :: Module stardelegate |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.delegates.stardelegate

     1  from PyQt4 import QtGui, QtCore
     2  from PyQt4.QtCore import Qt
     3

     4  from customdelegate import CustomDelegate, DocumentationMetaclass
     5  from camelot.view.controls import editors
     6  from camelot.view.art import Icon
     7

     8 -class StarDelegate(CustomDelegate):
     9      """Delegate for integer values from (1 to 5)(Rating Delegate)

    10

    11    """
    12

    13      __metaclass__ = DocumentationMetaclass
    14

    15      editor = editors.StarEditor
    16

    17 -    def __init__(self, parent, editable=True, maximum=5, **kwargs):
    18          CustomDelegate.__init__(self,

    19                                  parent=parent,

    20                                  editable=editable,

    21                                  maximum=maximum,

    22                                  **kwargs)
    23          self.maximum = maximum
    24

    25 -    def paint(self, painter, option, index):
    26          painter.save()
    27          self.drawBackground(painter, option, index)
    28          stars = index.model().data(index, Qt.EditRole).toInt()[0]
    29

    30          background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole))
    31

    32          rect = option.rect
    33          rect = QtCore.QRect(rect.left()+3, rect.top()+6, rect.width()-5, rect.height())
    34

    35          if( option.state & QtGui.QStyle.State_Selected ):
    36              painter.fillRect(option.rect, option.palette.highlight())
    37          else:
    38              if not self.editable:
    39                  painter.fillRect(option.rect, option.palette.window())
    40              else:
    41                  painter.fillRect(option.rect, background_color)
    42

    43          for i in range(5):
    44              if i+1<=stars:
    45                  icon = Icon('tango/16x16/status/weather-clear.png').getQPixmap()
    46                  QtGui.QApplication.style().drawItemPixmap(painter, rect, 1, icon)
    47                  rect = QtCore.QRect(rect.left()+20, rect.top(), rect.width(), rect.height())
    48          painter.restore()
    49