Adds pixmap support to clipboard (#445)

* adds pixmap setters and getters to qclipboard

* upgrade deps

* Adds  inlinestylesheet fix on objectname test
This commit is contained in:
Atul R 2020-03-14 19:29:26 +01:00 committed by GitHub
parent c37b23eca9
commit 22b28f8cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 108 additions and 107 deletions

View File

@ -77,7 +77,8 @@ npm i http://master-release.nodegui.org
```
**Community guides**
- [Tutorial: Build a native Meme Search Desktop app with Javascript (NodeGui) and Giphy API](https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/)
- [Tutorial: Build a native Meme Search Desktop app with Javascript (NodeGui) and Giphy API](https://www.sitepoint.com/build-native-desktop-gif-searcher-app-using-nodegui/)
- https://blog.logrocket.com/electron-alternatives-exploring-nodegui-and-react-nodegui/ - Electron alternatives: Exploring NodeGUI and React NodeGUI by [Siegfried Grimbeek](https://blog.logrocket.com/author/siegfriedgrimbeek/).
- https://hibbard.eu/node-gui/ - Excellent guide from [James Hibbard](https://github.com/jameshibbard).
@ -147,7 +148,6 @@ People maintaining this project.
<table>
<tr>
<td align="center"><a href="https://blog.atulr.com"><img src="https://avatars2.githubusercontent.com/u/4029423?v=4" width="100px;" alt="Atul R"/><br /><sub><b>Atul R</b></sub></a></td>
<td align="center"><a href="https://github.com/dimitarnestorov"><img src="https://avatars3.githubusercontent.com/u/8790386?s=460&v=4" width="100px;" alt="Dimitar"/><br /><sub><b>Dimitar Nestorov</b></sub></a></td>
</tr>
</table>
@ -196,6 +196,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

107
package-lock.json generated
View File

@ -1029,9 +1029,9 @@
}
},
"@types/json-schema": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.3.tgz",
"integrity": "sha512-Il2DtDVRGDcqjDtE+rF8iqg1CArehSK84HZJCT7AMITlyXRBpuPhqGLDQMowraqqu1coEaimg4ZOqggt6L6L+A==",
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.4.tgz",
"integrity": "sha512-8+KAKzEvSUdeo+kmqnKrqgeE+LcA0tjYWFY7RPProVYwnqDjukzO+3b6dLD56rYX5TdWejnEOLJYOIeh4CXKuA==",
"dev": true
},
"@types/minimatch": {
@ -1041,9 +1041,9 @@
"dev": true
},
"@types/node": {
"version": "13.9.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.0.tgz",
"integrity": "sha512-0ARSQootUG1RljH2HncpsY2TJBfGQIKOOi7kxzUY6z54ePu/ZD+wJA8zI2Q6v8rol2qpG/rvqsReco8zNMPvhQ==",
"version": "13.9.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.9.1.tgz",
"integrity": "sha512-E6M6N0blf/jiZx8Q3nb0vNaswQeEyn0XlupO+xN6DtJ6r6IT4nXrTry7zhIfYvFCl3/8Cu6WIysmUBKiqV0bqQ==",
"dev": true
},
"@types/parse-json": {
@ -1074,12 +1074,12 @@
"dev": true
},
"@typescript-eslint/eslint-plugin": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.22.0.tgz",
"integrity": "sha512-BvxRLaTDVQ3N+Qq8BivLiE9akQLAOUfxNHIEhedOcg8B2+jY8Rc4/D+iVprvuMX1AdezFYautuGDwr9QxqSxBQ==",
"version": "2.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.23.0.tgz",
"integrity": "sha512-8iA4FvRsz8qTjR0L/nK9RcRUN3QtIHQiOm69FzV7WS3SE+7P7DyGGwh3k4UNR2JBbk+Ej2Io+jLAaqKibNhmtw==",
"dev": true,
"requires": {
"@typescript-eslint/experimental-utils": "2.22.0",
"@typescript-eslint/experimental-utils": "2.23.0",
"eslint-utils": "^1.4.3",
"functional-red-black-tree": "^1.0.1",
"regexpp": "^3.0.0",
@ -1095,95 +1095,32 @@
}
},
"@typescript-eslint/experimental-utils": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.22.0.tgz",
"integrity": "sha512-sJt1GYBe6yC0dWOQzXlp+tiuGglNhJC9eXZeC8GBVH98Zv9jtatccuhz0OF5kC/DwChqsNfghHx7OlIDQjNYAQ==",
"version": "2.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.23.0.tgz",
"integrity": "sha512-OswxY59RcXH3NNPmq+4Kis2CYZPurRU6mG5xPcn24CjFyfdVli5mySwZz/g/xDbJXgDsYqNGq7enV0IziWGXVQ==",
"dev": true,
"requires": {
"@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.22.0",
"@typescript-eslint/typescript-estree": "2.23.0",
"eslint-scope": "^5.0.0"
}
},
"@typescript-eslint/parser": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.22.0.tgz",
"integrity": "sha512-FaZKC1X+nvD7qMPqKFUYHz3H0TAioSVFGvG29f796Nc5tBluoqfHgLbSFKsh7mKjRoeTm8J9WX2Wo9EyZWjG7w==",
"version": "2.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.23.0.tgz",
"integrity": "sha512-k61pn/Nepk43qa1oLMiyqApC6x5eP5ddPz6VUYXCAuXxbmRLqkPYzkFRKl42ltxzB2luvejlVncrEpflgQoSUg==",
"dev": true,
"requires": {
"@types/eslint-visitor-keys": "^1.0.0",
"@typescript-eslint/experimental-utils": "2.22.0",
"@typescript-eslint/typescript-estree": "2.22.0",
"@typescript-eslint/experimental-utils": "2.23.0",
"@typescript-eslint/typescript-estree": "2.23.0",
"eslint-visitor-keys": "^1.1.0"
},
"dependencies": {
"@typescript-eslint/experimental-utils": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.22.0.tgz",
"integrity": "sha512-sJt1GYBe6yC0dWOQzXlp+tiuGglNhJC9eXZeC8GBVH98Zv9jtatccuhz0OF5kC/DwChqsNfghHx7OlIDQjNYAQ==",
"dev": true,
"requires": {
"@types/json-schema": "^7.0.3",
"@typescript-eslint/typescript-estree": "2.22.0",
"eslint-scope": "^5.0.0"
}
},
"@typescript-eslint/typescript-estree": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.22.0.tgz",
"integrity": "sha512-2HFZW2FQc4MhIBB8WhDm9lVFaBDy6h9jGrJ4V2Uzxe/ON29HCHBTj3GkgcsgMWfsl2U5as+pTOr30Nibaw7qRQ==",
"dev": true,
"requires": {
"debug": "^4.1.1",
"eslint-visitor-keys": "^1.1.0",
"glob": "^7.1.6",
"is-glob": "^4.0.1",
"lodash": "^4.17.15",
"semver": "^6.3.0",
"tsutils": "^3.17.1"
}
},
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"dev": true,
"requires": {
"ms": "^2.1.1"
}
},
"glob": {
"version": "7.1.6",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
"dev": true
},
"semver": {
"version": "6.3.0",
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
"dev": true
}
}
},
"@typescript-eslint/typescript-estree": {
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.22.0.tgz",
"integrity": "sha512-2HFZW2FQc4MhIBB8WhDm9lVFaBDy6h9jGrJ4V2Uzxe/ON29HCHBTj3GkgcsgMWfsl2U5as+pTOr30Nibaw7qRQ==",
"version": "2.23.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.23.0.tgz",
"integrity": "sha512-pmf7IlmvXdlEXvE/JWNNJpEvwBV59wtJqA8MLAxMKLXNKVRC3HZBXR/SlZLPWTCcwOSg9IM7GeRSV3SIerGVqw==",
"dev": true,
"requires": {
"debug": "^4.1.1",

View File

@ -40,9 +40,9 @@
"devDependencies": {
"@types/bindings": "^1.3.0",
"@types/jest": "^25.1.1",
"@types/node": "^13.1.2",
"@typescript-eslint/eslint-plugin": "^2.10.0",
"@typescript-eslint/parser": "^2.10.0",
"@types/node": "^13.9.1",
"@typescript-eslint/eslint-plugin": "^2.23.0",
"@typescript-eslint/parser": "^2.23.0",
"clang-format": "^1.3.0",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",

View File

@ -22,4 +22,6 @@ class DLL_EXPORT QClipboardWrap : public Napi::ObjectWrap<QClipboardWrap> {
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value setText(const Napi::CallbackInfo& info);
Napi::Value text(const Napi::CallbackInfo& info);
Napi::Value setPixmap(const Napi::CallbackInfo& info);
Napi::Value pixmap(const Napi::CallbackInfo& info);
};

View File

@ -1,5 +1,5 @@
#include "QtGui/QClipboard/qclipboard_wrap.h"
#include <QtGui/QPixmap/qpixmap_wrap.h>
#include "Extras/Utils/nutils.h"
Napi::FunctionReference QClipboardWrap::constructor;
@ -10,6 +10,8 @@ Napi::Object QClipboardWrap::init(Napi::Env env, Napi::Object exports) {
Napi::Function func =
DefineClass(env, CLASSNAME,
{InstanceMethod("clear", &QClipboardWrap::clear),
InstanceMethod("setPixmap", &QClipboardWrap::setPixmap),
InstanceMethod("pixmap", &QClipboardWrap::pixmap),
InstanceMethod("setText", &QClipboardWrap::setText),
InstanceMethod("text", &QClipboardWrap::text),
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE(QClipboardWrap)});
@ -41,6 +43,29 @@ Napi::Value QClipboardWrap::clear(const Napi::CallbackInfo& info) {
return env.Null();
}
Napi::Value QClipboardWrap::setPixmap(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Object pixmapObject = info[0].As<Napi::Object>();
QPixmapWrap* pixmapWrap = Napi::ObjectWrap<QPixmapWrap>::Unwrap(pixmapObject);
Napi::Number mode = info[1].As<Napi::Number>();
this->instance->setPixmap(*pixmapWrap->getInternalInstance(),
static_cast<QClipboard::Mode>(mode.Int32Value()));
return env.Null();
}
Napi::Value QClipboardWrap::pixmap(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number mode = info[0].As<Napi::Number>();
QPixmap pixmap =
this->instance->pixmap(static_cast<QClipboard::Mode>(mode.Int32Value()));
auto instance = QPixmapWrap::constructor.New(
{Napi::External<QPixmap>::New(env, new QPixmap(pixmap))});
return instance;
}
Napi::Value QClipboardWrap::setText(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);

View File

@ -1,23 +1,49 @@
import { QMainWindow } from './lib/QtWidgets/QMainWindow';
import { QTabWidget } from './lib/QtWidgets/QTabWidget';
import { QLabel } from './lib/QtWidgets/QLabel';
import { QIcon } from './lib/QtGui/QIcon';
import {
QMainWindow,
QWidget,
QPushButton,
QLineEdit,
FlexLayout,
QApplication,
QClipboardMode,
QLabel,
QPixmap,
} from './index';
const win = new QMainWindow();
const tab = new QTabWidget();
const center = new QWidget();
const label = new QLabel();
label.setText('Hello');
const label2 = new QLabel();
label2.setText('LABEL');
label2.setInlineStyle('color: blue;');
label2.setInlineStyle('color: teal;');
const textInput = new QLineEdit();
const getBtn = new QPushButton();
const setBtn = new QPushButton();
tab.addTab(label, new QIcon(), 'I am label tab');
tab.addTab(label2, new QIcon(), 'TAB2');
win.setCentralWidget(tab);
console.log(tab.indexOf(label));
console.log(tab.indexOf(label2));
tab.setTabIcon(tab.indexOf(label2), new QIcon());
//----------
label.setText('Copy any image onto the clipboard and click `Get clipbard image button`');
getBtn.setText('Get clipboard image');
getBtn.addEventListener('clicked', () => {
const clip = QApplication.clipboard();
const pixmap = clip.pixmap(QClipboardMode.Clipboard);
label.setPixmap(pixmap);
});
//--------------
textInput.setPlaceholderText('Enter absolute image path to load into clipboard');
setBtn.setText('Set clipboard image');
setBtn.addEventListener('clicked', () => {
const clip = QApplication.clipboard();
const pixmap = new QPixmap();
pixmap.load(textInput.text());
clip.setPixmap(pixmap, QClipboardMode.Clipboard);
label.setText(`Loaded image at ${textInput.text()} to global clipboard`);
});
center.setLayout(new FlexLayout());
center.layout?.addWidget(textInput);
center.layout?.addWidget(setBtn);
center.layout?.addWidget(getBtn);
center.layout?.addWidget(label);
center.setInlineStyle(`width: 400; height: 400;`);
win.setCentralWidget(center);
win.show();
win.setFixedSize(400, 400);
(global as any).win = win;

View File

@ -1,5 +1,6 @@
import { Component, NativeElement } from '../core/Component';
import { checkIfNativeElement } from '../utils/helpers';
import { QPixmap } from './QPixmap';
/**
@ -39,6 +40,12 @@ export class QClipboard extends Component {
text(mode: QClipboardMode): string {
return this.native.text(mode);
}
setPixmap(pixmap: QPixmap, mode: QClipboardMode): void {
this.native.setPixmap(pixmap.native, mode);
}
pixmap(mode: QClipboardMode): QPixmap {
return new QPixmap(this.native.pixmap(mode));
}
}
export enum QClipboardMode {

View File

@ -189,6 +189,9 @@ export abstract class NodeWidget<Signals extends QWidgetSignals> extends YogaWid
}
setObjectName(objectName: string): void {
super.setObjectName(objectName);
if (this._rawInlineStyle) {
this.setInlineStyle(this._rawInlineStyle);
}
this.repolish();
}
setContextMenuPolicy(contextMenuPolicy: ContextMenuPolicy): void {