Skip to content

Commit c780008

Browse files
committed
GUI - improve nav button rendering
1 parent 7f78c8e commit c780008

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

gui/widgets/controllayer.cpp

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ void CircularButton::paintEvent(QPaintEvent *)
2727
{
2828
QPainter painter(this);
2929
painter.setRenderHint(QPainter::Antialiasing);
30+
painter.setRenderHint(QPainter::SmoothPixmapTransform);
3031

3132
// Create a circular path for the button
3233
QPainterPath circlePath;
@@ -48,6 +49,7 @@ void CircularButton::paintEvent(QPaintEvent *)
4849
gradient.setColorAt(1, QColor(255, 255, 255, 90));
4950
}
5051

52+
// Draw button background
5153
painter.fillPath(circlePath, gradient);
5254

5355
// Draw border - slightly brighter on hover
@@ -58,32 +60,13 @@ void CircularButton::paintEvent(QPaintEvent *)
5860
}
5961
painter.drawEllipse(buttonRect);
6062

61-
// Now create inverted icon using screen capture
6263
if (!icon().isNull()) {
63-
// For simplicity, just use cutout with inverted fill in the icon area
64-
QPixmap iconPixmap = icon().pixmap(iconSize());
65-
66-
// Create the button with inverted icon
67-
QPixmap finalButton(size());
68-
finalButton.fill(Qt::transparent);
69-
70-
QPainter finalPainter(&finalButton);
71-
finalPainter.setRenderHint(QPainter::Antialiasing);
72-
73-
// Draw button background
74-
finalPainter.fillPath(circlePath, gradient);
75-
finalPainter.setPen(QPen(QColor(255, 255, 255, 180), 1));
76-
finalPainter.drawEllipse(buttonRect);
77-
78-
// Draw the icon in inverted colors (white where normally black)
64+
// Calculate icon position
7965
QRect iconRect = QRect(0, 0, iconSize().width(), iconSize().height());
8066
iconRect.moveCenter(rect().center());
8167

82-
// Draw the icon directly (it's already black in the SVG)
83-
finalPainter.drawPixmap(iconRect, iconPixmap);
84-
85-
finalPainter.end();
86-
painter.drawPixmap(0, 0, finalButton);
68+
// Draw the icon directly - QIcon handles DPI scaling internally
69+
icon().paint(&painter, iconRect);
8770
}
8871
}
8972

@@ -102,30 +85,36 @@ ControlLayer::ControlLayer(QWidget *parent)
10285

10386
void ControlLayer::setupControls()
10487
{
88+
// Let Qt's style system determine appropriate icon size
89+
// PM_SmallIconSize gives platform-appropriate small icon size (usually 16x16 logical pixels)
90+
// This automatically scales with DPI and respects platform conventions
91+
int iconExtent = style()->pixelMetric(QStyle::PM_SmallIconSize, nullptr, this);
92+
QSize iconSize(iconExtent, iconExtent);
93+
10594
m_sizeDownButton = new CircularButton("", this); // Will use icon
10695
m_sizeDownButton->setIcon(QIcon(":/images/nav-controls/minus.svg"));
107-
m_sizeDownButton->setIconSize(QSize(13, 13));
96+
m_sizeDownButton->setIconSize(iconSize);
10897

10998
m_sizeUpButton = new CircularButton("", this); // Will use icon
11099
m_sizeUpButton->setIcon(QIcon(":/images/nav-controls/plus.svg"));
111-
m_sizeUpButton->setIconSize(QSize(13, 13));
100+
m_sizeUpButton->setIconSize(iconSize);
112101

113102
m_openExternalBrowserButton = new CircularButton("", this); // Will use icon
114103
m_openExternalBrowserButton->setIcon(QIcon(":/images/nav-controls/external-link.svg"));
115-
m_openExternalBrowserButton->setIconSize(QSize(13, 13));
104+
m_openExternalBrowserButton->setIconSize(iconSize);
116105

117106
m_resetBrowserButton = new CircularButton("", this); // Will use icon
118107
m_resetBrowserButton->setIcon(QIcon(":/images/nav-controls/refresh.svg"));
119-
m_resetBrowserButton->setIconSize(QSize(13, 13));
108+
m_resetBrowserButton->setIconSize(iconSize);
120109

121110
m_consoleToggleButton = new CircularButton("", this); // Will use icon
122111
m_consoleToggleButton->setIcon(QIcon(":/images/nav-controls/chevron-up.svg"));
123-
m_consoleToggleButton->setIconSize(QSize(13, 13));
112+
m_consoleToggleButton->setIconSize(iconSize);
124113
m_consoleToggleButton->setToolTip("Toggle Debug Pane");
125114

126115
m_saveImageButton = new CircularButton("", this); // Will use icon
127116
m_saveImageButton->setIcon(QIcon(":/images/nav-controls/image.svg"));
128-
m_saveImageButton->setIconSize(QSize(13, 13));
117+
m_saveImageButton->setIconSize(iconSize);
129118
m_saveImageButton->setToolTip("Save as Image");
130119

131120
// Add tooltips for all buttons

0 commit comments

Comments
 (0)