Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/cpp/include/nodegui/QtWidgets/QPainter/qpainter_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ class DLL_EXPORT QPainterWrap : public Napi::ObjectWrap<QPainterWrap> {
Napi::Value drawPointF(const Napi::CallbackInfo& info);
Napi::Value drawRect(const Napi::CallbackInfo& info);
Napi::Value drawRectF(const Napi::CallbackInfo& info);
Napi::Value drawRoundedRect(const Napi::CallbackInfo& info);
Napi::Value drawRoundedRectF(const Napi::CallbackInfo& info);
Napi::Value drawText(const Napi::CallbackInfo& info);
Napi::Value drawTextF(const Napi::CallbackInfo& info);
Napi::Value end(const Napi::CallbackInfo& info);
Napi::Value endNativePainting(const Napi::CallbackInfo& info);
Napi::Value eraseRect(const Napi::CallbackInfo& info);
Napi::Value eraseRectF(const Napi::CallbackInfo& info);
Napi::Value fillPath(const Napi::CallbackInfo& info);
Napi::Value fillRect(const Napi::CallbackInfo& info);
Napi::Value fillRectF(const Napi::CallbackInfo& info);
Napi::Value opacity(const Napi::CallbackInfo& info);
Expand Down
41 changes: 41 additions & 0 deletions src/cpp/lib/QtWidgets/QPainter/qpainter_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ Napi::Object QPainterWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("drawPointF", &QPainterWrap::drawPointF),
InstanceMethod("drawRect", &QPainterWrap::drawRect),
InstanceMethod("drawRectF", &QPainterWrap::drawRectF),
InstanceMethod("drawRoundedRect", &QPainterWrap::drawRoundedRect),
InstanceMethod("drawRoundedRectF", &QPainterWrap::drawRoundedRectF),
InstanceMethod("drawText", &QPainterWrap::drawText),
InstanceMethod("drawTextF", &QPainterWrap::drawTextF),
InstanceMethod("end", &QPainterWrap::end),
InstanceMethod("endNativePainting", &QPainterWrap::endNativePainting),
InstanceMethod("eraseRect", &QPainterWrap::eraseRect),
InstanceMethod("eraseRectF", &QPainterWrap::eraseRectF),
InstanceMethod("fillPath", &QPainterWrap::fillPath),
InstanceMethod("fillRect", &QPainterWrap::fillRect),
InstanceMethod("fillRectF", &QPainterWrap::fillRectF),
InstanceMethod("opacity", &QPainterWrap::opacity),
Expand Down Expand Up @@ -479,6 +482,18 @@ Napi::Value QPainterWrap::endNativePainting(const Napi::CallbackInfo& info) {
this->instance->endNativePainting();
return env.Null();
}
Napi::Value QPainterWrap::fillPath(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::Object pathObject = info[0].As<Napi::Object>();
QPainterPathWrap* pathWrap =
Napi::ObjectWrap<QPainterPathWrap>::Unwrap(pathObject);
QPainterPath* path = pathWrap->getInternalInstance();
Napi::Object brushObject = info[1].As<Napi::Object>();
QBrushWrap* brushWrap = Napi::ObjectWrap<QBrushWrap>::Unwrap(brushObject);
QBrush* brush = brushWrap->getInternalInstance();
this->instance->fillPath(*path, *brush);
return env.Null();
}
Napi::Value QPainterWrap::fillRect(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int x = info[0].As<Napi::Number>().Int32Value();
Expand Down Expand Up @@ -558,6 +573,32 @@ Napi::Value QPainterWrap::drawRectF(const Napi::CallbackInfo& info) {
this->instance->drawRect(QRectF(x, y, width, height));
return env.Null();
}
Napi::Value QPainterWrap::drawRoundedRect(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int x = info[0].As<Napi::Number>().Int32Value();
int y = info[1].As<Napi::Number>().Int32Value();
int width = info[2].As<Napi::Number>().Int32Value();
int height = info[3].As<Napi::Number>().Int32Value();
qreal xRadius = info[4].As<Napi::Number>().DoubleValue();
qreal yRadius = info[5].As<Napi::Number>().DoubleValue();
Qt::SizeMode mode = (Qt::SizeMode)info[6].As<Napi::Number>().Uint32Value();
this->instance->drawRoundedRect(QRect(x, y, width, height), xRadius, yRadius,
mode);
return env.Null();
}
Napi::Value QPainterWrap::drawRoundedRectF(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
qreal x = info[0].As<Napi::Number>().DoubleValue();
qreal y = info[1].As<Napi::Number>().DoubleValue();
qreal width = info[2].As<Napi::Number>().DoubleValue();
qreal height = info[3].As<Napi::Number>().DoubleValue();
qreal xRadius = info[4].As<Napi::Number>().DoubleValue();
qreal yRadius = info[5].As<Napi::Number>().DoubleValue();
Qt::SizeMode mode = (Qt::SizeMode)info[6].As<Napi::Number>().Uint32Value();
this->instance->drawRoundedRect(QRectF(x, y, width, height), xRadius, yRadius,
mode);
return env.Null();
}
Napi::Value QPainterWrap::eraseRect(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
int x = info[0].As<Napi::Number>().Int32Value();
Expand Down
31 changes: 29 additions & 2 deletions src/lib/QtWidgets/QPainter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import addon from '../utils/addon';
import { Component, NativeElement } from '../core/Component';
import { QPainterPath } from '../QtWidgets/QPainterPath';
import { PenStyle } from '../QtEnums';
import { PenStyle, SizeMode } from '../QtEnums';
import { QBrush } from '../QtGui/QBrush';
import { QColor } from '../QtGui/QColor';
import { QPoint } from '../QtCore/QPoint';
Expand Down Expand Up @@ -196,7 +196,31 @@ export class QPainter extends Component {
this.native.drawRectF(x, y, width, height);
}
// TODO: void drawRects(const QVector<QRectF> &rectangles)
// TODO: void drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize)

drawRoundedRect(
x: number,
y: number,
w: number,
h: number,
xRadius: number,
yRadius: number,
mode = SizeMode.AbsoluteSize,
): void {
this.native.drawRoundedRect(x, y, w, h, xRadius, yRadius, mode);
}

drawRoundedRectF(
x: number,
y: number,
w: number,
h: number,
xRadius: number,
yRadius: number,
mode = SizeMode.AbsoluteSize,
): void {
this.native.drawRoundedRectF(x, y, w, h, xRadius, yRadius, mode);
}

// TODO: void drawStaticText(int left, int top, const QStaticText &staticText)
drawText(x: number, y: number, text: string): void {
return this.native.drawText(x, y, text);
Expand All @@ -218,6 +242,9 @@ export class QPainter extends Component {
eraseRect(x: number, y: number, width: number, height: number): void {
this.native.eraseRect(x, y, width, height);
}
fillPath(path: QPainterPath, brush: QBrush): void {
this.native.fillPath(path.native, brush.native);
}
/**
* Version of eraseRect() which takes floating point parameters.
*/
Expand Down