Skip to content

Commit 937a564

Browse files
committed
Visualizer buttons have adaptive color now.
1 parent 6cfcd05 commit 937a564

File tree

3 files changed

+47
-95
lines changed

3 files changed

+47
-95
lines changed

src/frmmain.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,37 @@ void frmMain::applySettings() {
18101810
m_codeDrawer->setColorEnd(m_settings.colors("ToolpathEnd"));
18111811
m_codeDrawer->update();
18121812

1813+
// Adapt visualizer buttons colors
1814+
const int LIGHTBOUND = 127;
1815+
const int NORMALSHIFT = 40;
1816+
const int HIGHLIGHTSHIFT = 80;
1817+
1818+
QColor base = m_settings.colors("VisualizerBackground");
1819+
bool light = base.value() > LIGHTBOUND;
1820+
QColor normal, highlight;
1821+
1822+
normal.setHsv(base.hue(), base.saturation(), base.value() + (light ? -NORMALSHIFT : NORMALSHIFT));
1823+
highlight.setHsv(base.hue(), base.saturation(), base.value() + (light ? -HIGHLIGHTSHIFT : HIGHLIGHTSHIFT));
1824+
1825+
ui->glwVisualizer->setStyleSheet(QString("QToolButton {border: 1px solid %1; \
1826+
background-color: %3} QToolButton:hover {border: 1px solid %2;}")
1827+
.arg(normal.name()).arg(highlight.name())
1828+
.arg(base.name()));
1829+
1830+
ui->cmdFit->setIcon(QIcon(":/images/fit_1.png"));
1831+
ui->cmdIsometric->setIcon(QIcon(":/images/cube.png"));
1832+
ui->cmdFront->setIcon(QIcon(":/images/cubeFront.png"));
1833+
ui->cmdLeft->setIcon(QIcon(":/images/cubeLeft.png"));
1834+
ui->cmdTop->setIcon(QIcon(":/images/cubeTop.png"));
1835+
1836+
if (!light) {
1837+
Util::invertButtonIconColors(ui->cmdFit);
1838+
Util::invertButtonIconColors(ui->cmdIsometric);
1839+
Util::invertButtonIconColors(ui->cmdFront);
1840+
Util::invertButtonIconColors(ui->cmdLeft);
1841+
Util::invertButtonIconColors(ui->cmdTop);
1842+
}
1843+
18131844
ui->cboCommand->setMinimumHeight(ui->cboCommand->height());
18141845
ui->cmdClearConsole->setFixedHeight(ui->cboCommand->height());
18151846
ui->cmdCommandSend->setFixedHeight(ui->cboCommand->height());

src/frmmain.ui

-95
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ QSlider::handle:horizontal:hover {
159159
<property name="toolTip">
160160
<string>Isometric view</string>
161161
</property>
162-
<property name="styleSheet">
163-
<string notr="true">QToolButton { /* all types of tool button */
164-
color: lightgray;
165-
border: 1px solid lightgray;
166-
border-radius: 0px;
167-
background-color: white;
168-
}
169-
170-
QToolButton:hover { /* all types of tool button */
171-
border: 1px solid gray;
172-
color: gray;
173-
}
174-
175-
QToolButton:pressed {
176-
}
177-
178-
QToolButton:checked { /* all types of tool button */
179-
}</string>
180-
</property>
181162
<property name="text">
182163
<string/>
183164
</property>
@@ -204,25 +185,6 @@ QToolButton:checked { /* all types of tool button */
204185
<property name="toolTip">
205186
<string>Top view</string>
206187
</property>
207-
<property name="styleSheet">
208-
<string notr="true">QToolButton { /* all types of tool button */
209-
color: lightgray;
210-
border: 1px solid lightgray;
211-
border-radius: 0px;
212-
background-color: white;
213-
}
214-
215-
QToolButton:hover { /* all types of tool button */
216-
border: 1px solid gray;
217-
color: gray;
218-
}
219-
220-
QToolButton:pressed {
221-
}
222-
223-
QToolButton:checked { /* all types of tool button */
224-
}</string>
225-
</property>
226188
<property name="text">
227189
<string/>
228190
</property>
@@ -249,25 +211,6 @@ QToolButton:checked { /* all types of tool button */
249211
<property name="toolTip">
250212
<string>Front view</string>
251213
</property>
252-
<property name="styleSheet">
253-
<string notr="true">QToolButton { /* all types of tool button */
254-
color: lightgray;
255-
border: 1px solid lightgray;
256-
border-radius: 0px;
257-
background-color: white;
258-
}
259-
260-
QToolButton:hover { /* all types of tool button */
261-
border: 1px solid gray;
262-
color: gray;
263-
}
264-
265-
QToolButton:pressed {
266-
}
267-
268-
QToolButton:checked { /* all types of tool button */
269-
}</string>
270-
</property>
271214
<property name="text">
272215
<string/>
273216
</property>
@@ -294,25 +237,6 @@ QToolButton:checked { /* all types of tool button */
294237
<property name="toolTip">
295238
<string>Left view</string>
296239
</property>
297-
<property name="styleSheet">
298-
<string notr="true">QToolButton { /* all types of tool button */
299-
color: lightgray;
300-
border: 1px solid lightgray;
301-
border-radius: 0px;
302-
background-color: white;
303-
}
304-
305-
QToolButton:hover { /* all types of tool button */
306-
border: 1px solid gray;
307-
color: gray;
308-
}
309-
310-
QToolButton:pressed {
311-
}
312-
313-
QToolButton:checked { /* all types of tool button */
314-
}</string>
315-
</property>
316240
<property name="text">
317241
<string/>
318242
</property>
@@ -339,25 +263,6 @@ QToolButton:checked { /* all types of tool button */
339263
<property name="toolTip">
340264
<string>Fit</string>
341265
</property>
342-
<property name="styleSheet">
343-
<string notr="true">QToolButton { /* all types of tool button */
344-
color: lightgray;
345-
border: 1px solid lightgray;
346-
border-radius: 0px;
347-
background-color: white;
348-
}
349-
350-
QToolButton:hover { /* all types of tool button */
351-
border: 1px solid gray;
352-
color: gray;
353-
}
354-
355-
QToolButton:pressed {
356-
}
357-
358-
QToolButton:checked { /* all types of tool button */
359-
}</string>
360-
</property>
361266
<property name="text">
362267
<string/>
363268
</property>

src/utils/util.h

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
#define UTIL
66

77
#include <QColor>
8+
#include <QIcon>
9+
#include <QImage>
10+
#include <QAbstractButton>
811
#include <QVector3D>
912
#include <QEventLoop>
1013
#include <QTimer>
@@ -40,6 +43,19 @@ class Util
4043
QTimer::singleShot(ms, &loop, SLOT(quit()));
4144
loop.exec();
4245
}
46+
47+
static QIcon invertIconColors(QIcon icon)
48+
{
49+
QImage img = icon.pixmap(icon.actualSize(QSize(64, 64))).toImage();
50+
img.invertPixels();
51+
52+
return QIcon(QPixmap::fromImage(img));
53+
}
54+
55+
static void invertButtonIconColors(QAbstractButton *button)
56+
{
57+
button->setIcon(invertIconColors(button->icon()));
58+
}
4359
};
4460

4561
#endif // UTIL

0 commit comments

Comments
 (0)