From dc62a09e90155ee94e77d4f91629522f193c2034 Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:40:32 +0100 Subject: [PATCH] Add checkbox, combobox and qwidget styler --- src/elementstyler.cpp | 127 +++++++++++++++++++++++++++++++++++++++++ src/elementstyler.h | 24 ++++++++ src/xmlinputwindow.cpp | 1 + 3 files changed, 152 insertions(+) diff --git a/src/elementstyler.cpp b/src/elementstyler.cpp index 977f614..0323e5b 100644 --- a/src/elementstyler.cpp +++ b/src/elementstyler.cpp @@ -1,8 +1,11 @@ #include "elementstyler.h" #include +#include +#include #include #include +#include #include ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui) @@ -14,12 +17,47 @@ ElementStyler::ElementStyler(QObject *parent, QWidget *full_ui) } // Widgets + QMap qcheckbox_styler; + qcheckbox_styler["size"] = &ElementStyler::setFixedSize; + qcheckbox_styler["position"] = &ElementStyler::move; + qcheckbox_styler["visible"] = &ElementStyler::setVisible; + qcheckbox_styler["enabled"] = &ElementStyler::setEnabled; + qcheckbox_styler["text"] = &ElementStyler::setText; + qcheckbox_styler["checkable"] = &ElementStyler::setCheckable; + qcheckbox_styler["checked"] = &ElementStyler::setChecked; + styler["QCheckBox"] = qcheckbox_styler; + + QMap qcombobox_styler; + qcombobox_styler["size"] = &ElementStyler::setFixedSize; + qcombobox_styler["position"] = &ElementStyler::move; + qcombobox_styler["visible"] = &ElementStyler::setVisible; + qcombobox_styler["enabled"] = &ElementStyler::setEnabled; + qcombobox_styler["items"] = &ElementStyler::addItems; + qcombobox_styler["editable"] = &ElementStyler::setEditable; + qcombobox_styler["placeholder"] = &ElementStyler::setPlaceholderText; + styler["QComboBox"] = qcombobox_styler; + + QMap qwidget_styler; + qwidget_styler["size"] = &ElementStyler::setFixedSize; + qwidget_styler["position"] = &ElementStyler::move; + qwidget_styler["visible"] = &ElementStyler::setVisible; + qwidget_styler["enabled"] = &ElementStyler::setEnabled; + styler["QWidget"] = qwidget_styler; + + QMap qlistwidget_styler; + qwidget_styler["size"] = &ElementStyler::setFixedSize; + qwidget_styler["position"] = &ElementStyler::move; + qwidget_styler["visible"] = &ElementStyler::setVisible; + qwidget_styler["enabled"] = &ElementStyler::setEnabled; + styler["QListWidget"] = qlistwidget_styler; QMap qlabel_styler; qlabel_styler["text"] = &ElementStyler::setText; qlabel_styler["image"] = &ElementStyler::setPixmap; qlabel_styler["size"] = &ElementStyler::setFixedSize; qlabel_styler["position"] = &ElementStyler::move; + qlabel_styler["visible"] = &ElementStyler::setVisible; + qlabel_styler["enabled"] = &ElementStyler::setEnabled; styler["QLabel"] = qlabel_styler; // Layouts @@ -201,3 +239,92 @@ void ElementStyler::setFloatOpacity(QString element_id, QString opacity) } pointer->setOpacity(opacity.toFloat()); } + +template +void ElementStyler::setVisible(QString element_id, QString visible) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set visibility"; + return; + } + bool is_visible = QVariant::fromValue(visible).toBool(); + pointer->setVisible(is_visible); +} + +template +void ElementStyler::setToolTip(QString element_id, QString tooltip) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set tooltip"; + return; + } + pointer->setToolTip(tooltip); +} + +template +void ElementStyler::setEnabled(QString element_id, QString enabled) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set enabled state"; + return; + } + pointer->setEnabled(QVariant::fromValue(enabled).toBool()); +} + +template +void ElementStyler::setCheckable(QString element_id, QString checkable) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set checkable state"; + return; + } + pointer->setCheckable(QVariant::fromValue(checkable).toBool()); +} + +template +void ElementStyler::setChecked(QString element_id, QString checked) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set checked state"; + return; + } + pointer->setChecked(QVariant::fromValue(checked).toBool()); +} + +template +void ElementStyler::addItems(QString element_id, QString items) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set selectable items"; + return; + } + pointer->addItems(items.split(",")); +} + +template +void ElementStyler::setEditable(QString element_id, QString editable) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set editable state"; + return; + } + pointer->setEditable(QVariant::fromValue(editable).toBool()); +} + +template +void ElementStyler::setPlaceholderText(QString element_id, QString placeholder) +{ + T *pointer = ui->findChild(element_id); + if (pointer == nullptr) { + qDebug() << "Unable to locate element" << element_id << "to set placeholder text"; + return; + } + pointer->setPlaceholderText(placeholder); +} diff --git a/src/elementstyler.h b/src/elementstyler.h index f2cf1c3..eae1d9e 100644 --- a/src/elementstyler.h +++ b/src/elementstyler.h @@ -25,6 +25,9 @@ class ElementStyler : public QObject template void setText(QString element_id, QString text); + template + void setPlaceholderText(QString element_id, QString placeholder); + template void setPixmap(QString element_id, QString image_path); @@ -48,6 +51,27 @@ class ElementStyler : public QObject template void setFloatOpacity(QString element_id, QString opacity); + + template + void setVisible(QString element_id, QString visible); + + template + void setEnabled(QString element_id, QString enabled); + + template + void setToolTip(QString element_id, QString tooltip); + + template + void setCheckable(QString element_id, QString checkable); + + template + void setChecked(QString element_id, QString checked); + + template + void setEditable(QString element_id, QString editable); + + template + void addItems(QString element_id, QString items); }; #endif // ELEMENTSTYLER_H diff --git a/src/xmlinputwindow.cpp b/src/xmlinputwindow.cpp index 0838342..bfe64ce 100644 --- a/src/xmlinputwindow.cpp +++ b/src/xmlinputwindow.cpp @@ -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);