Extra methodsfor QPainter, string lists in QVariant, and default args for QClipboard (#858)
* Add string list support to `QVariant` * Add more methods to `QPainter` * Give the `QClipboard` methods default params to match C++ API * Code style fix for `nutils.cpp`
This commit is contained in:
parent
af64c4820f
commit
2901d09d01
@ -22,6 +22,7 @@ class DLL_EXPORT QVariantWrap : public Napi::ObjectWrap<QVariantWrap> {
|
||||
Napi::Value toInt(const Napi::CallbackInfo& info);
|
||||
Napi::Value toDouble(const Napi::CallbackInfo& info);
|
||||
Napi::Value toBool(const Napi::CallbackInfo& info);
|
||||
Napi::Value toStringList(const Napi::CallbackInfo& info);
|
||||
// wrapped methods
|
||||
};
|
||||
|
||||
|
||||
@ -44,4 +44,8 @@ class DLL_EXPORT QPainterWrap : public Napi::ObjectWrap<QPainterWrap> {
|
||||
Napi::Value save(const Napi::CallbackInfo& info);
|
||||
Napi::Value restore(const Napi::CallbackInfo& info);
|
||||
Napi::Value fillRect(const Napi::CallbackInfo& info);
|
||||
Napi::Value compositionMode(const Napi::CallbackInfo& info);
|
||||
Napi::Value setCompositionMode(const Napi::CallbackInfo& info);
|
||||
Napi::Value opacity(const Napi::CallbackInfo& info);
|
||||
Napi::Value setOpacity(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
@ -43,8 +43,17 @@ QVariant* extrautils::convertToQVariant(Napi::Env& env, Napi::Value& value) {
|
||||
} else if (value.IsSymbol()) {
|
||||
return new QVariant();
|
||||
} else if (value.IsArray()) {
|
||||
// TODO: fix this
|
||||
return new QVariant();
|
||||
// Note: This assumes an array of strings.
|
||||
Napi::Array array = value.As<Napi::Array>();
|
||||
QStringList value;
|
||||
uint32_t len = array.Length();
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
if (array.Get(i).IsString()) {
|
||||
std::string stringValue = array.Get(i).As<Napi::String>().Utf8Value();
|
||||
value.append(QString::fromUtf8(stringValue.c_str()));
|
||||
}
|
||||
}
|
||||
return new QVariant(value);
|
||||
} else if (value.IsArrayBuffer()) {
|
||||
// TODO: fix this
|
||||
return new QVariant();
|
||||
|
||||
@ -13,6 +13,7 @@ Napi::Object QVariantWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("toInt", &QVariantWrap::toInt),
|
||||
InstanceMethod("toDouble", &QVariantWrap::toDouble),
|
||||
InstanceMethod("toBool", &QVariantWrap::toBool),
|
||||
InstanceMethod("toStringList", &QVariantWrap::toStringList),
|
||||
StaticMethod("converToQVariant",
|
||||
&StaticQVariantWrapMethods::converToQVariant),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QVariantWrap)});
|
||||
@ -60,6 +61,16 @@ Napi::Value QVariantWrap::toBool(const Napi::CallbackInfo& info) {
|
||||
bool value = this->instance->value<bool>();
|
||||
return Napi::Value::From(env, value);
|
||||
}
|
||||
Napi::Value QVariantWrap::toStringList(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
QStringList value = this->instance->toStringList();
|
||||
Napi::Array result = Napi::Array::New(env, value.size());
|
||||
for (int i = 0; i < value.size(); i++) {
|
||||
result[i] = Napi::String::New(env, value[i].toStdString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Napi::Value StaticQVariantWrapMethods::converToQVariant(
|
||||
const Napi::CallbackInfo& info) {
|
||||
|
||||
@ -42,6 +42,10 @@ Napi::Object QPainterWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
&QPainterWrap::beginNativePainting),
|
||||
InstanceMethod("endNativePainting", &QPainterWrap::endNativePainting),
|
||||
InstanceMethod("fillRect", &QPainterWrap::fillRect),
|
||||
InstanceMethod("compositionMode", &QPainterWrap::compositionMode),
|
||||
InstanceMethod("setCompositionMode", &QPainterWrap::setCompositionMode),
|
||||
InstanceMethod("opacity", &QPainterWrap::opacity),
|
||||
InstanceMethod("setOpacity", &QPainterWrap::setOpacity),
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QPainterWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
@ -355,3 +359,30 @@ Napi::Value QPainterWrap::fillRect(const Napi::CallbackInfo& info) {
|
||||
this->instance->fillRect(x, y, width, height, *color);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QPainterWrap::compositionMode(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
uint mode = static_cast<uint>(this->instance->compositionMode());
|
||||
return Napi::Value::From(env, mode);
|
||||
}
|
||||
Napi::Value QPainterWrap::setCompositionMode(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
QPainter::CompositionMode mode =
|
||||
(QPainter::CompositionMode)info[0].As<Napi::Number>().Uint32Value();
|
||||
this->instance->setCompositionMode(mode);
|
||||
return env.Null();
|
||||
}
|
||||
Napi::Value QPainterWrap::opacity(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
qreal opacity = this->instance->opacity();
|
||||
return Napi::Value::From(env, opacity);
|
||||
}
|
||||
Napi::Value QPainterWrap::setOpacity(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
qreal opacity = info[0].As<Napi::Number>().DoubleValue();
|
||||
this->instance->setOpacity(opacity);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
@ -98,7 +98,7 @@ export { QSlider, QSliderSignals, TickPosition } from './lib/QtWidgets/QSlider';
|
||||
export { QTimeEdit } from './lib/QtWidgets/QTimeEdit';
|
||||
export { QTreeWidget, QTreeWidgetSignals } from './lib/QtWidgets/QTreeWidget';
|
||||
export { QTreeWidgetItem } from './lib/QtWidgets/QTreeWidgetItem';
|
||||
export { QPainter, RenderHint } from './lib/QtWidgets/QPainter';
|
||||
export { CompositionMode, QPainter, RenderHint } from './lib/QtWidgets/QPainter';
|
||||
export { QPainterPath } from './lib/QtWidgets/QPainterPath';
|
||||
export { QDialog, QDialogSignals } from './lib/QtWidgets/QDialog';
|
||||
export { QMessageBox, QMessageBoxSignals, QMessageBoxIcon, ButtonRole } from './lib/QtWidgets/QMessageBox';
|
||||
|
||||
@ -2,7 +2,7 @@ import { NativeElement, Component } from '../core/Component';
|
||||
import addon from '../utils/addon';
|
||||
import { checkIfNativeElement } from '../utils/helpers';
|
||||
|
||||
export type QVariantType = NativeElement | string | number | boolean;
|
||||
export type QVariantType = NativeElement | string | string[] | number | boolean;
|
||||
|
||||
export class QVariant extends Component {
|
||||
native: NativeElement;
|
||||
@ -31,4 +31,7 @@ export class QVariant extends Component {
|
||||
toBool(): boolean {
|
||||
return this.native.toBool();
|
||||
}
|
||||
toStringList(): string[] {
|
||||
return this.native.toStringList();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ import { checkIfNativeElement } from '../utils/helpers';
|
||||
import { QPixmap } from './QPixmap';
|
||||
|
||||
/**
|
||||
|
||||
|
||||
> The QClipboard class provides access to the window system clipboard.
|
||||
|
||||
* **This class is a JS wrapper around Qt's [QClipboard class](https://doc.qt.io/qt-5/QClipboard.html)**
|
||||
@ -31,16 +31,16 @@ export class QClipboard extends Component {
|
||||
throw new Error('QClipboard cannot be initialised this way. Use QApplication::clipboard()');
|
||||
}
|
||||
}
|
||||
clear(mode: QClipboardMode): void {
|
||||
clear(mode = QClipboardMode.Clipboard): void {
|
||||
this.native.clear(mode);
|
||||
}
|
||||
setText(text: string, mode: QClipboardMode): void {
|
||||
setText(text: string, mode = QClipboardMode.Clipboard): void {
|
||||
this.native.setText(text, mode);
|
||||
}
|
||||
text(mode: QClipboardMode): string {
|
||||
text(mode = QClipboardMode.Clipboard): string {
|
||||
return this.native.text(mode);
|
||||
}
|
||||
setPixmap(pixmap: QPixmap, mode: QClipboardMode): void {
|
||||
setPixmap(pixmap: QPixmap, mode = QClipboardMode.Clipboard): void {
|
||||
this.native.setPixmap(pixmap.native, mode);
|
||||
}
|
||||
pixmap(mode: QClipboardMode): QPixmap {
|
||||
|
||||
@ -185,6 +185,18 @@ export class QPainter extends Component {
|
||||
fillRect(x: number, y: number, width: number, height: number, color: QColor): void {
|
||||
this.native.fillRect(x, y, width, height, color.native);
|
||||
}
|
||||
compositionMode(): CompositionMode {
|
||||
return this.native.compositionMode();
|
||||
}
|
||||
setCompositionMode(mode: CompositionMode): void {
|
||||
this.native.setCompositionMode(mode);
|
||||
}
|
||||
opacity(): number {
|
||||
return this.native.opacity();
|
||||
}
|
||||
setOpacity(opacity: number): void {
|
||||
this.native.setOpacity(opacity);
|
||||
}
|
||||
}
|
||||
|
||||
export enum RenderHint {
|
||||
@ -196,3 +208,44 @@ export enum RenderHint {
|
||||
Qt4CompatiblePainting = 0x20,
|
||||
LosslessImageRendering = 0x40,
|
||||
}
|
||||
|
||||
export enum CompositionMode {
|
||||
CompositionMode_SourceOver = 0,
|
||||
CompositionMode_DestinationOver = 1,
|
||||
CompositionMode_Clear = 2,
|
||||
CompositionMode_Source = 3,
|
||||
CompositionMode_Destination = 4,
|
||||
CompositionMode_SourceIn = 5,
|
||||
CompositionMode_DestinationIn = 6,
|
||||
CompositionMode_SourceOut = 7,
|
||||
CompositionMode_DestinationOut = 8,
|
||||
CompositionMode_SourceAtop = 9,
|
||||
CompositionMode_DestinationAtop = 10,
|
||||
CompositionMode_Xor = 11,
|
||||
CompositionMode_Plus = 12,
|
||||
CompositionMode_Multiply = 13,
|
||||
CompositionMode_Screen = 14,
|
||||
CompositionMode_Overlay = 15,
|
||||
CompositionMode_Darken = 16,
|
||||
CompositionMode_Lighten = 17,
|
||||
CompositionMode_ColorDodge = 18,
|
||||
CompositionMode_ColorBurn = 19,
|
||||
CompositionMode_HardLight = 20,
|
||||
CompositionMode_SoftLight = 21,
|
||||
CompositionMode_Difference = 22,
|
||||
CompositionMode_Exclusion = 23,
|
||||
RasterOp_SourceOrDestination = 24,
|
||||
RasterOp_SourceAndDestination = 25,
|
||||
RasterOp_SourceXorDestination = 26,
|
||||
RasterOp_NotSourceAndNotDestination = 27,
|
||||
RasterOp_NotSourceOrNotDestination = 28,
|
||||
RasterOp_NotSourceXorDestination = 29,
|
||||
RasterOp_NotSource = 30,
|
||||
RasterOp_NotSourceAndDestination = 31,
|
||||
RasterOp_SourceAndNotDestination = 32,
|
||||
RasterOp_NotSourceOrDestination = 33,
|
||||
RasterOp_ClearDestination = 35,
|
||||
RasterOp_SetDestination = 36,
|
||||
RasterOp_NotDestination = 37,
|
||||
RasterOp_SourceOrNotDestination = 34,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user