Skip to content

Commit fd97b3b

Browse files
author
kusti8
committed
Add qpushbutton [publish binary]
1 parent 48d5edb commit fd97b3b

File tree

8 files changed

+290
-39
lines changed

8 files changed

+290
-39
lines changed

binding.gyp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"src/QtGui/qpixmap.cpp",
1313
"src/QtGui/qcombobox.cpp",
1414
"src/QtGui/qplaintextedit.cpp",
15+
"src/QtGui/qpushbutton.cpp",
1516
"src/misc.cpp",
1617
"src/utils/unwrapper.cpp",
1718
],
@@ -59,10 +60,12 @@
5960
"<!(moc src/QtGui/qlineedit.hpp -o src/QtGui/qlineedit.moc)",
6061
"<!(moc src/QtGui/qcombobox.hpp -o src/QtGui/qcombobox.moc)",
6162
"<!(moc src/QtGui/qplaintextedit.hpp -o src/QtGui/qplaintextedit.moc)",
63+
"<!(moc src/QtGui/qpushbutton.hpp -o src/QtGui/qpushbutton.moc)",
6264
"src/QtGui/qapplication.cpp",
6365
"src/QtGui/qlineedit.cpp",
6466
"src/QtGui/qcombobox.cpp",
6567
"src/QtGui/qplaintextedit.cpp",
68+
"src/QtGui/qpushbutton.cpp",
6669
],
6770
"cflags": ["<!@(pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)"],
6871
"ldflags": [

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
{
2-
"name": "node-qt-napi",
3-
"version": "0.0.2",
4-
"description": "",
5-
"main": "./lib/qt.js",
6-
"binary": {
7-
"module_name": "qt",
8-
"module_path": "./bindings/napi-v{napi_build_version}",
9-
"host": "https://github.com/kusti8/node-qt-napi/releases/download/",
10-
"napi_versions": [
11-
2,
12-
3,
13-
4
14-
],
15-
"remote_path": "{version}",
16-
"package_name": "{module_name}-v{version}-{napi_build_version}-{platform}-{arch}.tar.gz"
17-
},
18-
"dependencies": {
19-
"cross-env": "^6.0.3",
20-
"node-addon-api": "*",
21-
"node-pre-gyp": "^0.13.0"
22-
},
23-
"devDependencies": {
24-
"node-pre-gyp-github": "^1.4.3"
25-
},
26-
"scripts": {
27-
"test": "echo \"Error: no test specified\"",
28-
"install": "cross-env JOBS=max node-pre-gyp install --fallback-to-build"
29-
},
30-
"author": "Gustav Hansen",
31-
"license": "MIT",
32-
"repository": {
33-
"type": "git",
34-
"url": "https://github.com/kusti8/node-qt-napi.git"
35-
}
2+
"name": "node-qt-napi",
3+
"version": "0.0.3",
4+
"description": "",
5+
"main": "./lib/qt.js",
6+
"binary": {
7+
"module_name": "qt",
8+
"module_path": "./bindings/napi-v{napi_build_version}",
9+
"host": "https://github.com/kusti8/node-qt-napi/releases/download/",
10+
"napi_versions": [
11+
2,
12+
3,
13+
4
14+
],
15+
"remote_path": "{version}",
16+
"package_name": "{module_name}-v{version}-{napi_build_version}-{platform}-{arch}.tar.gz"
17+
},
18+
"dependencies": {
19+
"cross-env": "^6.0.3",
20+
"node-addon-api": "^2.0.0",
21+
"node-pre-gyp": "^0.13.0"
22+
},
23+
"devDependencies": {
24+
"node-pre-gyp-github": "^1.4.3"
25+
},
26+
"scripts": {
27+
"test": "echo \"Error: no test specified\"",
28+
"install": "cross-env JOBS=max node-pre-gyp install --fallback-to-build"
29+
},
30+
"author": "Gustav Hansen",
31+
"license": "MIT",
32+
"repository": {
33+
"type": "git",
34+
"url": "https://github.com/kusti8/node-qt-napi.git"
35+
}
3636
}

run-moc.sh

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/QtGui/qpushbutton.cpp

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include "qpushbutton.hpp"
2+
3+
Napi::FunctionReference QPushButtonWrap::constructor;
4+
5+
QWIDGET_IMPL_FUNCS(QPushButton)
6+
7+
void SlotHandlerPushButton::buttonReleasedSlot()
8+
{
9+
element->buttonReleasedCallback_.Call({});
10+
}
11+
12+
Napi::Object QPushButtonWrap::Init(Napi::Env env, Napi::Object exports)
13+
{
14+
Napi::HandleScope scope(env);
15+
// clang-format off
16+
Napi::Function func = DefineClass(env, "QPushButton", {
17+
InstanceMethod("setText", &QPushButtonWrap::setText),
18+
InstanceMethod("text", &QPushButtonWrap::text),
19+
InstanceMethod("buttonReleasedEvent", &QPushButtonWrap::buttonReleasedEvent),
20+
QWIDGET_JS_DEFINES(QPushButtonWrap)
21+
});
22+
// clang-format on
23+
24+
constructor = Napi::Persistent(func);
25+
constructor.SuppressDestruct();
26+
27+
exports.Set("QPushButton", func);
28+
return exports;
29+
}
30+
31+
QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap<QPushButtonWrap>(info), slotHandler(this)
32+
{
33+
Napi::Env env = info.Env();
34+
Napi::HandleScope scope(env);
35+
36+
if (info.Length() > 0)
37+
{
38+
QWidget *parent = unwrap(info[0]);
39+
q_ = new QPushButtonImpl(parent, env);
40+
}
41+
else
42+
{
43+
QPushButtonImpl *q_parent = 0;
44+
q_ = new QPushButtonImpl(q_parent, env);
45+
}
46+
q_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
47+
}
48+
49+
QPushButtonWrap::~QPushButtonWrap()
50+
{
51+
q_ = NULL;
52+
}
53+
54+
Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo &info)
55+
{
56+
q_->setText(QString::fromStdString(info[0].ToString().Utf8Value()));
57+
return Napi::Value();
58+
}
59+
60+
Napi::Value QPushButtonWrap::text(const Napi::CallbackInfo &info)
61+
{
62+
Napi::Env env = info.Env();
63+
Napi::HandleScope scope(env);
64+
65+
return Napi::String::New(env, q_->text().toStdString());
66+
}
67+
68+
Napi::Value QPushButtonWrap::buttonReleasedEvent(const Napi::CallbackInfo &info)
69+
{
70+
Napi::Env env = info.Env();
71+
Napi::HandleScope scope(env);
72+
73+
buttonReleasedCallback_ = Napi::Persistent(info[0].As<Napi::Function>());
74+
QObject::connect(q_, SIGNAL(released()), &slotHandler, SLOT(buttonReleasedSlot()));
75+
76+
return Napi::Value();
77+
}
78+
79+
#include "qpushbutton.moc"
80+
81+
// QWidget functions
82+
QWIDGET_BASE_FUNCS(QPushButtonWrap)

