feat: Render composite arrow and tool icon for active tool cursor
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -394,18 +394,34 @@ void ViewportWidget::onActiveToolChanged(int tool)
|
|||||||
if (m_toolIcons.contains(tool)) {
|
if (m_toolIcons.contains(tool)) {
|
||||||
QSvgRenderer* renderer = m_toolIcons.value(tool);
|
QSvgRenderer* renderer = m_toolIcons.value(tool);
|
||||||
if (renderer && renderer->isValid()) {
|
if (renderer && renderer->isValid()) {
|
||||||
|
const QSize cursorSize(48, 48);
|
||||||
|
QPixmap cursorPixmap(cursorSize);
|
||||||
|
cursorPixmap.fill(Qt::transparent);
|
||||||
|
QPainter painter(&cursorPixmap);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
|
// Draw arrow cursor manually
|
||||||
|
QPolygon arrowPolygon;
|
||||||
|
arrowPolygon << QPoint(0, 0) << QPoint(0, 11) << QPoint(4, 11) << QPoint(4, 16) << QPoint(7, 16) << QPoint(7, 11) << QPoint(11, 11);
|
||||||
|
painter.setPen(Qt::white);
|
||||||
|
painter.setBrush(Qt::black);
|
||||||
|
painter.drawPolygon(arrowPolygon);
|
||||||
|
|
||||||
|
// Render tool icon
|
||||||
const QSize iconSize(32, 32);
|
const QSize iconSize(32, 32);
|
||||||
|
QPixmap iconPixmap(iconSize);
|
||||||
|
iconPixmap.fill(Qt::transparent);
|
||||||
|
QPainter iconPainter(&iconPixmap);
|
||||||
|
renderer->render(&iconPainter);
|
||||||
|
iconPainter.end();
|
||||||
|
|
||||||
QPixmap pixmap(iconSize);
|
// Invert and draw icon onto cursor pixmap
|
||||||
pixmap.fill(Qt::transparent);
|
QImage iconImage = iconPixmap.toImage();
|
||||||
QPainter pixmapPainter(&pixmap);
|
iconImage.invertPixels(QImage::InvertRgb);
|
||||||
renderer->render(&pixmapPainter);
|
painter.drawImage(QRect(12, 12, iconSize.width(), iconSize.height()), iconImage);
|
||||||
pixmapPainter.end();
|
painter.end();
|
||||||
|
|
||||||
QImage image = pixmap.toImage();
|
setCursor(QCursor(cursorPixmap, 0, 0));
|
||||||
image.invertPixels(QImage::InvertRgb);
|
|
||||||
|
|
||||||
setCursor(QCursor(QPixmap::fromImage(image), 16, 16));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsetCursor();
|
unsetCursor();
|
||||||
|
|||||||
Reference in New Issue
Block a user