From 9df9421baf0081975bdb7d70d6ba6111667bb5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Borecki?= Date: Fri, 30 Aug 2019 21:48:01 +0200 Subject: [PATCH 1/3] Support for QDial and QAbstractSlider with docs --- config/application.gypi | 1 + config/moc.gypi | 23 +- config/moc.json | 1 + docs/api/QAbstractScrollArea.md | 4 +- docs/api/QAbstractSlider.md | 67 ++++ docs/api/QDial.md | 67 ++++ docs/react/README.md | 8 + .../QAbstractSlider/qabstractslider_macro.h | 91 +++++ src/cpp/QtWidgets/QDial/ndial.h | 42 +++ src/cpp/QtWidgets/QDial/qdial_wrap.cpp | 96 +++++ src/cpp/QtWidgets/QDial/qdial_wrap.h | 29 ++ src/cpp/autogen/ndial_moc.cpp | 336 ++++++++++++++++++ src/cpp/main.cpp | 2 + src/demo.ts | 23 ++ src/index.ts | 1 + src/lib/QtWidgets/QAbstractSlider/index.ts | 30 ++ src/lib/QtWidgets/QDial/index.ts | 53 +++ 17 files changed, 861 insertions(+), 13 deletions(-) create mode 100644 docs/api/QAbstractSlider.md create mode 100644 docs/api/QDial.md create mode 100644 src/cpp/QtWidgets/QAbstractSlider/qabstractslider_macro.h create mode 100644 src/cpp/QtWidgets/QDial/ndial.h create mode 100644 src/cpp/QtWidgets/QDial/qdial_wrap.cpp create mode 100644 src/cpp/QtWidgets/QDial/qdial_wrap.h create mode 100644 src/cpp/autogen/ndial_moc.cpp create mode 100644 src/lib/QtWidgets/QAbstractSlider/index.ts create mode 100644 src/lib/QtWidgets/QDial/index.ts diff --git a/config/application.gypi b/config/application.gypi index 9490b2d8d..60e08454d 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -17,6 +17,7 @@ '../src/cpp/core/FlexLayout/flexlayout_wrap.cpp', "../src/cpp/QtWidgets/QWidget/qwidget_wrap.cpp", "../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp", + "../src/cpp/QtWidgets/QDial/qdial_wrap.cpp", "../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp", "../src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp", "../src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp", diff --git a/config/moc.gypi b/config/moc.gypi index 874f4ab35..5ce3cc25a 100644 --- a/config/moc.gypi +++ b/config/moc.gypi @@ -2,16 +2,17 @@ # RUN: npm run automoc after updating moc.json { "sources": [ - "../src/cpp/autogen/nwidget_moc.cpp", - "../src/cpp/autogen/nlabel_moc.cpp", - "../src/cpp/autogen/ncheckbox_moc.cpp", - "../src/cpp/autogen/nlineedit_moc.cpp", - "../src/cpp/autogen/nmainwindow_moc.cpp", - "../src/cpp/autogen/nprogressbar_moc.cpp", - "../src/cpp/autogen/npushbutton_moc.cpp", - "../src/cpp/autogen/nspinbox_moc.cpp", - "../src/cpp/autogen/nradiobutton_moc.cpp", - "../src/cpp/autogen/nplaintextedit_moc.cpp", - "../src/cpp/autogen/nscrollarea_moc.cpp" + "..\\src\\cpp\\autogen\\nwidget_moc.cpp", + "..\\src\\cpp\\autogen\\nlabel_moc.cpp", + "..\\src\\cpp\\autogen\\ncheckbox_moc.cpp", + "..\\src\\cpp\\autogen\\ndial_moc.cpp", + "..\\src\\cpp\\autogen\\nlineedit_moc.cpp", + "..\\src\\cpp\\autogen\\nmainwindow_moc.cpp", + "..\\src\\cpp\\autogen\\nprogressbar_moc.cpp", + "..\\src\\cpp\\autogen\\npushbutton_moc.cpp", + "..\\src\\cpp\\autogen\\nspinbox_moc.cpp", + "..\\src\\cpp\\autogen\\nradiobutton_moc.cpp", + "..\\src\\cpp\\autogen\\nplaintextedit_moc.cpp", + "..\\src\\cpp\\autogen\\nscrollarea_moc.cpp" ] } \ No newline at end of file diff --git a/config/moc.json b/config/moc.json index 175118564..db5d1a0fb 100644 --- a/config/moc.json +++ b/config/moc.json @@ -4,6 +4,7 @@ "src/cpp/QtWidgets/QWidget/nwidget.h", "src/cpp/QtWidgets/QLabel/nlabel.h", "src/cpp/QtWidgets/QCheckBox/ncheckbox.h", + "src/cpp/QtWidgets/QDial/ndial.h", "src/cpp/QtWidgets/QLineEdit/nlineedit.h", "src/cpp/QtWidgets/QMainWindow/nmainwindow.h", "src/cpp/QtWidgets/QProgressBar/nprogressbar.h", diff --git a/docs/api/QAbstractScrollArea.md b/docs/api/QAbstractScrollArea.md index 3e3a66927..3ad273b3d 100644 --- a/docs/api/QAbstractScrollArea.md +++ b/docs/api/QAbstractScrollArea.md @@ -2,9 +2,9 @@ > Abstract class to add functionalities common to all scrollarea based widgets. -**This class implements all methods, properties of Qt's [QAbstractScrollArea class](https://doc.qt.io/qt-5/qabstractscrollarea.html) so that it can be inherited by all scoll based widgets** +**This class implements all methods, properties of Qt's [QAbstractScrollArea class](https://doc.qt.io/qt-5/qabstractscrollarea.html) so that it can be inherited by all scroll based widgets** -`QAbstractScrollArea` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all scrollable widget's easily. If you wish to create a scollarea use [QScrollArea](api/QScrollArea.md) instead. +`QAbstractScrollArea` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all scrollable widget's easily. If you wish to create a scrollarea use [QScrollArea](api/QScrollArea.md) instead. **QAbstractScrollArea is the base class for all widgets. It inherits from another abstract class [NodeWidget](api/NodeWidget.md)** diff --git a/docs/api/QAbstractSlider.md b/docs/api/QAbstractSlider.md new file mode 100644 index 000000000..d51524fb0 --- /dev/null +++ b/docs/api/QAbstractSlider.md @@ -0,0 +1,67 @@ +## Class: QAbstractSlider + +> Abstract class to add functionalities common to all slider based widgets. + +**This class implements all methods, properties of Qt's [QAbstractSlider class](https://doc.qt.io/qt-5/qabstractslider.html) so that it can be inherited by all slider based widgets** + +`QAbstractSlider` is an abstract class and hence no instances of the same should be created. It exists so that we can add similar functionalities to all slider widget's easily. If you wish to create a slider use [QDial](api/QDial.md) instead. + +**QAbstractSlider is the base class for all widgets. It inherits from another abstract class [NodeWidget](api/NodeWidget.md)** + +QAbstractSlider will list all methods and properties that are common to all slider widgets in the NodeGui world. + +### Static Methods + +QAbstractSlider can access all the static methods defined in [NodeWidget](api/NodeWidget.md) + +### Instance Properties + +QAbstractSlider can access all the instance properties defined in [NodeWidget](api/NodeWidget.md) + +### Instance Methods + +QAbstractSlider can access all the instance methods defined in [NodeWidget](api/NodeWidget.md) + +Additionally it also has the following instance methods: + +#### `widget.setSingleStep(step)` + +Sets the step value for user arrow key slider interaction. It calls the native method [QAbstractSlider: setSingleStep](https://doc.qt.io/qt-5/qabstractslider.html#singleStep-prop). + +- `step` number - Specified single step value. + +#### `widget.setMaximum(maximum)` + +Sets the maximum value for slider. It calls the native method [QAbstractSlider: setMaximum](https://doc.qt.io/qt-5/qabstractslider.html#maximum-prop). + +- `maximum` number - Specified maximum slider value. + +#### `widget.setMinimum(minimum)` + +Sets the minimum value for slider. It calls the native method [QAbstractSlider: setMinimum](https://doc.qt.io/qt-5/qabstractslider.html#minimum-prop). + +- `minimum` number - Specified minimum slider value. + +#### `widget.setValue(value)` + +Sets the current value for slider. It calls the native method [QAbstractSlider: setValue](https://doc.qt.io/qt-5/qabstractslider.html#value-prop). + +- `value` number - Specified current slider value. + +#### `widget.setOrientation(orientation)` + +Sets the current orientation for slider. It calls the native method [QAbstractSlider: setOrientation](https://doc.qt.io/qt-5/qabstractslider.html#orientation-prop). + +- `orientation` Orientation - Specifies visual orientation of the slider. [Orientation is an enum from Qt](api/QtEnums.md) + +#### `slider.maximum()` + +Returns the maximum value (Number) of the slider. It calls the native method [QAbstractSlider: maximum](https://doc.qt.io/qt-5/qabstractslider.html#maximum-prop). + +#### `slider.minimum()` + +Returns the minimum value (Number) of the slider. It calls the native method [QAbstractSlider: minimum](https://doc.qt.io/qt-5/qabstractslider.html#minimum-prop). + +#### `slider.value()` + +Returns the current value (Number) of the slider. It calls the native method [QAbstractSlider: value](https://doc.qt.io/qt-5/qabstractslider.html#value-prop). \ No newline at end of file diff --git a/docs/api/QDial.md b/docs/api/QDial.md new file mode 100644 index 000000000..0b9059c8c --- /dev/null +++ b/docs/api/QDial.md @@ -0,0 +1,67 @@ +## Class: QDial + +> Create and control spin box widgets. + +**This class is a JS wrapper around Qt's [QDial class](https://doc.qt.io/qt-5/qdial.html)** + +A `QDial` provides ability to add and manipulate native spin box widgets. + +**QDial inherits from [QAbstractSlider](api/QAbstractSlider.md)** + +### Example + +```javascript +const { QDial } = require("@nodegui/nodegui"); + +const dial = new QDial(); +``` + +### `new QDial(parent?)` + +- `parent` NodeWidget (_optional_). Any widget inheriting from NodeWidget can be passed as a parent. This will make this widget, the child of the parent widget. + +### Static Methods + +QDial can access all the static methods defined in [NodeWidget](api/NodeWidget.md) + +### Instance Properties + +QDial can access all the instance properties defined in [NodeWidget](api/NodeWidget.md) + +### Instance Methods + +QDial can access all the instance methods defined in [NodeWidget](api/NodeWidget.md). Additionally it also has the following instance methods: + +#### `dial.setNotchesVisible(visible)` + +Sets the visibility of notches drawn around the dial. It calls the native method [QDial: setNotchesVisible](https://doc.qt.io/qt-5/qdial.html#notchTarget-prop). + +- `visible` boolean - Set the value as current notch visibility. + +#### `dial.setWrapping(on)` + +Sets the ability to wrap arrow around the dial instead of limiting it to upper part of the dial. It calls the native method [QDial: setWrapping](https://doc.qt.io/qt-5/qdial.html#wrapping-prop). + +- `on` boolean - Set the value as current wrapping setting. + +#### `dial.setNotchTarget(target)` + +Sets the number of pixels between dial notches. It calls the native method [QDial: setNotchTarget](https://doc.qt.io/qt-5/qdial.html#notchTarget-prop). + +- `target` number - Specifies number of pixels between notches. + +#### `dial.notchTarget()` + +Returns the current number of pixels between dial notches. It calls the native method [QDial: notchTarget](https://doc.qt.io/qt-5/qdial.html#notchTarget-prop). + +#### `dial.notchesVisible()` + +Returns the visibility status (Boolean) of dial notches. It calls the native method [QDial: notchesVisible](https://doc.qt.io/qt-5/qdial.html#notchesVisible-prop). + +#### `dial.notchesVisible()` + +Returns the visibility status (Boolean) of dial notches. It calls the native method [QDial: notchesVisible](https://doc.qt.io/qt-5/qdial.html#notchesVisible-prop). + +#### `dial.wrapping()` + +Returns the current wrapping (Boolean) state of the dial. It calls the native method [QDial: wrapping](https://doc.qt.io/qt-5/qdial.html#wrapping-prop). \ No newline at end of file diff --git a/docs/react/README.md b/docs/react/README.md index f53b4a88d..0af42a33d 100644 --- a/docs/react/README.md +++ b/docs/react/README.md @@ -31,8 +31,15 @@ ### Modules from NodeGui: +- [QApplication (Application)](api/QApplication.md) - [QMainWindow (Window)](api/QMainWindow.md) - [QWidget (View)](api/QWidget.md) +- [QSpinBox ()](api/QSpinBox.md) +- [QAbstractScrollArea ()](api/QAbstractScrollArea.md) +- [QAbstractSlider ()](api/QAbstractSlider.md) +- [QDial ()](api/QDial.md) +- [QScrollArea ()](api/QScrollArea.md) +- [QPlainTextEdit (TextEdit)](api/QPlainTextEdit.md) - [QLabel (Text/Image)](api/QLabel.md) - [QPushButton (Button)](api/QPushButton.md) - [QRadioButton (RadioButton)](api/QRadioButton.md) @@ -41,6 +48,7 @@ - [QProgressBar (ProgressBar)](api/QProgressBar.md) - [FlexLayout](api/FlexLayout.md) - [QPixmap](api/QPixmap.md) +- [QIcon](api/QIcon.md) - [Qt Enums](api/QtEnums.md) ### Internal Modules diff --git a/src/cpp/QtWidgets/QAbstractSlider/qabstractslider_macro.h b/src/cpp/QtWidgets/QAbstractSlider/qabstractslider_macro.h new file mode 100644 index 000000000..f12ca9489 --- /dev/null +++ b/src/cpp/QtWidgets/QAbstractSlider/qabstractslider_macro.h @@ -0,0 +1,91 @@ + +#pragma once +#include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h" +#include "src/cpp/QtWidgets/QWidget/qwidget_macro.h" +#include "deps/spdlog/spdlog.h" +/* + + This macro adds common QAbstractSlider exported methods + The exported methods are taken into this macro to avoid writing them in each and every widget we export. + */ + +#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(); \ + 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(); \ + 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(); \ + 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(); \ + 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(); \ + this->instance->setOrientation(static_cast(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); \ +} \ +\ + +#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), \ + +#endif // QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE diff --git a/src/cpp/QtWidgets/QDial/ndial.h b/src/cpp/QtWidgets/QDial/ndial.h new file mode 100644 index 000000000..3e9029b26 --- /dev/null +++ b/src/cpp/QtWidgets/QDial/ndial.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include "src/cpp/core/NodeWidget/nodewidget.h" + +class NDial: public QDial, public NodeWidget +{ + NODEWIDGET_IMPLEMENTATIONS(QDial) +public: + using QDial::QDial; //inherit all constructors of QDial + + void connectWidgetSignalsToEventEmitter() { + // Qt Connects: Implement all signal connects here + QObject::connect(this, &QDial::valueChanged, [=]() { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "valueChanged") }); + }); + QObject::connect(this, &QDial::rangeChanged, [=]() { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "rangeChanged") }); + }); + QObject::connect(this, &QDial::sliderMoved, [=]() { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "sliderMoved") }); + }); + QObject::connect(this, &QDial::sliderPressed, [=]() { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "sliderPressed") }); + }); + QObject::connect(this, &QDial::sliderReleased, [=]() { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({ Napi::String::New(env, "sliderReleased") }); + }); + } +}; + + diff --git a/src/cpp/QtWidgets/QDial/qdial_wrap.cpp b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp new file mode 100644 index 000000000..98cdc1bd4 --- /dev/null +++ b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp @@ -0,0 +1,96 @@ + +#include "qDial_wrap.h" +#include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h" +#include "src/cpp/Extras/Utils/nutils.h" +#include + + +Napi::FunctionReference QDialWrap::constructor; + +Napi::Object QDialWrap::init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QDial"; + Napi::Function func = DefineClass(env, CLASSNAME, { + InstanceMethod("setNotchesVisible", &QDialWrap::setNotchesVisible), + InstanceMethod("setWrapping", &QDialWrap::setWrapping), + InstanceMethod("setNotchTarget", &QDialWrap::setNotchTarget), + InstanceMethod("notchTarget", &QDialWrap::notchTarget), + InstanceMethod("notchesVisible", &QDialWrap::notchesVisible), + InstanceMethod("wrapping", &QDialWrap::wrapping), + QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QDialWrap) + QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QDialWrap) + }); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +NDial* QDialWrap::getInternalInstance() { + return this->instance; +} + +QDialWrap::QDialWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + if(info.Length() == 1) { + Napi::Object parentObject = info[0].As(); + QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::Unwrap(parentObject); + this->instance = new NDial(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget + }else if (info.Length() == 0){ + this->instance = new NDial(); + }else { + Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException(); + } + // Adds measure function on yoga node so that widget size is calculated based on its own size. + YGNodeSetMeasureFunc(this->instance->getFlexNode(), &extrautils::measureQtWidget); +} + +QDialWrap::~QDialWrap() { + delete this->instance; +} + +Napi::Value QDialWrap::setNotchesVisible(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Boolean visible = info[0].As(); + this->instance->setNotchesVisible(visible.Value()); + return env.Null(); +} + +Napi::Value QDialWrap::setWrapping(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Boolean on = info[0].As(); + this->instance->setWrapping(on.Value()); + return env.Null(); +} + +Napi::Value QDialWrap::setNotchTarget(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Number target = info[0].As(); + this->instance->setNotchTarget(target.FloatValue()); + return env.Null(); +} + +Napi::Value QDialWrap::notchTarget(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + float target = this->instance->notchTarget(); + return Napi::Value::From(env, target); +} + +Napi::Value QDialWrap::notchesVisible(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + bool notchesVisible = this->instance->notchesVisible(); + return Napi::Value::From(env, notchesVisible); +} + +Napi::Value QDialWrap::wrapping(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + bool wrapping = this->instance->wrapping(); + return Napi::Value::From(env, wrapping); +} diff --git a/src/cpp/QtWidgets/QDial/qdial_wrap.h b/src/cpp/QtWidgets/QDial/qdial_wrap.h new file mode 100644 index 000000000..d89072976 --- /dev/null +++ b/src/cpp/QtWidgets/QDial/qdial_wrap.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "nDial.h" +#include "src/cpp/QtWidgets/QWidget/qwidget_macro.h" +#include "src/cpp/QtWidgets/QAbstractSlider/qabstractslider_macro.h" + +class QDialWrap : public Napi::ObjectWrap{ + private: + NDial* instance; + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QDialWrap(const Napi::CallbackInfo& info); + ~QDialWrap(); + NDial* getInternalInstance(); + //class constructor + static Napi::FunctionReference constructor; + //wrapped methods + Napi::Value setNotchesVisible(const Napi::CallbackInfo& info); + Napi::Value setWrapping(const Napi::CallbackInfo& info); + Napi::Value setNotchTarget(const Napi::CallbackInfo& info); + Napi::Value notchTarget(const Napi::CallbackInfo& info); + Napi::Value notchesVisible(const Napi::CallbackInfo& info); + Napi::Value wrapping(const Napi::CallbackInfo& info); + + QABSTRACTSLIDER_WRAPPED_METHODS_DECLARATION +}; + + diff --git a/src/cpp/autogen/ndial_moc.cpp b/src/cpp/autogen/ndial_moc.cpp new file mode 100644 index 000000000..d0996541f --- /dev/null +++ b/src/cpp/autogen/ndial_moc.cpp @@ -0,0 +1,336 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'ndial.h' +** +** Created by: The Qt Meta Object Compiler version 67 (Qt 5.13.0) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include +#include "../QtWidgets/QDial/ndial.h" +#include +#include +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'ndial.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 67 +#error "This file was generated using the moc from 5.13.0. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +struct qt_meta_stringdata_NDial_t { + QByteArrayData data[47]; + char stringdata0[542]; +}; +#define QT_MOC_LITERAL(idx, ofs, len) \ + Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ + qptrdiff(offsetof(qt_meta_stringdata_NDial_t, stringdata0) + ofs \ + - idx * sizeof(QByteArrayData)) \ + ) +static const qt_meta_stringdata_NDial_t qt_meta_stringdata_NDial = { + { +QT_MOC_LITERAL(0, 0, 5), // "NDial" +QT_MOC_LITERAL(1, 6, 8), // "yDisplay" +QT_MOC_LITERAL(2, 15, 11), // "yAlignItems" +QT_MOC_LITERAL(3, 27, 13), // "yAlignContent" +QT_MOC_LITERAL(4, 41, 10), // "yAlignSelf" +QT_MOC_LITERAL(5, 52, 15), // "yJustifyContent" +QT_MOC_LITERAL(6, 68, 10), // "yDirection" +QT_MOC_LITERAL(7, 79, 14), // "yFlexDirection" +QT_MOC_LITERAL(8, 94, 9), // "yOverflow" +QT_MOC_LITERAL(9, 104, 9), // "yPosition" +QT_MOC_LITERAL(10, 114, 9), // "yFlexWrap" +QT_MOC_LITERAL(11, 124, 5), // "yFlex" +QT_MOC_LITERAL(12, 130, 9), // "yFlexGrow" +QT_MOC_LITERAL(13, 140, 11), // "yFlexShrink" +QT_MOC_LITERAL(14, 152, 12), // "yAspectRatio" +QT_MOC_LITERAL(15, 165, 4), // "yTop" +QT_MOC_LITERAL(16, 170, 6), // "yRight" +QT_MOC_LITERAL(17, 177, 7), // "yBottom" +QT_MOC_LITERAL(18, 185, 5), // "yLeft" +QT_MOC_LITERAL(19, 191, 10), // "yFlexBasis" +QT_MOC_LITERAL(20, 202, 9), // "yMinWidth" +QT_MOC_LITERAL(21, 212, 10), // "yMinHeight" +QT_MOC_LITERAL(22, 223, 6), // "yWidth" +QT_MOC_LITERAL(23, 230, 7), // "yHeight" +QT_MOC_LITERAL(24, 238, 9), // "yMaxWidth" +QT_MOC_LITERAL(25, 248, 10), // "yMaxHeight" +QT_MOC_LITERAL(26, 259, 11), // "yPaddingTop" +QT_MOC_LITERAL(27, 271, 13), // "yPaddingRight" +QT_MOC_LITERAL(28, 285, 14), // "yPaddingBottom" +QT_MOC_LITERAL(29, 300, 12), // "yPaddingLeft" +QT_MOC_LITERAL(30, 313, 18), // "yPaddingHorizontal" +QT_MOC_LITERAL(31, 332, 16), // "yPaddingVertical" +QT_MOC_LITERAL(32, 349, 8), // "yPadding" +QT_MOC_LITERAL(33, 358, 10), // "yMarginTop" +QT_MOC_LITERAL(34, 369, 12), // "yMarginRight" +QT_MOC_LITERAL(35, 382, 13), // "yMarginBottom" +QT_MOC_LITERAL(36, 396, 11), // "yMarginLeft" +QT_MOC_LITERAL(37, 408, 17), // "yMarginHorizontal" +QT_MOC_LITERAL(38, 426, 15), // "yMarginVertical" +QT_MOC_LITERAL(39, 442, 7), // "yMargin" +QT_MOC_LITERAL(40, 450, 10), // "yBorderTop" +QT_MOC_LITERAL(41, 461, 12), // "yBorderRight" +QT_MOC_LITERAL(42, 474, 13), // "yBorderBottom" +QT_MOC_LITERAL(43, 488, 11), // "yBorderLeft" +QT_MOC_LITERAL(44, 500, 17), // "yBorderHorizontal" +QT_MOC_LITERAL(45, 518, 15), // "yBorderVertical" +QT_MOC_LITERAL(46, 534, 7) // "yBorder" + + }, + "NDial\0yDisplay\0yAlignItems\0yAlignContent\0" + "yAlignSelf\0yJustifyContent\0yDirection\0" + "yFlexDirection\0yOverflow\0yPosition\0" + "yFlexWrap\0yFlex\0yFlexGrow\0yFlexShrink\0" + "yAspectRatio\0yTop\0yRight\0yBottom\0yLeft\0" + "yFlexBasis\0yMinWidth\0yMinHeight\0yWidth\0" + "yHeight\0yMaxWidth\0yMaxHeight\0yPaddingTop\0" + "yPaddingRight\0yPaddingBottom\0yPaddingLeft\0" + "yPaddingHorizontal\0yPaddingVertical\0" + "yPadding\0yMarginTop\0yMarginRight\0" + "yMarginBottom\0yMarginLeft\0yMarginHorizontal\0" + "yMarginVertical\0yMargin\0yBorderTop\0" + "yBorderRight\0yBorderBottom\0yBorderLeft\0" + "yBorderHorizontal\0yBorderVertical\0" + "yBorder" +}; +#undef QT_MOC_LITERAL + +static const uint qt_meta_data_NDial[] = { + + // content: + 8, // revision + 0, // classname + 0, 0, // classinfo + 0, 0, // methods + 46, 14, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // properties: name, type, flags + 1, QMetaType::QString, 0x00095103, + 2, QMetaType::QString, 0x00095103, + 3, QMetaType::QString, 0x00095103, + 4, QMetaType::QString, 0x00095103, + 5, QMetaType::QString, 0x00095103, + 6, QMetaType::QString, 0x00095103, + 7, QMetaType::QString, 0x00095103, + 8, QMetaType::QString, 0x00095103, + 9, QMetaType::QString, 0x00095103, + 10, QMetaType::QString, 0x00095103, + 11, QMetaType::Float, 0x00095103, + 12, QMetaType::Float, 0x00095103, + 13, QMetaType::Float, 0x00095103, + 14, QMetaType::Float, 0x00095103, + 15, QMetaType::QString, 0x00095003, + 16, QMetaType::QString, 0x00095003, + 17, QMetaType::QString, 0x00095003, + 18, QMetaType::QString, 0x00095003, + 19, QMetaType::QString, 0x00095103, + 20, QMetaType::QString, 0x00095103, + 21, QMetaType::QString, 0x00095103, + 22, QMetaType::QString, 0x00095103, + 23, QMetaType::QString, 0x00095103, + 24, QMetaType::QString, 0x00095103, + 25, QMetaType::QString, 0x00095103, + 26, QMetaType::QString, 0x00095103, + 27, QMetaType::QString, 0x00095103, + 28, QMetaType::QString, 0x00095103, + 29, QMetaType::QString, 0x00095103, + 30, QMetaType::QString, 0x00095103, + 31, QMetaType::QString, 0x00095103, + 32, QMetaType::QString, 0x00095103, + 33, QMetaType::QString, 0x00095103, + 34, QMetaType::QString, 0x00095103, + 35, QMetaType::QString, 0x00095103, + 36, QMetaType::QString, 0x00095103, + 37, QMetaType::QString, 0x00095103, + 38, QMetaType::QString, 0x00095103, + 39, QMetaType::QString, 0x00095003, + 40, QMetaType::Float, 0x00095103, + 41, QMetaType::Float, 0x00095103, + 42, QMetaType::Float, 0x00095103, + 43, QMetaType::Float, 0x00095103, + 44, QMetaType::Float, 0x00095103, + 45, QMetaType::Float, 0x00095103, + 46, QMetaType::Float, 0x00095103, + + 0 // eod +}; + +void NDial::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + +#ifndef QT_NO_PROPERTIES + if (_c == QMetaObject::ReadProperty) { + auto *_t = static_cast(_o); + Q_UNUSED(_t) + void *_v = _a[0]; + switch (_id) { + case 0: *reinterpret_cast< QString*>(_v) = _t->_yDisplay; break; + case 1: *reinterpret_cast< QString*>(_v) = _t->_yAlignItems; break; + case 2: *reinterpret_cast< QString*>(_v) = _t->_yAlignContent; break; + case 3: *reinterpret_cast< QString*>(_v) = _t->_yAlignSelf; break; + case 4: *reinterpret_cast< QString*>(_v) = _t->_yJustifyContent; break; + case 5: *reinterpret_cast< QString*>(_v) = _t->_yDirection; break; + case 6: *reinterpret_cast< QString*>(_v) = _t->_yFlexDirection; break; + case 7: *reinterpret_cast< QString*>(_v) = _t->_yOverflow; break; + case 8: *reinterpret_cast< QString*>(_v) = _t->_yPosition; break; + case 9: *reinterpret_cast< QString*>(_v) = _t->_yFlexWrap; break; + case 10: *reinterpret_cast< float*>(_v) = _t->_yFlex; break; + case 11: *reinterpret_cast< float*>(_v) = _t->_yFlexGrow; break; + case 12: *reinterpret_cast< float*>(_v) = _t->_yFlexShrink; break; + case 13: *reinterpret_cast< float*>(_v) = _t->_yAspectRatio; break; + case 14: *reinterpret_cast< QString*>(_v) = _t->_yTop; break; + case 15: *reinterpret_cast< QString*>(_v) = _t->_yRight; break; + case 16: *reinterpret_cast< QString*>(_v) = _t->_yBottom; break; + case 17: *reinterpret_cast< QString*>(_v) = _t->_yLeft; break; + case 18: *reinterpret_cast< QString*>(_v) = _t->_yFlexBasis; break; + case 19: *reinterpret_cast< QString*>(_v) = _t->_yMinWidth; break; + case 20: *reinterpret_cast< QString*>(_v) = _t->_yMinHeight; break; + case 21: *reinterpret_cast< QString*>(_v) = _t->_yWidth; break; + case 22: *reinterpret_cast< QString*>(_v) = _t->_yHeight; break; + case 23: *reinterpret_cast< QString*>(_v) = _t->_yMaxWidth; break; + case 24: *reinterpret_cast< QString*>(_v) = _t->_yMaxHeight; break; + case 25: *reinterpret_cast< QString*>(_v) = _t->_yPaddingTop; break; + case 26: *reinterpret_cast< QString*>(_v) = _t->_yPaddingRight; break; + case 27: *reinterpret_cast< QString*>(_v) = _t->_yPaddingBottom; break; + case 28: *reinterpret_cast< QString*>(_v) = _t->_yPaddingLeft; break; + case 29: *reinterpret_cast< QString*>(_v) = _t->_yPaddingHorizontal; break; + case 30: *reinterpret_cast< QString*>(_v) = _t->_yPaddingVertical; break; + case 31: *reinterpret_cast< QString*>(_v) = _t->_yPadding; break; + case 32: *reinterpret_cast< QString*>(_v) = _t->_yMarginTop; break; + case 33: *reinterpret_cast< QString*>(_v) = _t->_yMarginRight; break; + case 34: *reinterpret_cast< QString*>(_v) = _t->_yMarginBottom; break; + case 35: *reinterpret_cast< QString*>(_v) = _t->_yMarginLeft; break; + case 36: *reinterpret_cast< QString*>(_v) = _t->_yMarginHorizontal; break; + case 37: *reinterpret_cast< QString*>(_v) = _t->_yMarginVertical; break; + case 38: *reinterpret_cast< QString*>(_v) = _t->_yMargin; break; + case 39: *reinterpret_cast< float*>(_v) = _t->_yBorderTop; break; + case 40: *reinterpret_cast< float*>(_v) = _t->_yBorderRight; break; + case 41: *reinterpret_cast< float*>(_v) = _t->_yBorderBottom; break; + case 42: *reinterpret_cast< float*>(_v) = _t->_yBorderLeft; break; + case 43: *reinterpret_cast< float*>(_v) = _t->_yBorderHorizontal; break; + case 44: *reinterpret_cast< float*>(_v) = _t->_yBorderVertical; break; + case 45: *reinterpret_cast< float*>(_v) = _t->_yBorder; break; + default: break; + } + } else if (_c == QMetaObject::WriteProperty) { + auto *_t = static_cast(_o); + Q_UNUSED(_t) + void *_v = _a[0]; + switch (_id) { + case 0: _t->setYDisplay(*reinterpret_cast< QString*>(_v)); break; + case 1: _t->setYAlignItems(*reinterpret_cast< QString*>(_v)); break; + case 2: _t->setYAlignContent(*reinterpret_cast< QString*>(_v)); break; + case 3: _t->setYAlignSelf(*reinterpret_cast< QString*>(_v)); break; + case 4: _t->setYJustifyContent(*reinterpret_cast< QString*>(_v)); break; + case 5: _t->setYDirection(*reinterpret_cast< QString*>(_v)); break; + case 6: _t->setYFlexDirection(*reinterpret_cast< QString*>(_v)); break; + case 7: _t->setYOverflow(*reinterpret_cast< QString*>(_v)); break; + case 8: _t->setYPosition(*reinterpret_cast< QString*>(_v)); break; + case 9: _t->setYFlexWrap(*reinterpret_cast< QString*>(_v)); break; + case 10: _t->setYFlex(*reinterpret_cast< float*>(_v)); break; + case 11: _t->setYFlexGrow(*reinterpret_cast< float*>(_v)); break; + case 12: _t->setYFlexShrink(*reinterpret_cast< float*>(_v)); break; + case 13: _t->setYAspectRatio(*reinterpret_cast< float*>(_v)); break; + case 14: _t->setYNodeTop(*reinterpret_cast< QString*>(_v)); break; + case 15: _t->setYNodeRight(*reinterpret_cast< QString*>(_v)); break; + case 16: _t->setYNodeBottom(*reinterpret_cast< QString*>(_v)); break; + case 17: _t->setYNodeLeft(*reinterpret_cast< QString*>(_v)); break; + case 18: _t->setYFlexBasis(*reinterpret_cast< QString*>(_v)); break; + case 19: _t->setYMinWidth(*reinterpret_cast< QString*>(_v)); break; + case 20: _t->setYMinHeight(*reinterpret_cast< QString*>(_v)); break; + case 21: _t->setYWidth(*reinterpret_cast< QString*>(_v)); break; + case 22: _t->setYHeight(*reinterpret_cast< QString*>(_v)); break; + case 23: _t->setYMaxWidth(*reinterpret_cast< QString*>(_v)); break; + case 24: _t->setYMaxHeight(*reinterpret_cast< QString*>(_v)); break; + case 25: _t->setYPaddingTop(*reinterpret_cast< QString*>(_v)); break; + case 26: _t->setYPaddingRight(*reinterpret_cast< QString*>(_v)); break; + case 27: _t->setYPaddingBottom(*reinterpret_cast< QString*>(_v)); break; + case 28: _t->setYPaddingLeft(*reinterpret_cast< QString*>(_v)); break; + case 29: _t->setYPaddingHorizontal(*reinterpret_cast< QString*>(_v)); break; + case 30: _t->setYPaddingVertical(*reinterpret_cast< QString*>(_v)); break; + case 31: _t->setYPadding(*reinterpret_cast< QString*>(_v)); break; + case 32: _t->setYMarginTop(*reinterpret_cast< QString*>(_v)); break; + case 33: _t->setYMarginRight(*reinterpret_cast< QString*>(_v)); break; + case 34: _t->setYMarginBottom(*reinterpret_cast< QString*>(_v)); break; + case 35: _t->setYMarginLeft(*reinterpret_cast< QString*>(_v)); break; + case 36: _t->setYMarginHorizontal(*reinterpret_cast< QString*>(_v)); break; + case 37: _t->setYMarginVertical(*reinterpret_cast< QString*>(_v)); break; + case 38: _t->setYMarginAll(*reinterpret_cast< QString*>(_v)); break; + case 39: _t->setYBorderTop(*reinterpret_cast< float*>(_v)); break; + case 40: _t->setYBorderRight(*reinterpret_cast< float*>(_v)); break; + case 41: _t->setYBorderBottom(*reinterpret_cast< float*>(_v)); break; + case 42: _t->setYBorderLeft(*reinterpret_cast< float*>(_v)); break; + case 43: _t->setYBorderHorizontal(*reinterpret_cast< float*>(_v)); break; + case 44: _t->setYBorderVertical(*reinterpret_cast< float*>(_v)); break; + case 45: _t->setYBorder(*reinterpret_cast< float*>(_v)); break; + default: break; + } + } else if (_c == QMetaObject::ResetProperty) { + } +#endif // QT_NO_PROPERTIES + Q_UNUSED(_o); + Q_UNUSED(_id); + Q_UNUSED(_c); + Q_UNUSED(_a); +} + +QT_INIT_METAOBJECT const QMetaObject NDial::staticMetaObject = { { + &QDial::staticMetaObject, + qt_meta_stringdata_NDial.data, + qt_meta_data_NDial, + qt_static_metacall, + nullptr, + nullptr +} }; + + +const QMetaObject *NDial::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; +} + +void *NDial::qt_metacast(const char *_clname) +{ + if (!_clname) return nullptr; + if (!strcmp(_clname, qt_meta_stringdata_NDial.stringdata0)) + return static_cast(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); + return QDial::qt_metacast(_clname); +} + +int NDial::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QDial::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + +#ifndef QT_NO_PROPERTIES + if (_c == QMetaObject::ReadProperty || _c == QMetaObject::WriteProperty + || _c == QMetaObject::ResetProperty || _c == QMetaObject::RegisterPropertyMetaType) { + qt_static_metacall(this, _c, _id, _a); + _id -= 46; + } else if (_c == QMetaObject::QueryPropertyDesignable) { + _id -= 46; + } else if (_c == QMetaObject::QueryPropertyScriptable) { + _id -= 46; + } else if (_c == QMetaObject::QueryPropertyStored) { + _id -= 46; + } else if (_c == QMetaObject::QueryPropertyEditable) { + _id -= 46; + } else if (_c == QMetaObject::QueryPropertyUser) { + _id -= 46; + } +#endif // QT_NO_PROPERTIES + return _id; +} +QT_WARNING_POP +QT_END_MOC_NAMESPACE diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index 92b1db612..e83db76ac 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -4,6 +4,7 @@ #include "src/cpp/QtGui/QIcon/qicon_wrap.h" #include "src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.h" #include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h" +#include "src/cpp/QtWidgets/Qdial/qdial_wrap.h" #include "src/cpp/QtWidgets/QLabel/qlabel_wrap.h" #include "src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.h" #include "src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h" @@ -39,6 +40,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QLineEditWrap::init(env, exports); QKeyEventWrap::init(env, exports); QPlainTextEditWrap::init(env, exports); + QDialWrap::init(env, exports); QLabelWrap::init(env, exports); QScrollAreaWrap::init(env, exports); return exports; diff --git a/src/demo.ts b/src/demo.ts index 02dc8c791..a0c5f8f2a 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -9,10 +9,13 @@ import { FlexLayout, QWidget, QIcon, + QDial, + QDialEvents, QPlainTextEdit } from "./index"; import { QScrollArea } from "./lib/QtWidgets/QScrollArea"; import { QPixmap } from "./lib/QtGui/QPixmap"; +import { Orientation } from "./lib/QtEnums"; const path = require("path"); @@ -27,6 +30,25 @@ checkbox.setText("Check me out?"); checkbox.setObjectName("check"); checkbox.setChecked(true); +const dial = new QDial(); +checkbox.setObjectName("dial"); +dial.setWrapping(true); +dial.setNotchesVisible(true); +dial.setSingleStep(10); +dial.setSingleStep(5); +dial.setMinimum(55); +dial.setMaximum(95); +setInterval(() => { + dial.setValue(Math.floor(Math.random() * 100)); + console.log(dial.minimum(), dial.maximum(), dial.value()); +}, 500); +dial.addEventListener(QDialEvents.sliderReleased, () => { + console.log('RELEASED!'); +}); +dial.addEventListener(QDialEvents.sliderPressed, () => { + console.log('PRESSED!'); +}); + const lineEdit = new QLineEdit(); lineEdit.setPlaceholderText("Enter your thoughts here"); lineEdit.setObjectName("editable"); @@ -75,6 +97,7 @@ if (rootView.layout) { rootView.layout.addWidget(progressbar); rootView.layout.addWidget(textEdit); rootView.layout.addWidget(scrollArea); + rootView.layout.addWidget(dial); } win.setCentralWidget(rootView); diff --git a/src/index.ts b/src/index.ts index 8cef147fd..07a392708 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,6 +10,7 @@ export { NodeLayout } from "./lib/QtWidgets/QLayout"; // Widgets: export { QCheckBox, QCheckBoxEvents } from "./lib/QtWidgets/QCheckBox"; export { QLabel, QLabelEvents } from "./lib/QtWidgets/QLabel"; +export { QDial, QDialEvents } from "./lib/QtWidgets/Qdial"; export { QLineEdit, QLineEditEvents } from "./lib/QtWidgets/QLineEdit"; export { QMainWindow, QMainWindowEvents } from "./lib/QtWidgets/QMainWindow"; export { QProgressBar, QProgressBarEvents } from "./lib/QtWidgets/QProgressBar"; diff --git a/src/lib/QtWidgets/QAbstractSlider/index.ts b/src/lib/QtWidgets/QAbstractSlider/index.ts new file mode 100644 index 000000000..ac587dbe9 --- /dev/null +++ b/src/lib/QtWidgets/QAbstractSlider/index.ts @@ -0,0 +1,30 @@ +import { NodeWidget, QWidget } from "../QWidget"; +import { Orientation } from "../../QtEnums"; + +export abstract class QAbstractSlider extends NodeWidget { + setSingleStep = (step: number) => { + this.native.setSingleStep(step); + }; + setMaximum(maximum: number) { + this.native.setMaximum(maximum); + } + setMinimum(minimum: number) { + this.native.setMinimum(minimum); + } + setValue(value: number) { + this.native.setValue(value); + } + setOrientation(orientation: Orientation) { + this.native.setOrientation(orientation); + } + + maximum(): number { + return this.native.maximum(); + } + minimum(): number { + return this.native.minimum(); + } + value(): number { + return this.native.value(); + } +} diff --git a/src/lib/QtWidgets/QDial/index.ts b/src/lib/QtWidgets/QDial/index.ts new file mode 100644 index 000000000..a66f7c608 --- /dev/null +++ b/src/lib/QtWidgets/QDial/index.ts @@ -0,0 +1,53 @@ +import addon from "../../core/addon"; +import { NodeWidget } from "../QWidget"; +import { BaseWidgetEvents } from "../../core/EventWidget"; +import { NativeElement } from "../../core/Component"; +import { QAbstractSlider } from "../QAbstractSlider"; + +export const QDialEvents = Object.freeze({ + ...BaseWidgetEvents, + valueChanged: "valueChanged", + rangeChanged: "rangeChanged", + sliderMoved: "sliderMoved", + sliderPressed: "sliderPressed", + sliderReleased: "sliderReleased" +}); +export class QDial extends QAbstractSlider { + native: NativeElement; + constructor(parent?: NodeWidget) { + let native; + if (parent) { + native = new addon.QDial(parent.native); + } else { + native = new addon.QDial(); + } + super(native); + this.native = native; + this.parent = parent; + // bind member functions + this.setNotchesVisible.bind(this); + this.setWrapping.bind(this); + this.setNotchTarget.bind(this); + this.notchTarget.bind(this); + this.notchesVisible.bind(this); + this.wrapping.bind(this); + } + setNotchesVisible(visible: boolean) { + this.native.setNotchesVisible(visible); + } + setWrapping(on: boolean) { + this.native.setWrapping(on); + } + setNotchTarget(target: number) { + this.native.setNotchTarget(target); + } + notchTarget(): number { + return this.native.notchTarget(); + } + notchesVisible(): boolean { + return this.native.notchesVisible(); + } + wrapping(): boolean { + return this.native.wrapping(); + } +} From 6cbb433aaae38ebdbbba56f18de7e7b772de379d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Borecki?= Date: Fri, 30 Aug 2019 21:53:31 +0200 Subject: [PATCH 2/3] Minor fixes for copied code and demo content --- config/moc.gypi | 24 ++++++++++++------------ docs/README.md | 2 ++ docs/api/QDial.md | 4 ++-- src/cpp/QtWidgets/QDial/qdial_wrap.cpp | 2 +- src/demo.ts | 18 ------------------ 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/config/moc.gypi b/config/moc.gypi index 5ce3cc25a..aabfe38d7 100644 --- a/config/moc.gypi +++ b/config/moc.gypi @@ -2,17 +2,17 @@ # RUN: npm run automoc after updating moc.json { "sources": [ - "..\\src\\cpp\\autogen\\nwidget_moc.cpp", - "..\\src\\cpp\\autogen\\nlabel_moc.cpp", - "..\\src\\cpp\\autogen\\ncheckbox_moc.cpp", - "..\\src\\cpp\\autogen\\ndial_moc.cpp", - "..\\src\\cpp\\autogen\\nlineedit_moc.cpp", - "..\\src\\cpp\\autogen\\nmainwindow_moc.cpp", - "..\\src\\cpp\\autogen\\nprogressbar_moc.cpp", - "..\\src\\cpp\\autogen\\npushbutton_moc.cpp", - "..\\src\\cpp\\autogen\\nspinbox_moc.cpp", - "..\\src\\cpp\\autogen\\nradiobutton_moc.cpp", - "..\\src\\cpp\\autogen\\nplaintextedit_moc.cpp", - "..\\src\\cpp\\autogen\\nscrollarea_moc.cpp" + "../src/cpp/autogen/nwidget_moc.cpp", + "../src/cpp/autogen/nlabel_moc.cpp", + "../src/cpp/autogen/ncheckbox_moc.cpp", + "../src/cpp/autogen/ndial_moc.cpp", + "../src/cpp/autogen/nlineedit_moc.cpp", + "../src/cpp/autogen/nmainwindow_moc.cpp", + "../src/cpp/autogen/nprogressbar_moc.cpp", + "../src/cpp/autogen/npushbutton_moc.cpp", + "../src/cpp/autogen/nspinbox_moc.cpp", + "../src/cpp/autogen/nradiobutton_moc.cpp", + "../src/cpp/autogen/nplaintextedit_moc.cpp", + "../src/cpp/autogen/nscrollarea_moc.cpp" ] } \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index 4426365c5..770c7d2ec 100644 --- a/docs/README.md +++ b/docs/README.md @@ -45,6 +45,8 @@ - [QWidget (View)](api/QWidget.md) - [QSpinBox ()](api/QSpinBox.md) - [QAbstractScrollArea ()](api/QAbstractScrollArea.md) +- [QAbstractSlider ()](api/QAbstractSlider.md) +- [QDial ()](api/QDial.md) - [QScrollArea ()](api/QScrollArea.md) - [QPlainTextEdit (TextEdit)](api/QPlainTextEdit.md) - [QLabel (Text/Image)](api/QLabel.md) diff --git a/docs/api/QDial.md b/docs/api/QDial.md index 0b9059c8c..cbc2698f4 100644 --- a/docs/api/QDial.md +++ b/docs/api/QDial.md @@ -1,10 +1,10 @@ ## Class: QDial -> Create and control spin box widgets. +> Create and control dial slider widgets. **This class is a JS wrapper around Qt's [QDial class](https://doc.qt.io/qt-5/qdial.html)** -A `QDial` provides ability to add and manipulate native spin box widgets. +A `QDial` provides ability to add and manipulate native dial slider widgets. **QDial inherits from [QAbstractSlider](api/QAbstractSlider.md)** diff --git a/src/cpp/QtWidgets/QDial/qdial_wrap.cpp b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp index 98cdc1bd4..a2653ea05 100644 --- a/src/cpp/QtWidgets/QDial/qdial_wrap.cpp +++ b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp @@ -1,5 +1,5 @@ -#include "qDial_wrap.h" +#include "qdial_wrap.h" #include "src/cpp/QtWidgets/QWidget/qwidget_wrap.h" #include "src/cpp/Extras/Utils/nutils.h" #include diff --git a/src/demo.ts b/src/demo.ts index a0c5f8f2a..e6dcd9a8f 100644 --- a/src/demo.ts +++ b/src/demo.ts @@ -10,12 +10,10 @@ import { QWidget, QIcon, QDial, - QDialEvents, QPlainTextEdit } from "./index"; import { QScrollArea } from "./lib/QtWidgets/QScrollArea"; import { QPixmap } from "./lib/QtGui/QPixmap"; -import { Orientation } from "./lib/QtEnums"; const path = require("path"); @@ -32,22 +30,6 @@ checkbox.setChecked(true); const dial = new QDial(); checkbox.setObjectName("dial"); -dial.setWrapping(true); -dial.setNotchesVisible(true); -dial.setSingleStep(10); -dial.setSingleStep(5); -dial.setMinimum(55); -dial.setMaximum(95); -setInterval(() => { - dial.setValue(Math.floor(Math.random() * 100)); - console.log(dial.minimum(), dial.maximum(), dial.value()); -}, 500); -dial.addEventListener(QDialEvents.sliderReleased, () => { - console.log('RELEASED!'); -}); -dial.addEventListener(QDialEvents.sliderPressed, () => { - console.log('PRESSED!'); -}); const lineEdit = new QLineEdit(); lineEdit.setPlaceholderText("Enter your thoughts here"); From e85ebedb57cdfe1ed19e0b9722e48dd4a64438a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Borecki?= Date: Fri, 30 Aug 2019 23:47:19 +0200 Subject: [PATCH 3/3] Update qdial_wrap.cpp --- src/cpp/QtWidgets/QDial/qdial_wrap.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpp/QtWidgets/QDial/qdial_wrap.cpp b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp index a2653ea05..8b6144f4a 100644 --- a/src/cpp/QtWidgets/QDial/qdial_wrap.cpp +++ b/src/cpp/QtWidgets/QDial/qdial_wrap.cpp @@ -17,7 +17,6 @@ Napi::Object QDialWrap::init(Napi::Env env, Napi::Object exports) { InstanceMethod("notchTarget", &QDialWrap::notchTarget), InstanceMethod("notchesVisible", &QDialWrap::notchesVisible), InstanceMethod("wrapping", &QDialWrap::wrapping), - QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QDialWrap) QABSTRACTSLIDER_WRAPPED_METHODS_EXPORT_DEFINE(QDialWrap) }); constructor = Napi::Persistent(func);