mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-27 06:01:14 +01:00
helpers
refactor color functions so they can be used on all widgets
This commit is contained in:
+12
-19
@@ -9,30 +9,23 @@ void create_dial_needle(QwtDial* dial)
|
||||
dial->setNeedle( needle );
|
||||
}
|
||||
|
||||
void set_thermo_color(QwtSlider* slider, QColor color, QColor bg)
|
||||
void set_widget_color(QWidget* widget, QColor color, QColor bg)
|
||||
{
|
||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(slider->objectName(), bg.name(), color.name());
|
||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg.name(), color.name());
|
||||
|
||||
slider->setStyleSheet(style);
|
||||
widget->setStyleSheet(style);
|
||||
}
|
||||
|
||||
void set_button_color(QPushButton* button, QColor color, QColor bg)
|
||||
void set_widget_color(QWidget* widget, QString color, QString bg)
|
||||
{
|
||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(button->objectName(), bg.name(), color.name());
|
||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(widget->objectName(), bg, color);
|
||||
|
||||
button->setStyleSheet(style);
|
||||
widget->setStyleSheet(style);
|
||||
}
|
||||
|
||||
void set_button_color(QPushButton* button, QString color, QString bg)
|
||||
QColor widget_bg_color(QWidget* widget)
|
||||
{
|
||||
QString style = QString("#%1 { background-color: %2; color: %3;}").arg(button->objectName(), bg, color);
|
||||
|
||||
button->setStyleSheet(style);
|
||||
}
|
||||
|
||||
QColor button_bg_color(QPushButton* button)
|
||||
{
|
||||
std::string input = button->styleSheet().toStdString();
|
||||
std::string input = widget->styleSheet().toStdString();
|
||||
QColor background_color;
|
||||
|
||||
// Find the position of "background-color:"
|
||||
@@ -49,9 +42,9 @@ QColor button_bg_color(QPushButton* button)
|
||||
return background_color;
|
||||
}
|
||||
|
||||
QColor button_color(QPushButton* button)
|
||||
QColor widget_color(QWidget* widget)
|
||||
{
|
||||
std::string input = button->styleSheet().toStdString();
|
||||
std::string input = widget->styleSheet().toStdString();
|
||||
QColor color;
|
||||
|
||||
// Find the position of "color:"
|
||||
@@ -67,9 +60,9 @@ QColor button_color(QPushButton* button)
|
||||
return color;
|
||||
}
|
||||
|
||||
void reset_button_color(QPushButton* button)
|
||||
void reset_widget_color(QWidget* widget)
|
||||
{
|
||||
button->setStyleSheet("");
|
||||
widget->setStyleSheet("");
|
||||
}
|
||||
|
||||
bool is_read_only(QWidget* widget)
|
||||
|
||||
+5
-6
@@ -14,12 +14,11 @@
|
||||
|
||||
void create_dial_needle(QwtDial* dial);
|
||||
|
||||
void set_thermo_color(QwtSlider* slider, QColor color, QColor bg);
|
||||
void set_button_color(QPushButton* button, QColor color, QColor bg);
|
||||
void set_button_color(QPushButton* button, QString color, QString bg);
|
||||
QColor button_bg_color(QPushButton* button);
|
||||
QColor button_color(QPushButton* button);
|
||||
void reset_button_color(QPushButton* button);
|
||||
void set_widget_color(QWidget* widget, QColor color, QColor bg);
|
||||
void set_widget_color(QWidget* widget, QString color, QString bg);
|
||||
QColor widget_bg_color(QWidget* widget);
|
||||
QColor widget_color(QWidget* widget);
|
||||
void reset_widget_color(QWidget* widget);
|
||||
void set_read_only(QWidget* widget, bool readOnly = true);
|
||||
bool is_read_only(QWidget* widget);
|
||||
QString network_reply_to_fix(QNetworkReply::NetworkError error);
|
||||
|
||||
+12
-12
@@ -290,31 +290,31 @@ void SimulatorBase::process_ui_button(json& uiItem)
|
||||
|
||||
if (bg_color == QColor(0x83, 0x91, 0x92))
|
||||
{
|
||||
reset_button_color(button);
|
||||
reset_widget_color(button);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0xFF, 0x00, 0x00))
|
||||
{
|
||||
set_button_color(button, QString("black"), QString("darkred"));
|
||||
set_widget_color(button, QString("black"), QString("darkred"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0x00, 0xFF, 0x00))
|
||||
{
|
||||
set_button_color(button, QString("white"), QString("darkgreen"));
|
||||
set_widget_color(button, QString("white"), QString("darkgreen"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0xFF8800))
|
||||
{
|
||||
set_button_color(button, QString("darkred"), QString("darkorange"));
|
||||
set_widget_color(button, QString("darkred"), QString("darkorange"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color != button_bg_color(button) || fg_color != button_color(button))
|
||||
if (bg_color != widget_bg_color(button) || fg_color != widget_color(button))
|
||||
{
|
||||
set_button_color(button, fg_color, bg_color);
|
||||
set_widget_color(button, fg_color, bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,30 +343,30 @@ void SimulatorBase::process_ui_led(json& uiItem)
|
||||
|
||||
if (bg_color == QColor(0x83, 0x91, 0x92))
|
||||
{
|
||||
reset_button_color(led);
|
||||
reset_widget_color(led);
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0xFF, 0x00, 0x00))
|
||||
{
|
||||
set_button_color(led, QString("black"), QString("darkred"));
|
||||
set_widget_color(led, QString("black"), QString("darkred"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0x00, 0xFF, 0x00))
|
||||
{
|
||||
set_button_color(led, QString("white"), QString("darkgreen"));
|
||||
set_widget_color(led, QString("white"), QString("darkgreen"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color == QColor(0xFF8800))
|
||||
{
|
||||
set_button_color(led, QString("darkred"), QString("darkorange"));
|
||||
set_widget_color(led, QString("darkred"), QString("darkorange"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (bg_color != button_bg_color(led))
|
||||
if (bg_color != widget_bg_color(led))
|
||||
{
|
||||
set_button_color(led, color, bg_color);
|
||||
set_widget_color(led, color, bg_color);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user