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