Skip to content

Commit

Permalink
Visualizer buttons have adaptive color now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denvi committed Mar 11, 2016
1 parent 6cfcd05 commit 937a564
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 95 deletions.
31 changes: 31 additions & 0 deletions src/frmmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1810,6 +1810,37 @@ void frmMain::applySettings() {
m_codeDrawer->setColorEnd(m_settings.colors("ToolpathEnd"));
m_codeDrawer->update();

// Adapt visualizer buttons colors
const int LIGHTBOUND = 127;
const int NORMALSHIFT = 40;
const int HIGHLIGHTSHIFT = 80;

QColor base = m_settings.colors("VisualizerBackground");
bool light = base.value() > LIGHTBOUND;
QColor normal, highlight;

normal.setHsv(base.hue(), base.saturation(), base.value() + (light ? -NORMALSHIFT : NORMALSHIFT));
highlight.setHsv(base.hue(), base.saturation(), base.value() + (light ? -HIGHLIGHTSHIFT : HIGHLIGHTSHIFT));

ui->glwVisualizer->setStyleSheet(QString("QToolButton {border: 1px solid %1; \
background-color: %3} QToolButton:hover {border: 1px solid %2;}")
.arg(normal.name()).arg(highlight.name())
.arg(base.name()));

ui->cmdFit->setIcon(QIcon(":/images/fit_1.png"));
ui->cmdIsometric->setIcon(QIcon(":/images/cube.png"));
ui->cmdFront->setIcon(QIcon(":/images/cubeFront.png"));
ui->cmdLeft->setIcon(QIcon(":/images/cubeLeft.png"));
ui->cmdTop->setIcon(QIcon(":/images/cubeTop.png"));

if (!light) {
Util::invertButtonIconColors(ui->cmdFit);
Util::invertButtonIconColors(ui->cmdIsometric);
Util::invertButtonIconColors(ui->cmdFront);
Util::invertButtonIconColors(ui->cmdLeft);
Util::invertButtonIconColors(ui->cmdTop);
}

ui->cboCommand->setMinimumHeight(ui->cboCommand->height());
ui->cmdClearConsole->setFixedHeight(ui->cboCommand->height());
ui->cmdCommandSend->setFixedHeight(ui->cboCommand->height());
Expand Down
95 changes: 0 additions & 95 deletions src/frmmain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,6 @@ QSlider::handle:horizontal:hover {
<property name="toolTip">
<string>Isometric view</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
color: lightgray;
border: 1px solid lightgray;
border-radius: 0px;
background-color: white;
}

QToolButton:hover { /* all types of tool button */
border: 1px solid gray;
color: gray;
}

QToolButton:pressed {
}

QToolButton:checked { /* all types of tool button */
}</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -204,25 +185,6 @@ QToolButton:checked { /* all types of tool button */
<property name="toolTip">
<string>Top view</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
color: lightgray;
border: 1px solid lightgray;
border-radius: 0px;
background-color: white;
}

QToolButton:hover { /* all types of tool button */
border: 1px solid gray;
color: gray;
}

QToolButton:pressed {
}

QToolButton:checked { /* all types of tool button */
}</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -249,25 +211,6 @@ QToolButton:checked { /* all types of tool button */
<property name="toolTip">
<string>Front view</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
color: lightgray;
border: 1px solid lightgray;
border-radius: 0px;
background-color: white;
}

QToolButton:hover { /* all types of tool button */
border: 1px solid gray;
color: gray;
}

QToolButton:pressed {
}

QToolButton:checked { /* all types of tool button */
}</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -294,25 +237,6 @@ QToolButton:checked { /* all types of tool button */
<property name="toolTip">
<string>Left view</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
color: lightgray;
border: 1px solid lightgray;
border-radius: 0px;
background-color: white;
}

QToolButton:hover { /* all types of tool button */
border: 1px solid gray;
color: gray;
}

QToolButton:pressed {
}

QToolButton:checked { /* all types of tool button */
}</string>
</property>
<property name="text">
<string/>
</property>
Expand All @@ -339,25 +263,6 @@ QToolButton:checked { /* all types of tool button */
<property name="toolTip">
<string>Fit</string>
</property>
<property name="styleSheet">
<string notr="true">QToolButton { /* all types of tool button */
color: lightgray;
border: 1px solid lightgray;
border-radius: 0px;
background-color: white;
}

QToolButton:hover { /* all types of tool button */
border: 1px solid gray;
color: gray;
}

QToolButton:pressed {
}

QToolButton:checked { /* all types of tool button */
}</string>
</property>
<property name="text">
<string/>
</property>
Expand Down
16 changes: 16 additions & 0 deletions src/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#define UTIL

#include <QColor>
#include <QIcon>
#include <QImage>
#include <QAbstractButton>
#include <QVector3D>
#include <QEventLoop>
#include <QTimer>
Expand Down Expand Up @@ -40,6 +43,19 @@ class Util
QTimer::singleShot(ms, &loop, SLOT(quit()));
loop.exec();
}

static QIcon invertIconColors(QIcon icon)
{
QImage img = icon.pixmap(icon.actualSize(QSize(64, 64))).toImage();
img.invertPixels();

return QIcon(QPixmap::fromImage(img));
}

static void invertButtonIconColors(QAbstractButton *button)
{
button->setIcon(invertIconColors(button->icon()));
}
};

#endif // UTIL
Expand Down

0 comments on commit 937a564

Please # to comment.