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

Source Code for Module Camelot.camelot.view.controls.delegates.plaintextdelegate

 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  from camelot.core.utils import ugettext 
 9  
 
10 -class PlainTextDelegate(CustomDelegate):
11 """Custom delegate for simple string values""" 12 13 __metaclass__ = DocumentationMetaclass 14 15 editor = editors.TextLineEditor 16
17 - def __init__(self, parent=None, length=20, editable=True, translate_content=False, **kwargs):
18 CustomDelegate.__init__(self, parent, editable, length=length, **kwargs) 19 self.editable = editable 20 self.length = length 21 self._translate_content = translate_content
22
23 - def paint(self, painter, option, index):
24 painter.save() 25 self.drawBackground(painter, option, index) 26 text = variant_to_pyobject(index.model().data(index, Qt.EditRole)) 27 28 background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) 29 30 rect = option.rect 31 rect = QtCore.QRect(rect.left(), rect.top(), rect.width(), rect.height()) 32 33 if( option.state & QtGui.QStyle.State_Selected ): 34 painter.fillRect(option.rect, option.palette.highlight()) 35 fontColor = QtGui.QColor() 36 if self.editable: 37 Color = option.palette.highlightedText().color() 38 fontColor.setRgb(Color.red(), Color.green(), Color.blue()) 39 else: 40 fontColor.setRgb(130,130,130) 41 else: 42 if self.editable: 43 painter.fillRect(option.rect, background_color) 44 fontColor = QtGui.QColor() 45 fontColor.setRgb(0,0,0) 46 else: 47 painter.fillRect(option.rect, option.palette.window()) 48 fontColor = QtGui.QColor() 49 fontColor.setRgb(130,130,130) 50 51 if text!=ValueLoading: 52 text = text or u'' 53 if self._translate_content: 54 text = ugettext(text) 55 else: 56 text = u'' 57 58 painter.setPen(fontColor.toRgb()) 59 rect = QtCore.QRect(option.rect.left(), 60 option.rect.top(), 61 option.rect.width(), 62 option.rect.height()) 63 painter.drawText(rect.x() + 2, 64 rect.y(), 65 rect.width() - 4, 66 rect.height(), 67 Qt.AlignVCenter | Qt.AlignLeft, 68 unicode(text)) 69 painter.restore()
70