+class NodeTagDelegate(QStyledItemDelegate):
+ def __init__(self, parent):
+ QStyledItemDelegate.__init__(self, parent)
+
+ def paint(self, painter, option, index):
+ model = index.model()
+ taglist = index.data().toStringList()
+ status_index = model.index(index.row(), 2, index.parent())
+ status_data = status_index.data().toString()
+
+ if taglist.isEmpty() or status_data not in (node_status['in'], ""):
+ return
+
+
+ fm = QFontMetrics(option.font)
+ rect = option.rect
+ rect.setHeight(rect.height() - 2)
+ rect.setX(rect.x() + 4)
+
+ for i in range(0, len(taglist), 2):
+ # This taglist is pretty much of a hack. Not quite sure the best
+ # way to use Qt data structures.
+ data = taglist[i]
+ status = taglist[i+1]
+ rect.setWidth(fm.width(QString(data)) + 8)
+ x, y, h, w = rect.x(), rect.y(), rect.height(), rect.width()
+
+ path = QPainterPath()
+ path.addRoundedRect(x, y, w, h, 4, 4)
+
+ painter.save()
+ painter.setRenderHint(QPainter.Antialiasing)
+ painter.drawRoundedRect(rect, 4, 4)
+
+ if status == 'in': # already in the slice
+ painter.fillPath(path, QColor("cyan"))
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(option.rect, 0, QString(data))
+
+ elif status == 'add': # newly added to the slice
+ painter.fillPath(path, QColor.fromRgb(0, 250, 0))
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(option.rect, 0, QString(data))
+
+ elif status == 'remove': # removed from the slice
+ painter.fillPath(path, QColor.fromRgb(250, 0, 0))
+ painter.setPen(QColor.fromRgb(0, 0, 0))
+ painter.drawText(option.rect, 0, QString(data))
+
+ painter.restore()
+ rect.setX(rect.x() + rect.width() + 4)
+
+