Skip to content

Commit

Permalink
Add checkbox, combobox and qwidget styler
Browse files Browse the repository at this point in the history
  • Loading branch information
Salanto committed Mar 24, 2024
1 parent 1e1bf0d commit dc62a09
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
127 changes: 127 additions & 0 deletions src/elementstyler.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "elementstyler.h"
#include <QDebug>

#include <QCheckBox>
#include <QComboBox>
#include <QGraphicsDropShadowEffect>
#include <QLabel>
#include <QListWidget>
#include <QWidget>

ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
Expand All @@ -14,12 +17,47 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui)
}

// Widgets
QMap<QString, ElementStylist> qcheckbox_styler;
qcheckbox_styler["size"] = &ElementStyler::setFixedSize<QCheckBox>;
qcheckbox_styler["position"] = &ElementStyler::move<QCheckBox>;
qcheckbox_styler["visible"] = &ElementStyler::setVisible<QCheckBox>;
qcheckbox_styler["enabled"] = &ElementStyler::setEnabled<QCheckBox>;
qcheckbox_styler["text"] = &ElementStyler::setText<QCheckBox>;
qcheckbox_styler["checkable"] = &ElementStyler::setCheckable<QCheckBox>;
qcheckbox_styler["checked"] = &ElementStyler::setChecked<QCheckBox>;
styler["QCheckBox"] = qcheckbox_styler;

QMap<QString, ElementStylist> qcombobox_styler;
qcombobox_styler["size"] = &ElementStyler::setFixedSize<QComboBox>;
qcombobox_styler["position"] = &ElementStyler::move<QComboBox>;
qcombobox_styler["visible"] = &ElementStyler::setVisible<QComboBox>;
qcombobox_styler["enabled"] = &ElementStyler::setEnabled<QComboBox>;
qcombobox_styler["items"] = &ElementStyler::addItems<QComboBox>;
qcombobox_styler["editable"] = &ElementStyler::setEditable<QComboBox>;
qcombobox_styler["placeholder"] = &ElementStyler::setPlaceholderText<QComboBox>;
styler["QComboBox"] = qcombobox_styler;

QMap<QString, ElementStylist> qwidget_styler;
qwidget_styler["size"] = &ElementStyler::setFixedSize<QWidget>;
qwidget_styler["position"] = &ElementStyler::move<QWidget>;
qwidget_styler["visible"] = &ElementStyler::setVisible<QWidget>;
qwidget_styler["enabled"] = &ElementStyler::setEnabled<QWidget>;
styler["QWidget"] = qwidget_styler;

QMap<QString, ElementStylist> qlistwidget_styler;
qwidget_styler["size"] = &ElementStyler::setFixedSize<QListWidget>;
qwidget_styler["position"] = &ElementStyler::move<QListWidget>;
qwidget_styler["visible"] = &ElementStyler::setVisible<QListWidget>;
qwidget_styler["enabled"] = &ElementStyler::setEnabled<QListWidget>;
styler["QListWidget"] = qlistwidget_styler;

QMap<QString, ElementStylist> qlabel_styler;
qlabel_styler["text"] = &ElementStyler::setText<QLabel>;
qlabel_styler["image"] = &ElementStyler::setPixmap<QLabel>;
qlabel_styler["size"] = &ElementStyler::setFixedSize<QLabel>;
qlabel_styler["position"] = &ElementStyler::move<QLabel>;
qlabel_styler["visible"] = &ElementStyler::setVisible<QLabel>;
qlabel_styler["enabled"] = &ElementStyler::setEnabled<QLabel>;
styler["QLabel"] = qlabel_styler;

// Layouts
Expand Down Expand Up @@ -201,3 +239,92 @@ void ElementStyler::setFloatOpacity(QString element_id, QString opacity)
}
pointer->setOpacity(opacity.toFloat());
}

template<typename T>
void ElementStyler::setVisible(QString element_id, QString visible)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set visibility";
return;
}
bool is_visible = QVariant::fromValue<QString>(visible).toBool();
pointer->setVisible(is_visible);
}

template<typename T>
void ElementStyler::setToolTip(QString element_id, QString tooltip)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set tooltip";
return;
}
pointer->setToolTip(tooltip);
}

template<typename T>
void ElementStyler::setEnabled(QString element_id, QString enabled)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set enabled state";
return;
}
pointer->setEnabled(QVariant::fromValue<QString>(enabled).toBool());
}

template<typename T>
void ElementStyler::setCheckable(QString element_id, QString checkable)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set checkable state";
return;
}
pointer->setCheckable(QVariant::fromValue<QString>(checkable).toBool());
}

template<typename T>
void ElementStyler::setChecked(QString element_id, QString checked)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set checked state";
return;
}
pointer->setChecked(QVariant::fromValue<QString>(checked).toBool());
}

template<typename T>
void ElementStyler::addItems(QString element_id, QString items)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set selectable items";
return;
}
pointer->addItems(items.split(","));
}

template<typename T>
void ElementStyler::setEditable(QString element_id, QString editable)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set editable state";
return;
}
pointer->setEditable(QVariant::fromValue<QString>(editable).toBool());
}

template<typename T>
void ElementStyler::setPlaceholderText(QString element_id, QString placeholder)
{
T *pointer = ui->findChild<T *>(element_id);
if (pointer == nullptr) {
qDebug() << "Unable to locate element" << element_id << "to set placeholder text";
return;
}
pointer->setPlaceholderText(placeholder);
}
24 changes: 24 additions & 0 deletions src/elementstyler.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class ElementStyler : public QObject
template<typename T>
void setText(QString element_id, QString text);

template<typename T>
void setPlaceholderText(QString element_id, QString placeholder);

template<typename T>
void setPixmap(QString element_id, QString image_path);

Expand All @@ -48,6 +51,27 @@ class ElementStyler : public QObject

template<typename T>
void setFloatOpacity(QString element_id, QString opacity);

template<typename T>
void setVisible(QString element_id, QString visible);

template<typename T>
void setEnabled(QString element_id, QString enabled);

template<typename T>
void setToolTip(QString element_id, QString tooltip);

template<typename T>
void setCheckable(QString element_id, QString checkable);

template<typename T>
void setChecked(QString element_id, QString checked);

template<typename T>
void setEditable(QString element_id, QString editable);

template<typename T>
void addItems(QString element_id, QString items);
};

#endif // ELEMENTSTYLER_H
1 change: 1 addition & 0 deletions src/xmlinputwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ XMLInputWindow::XMLInputWindow(QWidget *parent)
lbl->setText("Enter XML here.");
edit = new QTextEdit(this);
edit->setPlaceholderText("Add XML here!");
edit->setAcceptRichText(false);
QPushButton *button = new QPushButton(this);
button->setText("Spawn UI");
layout->addWidget(lbl);
Expand Down

0 comments on commit dc62a09

Please sign in to comment.