1
2 from customdelegate import CustomDelegate, DocumentationMetaclass, ValueLoading
3 from camelot.view.controls import editors
4 from camelot.core.utils import variant_to_pyobject
5
6 from PyQt4 import QtCore, QtGui
7 from PyQt4.QtCore import Qt
8
10
11 __metaclass__ = DocumentationMetaclass
12
13 editor = editors.DateTimeEditor
14
15 - def __init__(self, parent=None, editable=True, **kwargs):
19
20 - def paint(self, painter, option, index):
21 painter.save()
22 self.drawBackground(painter, option, index)
23 dateTime = variant_to_pyobject(index.model().data(index, Qt.EditRole))
24 if dateTime not in (ValueLoading, None):
25 dateTime = QtCore.QDateTime(dateTime.year, dateTime.month, dateTime.day,
26 dateTime.hour, dateTime.minute, dateTime.second)
27 formattedDateTime = dateTime.toString(self.dateTime_format)
28 else:
29 formattedDateTime = ''
30 background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole))
31 rect = option.rect
32 rect = QtCore.QRect(rect.left()+3, rect.top()+6, 16, 16)
33
34 if( option.state & QtGui.QStyle.State_Selected ):
35 painter.fillRect(option.rect, option.palette.highlight())
36 fontColor = QtGui.QColor()
37 if self.editable:
38 Color = option.palette.highlightedText().color()
39 fontColor.setRgb(Color.red(), Color.green(), Color.blue())
40 else:
41 fontColor.setRgb(130,130,130)
42 else:
43 if self.editable:
44 painter.fillRect(option.rect, background_color)
45 fontColor = QtGui.QColor()
46 fontColor.setRgb(0,0,0)
47 else:
48 painter.fillRect(option.rect, option.palette.window())
49 fontColor = QtGui.QColor()
50 fontColor.setRgb(130,130,130)
51
52
53 painter.setPen(fontColor.toRgb())
54 rect = QtCore.QRect(option.rect.left(),
55 option.rect.top(),
56 option.rect.width(),
57 option.rect.height())
58
59 painter.drawText(rect.x()+2,
60 rect.y(),
61 rect.width()-4,
62 rect.height(),
63 Qt.AlignVCenter | Qt.AlignRight,
64 str(formattedDateTime))
65 painter.restore()
66