00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 from PyQt4.QtCore import *
00029 from PyQt4.QtGui import *
00030 
00031 from Koo.Common import Common
00032 from Koo.Fields.AbstractFieldWidget import *
00033 from Koo.Fields.AbstractFieldDelegate import *
00034 
00035 
00036 class ProgressBarFieldWidget(AbstractFieldWidget):
00037         def __init__(self, parent, view, attrs={}):
00038                 AbstractFieldWidget.__init__(self, parent, view, attrs)
00039 
00040                 self.uiBar = QProgressBar( self )
00041                 self.uiBar.setMinimum( 0 )
00042                 self.uiBar.setMaximum( 100 )
00043                 layout = QHBoxLayout( self )
00044                 layout.setContentsMargins( 0, 0, 0, 0 )
00045                 layout.addWidget( self.uiBar )
00046 
00047                 self.installPopupMenu( self.uiBar )
00048 
00049         def clear(self):
00050                 self.uiBar.reset()
00051 
00052         def showValue(self):
00053                 value = self.record.value(self.name)
00054                 if not value:
00055                         self.clear()
00056                 value = max( min( value, 100 ), 0 )
00057                 self.uiBar.setValue( value )
00058 
00059 class ProgressBarFieldDelegate( AbstractFieldDelegate ):
00060 
00061         def createEditor(self, parent, option, index):
00062                 return None
00063 
00064         def paint(self, painter, option, index):
00065                 
00066                 itemOption = QStyleOptionViewItemV4(option)
00067                 
00068                 
00069                 QApplication.style().drawControl(QStyle.CE_ItemViewItem, itemOption, painter, None)
00070 
00071                 
00072                 opts = QStyleOptionProgressBarV2()
00073                 opts.rect = option.rect
00074                 opts.minimum = 1
00075                 opts.maximum = 100
00076                 opts.textVisible = True
00077                 percent, ok = index.data(Qt.DisplayRole).toDouble()
00078                 percent = max( min( percent, 100 ), 0 )
00079                 opts.progress = percent
00080                 opts.text = QString( '%d%%' % percent )
00081                 
00082                 
00083                 QApplication.style().drawControl(QStyle.CE_ProgressBar, opts, painter, None)
00084