Skip to content

Commit 62503e8

Browse files
author
kusti8
committed
Add activated to combobox and isNull to pixmap. Also improve mouse events
1 parent 801c8c1 commit 62503e8

File tree

6 files changed

+52
-11
lines changed

6 files changed

+52
-11
lines changed

src/QtGui/qcombobox.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ void SlotHandlerComboBox::currentTextChangedSlot(const QString &text)
1010
element->currentTextChangedCallback_.Call({Napi::String::New(env, text.toStdString())});
1111
}
1212

13+
void SlotHandlerComboBox::activatedSlot(const QString &text)
14+
{
15+
Napi::Env env = element->activatedCallback_.Env();
16+
element->activatedCallback_.Call({Napi::String::New(env, text.toStdString())});
17+
}
18+
1319
Napi::Object QComboBoxWrap::Init(Napi::Env env, Napi::Object exports)
1420
{
1521
Napi::HandleScope scope(env);
@@ -25,6 +31,7 @@ Napi::Object QComboBoxWrap::Init(Napi::Env env, Napi::Object exports)
2531
InstanceMethod("isEditable", &QComboBoxWrap::isEditable),
2632
InstanceMethod("setEditable", &QComboBoxWrap::setEditable),
2733
InstanceMethod("currentTextChangedEvent", &QComboBoxWrap::currentTextChangedEvent),
34+
InstanceMethod("activatedEvent", &QComboBoxWrap::activatedEvent),
2835
QWIDGET_JS_DEFINES(QComboBoxWrap)
2936
});
3037
// clang-format on
@@ -145,6 +152,17 @@ Napi::Value QComboBoxWrap::currentTextChangedEvent(const Napi::CallbackInfo &inf
145152
return Napi::Value();
146153
}
147154

155+
Napi::Value QComboBoxWrap::activatedEvent(const Napi::CallbackInfo &info)
156+
{
157+
Napi::Env env = info.Env();
158+
Napi::HandleScope scope(env);
159+
160+
activatedCallback_ = Napi::Persistent(info[0].As<Napi::Function>());
161+
QObject::connect(q_, SIGNAL(activated(const QString &)), &slotHandler, SLOT(activatedSlot(const QString &)));
162+
163+
return Napi::Value();
164+
}
165+
148166
#include "qcombobox.moc"
149167

150168
// QWidget functions

src/QtGui/qcombobox.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SlotHandlerComboBox : public QObject
2323

2424
public slots:
2525
void currentTextChangedSlot(const QString &text);
26+
void activatedSlot(const QString &text);
2627
};
2728

2829
class QComboBoxWrap : public Napi::ObjectWrap<QComboBoxWrap>
@@ -35,6 +36,7 @@ class QComboBoxWrap : public Napi::ObjectWrap<QComboBoxWrap>
3536

3637
QComboBoxImpl *q_;
3738
Napi::FunctionReference currentTextChangedCallback_;
39+
Napi::FunctionReference activatedCallback_;
3840

3941
private:
4042
static Napi::FunctionReference constructor;
@@ -49,6 +51,7 @@ class QComboBoxWrap : public Napi::ObjectWrap<QComboBoxWrap>
4951
Napi::Value isEditable(const Napi::CallbackInfo &info);
5052
Napi::Value setEditable(const Napi::CallbackInfo &info);
5153
Napi::Value currentTextChangedEvent(const Napi::CallbackInfo &info);
54+
Napi::Value activatedEvent(const Napi::CallbackInfo &info);
5255

5356
SlotHandlerComboBox slotHandler;
5457

src/QtGui/qcombobox.moc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE
2121
QT_WARNING_PUSH
2222
QT_WARNING_DISABLE_DEPRECATED
2323
struct qt_meta_stringdata_SlotHandlerComboBox_t {
24-
QByteArrayData data[4];
25-
char stringdata0[49];
24+
QByteArrayData data[5];
25+
char stringdata0[63];
2626
};
2727
#define QT_MOC_LITERAL(idx, ofs, len) \
2828
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@@ -34,11 +34,12 @@ static const qt_meta_stringdata_SlotHandlerComboBox_t qt_meta_stringdata_SlotHan
3434
QT_MOC_LITERAL(0, 0, 19), // "SlotHandlerComboBox"
3535
QT_MOC_LITERAL(1, 20, 22), // "currentTextChangedSlot"
3636
QT_MOC_LITERAL(2, 43, 0), // ""
37-
QT_MOC_LITERAL(3, 44, 4) // "text"
37+
QT_MOC_LITERAL(3, 44, 4), // "text"
38+
QT_MOC_LITERAL(4, 49, 13) // "activatedSlot"
3839

