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

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

 1  
 
 2  from PyQt4 import QtGui, QtCore 
 3  from PyQt4.QtCore import Qt 
 4  
 
 5  from customdelegate import CustomDelegate, DocumentationMetaclass 
 6  from camelot.view.controls import editors 
 7  
 
8 -class BoolDelegate(CustomDelegate):
9 """Custom delegate for boolean values""" 10 11 __metaclass__ = DocumentationMetaclass 12 13 editor = editors.BoolEditor 14
15 - def paint(self, painter, option, index):
16 painter.save() 17 self.drawBackground(painter, option, index) 18 checked = index.model().data(index, Qt.EditRole).toBool() 19 20 background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole)) 21 22 check_option = QtGui.QStyleOptionButton() 23 24 rect = QtCore.QRect(option.rect.left(), 25 option.rect.top(), 26 option.rect.width(), 27 option.rect.height()) 28 29 check_option.rect = rect 30 check_option.palette = option.palette 31 if (option.state & QtGui.QStyle.State_Selected): 32 painter.fillRect(option.rect, option.palette.highlight()) 33 elif not self.editable: 34 painter.fillRect(option.rect, option.palette.window()) 35 else: 36 painter.fillRect(option.rect, background_color) 37 38 if checked: 39 check_option.state = option.state | QtGui.QStyle.State_On 40 else: 41 check_option.state = option.state | QtGui.QStyle.State_Off 42 43 44 45 QtGui.QApplication.style().drawControl(QtGui.QStyle.CE_CheckBox, 46 check_option, 47 painter) 48 49 50 painter.restore()
51
52 -class TextBoolDelegate(BoolDelegate):
53 54 editor = editors.TextBoolEditor
55