33 const QPointF &position,
35 bool isSelected,
bool isHovered,
bool hasFocus,
36 const QColor &highlightColor,
45 borderColor = highlightColor;
46 borderColor.setAlpha(255);
47 borderWidth = hasFocus ? 2 : 1;
50 borderColor = highlightColor;
51 borderColor.setAlpha(192);
53 borderColor = QColor(0, 0, 0, 128);
57 const QPointF alignedPosition(qRound(position.x() + 0.5) - 0.5, position.y());
58 const qreal halfWidth = size.width() * 0.5;
59 QPainterPath path(alignedPosition);
61 alignedPosition.x() - halfWidth,
62 alignedPosition.y() + size.height() - size.width(),
71 painter.setClipRect(QRectF(QPointF(alignedPosition.x() - halfWidth, alignedPosition.y()), QSizeF(halfWidth, size.height())));
72 painter.setPen(Qt::NoPen);
73 painter.setBrush(color1.
color);
74 painter.drawPath(path);
75 painter.setClipRect(QRectF(alignedPosition, QSizeF(halfWidth, size.height())));
76 painter.setBrush(color2.
color);
77 painter.drawPath(path);
78 painter.setClipping(
false);
79 painter.setPen(QPen(borderColor, borderWidth));
80 painter.setBrush(Qt::NoBrush);
81 painter.drawPath(path);
83 painter.setPen(QPen(borderColor, borderWidth));
86 painter.setBrush(color1.
color);
89 painter.setBrush(color2.
color);
91 painter.drawPath(path);
94 constexpr QSizeF typeIndicatorSize(5.0, 5.0);
96 QPointF typeIndicatorPosition(
97 alignedPosition.x() - halfWidth - 1.0,
98 alignedPosition.y() + size.height() - typeIndicatorSize.height() + 1.0
101 painter.setPen(QPen(Qt::white, 1));
102 painter.setBrush(Qt::black);
104 painter.setPen(QPen(Qt::black, 1));
105 painter.setBrush(Qt::white);
107 painter.drawEllipse(QRectF(typeIndicatorPosition, typeIndicatorSize));
110 QPointF typeIndicatorPosition(
111 alignedPosition.x() + halfWidth - typeIndicatorSize.width() + 1.0,
112 alignedPosition.y() + size.height() - typeIndicatorSize.height() + 1.0
115 painter.setPen(QPen(Qt::white, 1));
116 painter.setBrush(Qt::black);
118 painter.setPen(QPen(Qt::black, 1));
119 painter.setBrush(Qt::white);
121 painter.drawEllipse(QRectF(typeIndicatorPosition, typeIndicatorSize));
128 const QPointF &position,
130 bool isSelected,
bool isHovered,
bool hasFocus,
131 const QColor &borderColor,
132 const QColor &fillColor,
133 const QColor &highlightColor)
140 brushColor = highlightColor;
141 penWidth = hasFocus ? 2 : 1;
144 brushColor = highlightColor;
145 brushColor.setAlpha(192);
147 brushColor = fillColor;
151 const QPointF alignedPosition(qRound(position.x() + 0.5) - 0.5, qRound(position.y() + 0.5) - 0.5);
152 const qreal alignedSize = qRound(size);
153 const qreal handleSizeOverTwo = alignedSize * 0.5;
154 const QPointF points[4] =
157 QPointF(-handleSizeOverTwo, handleSizeOverTwo),
159 QPointF(handleSizeOverTwo, handleSizeOverTwo)
161 painter.translate(alignedPosition);
162 painter.setPen(QPen(borderColor, penWidth));
163 painter.setBrush(brushColor);
164 painter.drawPolygon(points, 4);