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

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

     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.core.utils import variant_to_pyobject
     7  from camelot.view.proxy import ValueLoading
     8

     9 -class CodeDelegate(CustomDelegate):
    10

    11      __metaclass__ = DocumentationMetaclass
    12

    13      editor = editors.CodeEditor
    14

    15 -    def __init__(self, parent=None, parts=[], separator=u'.', **kwargs):
    16          CustomDelegate.__init__(self, parent=parent, parts=parts, **kwargs)
    17          self.parts = parts
    18          self.separator = separator
    19

    20 -    def paint(self, painter, option, index):
    21          painter.save()
    22          numParts = len(self.parts)
    23          self.drawBackground(painter, option, index)
    24

    25          background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole))
    26

    27          if( option.state & QtGui.QStyle.State_Selected ):
    28              painter.fillRect(option.rect, option.palette.highlight())
    29              fontColor = QtGui.QColor()
    30              if self.editable:
    31                  Color = option.palette.highlightedText().color()
    32                  fontColor.setRgb(Color.red(), Color.green(), Color.blue())
    33              else:
    34                  fontColor.setRgb(130,130,130)
    35          else:
    36              if self.editable:
    37                  painter.fillRect(option.rect, background_color)
    38                  fontColor = QtGui.QColor()
    39                  fontColor.setRgb(0,0,0)
    40              else:
    41                  painter.fillRect(option.rect, option.palette.window())
    42                  fontColor = QtGui.QColor()
    43                  fontColor.setRgb(130,130,130)
    44

    45          rect = option.rect
    46          rect = QtCore.QRect(rect.left()+3, rect.top()+6, rect.width(), rect.height()-3)
    47

    48          if numParts != 0:
    49              value = variant_to_pyobject(index.model().data(index, Qt.EditRole)) or []
    50              if value == ValueLoading:
    51                  value = []
    52              value = self.separator.join([unicode(i) for i in value])
    53

    54              painter.setPen(fontColor.toRgb())
    55              painter.drawText(rect.x(),

    56                             rect.y()-4,

    57                             rect.width()-6,

    58                             rect.height(),

    59                             Qt.AlignVCenter | Qt.AlignRight,

    60                             value)
    61

    62          painter.restore()
    63