Skip to content

Commit

Permalink
Some color for the world
Browse files Browse the repository at this point in the history
  • Loading branch information
Salanto committed Mar 27, 2024
1 parent dcb0ea8 commit d7f08b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/elementstyler.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "elementstyler.h"
#include <QDebug>
#include "qfontdatabase.h"
#include "qobjectdefs.h"

#include <QCheckBox>
#include <QComboBox>
Expand Down Expand Up @@ -112,6 +113,7 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
qlabel_styler["enabled"] = &ElementStyler::setEnabled<QLabel>;
qlabel_styler["font"] = &ElementStyler::setFont<QLabel>;
qlabel_styler["pointsize"] = &ElementStyler::setPointSize<QLabel>;
qlabel_styler["color"] = &ElementStyler::setStylesheetColor<QLabel>;
styler["QLabel"] = qlabel_styler;

QMap<QString, ElementStylist> qpushbutton_styler;
Expand All @@ -122,6 +124,7 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
qpushbutton_styler["text"] = &ElementStyler::setText<QPushButton>;
qpushbutton_styler["font"] = &ElementStyler::setFont<QPushButton>;
qpushbutton_styler["pointsize"] = &ElementStyler::setPointSize<QPushButton>;
qpushbutton_styler["color"] = &ElementStyler::setStylesheetColor<QPushButton>;
styler["QPushButton"] = qpushbutton_styler;

// Layouts
Expand Down Expand Up @@ -506,3 +509,26 @@ void ElementStyler::setPointSize(QString element_id, QString point_size)
font.setPointSize(point_size.toInt());
pointer->setFont(font);
}

template<typename T>
void ElementStyler::setStylesheetColor(QString element_id, QString color)
{
T *pointer = ui->findChild<T *>(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<QColor>(l_color).toString());
QString stylesheet = pointer->styleSheet();
qDebug() << stylesheet;
stylesheet.append(stylesheet_entry);
qDebug() << stylesheet;
pointer->setStyleSheet(stylesheet);
}
3 changes: 3 additions & 0 deletions src/elementstyler.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ElementStyler : public QObject
template<typename T>
void setColor(QString element_id, QString color);

template<typename T>
void setStylesheetColor(QString element_id, QString color);

template<typename T>
void setFloatStrength(QString element_id, QString strength);

Expand Down

0 comments on commit d7f08b2

Please sign in to comment.