Add QSlider and other improvements (#348)
This commit is contained in:
parent
3a8f405e2d
commit
8d5b3ca476
@ -94,6 +94,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QMenuBar/qmenubar_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QMenu/qmenu_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGroupBox/qgroupbox_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTimeEdit/qtimeedit_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTreeWidget/qtreewidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTreeWidgetItem/qtreewidgetitem_wrap.cpp"
|
||||
@ -137,6 +138,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QBoxLayout/nboxlayout.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QComboBox/ncombobox.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGroupBox/ngroupbox.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSlider/nslider.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTimeEdit/ntimeedit.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTreeWidget/ntreewidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QButtonGroup/nbuttongroup.hpp"
|
||||
|
||||
@ -20,4 +20,11 @@ class QKeySequenceWrap : public Napi::ObjectWrap<QKeySequenceWrap> {
|
||||
QKeySequence *getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value count(const Napi::CallbackInfo &info);
|
||||
Napi::Value isEmpty(const Napi::CallbackInfo &info);
|
||||
Napi::Value matches(const Napi::CallbackInfo &info);
|
||||
Napi::Value toString(const Napi::CallbackInfo &info);
|
||||
};
|
||||
|
||||
namespace StaticQKeySequenceWrapMethods {
|
||||
Napi::Value fromQVariant(const Napi::CallbackInfo &info);
|
||||
} // namespace StaticQKeySequenceWrapMethods
|
||||
|
||||
@ -6,32 +6,32 @@
|
||||
|
||||
/*
|
||||
|
||||
This macro adds common QAbstractScrollArea exported methods
|
||||
This macro adds common QAbstractButton exported methods
|
||||
The exported methods are taken into this macro to avoid writing them in each
|
||||
and every widget we export.
|
||||
*/
|
||||
|
||||
#ifndef QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION
|
||||
#define QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION \
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
Napi::Value setText(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
\
|
||||
Napi::String napiText = info[0].As<Napi::String>(); \
|
||||
std::string text = napiText.Utf8Value(); \
|
||||
this->instance->setText(QString::fromUtf8(text.c_str())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setIcon(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
\
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>(); \
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject); \
|
||||
this->instance->setIcon(*iconWrap->getInternalInstance()); \
|
||||
return env.Null(); \
|
||||
#define QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION \
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
Napi::Value animateClick(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int msec = info[0].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->animateClick(msec); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value click(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->click(); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value toggle(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
this->instance->toggle(); \
|
||||
return env.Null(); \
|
||||
}
|
||||
|
||||
#endif // QABSTRACTBUTTON_WRAPPED_METHODS_DECLARATION
|
||||
@ -39,8 +39,9 @@
|
||||
#ifndef QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
InstanceMethod("setText", &WidgetWrapName::setText), \
|
||||
InstanceMethod("setIcon", &WidgetWrapName::setIcon),
|
||||
InstanceMethod("animateClick", &WidgetWrapName::animateClick), \
|
||||
InstanceMethod("click", &WidgetWrapName::click), \
|
||||
InstanceMethod("toggle", &WidgetWrapName::toggle),
|
||||
|
||||
#endif // QABSTRACTBUTTON_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
|
||||
@ -10,83 +10,32 @@
|
||||
*/
|
||||
|
||||
#ifndef QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION
|
||||
#define QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION \
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
Napi::Value setSingleStep(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number step = info[0].As<Napi::Number>(); \
|
||||
this->instance->setSingleStep(step.Int32Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setMaximum(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number maximum = info[0].As<Napi::Number>(); \
|
||||
this->instance->setMaximum(maximum.Int32Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value setMinimum(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number minimum = info[0].As<Napi::Number>(); \
|
||||
this->instance->setMinimum(minimum.Int32Value()); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value 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 setOrientation(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
Napi::Number orientation = info[0].As<Napi::Number>(); \
|
||||
this->instance->setOrientation( \
|
||||
static_cast<Qt::Orientation>(orientation.Int32Value())); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
\
|
||||
Napi::Value maximum(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int maximum = this->instance->maximum(); \
|
||||
return Napi::Number::New(env, maximum); \
|
||||
} \
|
||||
\
|
||||
Napi::Value minimum(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int minimum = this->instance->minimum(); \
|
||||
return Napi::Number::New(env, minimum); \
|
||||
} \
|
||||
\
|
||||
Napi::Value 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); \
|
||||
#define QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION \
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION \
|
||||
Napi::Value triggerAction(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int action = info[0].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->triggerAction( \
|
||||
static_cast<QAbstractSlider::SliderAction>(action)); \
|
||||
return env.Null(); \
|
||||
} \
|
||||
Napi::Value setRange(const Napi::CallbackInfo& info) { \
|
||||
Napi::Env env = info.Env(); \
|
||||
Napi::HandleScope scope(env); \
|
||||
int min = info[0].As<Napi::Number>().Int32Value(); \
|
||||
int max = info[1].As<Napi::Number>().Int32Value(); \
|
||||
this->instance->setRange(min, max); \
|
||||
return env.Null(); \
|
||||
}
|
||||
|
||||
#endif // QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
#ifndef QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
#define QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
InstanceMethod("setSingleStep", &WidgetWrapName::setSingleStep), \
|
||||
InstanceMethod("setMaximum", &WidgetWrapName::setMaximum), \
|
||||
InstanceMethod("setMinimum", &WidgetWrapName::setMinimum), \
|
||||
InstanceMethod("setValue", &WidgetWrapName::setValue), \
|
||||
InstanceMethod("setOrientation", &WidgetWrapName::setOrientation), \
|
||||
InstanceMethod("maximum", &WidgetWrapName::maximum), \
|
||||
InstanceMethod("minimum", &WidgetWrapName::minimum), \
|
||||
InstanceMethod("value", &WidgetWrapName::value),
|
||||
#define QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(WidgetWrapName) \
|
||||
InstanceMethod("triggerAction", &WidgetWrapName::triggerAction), \
|
||||
InstanceMethod("setRange", &WidgetWrapName::setRange),
|
||||
|
||||
#endif // QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
|
||||
|
||||
18
src/cpp/include/nodegui/QtWidgets/QSlider/nslider.hpp
Normal file
18
src/cpp/include/nodegui/QtWidgets/QSlider/nslider.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSlider>
|
||||
|
||||
#include "QtWidgets/QAbstractSlider/qabstractslider_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
|
||||
class NSlider : public QSlider, public NodeWidget {
|
||||
Q_OBJECT
|
||||
NODEWIDGET_IMPLEMENTATIONS(QSlider)
|
||||
public:
|
||||
using QSlider::QSlider; // inherit all constructors of QSlider
|
||||
|
||||
void connectSignalsToEventEmitter() {
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QABSTRACT_SLIDER_SIGNALS
|
||||
}
|
||||
};
|
||||
24
src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h
Normal file
24
src/cpp/include/nodegui/QtWidgets/QSlider/qslider_wrap.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "QtWidgets/QAbstractSlider/qabstractslider_macro.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "nslider.hpp"
|
||||
|
||||
class QSliderWrap : public Napi::ObjectWrap<QSliderWrap> {
|
||||
QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
QPointer<NSlider> instance;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QSliderWrap(const Napi::CallbackInfo& info);
|
||||
~QSliderWrap();
|
||||
NSlider* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
};
|
||||
@ -11,20 +11,30 @@ Napi::Object QKeySequenceWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::Function func =
|
||||
DefineClass(env, CLASSNAME,
|
||||
{InstanceMethod("count", &QKeySequenceWrap::count),
|
||||
InstanceMethod("isEmpty", &QKeySequenceWrap::isEmpty),
|
||||
InstanceMethod("matches", &QKeySequenceWrap::matches),
|
||||
InstanceMethod("toString$", &QKeySequenceWrap::toString),
|
||||
StaticMethod("fromQVariant",
|
||||
&StaticQKeySequenceWrapMethods::fromQVariant),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QKeySequenceWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QKeySequenceWrap::QKeySequenceWrap(const Napi::CallbackInfo &info)
|
||||
QKeySequenceWrap::QKeySequenceWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QKeySequenceWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
if (info.Length() == 1) {
|
||||
Napi::String sequenceString = info[0].As<Napi::String>();
|
||||
QString keySequence = QString::fromStdString(sequenceString.Utf8Value());
|
||||
this->instance = std::make_unique<QKeySequence>(keySequence);
|
||||
if (info[0].IsExternal()) {
|
||||
this->instance = std::unique_ptr<QKeySequence>(
|
||||
info[0].As<Napi::External<QKeySequence>>().Data());
|
||||
} else {
|
||||
Napi::String sequenceString = info[0].As<Napi::String>();
|
||||
QString keySequence = QString::fromStdString(sequenceString.Utf8Value());
|
||||
this->instance = std::make_unique<QKeySequence>(keySequence);
|
||||
}
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = std::make_unique<QKeySequence>();
|
||||
} else {
|
||||
@ -36,14 +46,56 @@ QKeySequenceWrap::QKeySequenceWrap(const Napi::CallbackInfo &info)
|
||||
|
||||
QKeySequenceWrap::~QKeySequenceWrap() { this->instance.reset(); }
|
||||
|
||||
QKeySequence *QKeySequenceWrap::getInternalInstance() {
|
||||
QKeySequence* QKeySequenceWrap::getInternalInstance() {
|
||||
return this->instance.get();
|
||||
}
|
||||
|
||||
Napi::Value QKeySequenceWrap::count(const Napi::CallbackInfo &info) {
|
||||
Napi::Value QKeySequenceWrap::count(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int count = this->instance->count();
|
||||
return Napi::Value::From(env, count);
|
||||
}
|
||||
|
||||
Napi::Value QKeySequenceWrap::isEmpty(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
return Napi::Value::From(env, this->instance->isEmpty());
|
||||
}
|
||||
|
||||
Napi::Value QKeySequenceWrap::matches(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object keyObject = info[0].As<Napi::Object>();
|
||||
QKeySequenceWrap* keyWrap =
|
||||
Napi::ObjectWrap<QKeySequenceWrap>::Unwrap(keyObject);
|
||||
QKeySequence::SequenceMatch match =
|
||||
this->instance->matches(*keyWrap->getInternalInstance());
|
||||
return Napi::Value::From(env, static_cast<int>(match));
|
||||
}
|
||||
|
||||
Napi::Value QKeySequenceWrap::toString(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int format = info[0].As<Napi::Number>().Int32Value();
|
||||
QString result = this->instance->toString(
|
||||
static_cast<QKeySequence::SequenceFormat>(format));
|
||||
return Napi::Value::From(env, result.toStdString());
|
||||
}
|
||||
|
||||
Napi::Value StaticQKeySequenceWrapMethods::fromQVariant(
|
||||
const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
Napi::Object variantObject = info[0].As<Napi::Object>();
|
||||
QVariantWrap* variantWrap =
|
||||
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
|
||||
QVariant* variant = variantWrap->getInternalInstance();
|
||||
QKeySequence key = variant->value<QKeySequence>();
|
||||
auto instance = QKeySequenceWrap::constructor.New(
|
||||
{Napi::External<QKeySequence>::New(env, new QKeySequence(key))});
|
||||
return instance;
|
||||
}
|
||||
|
||||
45
src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp
Normal file
45
src/cpp/lib/QtWidgets/QSlider/qslider_wrap.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "QtWidgets/QSlider/qslider_wrap.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
|
||||
Napi::FunctionReference QSliderWrap::constructor;
|
||||
|
||||
Napi::Object QSliderWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QSlider";
|
||||
Napi::Function func =
|
||||
DefineClass(env, CLASSNAME,
|
||||
{QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QSliderWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NSlider* QSliderWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QSliderWrap::QSliderWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QSliderWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NSlider(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NSlider();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
|
||||
this->rawData = extrautils::configureQWidget(
|
||||
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
|
||||
true);
|
||||
}
|
||||
|
||||
QSliderWrap::~QSliderWrap() { extrautils::safeDelete(this->instance); }
|
||||
@ -53,6 +53,7 @@
|
||||
#include "QtWidgets/QRadioButton/qradiobutton_wrap.h"
|
||||
#include "QtWidgets/QScrollArea/qscrollarea_wrap.h"
|
||||
#include "QtWidgets/QShortcut/qshortcut_wrap.h"
|
||||
#include "QtWidgets/QSlider/qslider_wrap.h"
|
||||
#include "QtWidgets/QSpinBox/qspinbox_wrap.h"
|
||||
#include "QtWidgets/QStackedWidget/qstackedwidget_wrap.h"
|
||||
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
|
||||
@ -135,6 +136,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QMenuWrap::init(env, exports);
|
||||
QMenuBarWrap::init(env, exports);
|
||||
QMessageBoxWrap::init(env, exports);
|
||||
QSliderWrap::init(env, exports);
|
||||
QTimeEditWrap::init(env, exports);
|
||||
QButtonGroupWrap::init(env, exports);
|
||||
return exports;
|
||||
|
||||
@ -52,6 +52,7 @@ export { QMenu, QMenuSignals } from './lib/QtWidgets/QMenu';
|
||||
export { QMenuBar, QMenuBarSignals } from './lib/QtWidgets/QMenuBar';
|
||||
export { QPlainTextEdit, QPlainTextEditSignals, LineWrapMode } from './lib/QtWidgets/QPlainTextEdit';
|
||||
export { QScrollArea, QScrollAreaSignals } from './lib/QtWidgets/QScrollArea';
|
||||
export { QSlider, QSliderSignals, TickPosition } from './lib/QtWidgets/QSlider';
|
||||
export { QTimeEdit } from './lib/QtWidgets/QTimeEdit';
|
||||
export { QTreeWidget, QTreeWidgetSignals } from './lib/QtWidgets/QTreeWidget';
|
||||
export { QTreeWidgetItem } from './lib/QtWidgets/QTreeWidgetItem';
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { Component, NativeElement } from '../core/Component';
|
||||
import { QVariant } from '../QtCore/QVariant';
|
||||
|
||||
/**
|
||||
|
||||
@ -18,11 +20,15 @@ const keySequence = new QKeySequence(`Ctrl+L`);
|
||||
export class QKeySequence extends Component {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
constructor(native: NativeElement);
|
||||
constructor(keySequence: string);
|
||||
constructor(keySequence?: string) {
|
||||
constructor(arg?: string | NativeElement) {
|
||||
super();
|
||||
if (typeof keySequence === 'string') {
|
||||
if (typeof arg === 'string') {
|
||||
const keySequence = arg;
|
||||
this.native = new addon.QKeySequence(keySequence);
|
||||
} else if (checkIfNativeElement(arg)) {
|
||||
this.native = arg as NativeElement;
|
||||
} else {
|
||||
this.native = new addon.QKeySequence();
|
||||
}
|
||||
@ -30,4 +36,27 @@ export class QKeySequence extends Component {
|
||||
count(): number {
|
||||
return this.native.count();
|
||||
}
|
||||
isEmpty(): boolean {
|
||||
return this.native.isEmpty();
|
||||
}
|
||||
matches(seq: QKeySequence): SequenceMatch {
|
||||
return this.native.matches(seq.native);
|
||||
}
|
||||
toString(format: SequenceFormat): string {
|
||||
return this.native.toString$(format);
|
||||
}
|
||||
static fromQVariant(variant: QVariant): QKeySequence {
|
||||
return new QKeySequence(addon.QKeySequence.fromQVariant(variant.native));
|
||||
}
|
||||
}
|
||||
|
||||
export enum SequenceMatch {
|
||||
NoMatch,
|
||||
PartialMatch,
|
||||
ExactMatch,
|
||||
}
|
||||
|
||||
export enum SequenceFormat {
|
||||
NativeText,
|
||||
PortableText,
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { NodeWidget, QWidgetSignals } from './QWidget';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { QKeySequence } from '../QtGui/QKeySequence';
|
||||
|
||||
/**
|
||||
|
||||
@ -13,11 +14,63 @@ It is inherited by QCheckBox, QPushButton, QRadioButton, and QToolButton.
|
||||
|
||||
*/
|
||||
export abstract class QAbstractButton<Signals extends QAbstractButtonSignals> extends NodeWidget<Signals> {
|
||||
setText(text: string): void {
|
||||
this.native.setText(text);
|
||||
animateClick(msec: number): void {
|
||||
this.native.animateClick(msec);
|
||||
}
|
||||
click(): void {
|
||||
this.native.click();
|
||||
}
|
||||
toggle(): void {
|
||||
this.native.toggle();
|
||||
}
|
||||
setAutoExclusive(enable: boolean): void {
|
||||
this.setProperty('autoExclusive', enable);
|
||||
}
|
||||
autoExclusive(): boolean {
|
||||
return this.property('autoExclusive').toBool();
|
||||
}
|
||||
setAutoRepeat(enable: boolean): void {
|
||||
this.setProperty('autoRepeat', enable);
|
||||
}
|
||||
autoRepeat(): boolean {
|
||||
return this.property('autoRepeat').toBool();
|
||||
}
|
||||
setAutoRepeatDelay(delay: number): void {
|
||||
this.setProperty('autoRepeatDelay', delay);
|
||||
}
|
||||
autoRepeatDelay(): number {
|
||||
return this.property('autoRepeatDelay').toInt();
|
||||
}
|
||||
setAutoRepeatInterval(interval: number): void {
|
||||
this.setProperty('autoRepeatInterval', interval);
|
||||
}
|
||||
autoRepeatInterval(): number {
|
||||
return this.property('autoRepeatInterval').toInt();
|
||||
}
|
||||
setCheckable(checkable: boolean): void {
|
||||
this.setProperty('checkable', checkable);
|
||||
}
|
||||
isCheckable(): boolean {
|
||||
return this.property('checkable').toBool();
|
||||
}
|
||||
setChecked(checked: boolean): void {
|
||||
this.setProperty('checked', checked);
|
||||
}
|
||||
isChecked(): boolean {
|
||||
return this.property('checked').toBool();
|
||||
}
|
||||
setDown(down: boolean): void {
|
||||
this.setProperty('down', down);
|
||||
}
|
||||
isDown(): boolean {
|
||||
return this.property('down').toBool();
|
||||
}
|
||||
setIcon(icon: QIcon): void {
|
||||
this.native.setIcon(icon.native);
|
||||
this.setProperty('icon', icon.native);
|
||||
}
|
||||
icon(): QIcon {
|
||||
const icon = this.property('icon');
|
||||
return QIcon.fromQVariant(icon);
|
||||
}
|
||||
setIconSize(iconSize: QSize): void {
|
||||
this.setProperty('iconSize', iconSize.native);
|
||||
@ -26,6 +79,19 @@ export abstract class QAbstractButton<Signals extends QAbstractButtonSignals> ex
|
||||
const iconSize = this.property('iconSize');
|
||||
return QSize.fromQVariant(iconSize);
|
||||
}
|
||||
setShortcut(key: QKeySequence): void {
|
||||
this.setProperty('shortcut', key.native);
|
||||
}
|
||||
shortcut(): QKeySequence {
|
||||
const key = this.property('shortcut');
|
||||
return QKeySequence.fromQVariant(key);
|
||||
}
|
||||
setText(text: string): void {
|
||||
this.setProperty('text', text);
|
||||
}
|
||||
text(): string {
|
||||
return this.property('text').toString();
|
||||
}
|
||||
}
|
||||
export interface QAbstractButtonSignals extends QWidgetSignals {
|
||||
clicked: (checked: boolean) => void;
|
||||
|
||||
@ -15,30 +15,89 @@ QAbstractSlider will list all methods and properties that are common to all slid
|
||||
|
||||
*/
|
||||
export abstract class QAbstractSlider<Signals extends QAbstractSliderSignals> extends NodeWidget<Signals> {
|
||||
setSingleStep(step: number): void {
|
||||
this.native.setSingleStep(step);
|
||||
triggerAction(action: SliderAction): void {
|
||||
this.native.triggerAction(action);
|
||||
}
|
||||
setRange(min: number, max: number): void {
|
||||
this.native.setRange(min, max);
|
||||
}
|
||||
setInvertedAppearance(inverted: boolean): void {
|
||||
this.setProperty('invertedAppearance', inverted);
|
||||
}
|
||||
invertedAppearance(): boolean {
|
||||
return this.property('invertedAppearance').toBool();
|
||||
}
|
||||
setInvertedControls(inverted: boolean): void {
|
||||
this.setProperty('invertedControls', inverted);
|
||||
}
|
||||
invertedControls(): boolean {
|
||||
return this.property('invertedControls').toBool();
|
||||
}
|
||||
setMaximum(maximum: number): void {
|
||||
this.native.setMaximum(maximum);
|
||||
this.setProperty('maximum', maximum);
|
||||
}
|
||||
maximum(): number {
|
||||
return this.native.maximum();
|
||||
return this.property('maximum').toInt();
|
||||
}
|
||||
setMinimum(minimum: number): void {
|
||||
this.native.setMinimum(minimum);
|
||||
this.setProperty('minimum', minimum);
|
||||
}
|
||||
minimum(): number {
|
||||
return this.native.minimum();
|
||||
}
|
||||
setValue(value: number): void {
|
||||
this.native.setValue(value);
|
||||
}
|
||||
value(): number {
|
||||
return this.native.value();
|
||||
return this.property('minimum').toInt();
|
||||
}
|
||||
setOrientation(orientation: Orientation): void {
|
||||
this.native.setOrientation(orientation);
|
||||
this.setProperty('orientation', orientation);
|
||||
}
|
||||
orientation(): Orientation {
|
||||
return this.property('orientation').toInt();
|
||||
}
|
||||
setPageStep(step: number): void {
|
||||
this.setProperty('pageStep', step);
|
||||
}
|
||||
pageStep(): number {
|
||||
return this.property('pageStep').toInt();
|
||||
}
|
||||
setSingleStep(step: number): void {
|
||||
this.setProperty('singleStep', step);
|
||||
}
|
||||
singleStep(): number {
|
||||
return this.property('singleStep').toInt();
|
||||
}
|
||||
setSliderDown(down: boolean): void {
|
||||
this.setProperty('sliderDown', down);
|
||||
}
|
||||
isSliderDown(): boolean {
|
||||
return this.property('sliderDown').toBool();
|
||||
}
|
||||
setSliderPosition(position: number): void {
|
||||
this.setProperty('sliderPosition', position);
|
||||
}
|
||||
sliderPosition(): number {
|
||||
return this.property('sliderPosition').toInt();
|
||||
}
|
||||
setTracking(enable: boolean): void {
|
||||
this.setProperty('tracking', enable);
|
||||
}
|
||||
hasTracking(): boolean {
|
||||
return this.property('tracking').toBool();
|
||||
}
|
||||
setValue(value: number): void {
|
||||
this.setProperty('value', value);
|
||||
}
|
||||
value(): number {
|
||||
return this.property('value').toInt();
|
||||
}
|
||||
}
|
||||
|
||||
export enum SliderAction {
|
||||
SliderNoAction,
|
||||
SliderSingleStepAdd,
|
||||
SliderSingleStepSub,
|
||||
SliderPageStepAdd,
|
||||
SliderPageStepSub,
|
||||
SliderToMinimum,
|
||||
SliderToMaximum,
|
||||
SliderMove,
|
||||
}
|
||||
|
||||
export interface QAbstractSliderSignals extends QWidgetSignals {
|
||||
|
||||
60
src/lib/QtWidgets/QSlider.ts
Normal file
60
src/lib/QtWidgets/QSlider.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QAbstractSlider, QAbstractSliderSignals } from './QAbstractSlider';
|
||||
|
||||
/**
|
||||
|
||||
> Create and control slider widgets.
|
||||
|
||||
* **This class is a JS wrapper around Qt's [QSlider class](https://doc.qt.io/qt-5/qslider.html)**
|
||||
|
||||
A `QSlider` provides ability to add and manipulate native slider widgets.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const { QSlider } = require("@nodegui/nodegui");
|
||||
|
||||
const slider = new QSlider();
|
||||
```
|
||||
*/
|
||||
export class QSlider extends QAbstractSlider<QSliderSignals> {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
constructor(parent: NodeWidget<any>);
|
||||
constructor(parent?: NodeWidget<any>) {
|
||||
let native;
|
||||
if (parent) {
|
||||
native = new addon.QSlider(parent.native);
|
||||
} else {
|
||||
native = new addon.QSlider();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
this.setNodeParent(parent);
|
||||
}
|
||||
setTickInterval(ti: number): void {
|
||||
this.setProperty('tickInterval', ti);
|
||||
}
|
||||
tickInterval(): number {
|
||||
return this.property('tickInterval').toInt();
|
||||
}
|
||||
setTickPosition(position: TickPosition): void {
|
||||
this.setProperty('tickPosition', position);
|
||||
}
|
||||
tickPosition(): TickPosition {
|
||||
return this.property('tickPosition').toInt();
|
||||
}
|
||||
}
|
||||
|
||||
export enum TickPosition {
|
||||
NoTicks,
|
||||
TicksAbove,
|
||||
TicksBelow,
|
||||
TicksBothSides,
|
||||
TicksLeft = TicksAbove,
|
||||
TicksRight = TicksBelow,
|
||||
}
|
||||
|
||||
export type QSliderSignals = QAbstractSliderSignals;
|
||||
Loading…
Reference in New Issue
Block a user