Skip to content

Added a few missing methods to QTWidget #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 98 additions & 1 deletion src/QtGui/qpainter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "qpainterpath.h"
#include "qfont.h"
#include "qmatrix.h"
#include "../QtCore/qpointf.h"

using namespace v8;

Expand Down Expand Up @@ -85,7 +86,13 @@ void QPainterWrap::Initialize(Handle<Object> target) {
FunctionTemplate::New(DrawImage)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("strokePath"),
FunctionTemplate::New(StrokePath)->GetFunction());

tpl->PrototypeTemplate()->Set(String::NewSymbol("drawEllipse"),
FunctionTemplate::New(DrawEllipse)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("setBrush"),
FunctionTemplate::New(SetBrush)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("fillPath"),
FunctionTemplate::New(FillPath)->GetFunction());

constructor = Persistent<Function>::New(tpl->GetFunction());
target->Set(String::NewSymbol("QPainter"), constructor);
}
Expand Down Expand Up @@ -445,3 +452,93 @@ Handle<Value> QPainterWrap::StrokePath(const Arguments& args) {

return scope.Close(Undefined());
}

// void QPainter::drawEllipse ( const QPoint & center, int rx, int ry )
Handle<Value> QPainterWrap::DrawEllipse(const Arguments& args) {
HandleScope scope;

QPainterWrap* w = ObjectWrap::Unwrap<QPainterWrap>(args.This());
QPainter* q = w->GetWrapped();

QString arg0_constructor;
if (args[0]->IsObject()) {
arg0_constructor =
qt_v8::ToQString(args[0]->ToObject()->GetConstructorName());
}

if (arg0_constructor != "QPointF")
return ThrowException(Exception::TypeError(
String::New("QPainterPathWrap::DrawEllipse: argument not recognized")));

QPointFWrap* pointf_wrap = ObjectWrap::Unwrap<QPointFWrap>(args[0]->ToObject());
QPointF* pointf = pointf_wrap->GetWrapped();

q->drawEllipse( *pointf, args[1]->IntegerValue(), args[2]->IntegerValue() );

return scope.Close(Undefined());
}

Handle<Value> QPainterWrap::FillPath(const Arguments& args) {
HandleScope scope;

QPainterWrap* w = ObjectWrap::Unwrap<QPainterWrap>(args.This());
QPainter* q = w->GetWrapped();

QString arg0_constructor;
if (args[0]->IsObject()) {
arg0_constructor =
qt_v8::ToQString(args[0]->ToObject()->GetConstructorName());
}

if (arg0_constructor != "QPainterPath")
return ThrowException(Exception::TypeError(
String::New("QPainterPathWrap::FillPath: argument not recognized")));

QString arg1_constructor;
if (args[1]->IsObject()) {
arg1_constructor =
qt_v8::ToQString(args[1]->ToObject()->GetConstructorName());
}

if (arg1_constructor != "QBrush")
return ThrowException(Exception::TypeError(
String::New("QBrush::FillPath: argument not recognized")));


// Unwrap QPainterPath
QPainterPathWrap* path_wrap = ObjectWrap::Unwrap<QPainterPathWrap>(args[0]->ToObject());
QPainterPath* path = path_wrap->GetWrapped();

// Unwrap QBrush
QBrushWrap* brush_wrap = ObjectWrap::Unwrap<QBrushWrap>(args[1]->ToObject());
QBrush* brush = brush_wrap->GetWrapped();

q->fillPath( *path, *brush );

return scope.Close(Undefined());
}

Handle<Value> QPainterWrap::SetBrush(const Arguments& args) {
HandleScope scope;

QPainterWrap* w = ObjectWrap::Unwrap<QPainterWrap>(args.This());
QPainter* q = w->GetWrapped();

QString arg0_constructor;
if (args[0]->IsObject()) {
arg0_constructor =
qt_v8::ToQString(args[0]->ToObject()->GetConstructorName());
}

if (arg0_constructor != "QBrush")
return ThrowException(Exception::TypeError(
String::New("QPainterPathWrap::SetBrush: argument not recognized")));

// Unwrap QBrush
QBrushWrap* brush_wrap = ObjectWrap::Unwrap<QBrushWrap>(args[0]->ToObject());
QBrush* brush = brush_wrap->GetWrapped();

q->setBrush( *brush );

return scope.Close(Undefined());
}
5 changes: 4 additions & 1 deletion src/QtGui/qpainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ class QPainterWrap : public node::ObjectWrap {
static v8::Handle<v8::Value> SetPen(const v8::Arguments& args);
static v8::Handle<v8::Value> SetFont(const v8::Arguments& args);
static v8::Handle<v8::Value> SetMatrix(const v8::Arguments& args);

static v8::Handle<v8::Value> SetBrush(const v8::Arguments& args);

// Paint actions
static v8::Handle<v8::Value> FillRect(const v8::Arguments& args);
static v8::Handle<v8::Value> DrawText(const v8::Arguments& args);
static v8::Handle<v8::Value> DrawPixmap(const v8::Arguments& args);
static v8::Handle<v8::Value> DrawImage(const v8::Arguments& args);
static v8::Handle<v8::Value> StrokePath(const v8::Arguments& args);
static v8::Handle<v8::Value> DrawEllipse(const v8::Arguments& args);
static v8::Handle<v8::Value> FillPath(const v8::Arguments& args);

// Wrapped object
QPainter* q_;
Expand Down
15 changes: 14 additions & 1 deletion src/QtGui/qwidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ void QWidgetWrap::Initialize(Handle<Object> target) {
FunctionTemplate::New(X)->GetFunction());
tpl->PrototypeTemplate()->Set(String::NewSymbol("y"),
FunctionTemplate::New(Y)->GetFunction());

tpl->PrototypeTemplate()->Set(String::NewSymbol("showMaximized"),
FunctionTemplate::New(Show)->GetFunction());

// Events
tpl->PrototypeTemplate()->Set(String::NewSymbol("paintEvent"),
FunctionTemplate::New(PaintEvent)->GetFunction());
Expand Down Expand Up @@ -515,3 +517,14 @@ Handle<Value> QWidgetWrap::Y(const Arguments& args) {

return scope.Close(Integer::New(q->y()));
}

Handle<Value> QWidgetWrap::showMaximized(const Arguments& args) {
HandleScope scope;

QWidgetWrap* w = node::ObjectWrap::Unwrap<QWidgetWrap>(args.This());
QWidgetImpl* q = w->GetWrapped();

q->showMaximized();

return scope.Close(Undefined());
}
1 change: 1 addition & 0 deletions src/QtGui/qwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class QWidgetWrap : public node::ObjectWrap {
static v8::Handle<v8::Value> Move(const v8::Arguments& args);
static v8::Handle<v8::Value> X(const v8::Arguments& args);
static v8::Handle<v8::Value> Y(const v8::Arguments& args);
static v8::Handle<v8::Value> showMaximized(const v8::Arguments& args);

// QUIRK
// Event binding. These functions bind implemented event handlers above
Expand Down