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

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

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

     4  from customdelegate import CustomDelegate, DocumentationMetaclass, not_editable_background, not_editable_foreground
     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 FileDelegate(CustomDelegate):
    10      """Delegate for camelot.types.file fields.  Expects values of type camelot.core.files.storage.StoredFile.

    11    """
    12

    13      __metaclass__ = DocumentationMetaclass
    14

    15      editor = editors.FileEditor
    16

    17 -    def paint(self, painter, option, index, background_color=QtGui.QColor("white")):
    18          painter.save()
    19          self.drawBackground(painter, option, index)
    20          if (option.state & QtGui.QStyle.State_Selected):
    21              painter.fillRect(option.rect, option.palette.highlight())
    22              painter.setPen(option.palette.highlightedText().color())
    23          elif not self.editable:
    24              painter.fillRect(option.rect, QtGui.QColor(not_editable_background))
    25              painter.setPen(QtGui.QColor(not_editable_foreground))
    26          else:
    27              painter.fillRect(option.rect, background_color)
    28          value =  variant_to_pyobject(index.model().data(index, Qt.EditRole))
    29          if value not in (None, ValueLoading):
    30

    31              painter.drawText(option.rect.x()+2,

    32                               option.rect.y(),

    33                               option.rect.width()-4,

    34                               option.rect.height(),

    35                               Qt.AlignVCenter | Qt.AlignLeft,

    36                               value.verbose_name)
    37

    38          painter.restore()
    39