3940
},
4041
"SlotHandlerComboBox\0currentTextChangedSlot\0"
41-
"\0text"
42+
"\0text\0activatedSlot"
4243
};
4344
#undef QT_MOC_LITERAL
4445

@@ -48,17 +49,19 @@ static const uint qt_meta_data_SlotHandlerComboBox[] = {
4849
7, // revision
4950
0, // classname
5051
0, 0, // classinfo
51-
1, 14, // methods
52+
2, 14, // methods
5253
0, 0, // properties
5354
0, 0, // enums/sets
5455
0, 0, // constructors
5556
0, // flags
5657
0, // signalCount
5758

5859
// slots: name, argc, parameters, tag, flags
59-
1, 1, 19, 2, 0x0a /* Public */,
60+
1, 1, 24, 2, 0x0a /* Public */,
61+
4, 1, 27, 2, 0x0a /* Public */,
6062

6163
// slots: parameters
64+
QMetaType::Void, QMetaType::QString, 3,
6265
QMetaType::Void, QMetaType::QString, 3,
6366

6467
0 // eod
@@ -71,6 +74,7 @@ void SlotHandlerComboBox::qt_static_metacall(QObject *_o, QMetaObject::Call _c,
7174
Q_UNUSED(_t)
7275
switch (_id) {
7376
case 0: _t->currentTextChangedSlot((*reinterpret_cast< const QString(*)>(_a[1]))); break;
77+
case 1: _t->activatedSlot((*reinterpret_cast< const QString(*)>(_a[1]))); break;
7478
default: ;
7579
}
7680
}
@@ -101,13 +105,13 @@ int SlotHandlerComboBox::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
101105
if (_id < 0)
102106
return _id;
103107
if (_c == QMetaObject::InvokeMetaMethod) {
104-
if (_id < 1)
108+
if (_id < 2)
105109
qt_static_metacall(this, _c, _id, _a);
106-
_id -= 1;
110+
_id -= 2;
107111
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
108-
if (_id < 1)
112+
if (_id < 2)
109113
*reinterpret_cast<int*>(_a[0]) = -1;
110-
_id -= 1;
114+
_id -= 2;
111115
}
112116
return _id;
113117
}

src/QtGui/qpixmap.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Napi::Object QPixmapWrap::Init(Napi::Env env, Napi::Object exports)
1414
InstanceMethod("scaledToHeight", &QPixmapWrap::scaledToHeight),
1515
InstanceMethod("scaledTile", &QPixmapWrap::scaledTile),
1616
InstanceMethod("height", &QPixmapWrap::height),
17-
InstanceMethod("width", &QPixmapWrap::width)
17+
InstanceMethod("width", &QPixmapWrap::width),
18+
InstanceMethod("isNull", &QPixmapWrap::isNull)
1819
});
1920
// clang-format on
2021

@@ -134,4 +135,12 @@ Napi::Value QPixmapWrap::width(const Napi::CallbackInfo &info)
134135
Napi::HandleScope scope(env);
135136

136137
return Napi::Number::New(env, q_->width());
138+
}
139+
140+
Napi::Value QPixmapWrap::isNull(const Napi::CallbackInfo &info)
141+
{
142+
Napi::Env env = info.Env();
143+
Napi::HandleScope scope(env);
144+
145+
return Napi::Boolean::New(env, q_->isNull());
137146
}

src/QtGui/qpixmap.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ class QPixmapWrap : public Napi::ObjectWrap<QPixmapWrap>
3030
Napi::Value scaledTile(const Napi::CallbackInfo &info);
3131
Napi::Value height(const Napi::CallbackInfo &info);
3232
Napi::Value width(const Napi::CallbackInfo &info);
33+
Napi::Value isNull(const Napi::CallbackInfo &info);
3334
};
3435
#endif

src/QtGui/qwidget_macros.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,21 @@
121121
{ \
122122
className::mousePressEvent(e); \
123123
if (mousePressCallback_.IsEmpty()) \
124+
{ \
125+
e->ignore(); \
124126
return; \
127+
} \
125128
\
126129
mousePressCallback_.Call({}); \
127130
} \
128131
void className##Impl::mouseReleaseEvent(QMouseEvent *e) \
129132
{ \
130133
className::mouseReleaseEvent(e); \
131134
if (mouseReleaseCallback_.IsEmpty()) \
135+
{ \
136+
e->ignore(); \
132137
return; \
138+
} \
133139
\
134140
mouseReleaseCallback_.Call({}); \
135141
}

0 commit comments

Comments
 (0)