diff --git a/src/elementstyler.cpp b/src/elementstyler.cpp index c33081e..ec296ec 100644 --- a/src/elementstyler.cpp +++ b/src/elementstyler.cpp @@ -1,6 +1,7 @@ #include "elementstyler.h" #include #include "qfontdatabase.h" +#include "qobjectdefs.h" #include #include @@ -112,6 +113,7 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui) qlabel_styler["enabled"] = &ElementStyler::setEnabled; qlabel_styler["font"] = &ElementStyler::setFont; qlabel_styler["pointsize"] = &ElementStyler::setPointSize; + qlabel_styler["color"] = &ElementStyler::setStylesheetColor; styler["QLabel"] = qlabel_styler; QMap qpushbutton_styler; @@ -122,6 +124,7 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui) qpushbutton_styler["text"] = &ElementStyler::setText; qpushbutton_styler["font"] = &ElementStyler::setFont; qpushbutton_styler["pointsize"] = &ElementStyler::setPointSize; + qpushbutton_styler["color"] = &ElementStyler::setStylesheetColor; styler["QPushButton"] = qpushbutton_styler; // Layouts @@ -506,3 +509,26 @@ void ElementStyler::setPointSize(QString element_id, QString point_size) font.setPointSize(point_size.toInt()); pointer->setFont(font); } + +template +void ElementStyler::setStylesheetColor(QString element_id, QString color) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to apply text color"; + return; + } + QColor l_color = QColor::fromString(color); + if (!l_color.isValid()) { + qDebug() << "Unable to parse color. Provided color" << color << "is not valid."; + return; + } + QString stylesheet_entry = QString("%1 {color: %2 }") + .arg(pointer->metaObject()->className(), + QVariant::fromValue(l_color).toString()); + QString stylesheet = pointer->styleSheet(); + qDebug() << stylesheet; + stylesheet.append(stylesheet_entry); + qDebug() << stylesheet; + pointer->setStyleSheet(stylesheet); +} diff --git a/src/elementstyler.h b/src/elementstyler.h index 4f8ab5b..5aa3f4b 100644 --- a/src/elementstyler.h +++ b/src/elementstyler.h @@ -40,6 +40,9 @@ class ElementStyler : public QObject template void setColor(QString element_id, QString color); + template + void setStylesheetColor(QString element_id, QString color); + template void setFloatStrength(QString element_id, QString strength);