Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

resize, enter, leave, close events #4

Open
wants to merge 1 commit into from

4 participants

@Benvie

Working on tests but I'm slow at them

@arturadib
Owner

Thanks, Brandon! We're in the middle of a workweek but I'll take a look at this asap.

Tests are always welcome - they're normally the first thing I look at to get an idea of what's been done :) (Check out test/qwidget.js for event testing examples).

@kf6kjg

What is the progress on building the tests and applying the pull? These are pretty critical events - especially the close event!

@waddlesplash

@arturadib I second the above. When can it be merged? (It's now been 7mo since above comment).

@arturadib
Owner

@waddlesplash if someone can write tests I'd happily merge it :) it's not hard, see e.g. test/qwidget.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 10, 2012
  1. @Benvie
This page is out of date. Refresh to see the latest.
View
3  binding.gyp
@@ -10,6 +10,9 @@
'src/QtGui/qapplication.cc',
'src/QtGui/qwidget.cc',
+ 'src/QtGui/qevent.cc',
+ 'src/QtGui/qcloseevent.cc',
+ 'src/QtGui/qresizeevent.cc',
'src/QtGui/qmouseevent.cc',
'src/QtGui/qkeyevent.cc',
'src/QtGui/qpixmap.cc',
View
126 src/QtGui/qcloseevent.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include "qcloseevent.h"
+
+using namespace v8;
+
+Persistent<Function> QCloseEventWrap::constructor;
+
+QCloseEventWrap::QCloseEventWrap() : q_(NULL) {
+ // Standalone constructor not implemented
+ // Use SetWrapped()
+}
+
+QCloseEventWrap::~QCloseEventWrap() {
+ delete q_;
+}
+
+void QCloseEventWrap::Initialize(Handle<Object> target) {
+ // Prepare constructor template
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ tpl->SetClassName(String::NewSymbol("QCloseEvent"));
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("accept"),
+ FunctionTemplate::New(Accept)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("ignore"),
+ FunctionTemplate::New(Ignore)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("isAccepted"),
+ FunctionTemplate::New(IsAccepted)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("setAccepted"),
+ FunctionTemplate::New(SetAccepted)->GetFunction());
+
+ constructor = Persistent<Function>::New(tpl->GetFunction());
+ target->Set(String::NewSymbol("QCloseEvent"), constructor);
+}
+
+Handle<Value> QCloseEventWrap::New(const Arguments& args) {
+ HandleScope scope;
+
+ QCloseEventWrap* w = new QCloseEventWrap();
+ w->Wrap(args.This());
+
+ return args.This();
+}
+
+Handle<Value> QCloseEventWrap::NewInstance(QCloseEvent q) {
+ HandleScope scope;
+
+ Local<Object> instance = constructor->NewInstance(0, NULL);
+ QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(instance);
+ w->SetWrapped(q);
+
+ return scope.Close(instance);
+}
+
+Handle<Value> QCloseEventWrap::Accept(const Arguments& args) {
+ HandleScope scope;
+
+ QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
+ QCloseEvent* q = w->GetWrapped();
+
+ q->accept();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QCloseEventWrap::Ignore(const Arguments& args) {
+ HandleScope scope;
+
+ QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
+ QCloseEvent* q = w->GetWrapped();
+
+ q->ignore();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QCloseEventWrap::IsAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
+ QCloseEvent* q = w->GetWrapped();
+
+ return scope.Close(Boolean::New(q->isAccepted()));
+}
+
+Handle<Value> QCloseEventWrap::SetAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QCloseEventWrap* w = node::ObjectWrap::Unwrap<QCloseEventWrap>(args.This());
+ QCloseEvent* q = w->GetWrapped();
+
+ q->setAccepted(args[0]->BooleanValue());
+
+ return scope.Close(Undefined());
+}
+
View
63 src/QtGui/qcloseevent.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef QCLOSEEVENTWRAP_H
+#define QCLOSEEVENTWRAP_H
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include <QCloseEvent>
+
+class QCloseEventWrap : public node::ObjectWrap {
+ public:
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Handle<v8::Value> NewInstance(QCloseEvent q);
+ QCloseEvent* GetWrapped() const { return q_; };
+ void SetWrapped(QCloseEvent q) {
+ if (q_) delete q_;
+ q_ = new QCloseEvent(q);
+ };
+
+ private:
+ QCloseEventWrap();
+ ~QCloseEventWrap();
+ static v8::Persistent<v8::Function> constructor;
+ static v8::Handle<v8::Value> New(const v8::Arguments& args);
+
+ // Wrapped methods
+ static v8::Handle<v8::Value> Accept(const v8::Arguments& args);
+ static v8::Handle<v8::Value> Ignore(const v8::Arguments& args);
+ static v8::Handle<v8::Value> IsAccepted(const v8::Arguments& args);
+ static v8::Handle<v8::Value> SetAccepted(const v8::Arguments& args);
+
+ // Wrapped object
+ QCloseEvent* q_;
+};
+
+#endif
View
126 src/QtGui/qevent.cc
@@ -0,0 +1,126 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include "qevent.h"
+
+using namespace v8;
+
+Persistent<Function> QEventWrap::constructor;
+
+QEventWrap::QEventWrap() : q_(NULL) {
+ // Standalone constructor not implemented
+ // Use SetWrapped()
+}
+
+QEventWrap::~QEventWrap() {
+ delete q_;
+}
+
+void QEventWrap::Initialize(Handle<Object> target) {
+ // Prepare constructor template
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ tpl->SetClassName(String::NewSymbol("QEvent"));
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("accept"),
+ FunctionTemplate::New(Accept)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("ignore"),
+ FunctionTemplate::New(Ignore)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("isAccepted"),
+ FunctionTemplate::New(IsAccepted)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("setAccepted"),
+ FunctionTemplate::New(SetAccepted)->GetFunction());
+
+ constructor = Persistent<Function>::New(tpl->GetFunction());
+ target->Set(String::NewSymbol("QEvent"), constructor);
+}
+
+Handle<Value> QEventWrap::New(const Arguments& args) {
+ HandleScope scope;
+
+ QEventWrap* w = new QEventWrap();
+ w->Wrap(args.This());
+
+ return args.This();
+}
+
+Handle<Value> QEventWrap::NewInstance(QEvent q) {
+ HandleScope scope;
+
+ Local<Object> instance = constructor->NewInstance(0, NULL);
+ QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(instance);
+ w->SetWrapped(q);
+
+ return scope.Close(instance);
+}
+
+Handle<Value> QEventWrap::Accept(const Arguments& args) {
+ HandleScope scope;
+
+ QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
+ QEvent* q = w->GetWrapped();
+
+ q->accept();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QEventWrap::Ignore(const Arguments& args) {
+ HandleScope scope;
+
+ QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
+ QEvent* q = w->GetWrapped();
+
+ q->ignore();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QEventWrap::IsAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
+ QEvent* q = w->GetWrapped();
+
+ return scope.Close(Boolean::New(q->isAccepted()));
+}
+
+Handle<Value> QEventWrap::SetAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QEventWrap* w = node::ObjectWrap::Unwrap<QEventWrap>(args.This());
+ QEvent* q = w->GetWrapped();
+
+ q->setAccepted(args[0]->BooleanValue());
+
+ return scope.Close(Undefined());
+}
+
View
63 src/QtGui/qevent.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef QEVENTWRAP_H
+#define QEVENTWRAP_H
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include <QEvent>
+
+class QEventWrap : public node::ObjectWrap {
+ public:
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Handle<v8::Value> NewInstance(QEvent q);
+ QEvent* GetWrapped() const { return q_; };
+ void SetWrapped(QEvent q) {
+ if (q_) delete q_;
+ q_ = new QEvent(q);
+ };
+
+ private:
+ QEventWrap();
+ ~QEventWrap();
+ static v8::Persistent<v8::Function> constructor;
+ static v8::Handle<v8::Value> New(const v8::Arguments& args);
+
+ // Wrapped methods
+ static v8::Handle<v8::Value> Accept(const v8::Arguments& args);
+ static v8::Handle<v8::Value> Ignore(const v8::Arguments& args);
+ static v8::Handle<v8::Value> IsAccepted(const v8::Arguments& args);
+ static v8::Handle<v8::Value> SetAccepted(const v8::Arguments& args);
+
+ // Wrapped object
+ QEvent* q_;
+};
+
+#endif
View
149 src/QtGui/qresizeevent.cc
@@ -0,0 +1,149 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include "../QtCore/qsize.h"
+#include "qresizeevent.h"
+
+using namespace v8;
+
+Persistent<Function> QResizeEventWrap::constructor;
+
+QResizeEventWrap::QResizeEventWrap() : q_(NULL) {
+ // Standalone constructor not implemented
+ // Use SetWrapped()
+}
+
+QResizeEventWrap::~QResizeEventWrap() {
+ delete q_;
+}
+
+void QResizeEventWrap::Initialize(Handle<Object> target) {
+ // Prepare constructor template
+ Local<FunctionTemplate> tpl = FunctionTemplate::New(New);
+ tpl->SetClassName(String::NewSymbol("QResizeEvent"));
+ tpl->InstanceTemplate()->SetInternalFieldCount(1);
+
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("accept"),
+ FunctionTemplate::New(Accept)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("ignore"),
+ FunctionTemplate::New(Ignore)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("isAccepted"),
+ FunctionTemplate::New(IsAccepted)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("setAccepted"),
+ FunctionTemplate::New(SetAccepted)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("oldSize"),
+ FunctionTemplate::New(OldSize)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("size"),
+ FunctionTemplate::New(Size)->GetFunction());
+
+ constructor = Persistent<Function>::New(tpl->GetFunction());
+ target->Set(String::NewSymbol("QResizeEvent"), constructor);
+}
+
+Handle<Value> QResizeEventWrap::New(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = new QResizeEventWrap();
+ w->Wrap(args.This());
+
+ return args.This();
+}
+
+Handle<Value> QResizeEventWrap::NewInstance(QResizeEvent q) {
+ HandleScope scope;
+
+ Local<Object> instance = constructor->NewInstance(0, NULL);
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(instance);
+ w->SetWrapped(q);
+
+ return scope.Close(instance);
+}
+
+Handle<Value> QResizeEventWrap::Accept(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ q->accept();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QResizeEventWrap::Ignore(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ q->ignore();
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QResizeEventWrap::IsAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ return scope.Close(Boolean::New(q->isAccepted()));
+}
+
+Handle<Value> QResizeEventWrap::SetAccepted(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ q->setAccepted(args[0]->BooleanValue());
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QResizeEventWrap::Size(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ return scope.Close(QSizeWrap::NewInstance(q->size()));
+}
+
+
+Handle<Value> QResizeEventWrap::OldSize(const Arguments& args) {
+ HandleScope scope;
+
+ QResizeEventWrap* w = node::ObjectWrap::Unwrap<QResizeEventWrap>(args.This());
+ QResizeEvent* q = w->GetWrapped();
+
+ return scope.Close(QSizeWrap::NewInstance(q->oldSize()));
+}
View
65 src/QtGui/qresizeevent.h
@@ -0,0 +1,65 @@
+// Copyright (c) 2012, Artur Adib
+// All rights reserved.
+//
+// Author(s): Artur Adib <aadib@mozilla.com>
+//
+// You may use this file under the terms of the New BSD license as follows:
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of Artur Adib nor the
+// names of contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef QRESIZEEVENTWRAP_H
+#define QRESIZEEVENTWRAP_H
+
+#define BUILDING_NODE_EXTENSION
+#include <node.h>
+#include <QResizeEvent>
+
+class QResizeEventWrap : public node::ObjectWrap {
+ public:
+ static void Initialize(v8::Handle<v8::Object> target);
+ static v8::Handle<v8::Value> NewInstance(QResizeEvent q);
+ QResizeEvent* GetWrapped() const { return q_; };
+ void SetWrapped(QResizeEvent q) {
+ if (q_) delete q_;
+ q_ = new QResizeEvent(q);
+ };
+
+ private:
+ QResizeEventWrap();
+ ~QResizeEventWrap();
+ static v8::Persistent<v8::Function> constructor;
+ static v8::Handle<v8::Value> New(const v8::Arguments& args);
+
+ // Wrapped methods
+ static v8::Handle<v8::Value> Accept(const v8::Arguments& args);
+ static v8::Handle<v8::Value> Ignore(const v8::Arguments& args);
+ static v8::Handle<v8::Value> IsAccepted(const v8::Arguments& args);
+ static v8::Handle<v8::Value> SetAccepted(const v8::Arguments& args);
+ static v8::Handle<v8::Value> OldSize(const v8::Arguments& args);
+ static v8::Handle<v8::Value> Size(const v8::Arguments& args);
+
+ // Wrapped object
+ QResizeEvent* q_;
+};
+
+#endif
View
151 src/QtGui/qwidget.cc
@@ -32,6 +32,9 @@
#include "../qt_v8.h"
#include "../QtCore/qsize.h"
#include "qwidget.h"
+#include "qevent.h"
+#include "qcloseevent.h"
+#include "qresizeevent.h"
#include "qmouseevent.h"
#include "qkeyevent.h"
@@ -52,6 +55,10 @@ QWidgetImpl::QWidgetImpl(QWidgetImpl* parent) : QWidget(parent) {
mouseMoveCallback_ = Persistent<Boolean>::New(Boolean::New(false));
keyPressCallback_ = Persistent<Boolean>::New(Boolean::New(false));
keyReleaseCallback_ = Persistent<Boolean>::New(Boolean::New(false));
+ enterCallback_ = Persistent<Boolean>::New(Boolean::New(false));
+ leaveCallback_ = Persistent<Boolean>::New(Boolean::New(false));
+ closeCallback_ = Persistent<Boolean>::New(Boolean::New(false));
+ resizeCallback_ = Persistent<Boolean>::New(Boolean::New(false));
}
QWidgetImpl::~QWidgetImpl() {
@@ -61,6 +68,10 @@ QWidgetImpl::~QWidgetImpl() {
mouseMoveCallback_.Dispose();
keyPressCallback_.Dispose();
keyReleaseCallback_.Dispose();
+ enterCallback_.Dispose();
+ leaveCallback_.Dispose();
+ closeCallback_.Dispose();
+ resizeCallback_.Dispose();
}
void QWidgetImpl::paintEvent(QPaintEvent* e) {
@@ -161,6 +172,76 @@ void QWidgetImpl::keyReleaseEvent(QKeyEvent* e) {
cb->Call(Context::GetCurrent()->Global(), argc, argv);
}
+
+void QWidgetImpl::enterEvent(QEvent* e) {
+ e->ignore(); // ensures event bubbles up
+
+ HandleScope scope;
+
+ if (!enterCallback_->IsFunction())
+ return;
+
+ const unsigned argc = 1;
+ Handle<Value> argv[argc] = {
+ QEventWrap::NewInstance(*e)
+ };
+ Handle<Function> cb = Persistent<Function>::Cast(enterCallback_);
+
+ cb->Call(Context::GetCurrent()->Global(), argc, argv);
+}
+
+void QWidgetImpl::leaveEvent(QEvent* e) {
+ e->ignore(); // ensures event bubbles up
+
+ HandleScope scope;
+
+ if (!leaveCallback_->IsFunction())
+ return;
+
+ const unsigned argc = 1;
+ Handle<Value> argv[argc] = {
+ QEventWrap::NewInstance(*e)
+ };
+ Handle<Function> cb = Persistent<Function>::Cast(leaveCallback_);
+
+ cb->Call(Context::GetCurrent()->Global(), argc, argv);
+}
+
+void QWidgetImpl::closeEvent(QCloseEvent* e) {
+ e->accept(); // accept close event by default
+
+ HandleScope scope;
+
+ if (!closeCallback_->IsFunction())
+ return;
+
+ const unsigned argc = 1;
+ Handle<Value> argv[argc] = {
+ QCloseEventWrap::NewInstance(*e)
+ };
+ Handle<Function> cb = Persistent<Function>::Cast(closeCallback_);
+
+ cb->Call(Context::GetCurrent()->Global(), argc, argv);
+}
+
+void QWidgetImpl::resizeEvent(QResizeEvent* e) {
+ e->ignore(); // accept close event by default
+
+ HandleScope scope;
+
+ if (!resizeCallback_->IsFunction())
+ return;
+
+ const unsigned argc = 1;
+ Handle<Value> argv[argc] = {
+ QResizeEventWrap::NewInstance(*e)
+ };
+ Handle<Function> cb = Persistent<Function>::Cast(resizeCallback_);
+
+ cb->Call(Context::GetCurrent()->Global(), argc, argv);
+}
+
+
//
// QWidgetWrap()
//
@@ -226,6 +307,14 @@ void QWidgetWrap::Initialize(Handle<Object> target) {
FunctionTemplate::New(KeyPressEvent)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("keyReleaseEvent"),
FunctionTemplate::New(KeyReleaseEvent)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("enterEvent"),
+ FunctionTemplate::New(EnterEvent)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("leaveEvent"),
+ FunctionTemplate::New(LeaveEvent)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("closeEvent"),
+ FunctionTemplate::New(CloseEvent)->GetFunction());
+ tpl->PrototypeTemplate()->Set(String::NewSymbol("resizeEvent"),
+ FunctionTemplate::New(ResizeEvent)->GetFunction());
constructor = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("QWidget"), constructor);
@@ -443,6 +532,68 @@ Handle<Value> QWidgetWrap::KeyReleaseEvent(const Arguments& args) {
return scope.Close(Undefined());
}
+//
+// EnterEvent()
+// Binds a callback to Qt's event
+//
+Handle<Value> QWidgetWrap::EnterEvent(const Arguments& args) {
+ HandleScope scope;
+
+ QWidgetWrap* w = node::ObjectWrap::Unwrap<QWidgetWrap>(args.This());
+ QWidgetImpl* q = w->GetWrapped();
+
+ q->enterCallback_.Dispose();
+ q->enterCallback_ = Persistent<Function>::New(
+ Local<Function>::Cast(args[0]));
+
+ return scope.Close(Undefined());
+}
+
+//
+// LeaveEvent()
+// Binds a callback to Qt's event
+//
+Handle<Value> QWidgetWrap::LeaveEvent(const Arguments& args) {
+ HandleScope scope;
+
+ QWidgetWrap* w = node::ObjectWrap::Unwrap<QWidgetWrap>(args.This());
+ QWidgetImpl* q = w->GetWrapped();
+
+ q->leaveCallback_.Dispose();
+ q->leaveCallback_ = Persistent<Function>::New(
+ Local<Function>::Cast(args[0]));
+
+ return scope.Close(Undefined());
+}
+
+Handle<Value> QWidgetWrap::CloseEvent(const Arguments& args) {
+ HandleScope scope;
+
+ QWidgetWrap* w = node::ObjectWrap::Unwrap<QWidgetWrap>(args.This());
+ QWidgetImpl* q = w->GetWrapped();
+
+ q->closeCallback_.Dispose();
+ q->closeCallback_ = Persistent<Function>::New(
+ Local<Function>::Cast(args[0]));
+
+ return scope.Close(Undefined());
+}
+
+
+Handle<Value> QWidgetWrap::ResizeEvent(const Arguments& args) {
+ HandleScope scope;
+
+ QWidgetWrap* w = node::ObjectWrap::Unwrap<QWidgetWrap>(args.This());
+ QWidgetImpl* q = w->GetWrapped();
+
+ q->resizeCallback_.Dispose();
+ q->resizeCallback_ = Persistent<Function>::New(
+ Local<Function>::Cast(args[0]));
+
+ return scope.Close(Undefined());
+}
+
+
Handle<Value> QWidgetWrap::Update(const Arguments& args) {
HandleScope scope;
View
12 src/QtGui/qwidget.h
@@ -48,6 +48,10 @@ class QWidgetImpl : public QWidget {
v8::Persistent<v8::Value> mouseMoveCallback_;
v8::Persistent<v8::Value> keyPressCallback_;
v8::Persistent<v8::Value> keyReleaseCallback_;
+ v8::Persistent<v8::Value> enterCallback_;
+ v8::Persistent<v8::Value> leaveCallback_;
+ v8::Persistent<v8::Value> closeCallback_;
+ v8::Persistent<v8::Value> resizeCallback_;
private:
void paintEvent(QPaintEvent* e);
@@ -56,6 +60,10 @@ class QWidgetImpl : public QWidget {
void mouseMoveEvent(QMouseEvent* e);
void keyPressEvent(QKeyEvent* e);
void keyReleaseEvent(QKeyEvent* e);
+ void enterEvent(QEvent* e);
+ void leaveEvent(QEvent* e);
+ void closeEvent(QCloseEvent* e);
+ void resizeEvent(QResizeEvent* e);
};
//
@@ -100,6 +108,10 @@ class QWidgetWrap : public node::ObjectWrap {
static v8::Handle<v8::Value> MouseMoveEvent(const v8::Arguments& args);
static v8::Handle<v8::Value> KeyPressEvent(const v8::Arguments& args);
static v8::Handle<v8::Value> KeyReleaseEvent(const v8::Arguments& args);
+ static v8::Handle<v8::Value> EnterEvent(const v8::Arguments& args);
+ static v8::Handle<v8::Value> LeaveEvent(const v8::Arguments& args);
+ static v8::Handle<v8::Value> CloseEvent(const v8::Arguments& args);
+ static v8::Handle<v8::Value> ResizeEvent(const v8::Arguments& args);
// Wrapped object
QWidgetImpl* q_;
View
6 src/qt.cc
@@ -35,6 +35,9 @@
#include "QtGui/qapplication.h"
#include "QtGui/qwidget.h"
+#include "QtGui/qevent.h"
+#include "QtGui/qcloseevent.h"
+#include "QtGui/qresizeevent.h"
#include "QtGui/qmouseevent.h"
#include "QtGui/qkeyevent.h"
#include "QtGui/qpixmap.h"
@@ -58,6 +61,9 @@ void Initialize(Handle<Object> target) {
QApplicationWrap::Initialize(target);
QWidgetWrap::Initialize(target);
QSizeWrap::Initialize(target);
+ QEventWrap::Initialize(target);
+ QCloseEventWrap::Initialize(target);
+ QResizeEventWrap::Initialize(target);
QMouseEventWrap::Initialize(target);
QKeyEventWrap::Initialize(target);
QTestEventListWrap::Initialize(target);
Something went wrong with that request. Please try again.