def realRender(self, painter, renderPath): # TODO/PORT: Still needs work. """ TOWRITE :param `painter`: TOWRITE :type `painter`: `QPainter`_ :param `renderPath`: TOWRITE :type `renderPath`: `QPainterPath`_ """ color1 = self.objectColor() #QColor # lighter color color2 = color1.darker(150) #QColor # darker color # If we have a dark color, lighten it darkness = color1.lightness() #int threshold = 32 #int #TODO: This number may need adjusted or maybe just add it to settings. if darkness < threshold: color2 = color1 if not darkness: color1 = QColor(threshold, threshold, threshold) # lighter() does not affect pure black else : color1 = color2.lighter(100 + threshold) count = renderPath.elementCount() # int for i in range(0, count - 1): # for(int i = 0; i < count-1; ++i); elem = renderPath.elementAt(i) # QPainterPath::Element next = renderPath.elementAt(i + 1) # QPainterPath::Element if next.isMoveTo(): continue elemPath = QPainterPath() elemPath.moveTo(elem.x, elem.y) elemPath.lineTo(next.x, next.y) renderPen = QPen(QColor(0, 0, 0, 0)) renderPen.setWidthF(0) painter.setPen(renderPen) stroker = QPainterPathStroker() stroker.setWidth(0.35) stroker.setCapStyle(Qt.RoundCap) stroker.setJoinStyle(Qt.RoundJoin) realPath = stroker.createStroke(elemPath) # QPainterPath painter.drawPath(realPath) grad = QLinearGradient(elemPath.pointAtPercent(0.5), elemPath.pointAtPercent(0.0)) grad.setColorAt(0, color1) grad.setColorAt(1, color2) grad.setSpread(QGradient.ReflectSpread) painter.fillPath(realPath, QBrush(grad))
def paint(self, painter, option, index): name_rect = option.rect.adjusted(4, 0, -4, 0) item_rect = option.rect.adjusted(1, 1, -1, 0) painter.fillRect(item_rect, QColor(index.data(item_background))) if option.state & QStyle.State_Selected: g_selected = QLinearGradient(0, item_rect.y(), 0, item_rect.y() + item_rect.height()) g_selected.setColorAt(0.0, QColor(100, 100, 100, 200)) g_selected.setColorAt(1.0 / item_rect.height(), QColor(100, 200, 255, 255)) g_selected.setColorAt(1.0 - 1.0 / item_rect.height(), QColor(100, 200, 255, 255)) g_selected.setColorAt(1.0, QColor(255, 255, 255, 0)) g_selected.setSpread(QGradient.ReflectSpread) painter.fillRect(item_rect, g_selected) elif option.state & QStyle.State_MouseOver: g_hover = QLinearGradient(0, item_rect.y(), 0, item_rect.y() + item_rect.height()) g_hover.setColorAt(0.0, QColor(255, 255, 255, 200)) g_hover.setColorAt(1.0 / item_rect.height(), QColor(255, 255, 255, 50)) g_hover.setColorAt(1.0 - 1.0 / item_rect.height(), QColor(255, 255, 255, 0)) g_hover.setColorAt(1.0, QColor(100, 100, 100, 200)) painter.fillRect(item_rect, g_hover) painter.save() painter.setPen( QPen( QColor( index.data(item_color) if self.role == file_convert else '#000'))) painter.drawText(name_rect, Qt.AlignVCenter, index.data(self.role)) painter.restore()