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

# Source Code for Module Camelot.camelot.view.controls.delegates.intervalsdelegate

     1  from PyQt4 import QtGui
     2  from PyQt4.QtCore import Qt
     3

     4  from customdelegate import DocumentationMetaclass
     5  from camelot.core.utils import variant_to_pyobject
     6  from camelot.view.proxy import ValueLoading
     7

     8 -class IntervalsDelegate(QtGui.QItemDelegate):
     9      """Custom delegate for visualizing camelot.container.IntervalsContainer

    10    data

    11    """
    12

    13      __metaclass__ = DocumentationMetaclass
    14

    15 -    def __init__(self, parent=None, editable=False, **kwargs):
    16          QtGui.QItemDelegate.__init__(self, parent)
    17          self.editable = editable
    18

    19 -    def paint(self, painter, option, index):
    20          painter.save()
    21          self.drawBackground(painter, option, index)
    22          intervals = variant_to_pyobject(index.model().data(index, Qt.EditRole))
    23

    24          background_color = QtGui.QColor(index.model().data(index, Qt.BackgroundRole))
    25

    26          if( option.state & QtGui.QStyle.State_Selected ):
    27              painter.fillRect(option.rect, option.palette.highlight())
    28          else:
    29              if not self.editable:
    30                  painter.fillRect(option.rect, option.palette.window())
    31              else:
    32                  painter.fillRect(option.rect, background_color)
    33

    34

    35

    36          if intervals and intervals!=ValueLoading:
    37              rect = option.rect
    38              xscale = float(rect.width()-4)/(intervals.max-intervals.min)
    39              xoffset = intervals.min * xscale + rect.x()
    40              yoffset = rect.y() + rect.height()/2
    41              for interval in intervals.intervals:
    42                  qcolor = QtGui.QColor()
    43                  qcolor.setRgb(*interval.color)
    44                  pen = QtGui.QPen(qcolor)
    45                  pen.setWidth(3)
    46                  painter.setPen(pen)
    47                  x1, x2 =  xoffset + interval.begin*xscale, xoffset + interval.end*xscale
    48                  painter.drawLine(x1, yoffset, x2, yoffset)
    49                  painter.drawEllipse(x1-1, yoffset-1, 2, 2)
    50                  painter.drawEllipse(x2-1, yoffset-1, 2, 2)
    51                  pen = QtGui.QPen(Qt.white)
    52

    53          painter.restore()
    54

    55 -    def createEditor(self, parent, option, index):
    56          pass
    57

    58 -    def setEditorData(self, editor, index):
    59          pass
    60

    61 -    def setModelData(self, editor, model, index):
    62          pass
    63