src/QtGui/qpushbutton.hpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef QPUSHBUTTONWRAP_H
2+
#define QPUSHBUTTONWRAP_H
3+
#include <QPushButton>
4+
#include <QObject>
5+
#include <napi.h>
6+
#include "qwidget.hpp"
7+
#include "qwidget_macros.hpp"
8+
#include "../utils/unwrapper.hpp"
9+
#include <iostream>
10+
11+
QWIDGET_IMPL_DEF(QPushButton)
12+
13+
class QPushButtonWrap;
14+
class SlotHandlerPushButton : public QObject
15+
{
16+
17+
Q_OBJECT
18+
19+
public:
20+
SlotHandlerPushButton(QPushButtonWrap *element) : element(element){};
21+
QPushButtonWrap *element;
22+
23+
public slots:
24+
void buttonReleasedSlot();
25+
};
26+
27+
class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap>
28+
{
29+
public:
30+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
31+
32+
QPushButtonWrap(const Napi::CallbackInfo &info);
33+
~QPushButtonWrap();
34+
35+
QPushButtonImpl *q_;
36+
37+
Napi::FunctionReference buttonReleasedCallback_;
38+
39+
private:
40+
static Napi::FunctionReference constructor;
41+
42+
Napi::Value setText(const Napi::CallbackInfo &info);
43+
Napi::Value text(const Napi::CallbackInfo &info);
44+
Napi::Value buttonReleasedEvent(const Napi::CallbackInfo &info);
45+
46+
SlotHandlerPushButton slotHandler;
47+
48+
// QWidget Funcs
49+
QWIDGET_DEFS
50+
};
51+
#endif

src/QtGui/qpushbutton.moc

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/****************************************************************************
2+
** Meta object code from reading C++ file 'qpushbutton.hpp'
3+
**
4+
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.9.5)
5+
**
6+
** WARNING! All changes made in this file will be lost!
7+
*****************************************************************************/
8+
9+
#include "qpushbutton.hpp"
10+
#include <QtCore/qbytearray.h>
11+
#include <QtCore/qmetatype.h>
12+
#if !defined(Q_MOC_OUTPUT_REVISION)
13+
#error "The header file 'qpushbutton.hpp' doesn't include <QObject>."
14+
#elif Q_MOC_OUTPUT_REVISION != 67
15+
#error "This file was generated using the moc from 5.9.5. It"
16+
#error "cannot be used with the include files from this version of Qt."
17+
#error "(The moc has changed too much.)"
18+
#endif
19+
20+
QT_BEGIN_MOC_NAMESPACE
21+
QT_WARNING_PUSH
22+
QT_WARNING_DISABLE_DEPRECATED
23+
struct qt_meta_stringdata_SlotHandlerPushButton_t {
24+
QByteArrayData data[3];
25+
char stringdata0[42];
26+
};
27+
#define QT_MOC_LITERAL(idx, ofs, len) \
28+
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
29+
qptrdiff(offsetof(qt_meta_stringdata_SlotHandlerPushButton_t, stringdata0) + ofs \
30+
- idx * sizeof(QByteArrayData)) \
31+
)
32+
static const qt_meta_stringdata_SlotHandlerPushButton_t qt_meta_stringdata_SlotHandlerPushButton = {
33+
{
34+
QT_MOC_LITERAL(0, 0, 21), // "SlotHandlerPushButton"
35+
QT_MOC_LITERAL(1, 22, 18), // "buttonReleasedSlot"
36+
QT_MOC_LITERAL(2, 41, 0) // ""
37+
38+
},
39+
"SlotHandlerPushButton\0buttonReleasedSlot\0"
40+
""
41+
};
42+
#undef QT_MOC_LITERAL
43+
44+
static const uint qt_meta_data_SlotHandlerPushButton[] = {
45+
46+
// content:
47+
7, // revision
48+
0, // classname
49+
0, 0, // classinfo
50+
1, 14, // methods
51+
0, 0, // properties
52+
0, 0, // enums/sets
53+
0, 0, // constructors
54+
0, // flags
55+
0, // signalCount
56+
57+
// slots: name, argc, parameters, tag, flags
58+
1, 0, 19, 2, 0x0a /* Public */,
59+
60+
// slots: parameters
61+
QMetaType::Void,
62+
63+
0 // eod
64+
};
65+
66+
void SlotHandlerPushButton::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
67+
{
68+
if (_c == QMetaObject::InvokeMetaMethod) {
69+
SlotHandlerPushButton *_t = static_cast<SlotHandlerPushButton *>(_o);
70+
Q_UNUSED(_t)
71+
switch (_id) {
72+
case 0: _t->buttonReleasedSlot(); break;
73+
default: ;
74+
}
75+
}
76+
Q_UNUSED(_a);
77+
}
78+
79+
const QMetaObject SlotHandlerPushButton::staticMetaObject = {
80+
{ &QObject::staticMetaObject, qt_meta_stringdata_SlotHandlerPushButton.data,
81+
qt_meta_data_SlotHandlerPushButton, qt_static_metacall, nullptr, nullptr}
82+
};
83+
84+
85+
const QMetaObject *SlotHandlerPushButton::metaObject() const
86+
{
87+
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
88+
}
89+
90+
void *SlotHandlerPushButton::qt_metacast(const char *_clname)
91+
{
92+
if (!_clname) return nullptr;
93+
if (!strcmp(_clname, qt_meta_stringdata_SlotHandlerPushButton.stringdata0))
94+
return static_cast<void*>(this);
95+
return QObject::qt_metacast(_clname);
96+
}
97+
98+
int SlotHandlerPushButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
99+
{
100+
_id = QObject::qt_metacall(_c, _id, _a);
101+
if (_id < 0)
102+
return _id;
103+
if (_c == QMetaObject::InvokeMetaMethod) {
104+
if (_id < 1)
105+
qt_static_metacall(this, _c, _id, _a);
106+
_id -= 1;
107+
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
108+
if (_id < 1)
109+
*reinterpret_cast<int*>(_a[0]) = -1;
110+
_id -= 1;
111+
}
112+
return _id;
113+
}
114+
QT_WARNING_POP
115+
QT_END_MOC_NAMESPACE

src/qt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "QtGui/qpixmap.hpp"
88
#include "QtGui/qcombobox.hpp"
99
#include "QtGui/qplaintextedit.hpp"
10+
#include "QtGui/qpushbutton.hpp"
1011
#include "misc.hpp"
1112

1213
Napi::Object Init(Napi::Env env, Napi::Object exports)
@@ -19,6 +20,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
1920
QPixmapWrap::Init(env, exports);
2021
QComboBoxWrap::Init(env, exports);
2122
QPlainTextEditWrap::Init(env, exports);
23+
QPushButtonWrap::Init(env, exports);
2224
MiscInit(env, exports);
2325
return exports;
2426
}

0 commit comments

Comments
 (0)