Adds progress bar value, max, min

This commit is contained in:
Atul R 2019-08-12 22:46:23 +02:00
parent e9414162cf
commit 69a4897ce3
4 changed files with 58 additions and 1 deletions

View File

@ -29,6 +29,9 @@ button.setText("Push Push Push!");
button.setObjectName("btn");
const progressbar = new QProgressBar();
progressbar.setValue(6);
progressbar.setMinimum(1);
progressbar.setMaximum(15);
const radioButton = new QRadioButton();
radioButton.setText("Roger that!");

View File

@ -11,6 +11,10 @@ Napi::Object QProgressBarWrap::init(Napi::Env env, Napi::Object exports) {
Napi::HandleScope scope(env);
char CLASSNAME[] = "QProgressBar";
Napi::Function func = DefineClass(env, CLASSNAME, {
InstanceMethod("setValue", &QProgressBarWrap::setValue),
InstanceMethod("setMaximum", &QProgressBarWrap::setMaximum),
InstanceMethod("setMinimum", &QProgressBarWrap::setMinimum),
InstanceMethod("value", &QProgressBarWrap::value),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QProgressBarWrap)
});
constructor = Napi::Persistent(func);
@ -43,3 +47,33 @@ QProgressBarWrap::~QProgressBarWrap() {
delete this->instance;
}
Napi::Value QProgressBarWrap::setValue(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setValue(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::setMaximum(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setMaximum(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::setMinimum(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number value = info[0].As<Napi::Number>();
this->instance->setMinimum(value.Int32Value());
return env.Null();
}
Napi::Value QProgressBarWrap::value(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
int value = this->instance->value();
return Napi::Number::New(env, value);
}

View File

@ -15,7 +15,11 @@ class QProgressBarWrap : public Napi::ObjectWrap<QProgressBarWrap>{
//class constructor
static Napi::FunctionReference constructor;
//wrapped methods
Napi::Value setValue(const Napi::CallbackInfo& info);
Napi::Value setMaximum(const Napi::CallbackInfo& info);
Napi::Value setMinimum(const Napi::CallbackInfo& info);
Napi::Value value(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};

View File

@ -19,5 +19,21 @@ export class QProgressBar extends NodeWidget {
this.native = native;
this.parent = parent;
// bind member functions
this.setValue.bind(this);
this.setMinimum.bind(this);
this.setMaximum.bind(this);
this.value.bind(this);
}
setValue(value: number) {
this.native.setValue(value);
}
setMinimum(min: number) {
this.native.setMinimum(min);
}
setMaximum(max: number) {
this.native.setMaximum(max);
}
value(): number {
return this.native.value();
}
}