Commit 63ad450f authored by NICLAUSSE Nicolas's avatar NICLAUSSE Nicolas
Browse files

add the possibility of overriding textOn and textOff for dtkWidgetsParameterBoolPushButton

parent 4c7e4353
......@@ -43,14 +43,6 @@
"widget_read_only": true
}
},
{
"parameter": {
"widget": "dtkWidgetsParameterBoolPushButton",
"uid": "push_button_ro",
"advanced": false,
"widget_read_only": true
}
},
{
"parameter": {
"widget": "dtkWidgetsParameterFileBrowse",
......@@ -153,6 +145,8 @@
"widget": "dtkWidgetsParameterBoolPushButton",
"uid": "push_button",
"advanced": false,
"textOn": "Nobody expects the spanish inquisition!",
"textOff": "Hit me",
"widget_read_only": false
}
},
......
......@@ -26,6 +26,8 @@ public:
QPushButton *push_button = nullptr;
bool running = false;
QString on_text = "Running ...";
QString off_text = "Run";
};
// ///////////////////////////////////////////////////////////////////
......@@ -47,6 +49,17 @@ dtkWidgetsParameterBoolPushButton::~dtkWidgetsParameterBoolPushButton(void)
delete d;
}
void dtkWidgetsParameterBoolPushButton::setOnText(const QString & text)
{
d->on_text = text;
}
void dtkWidgetsParameterBoolPushButton::setOffText(const QString & text)
{
d->off_text = text;
d->push_button->setText(d->off_text);
}
void dtkWidgetsParameterBoolPushButton::setReadOnly(bool val)
{
this->dtkWidgetsParameter::m_readonly = val;
......@@ -79,10 +92,10 @@ bool dtkWidgetsParameterBoolPushButton::connect(dtkCoreParameter *p)
auto setAppearance = [this] (bool state) {
if (state) {
this->d->push_button->setStyleSheet("background-color: red");
this->d->push_button->setText("Running...");
this->d->push_button->setText(d->on_text);
} else {
this->d->push_button->setStyleSheet("");
this->d->push_button->setText("Run");
this->d->push_button->setText(d->off_text);
}
};
......
......@@ -31,6 +31,8 @@ public:
public:
bool connect(dtkCoreParameter *) override;
void setReadOnly(bool) override;
void setOnText(const QString&);
void setOffText(const QString&);
private:
using dtkWidgetsParameterBase<dtk::d_bool>::m_parameter;
......
......@@ -14,6 +14,7 @@
#include "dtkWidgetsParameterMenuBarGenerator.h"
#include "dtkWidgetsParameterBoolPushButton.h"
#include "dtkWidgetsParameterFactory.h"
#include "dtkWidgetsParameter.h"
#include "dtkWidgetsMenu.h"
......@@ -107,6 +108,15 @@ void dtkWidgetsParameterMenuBarGeneratorPrivate::parseParameter(dtkWidgetsMenu *
if(parameter_object.contains("widget_read_only")) {
param_widget->setReadOnly(parameter_object["widget_read_only"].toBool());
}
auto bool_widget = dynamic_cast<dtkWidgetsParameterBoolPushButton*>(param_widget);
if (bool_widget) {
if (parameter_object.contains("textOn")) {
bool_widget->setOnText(parameter_object["textOn"].toString());
}
if (parameter_object.contains("textOff")) {
bool_widget->setOffText(parameter_object["textOff"].toString());
}
}
parameters_widgets[parameter_uid] = param_widget;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment