Skip to content

Commit

Permalink
Add qpushbutton [publish binary]
Browse files Browse the repository at this point in the history
  • Loading branch information
kusti8 committed Jan 9, 2020
1 parent 48d5edb commit fd97b3b
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 39 deletions.
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"src/QtGui/qpixmap.cpp",
"src/QtGui/qcombobox.cpp",
"src/QtGui/qplaintextedit.cpp",
"src/QtGui/qpushbutton.cpp",
"src/misc.cpp",
"src/utils/unwrapper.cpp",
],
Expand Down Expand Up @@ -59,10 +60,12 @@
"<!(moc src/QtGui/qlineedit.hpp -o src/QtGui/qlineedit.moc)",
"<!(moc src/QtGui/qcombobox.hpp -o src/QtGui/qcombobox.moc)",
"<!(moc src/QtGui/qplaintextedit.hpp -o src/QtGui/qplaintextedit.moc)",
"<!(moc src/QtGui/qpushbutton.hpp -o src/QtGui/qpushbutton.moc)",
"src/QtGui/qapplication.cpp",
"src/QtGui/qlineedit.cpp",
"src/QtGui/qcombobox.cpp",
"src/QtGui/qplaintextedit.cpp",
"src/QtGui/qpushbutton.cpp",
],
"cflags": ["<!@(pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)"],
"ldflags": [
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 34 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"name": "node-qt-napi",
"version": "0.0.2",
"description": "",
"main": "./lib/qt.js",
"binary": {
"module_name": "qt",
"module_path": "./bindings/napi-v{napi_build_version}",
"host": "https://github.com/kusti8/node-qt-napi/releases/download/",
"napi_versions": [
2,
3,
4
],
"remote_path": "{version}",
"package_name": "{module_name}-v{version}-{napi_build_version}-{platform}-{arch}.tar.gz"
},
"dependencies": {
"cross-env": "^6.0.3",
"node-addon-api": "*",
"node-pre-gyp": "^0.13.0"
},
"devDependencies": {
"node-pre-gyp-github": "^1.4.3"
},
"scripts": {
"test": "echo \"Error: no test specified\"",
"install": "cross-env JOBS=max node-pre-gyp install --fallback-to-build"
},
"author": "Gustav Hansen",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/kusti8/node-qt-napi.git"
}
"name": "node-qt-napi",
"version": "0.0.3",
"description": "",
"main": "./lib/qt.js",
"binary": {
"module_name": "qt",
"module_path": "./bindings/napi-v{napi_build_version}",
"host": "https://github.com/kusti8/node-qt-napi/releases/download/",
"napi_versions": [
2,
3,
4
],
"remote_path": "{version}",
"package_name": "{module_name}-v{version}-{napi_build_version}-{platform}-{arch}.tar.gz"
},
"dependencies": {
"cross-env": "^6.0.3",
"node-addon-api": "^2.0.0",
"node-pre-gyp": "^0.13.0"
},
"devDependencies": {
"node-pre-gyp-github": "^1.4.3"
},
"scripts": {
"test": "echo \"Error: no test specified\"",
"install": "cross-env JOBS=max node-pre-gyp install --fallback-to-build"
},
"author": "Gustav Hansen",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/kusti8/node-qt-napi.git"
}
}
2 changes: 0 additions & 2 deletions run-moc.sh

This file was deleted.

82 changes: 82 additions & 0 deletions src/QtGui/qpushbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "qpushbutton.hpp"

Napi::FunctionReference QPushButtonWrap::constructor;

QWIDGET_IMPL_FUNCS(QPushButton)

void SlotHandlerPushButton::buttonReleasedSlot()
{
element->buttonReleasedCallback_.Call({});
}

Napi::Object QPushButtonWrap::Init(Napi::Env env, Napi::Object exports)
{
Napi::HandleScope scope(env);
// clang-format off
Napi::Function func = DefineClass(env, "QPushButton", {
InstanceMethod("setText", &QPushButtonWrap::setText),
InstanceMethod("text", &QPushButtonWrap::text),
InstanceMethod("buttonReleasedEvent", &QPushButtonWrap::buttonReleasedEvent),
QWIDGET_JS_DEFINES(QPushButtonWrap)
});
// clang-format on

constructor = Napi::Persistent(func);
constructor.SuppressDestruct();

exports.Set("QPushButton", func);
return exports;
}

QPushButtonWrap::QPushButtonWrap(const Napi::CallbackInfo &info) : Napi::ObjectWrap<QPushButtonWrap>(info), slotHandler(this)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

if (info.Length() > 0)
{
QWidget *parent = unwrap(info[0]);
q_ = new QPushButtonImpl(parent, env);
}
else
{
QPushButtonImpl *q_parent = 0;
q_ = new QPushButtonImpl(q_parent, env);
}
q_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
}

QPushButtonWrap::~QPushButtonWrap()
{
q_ = NULL;
}

Napi::Value QPushButtonWrap::setText(const Napi::CallbackInfo &info)
{
q_->setText(QString::fromStdString(info[0].ToString().Utf8Value()));
return Napi::Value();
}

Napi::Value QPushButtonWrap::text(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

return Napi::String::New(env, q_->text().toStdString());
}

