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

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

     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 SmileyDelegate(CustomDelegate):
     9      """Delegate for Smiley's

    10    """
    11

    12      __metaclass__ = DocumentationMetaclass
    13

    14      editor = editors.SmileyEditor
    15

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

    18                                  parent=parent,

    19                                  editable=editable,

    20                                  maximum=1,

    21                                  **kwargs)
    22

    23 -    def paint(self, painter, option, index):
    24          painter.save()
    25          img = index.model().data(index, Qt.DisplayRole).toString()
    26

    27          background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole))
    28

    29          imgPath = 'tango/16x16/emotes/' + img + '.png'
    30          self.drawBackground(painter, option, index)
    31          rect = option.rect
    32          rect = QtCore.QRect(rect.left()+3, rect.top()+6, rect.width()-5, rect.height())
    33

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

    42          icon = Icon(imgPath).getQPixmap()
    43          QtGui.QApplication.style().drawItemPixmap(painter, rect, 1, icon)
    44          rect = QtCore.QRect(rect.left()+20, rect.top(), rect.width(), rect.height())
    45          painter.restore()
    46