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

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

 1  from PyQt4 import QtGui, QtCore 
 2  from PyQt4.QtCore import Qt 
 3  
 
 4  from customdelegate import CustomDelegate, DocumentationMetaclass, not_editable_background 
 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 ColorDelegate(CustomDelegate):
10 11 __metaclass__ = DocumentationMetaclass 12 13 editor = editors.ColorEditor 14
15 - def paint(self, painter, option, index):
16 painter.save() 17 self.drawBackground(painter, option, index) 18 background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) 19 if (option.state & QtGui.QStyle.State_Selected): 20 painter.fillRect(option.rect, option.palette.highlight()) 21 elif not self.editable: 22 painter.fillRect(option.rect, QtGui.QColor(not_editable_background)) 23 else: 24 painter.fillRect(option.rect, background_color) 25 color = variant_to_pyobject(index.model().data(index, Qt.EditRole)) 26 if color not in (None, ValueLoading): 27 pixmap = QtGui.QPixmap(16, 16) 28 qcolor = QtGui.QColor() 29 qcolor.setRgb(*color) 30 pixmap.fill(qcolor) 31 rect = QtCore.QRect(option.rect.left()+40, 32 option.rect.top(), 33 option.rect.width()-23, 34 option.rect.height()) 35 36 QtGui.QApplication.style().drawItemPixmap(painter, 37 rect, 38 Qt.AlignVCenter, 39 pixmap) 40 41 painter.restore()
42