Napi::Value QPushButtonWrap::buttonReleasedEvent(const Napi::CallbackInfo &info)
{
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

buttonReleasedCallback_ = Napi::Persistent(info[0].As<Napi::Function>());
QObject::connect(q_, SIGNAL(released()), &slotHandler, SLOT(buttonReleasedSlot()));

return Napi::Value();
}

#include "qpushbutton.moc"

// QWidget functions
QWIDGET_BASE_FUNCS(QPushButtonWrap)
51 changes: 51 additions & 0 deletions src/QtGui/qpushbutton.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef QPUSHBUTTONWRAP_H
#define QPUSHBUTTONWRAP_H
#include <QPushButton>
#include <QObject>
#include <napi.h>
#include "qwidget.hpp"
#include "qwidget_macros.hpp"
#include "../utils/unwrapper.hpp"
#include <iostream>

QWIDGET_IMPL_DEF(QPushButton)

class QPushButtonWrap;
class SlotHandlerPushButton : public QObject
{

Q_OBJECT

public:
SlotHandlerPushButton(QPushButtonWrap *element) : element(element){};
QPushButtonWrap *element;

public slots:
void buttonReleasedSlot();
};

class QPushButtonWrap : public Napi::ObjectWrap<QPushButtonWrap>
{
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);

QPushButtonWrap(const Napi::CallbackInfo &info);
~QPushButtonWrap();

QPushButtonImpl *q_;

Napi::FunctionReference buttonReleasedCallback_;

private:
static Napi::FunctionReference constructor;

Napi::Value setText(const Napi::CallbackInfo &info);
Napi::Value text(const Napi::CallbackInfo &info);
Napi::Value buttonReleasedEvent(const Napi::CallbackInfo &info);

SlotHandlerPushButton slotHandler;

// QWidget Funcs
QWIDGET_DEFS
};
#endif
115 changes: 115 additions & 0 deletions src/QtGui/qpushbutton.moc
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/****************************************************************************
** Meta object code from reading C++ file 'qpushbutton.hpp'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.9.5)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/

#include "qpushbutton.hpp"
#include <QtCore/qbytearray.h>
#include <QtCore/qmetatype.h>
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qpushbutton.hpp' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.9.5. 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_SlotHandlerPushButton_t {
QByteArrayData data[3];
char stringdata0[42];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
qptrdiff(offsetof(qt_meta_stringdata_SlotHandlerPushButton_t, stringdata0) + ofs \
- idx * sizeof(QByteArrayData)) \
)
static const qt_meta_stringdata_SlotHandlerPushButton_t qt_meta_stringdata_SlotHandlerPushButton = {
{
QT_MOC_LITERAL(0, 0, 21), // "SlotHandlerPushButton"
QT_MOC_LITERAL(1, 22, 18), // "buttonReleasedSlot"
QT_MOC_LITERAL(2, 41, 0) // ""

},
"SlotHandlerPushButton\0buttonReleasedSlot\0"
""
};
#undef QT_MOC_LITERAL

static const uint qt_meta_data_SlotHandlerPushButton[] = {

// content:
7, // revision
0, // classname
0, 0, // classinfo
1, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
0, // flags
0, // signalCount

// slots: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x0a /* Public */,

// slots: parameters
QMetaType::Void,

0 // eod
};

void SlotHandlerPushButton::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a)
{
if (_c == QMetaObject::InvokeMetaMethod) {
SlotHandlerPushButton *_t = static_cast<SlotHandlerPushButton *>(_o);
Q_UNUSED(_t)
switch (_id) {
case 0: _t->buttonReleasedSlot(); break;
default: ;
}
}
Q_UNUSED(_a);
}

const QMetaObject SlotHandlerPushButton::staticMetaObject = {
{ &QObject::staticMetaObject, qt_meta_stringdata_SlotHandlerPushButton.data,
qt_meta_data_SlotHandlerPushButton, qt_static_metacall, nullptr, nullptr}
};


const QMetaObject *SlotHandlerPushButton::metaObject() const
{
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
}

void *SlotHandlerPushButton::qt_metacast(const char *_clname)
{
if (!_clname) return nullptr;
if (!strcmp(_clname, qt_meta_stringdata_SlotHandlerPushButton.stringdata0))
return static_cast<void*>(this);
return QObject::qt_metacast(_clname);
}

int SlotHandlerPushButton::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
_id = QObject::qt_metacall(_c, _id, _a);
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1)
qt_static_metacall(this, _c, _id, _a);
_id -= 1;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1;
}
return _id;
}
QT_WARNING_POP
QT_END_MOC_NAMESPACE
2 changes: 2 additions & 0 deletions src/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "QtGui/qpixmap.hpp"
#include "QtGui/qcombobox.hpp"
#include "QtGui/qplaintextedit.hpp"
#include "QtGui/qpushbutton.hpp"
#include "misc.hpp"

Napi::Object Init(Napi::Env env, Napi::Object exports)
Expand All @@ -19,6 +20,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
QPixmapWrap::Init(env, exports);
QComboBoxWrap::Init(env, exports);
QPlainTextEditWrap::Init(env, exports);
QPushButtonWrap::Init(env, exports);
MiscInit(env, exports);
return exports;
}
Expand Down

0 comments on commit fd97b3b

Please sign in to comment.