Added Image rendering support via qlabel and qpixmap
This commit is contained in:
parent
e50666c566
commit
e6eccd06a9
@ -14,6 +14,7 @@
|
||||
"../src/cpp/QtGui/QApplication/qapplication_wrap.cpp",
|
||||
"../src/cpp/QtGui/QWidget/qwidget_wrap.cpp",
|
||||
"../src/cpp/QtGui/QEvent/QKeyEvent/qkeyevent_wrap.cpp",
|
||||
"../src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp",
|
||||
'../src/cpp/core/FlexLayout/flexlayout_wrap.cpp',
|
||||
"../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp",
|
||||
"../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp",
|
||||
|
||||
@ -37,13 +37,14 @@
|
||||
|
||||
- [QMainWindow (Window)](api/QMainWindow.md)
|
||||
- [QWidget (View)](api/QWidget.md)
|
||||
- [QLabel (Text)](api/QLabel.md)
|
||||
- [QLabel (Text/Image)](api/QLabel.md)
|
||||
- [QPushButton (Button)](api/QPushButton.md)
|
||||
- [QRadioButton (RadioButton)](api/QRadioButton.md)
|
||||
- [QCheckBox (CheckBox)](api/QCheckBox.md)
|
||||
- [QLineEdit (LineEdit)](api/QLineEdit.md)
|
||||
- [QProgressBar (ProgressBar)](api/QProgressBar.md)
|
||||
- [FlexLayout](api/FlexLayout.md)
|
||||
- [QPixmap](api/QPixmap.md)
|
||||
|
||||
### Internal Modules
|
||||
|
||||
|
||||
@ -48,3 +48,9 @@ returns the current text from the label.
|
||||
#### `label.setWordWrap(on)`
|
||||
|
||||
- `on` boolean - If true it sets wordwrap on the label
|
||||
|
||||
#### `label.setPixmap(pixMap)`
|
||||
|
||||
Images in the form of a pixmap can be set as the label content
|
||||
|
||||
- `pixMap` [QPixmap](api/QPixmap.md) - Allows to set image content in the form of a QPixmap on the label
|
||||
|
||||
43
docs/api/QPixmap.md
Normal file
43
docs/api/QPixmap.md
Normal file
@ -0,0 +1,43 @@
|
||||
## Class: QPixmap
|
||||
|
||||
> The QPixmap class helps hold an image in the form of off-screen image representation.
|
||||
|
||||
**This class is a JS wrapper around Qt's [QPixmap class](https://doc.qt.io/qt-5/qpixmap.html)**
|
||||
|
||||
A `QPixmap` provides ability to store an image in the memory.
|
||||
|
||||
**QPixmap inherits from [Component](api/Component.md)**
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const { QPixmap } = require("@nodegui/nodegui");
|
||||
|
||||
const imageUrl = "path/to/png";
|
||||
const pixMap = new QPixmap(imageUrl);
|
||||
```
|
||||
|
||||
### `new QPixmap(imageUrl?)`
|
||||
|
||||
- `imageUrl` string (_optional_). Absolute path of the image that needs to be loaded in the memory.
|
||||
|
||||
### Static Methods
|
||||
|
||||
QPixmap can access all the static methods defined in [Component](api/Component.md)
|
||||
|
||||
### Instance Properties
|
||||
|
||||
QPixmap can access all the instance properties defined in [Component](api/Component.md)
|
||||
|
||||
### Instance Methods
|
||||
|
||||
QPixmap can access all the instance methods defined in [Component](api/Component.md)
|
||||
|
||||
Additionally it also has the following instance methods:
|
||||
|
||||
#### `pixMap.load(imageUrl)`
|
||||
|
||||
loads an image from the url into memory as a Pixmap.
|
||||
returns true if load was successful otherwise returns false.
|
||||
|
||||
- `imageUrl` string (_optional_). Absolute path of the image that needs to be loaded in the memory.
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@nodegui/nodegui",
|
||||
"version": "0.0.6-alpha",
|
||||
"version": "0.0.7-alpha",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#ifndef QAPPLICATION_WRAP_H
|
||||
#define QAPPLICATION_WRAP_H
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <QApplication>
|
||||
@ -22,4 +21,3 @@ public:
|
||||
Napi::Value exec(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
#endif
|
||||
57
src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp
Normal file
57
src/cpp/QtGui/QPixmap/qpixmap_wrap.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "qpixmap_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
|
||||
Napi::FunctionReference QPixmapWrap::constructor;
|
||||
|
||||
Napi::Object QPixmapWrap::init(Napi::Env env, Napi::Object exports)
|
||||
{
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QPixmap";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME,{
|
||||
InstanceMethod("load", &QPixmapWrap::load),
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
QPixmapWrap::QPixmapWrap(const Napi::CallbackInfo& info) : Napi::ObjectWrap<QPixmapWrap>(info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
if(info.Length() == 1) {
|
||||
Napi::String url = info[0].As<Napi::String>();
|
||||
QString imageUrl = QString::fromUtf8(url.Utf8Value().c_str());
|
||||
this->instance = new QPixmap(imageUrl);
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new QPixmap();
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
}
|
||||
|
||||
QPixmapWrap::~QPixmapWrap()
|
||||
{
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
QPixmap* QPixmapWrap::getInternalInstance()
|
||||
{
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QPixmapWrap::load(const Napi::CallbackInfo& info)
|
||||
{
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
bool loadSuccess = false;
|
||||
if(info.Length() == 1) {
|
||||
Napi::String url = info[0].As<Napi::String>();
|
||||
QString imageUrl = QString::fromUtf8(url.Utf8Value().c_str());
|
||||
loadSuccess = this->instance->load(imageUrl);
|
||||
}else {
|
||||
extrautils::throwTypeError(env, "Wrong number of arguments");
|
||||
}
|
||||
return Napi::Boolean::New(env, loadSuccess);
|
||||
}
|
||||
|
||||
18
src/cpp/QtGui/QPixmap/qpixmap_wrap.h
Normal file
18
src/cpp/QtGui/QPixmap/qpixmap_wrap.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include <QPixmap>
|
||||
|
||||
class QPixmapWrap : public Napi::ObjectWrap<QPixmapWrap> {
|
||||
private:
|
||||
QPixmap* instance;
|
||||
public:
|
||||
static Napi::FunctionReference constructor;
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QPixmapWrap(const Napi::CallbackInfo& info);
|
||||
~QPixmapWrap();
|
||||
QPixmap* getInternalInstance();
|
||||
// Wrapped methods
|
||||
Napi::Value load(const Napi::CallbackInfo& info);
|
||||
};
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "qlabel_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h"
|
||||
#include "src/cpp/Extras/Utils/nutils.h"
|
||||
#include <QWidget>
|
||||
|
||||
@ -12,7 +13,7 @@ Napi::Object QLabelWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
InstanceMethod("setWordWrap", &QLabelWrap::setWordWrap),
|
||||
InstanceMethod("setText", &QLabelWrap::setText),
|
||||
InstanceMethod("text", &QLabelWrap::text),
|
||||
InstanceMethod("getFlexNode", &QLabelWrap::getFlexNode),
|
||||
InstanceMethod("setPixmap", &QLabelWrap::setPixmap),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLabelWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
@ -74,3 +75,14 @@ Napi::Value QLabelWrap::text(const Napi::CallbackInfo &info)
|
||||
std::string labelText = this->instance->text().toStdString();
|
||||
return Napi::String::New(env, labelText);
|
||||
}
|
||||
|
||||
Napi::Value QLabelWrap::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);
|
||||
this->instance->setPixmap(*pixmapWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
@ -19,6 +19,7 @@ class QLabelWrap : public Napi::ObjectWrap<QLabelWrap>{
|
||||
Napi::Value setWordWrap(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);
|
||||
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "src/cpp/QtGui/QApplication/qapplication_wrap.h"
|
||||
#include "src/cpp/QtGui/QWidget/qwidget_wrap.h"
|
||||
#include "src/cpp/QtGui/QPixmap/qpixmap_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QLayout/qlayout_wrap.h"
|
||||
#include "src/cpp/QtWidgets/QLabel/qlabel_wrap.h"
|
||||
@ -21,6 +22,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
InitPrivateHelpers(env);
|
||||
QApplicationWrap::init(env, exports);
|
||||
QWidgetWrap::init(env, exports);
|
||||
QPixmapWrap::init(env, exports);
|
||||
QGridLayoutWrap::init(env, exports);
|
||||
FlexLayoutWrap::init(env, exports);
|
||||
QMainWindowWrap::init(env,exports);
|
||||
|
||||
17
src/lib/QtGui/QPixmap/index.ts
Normal file
17
src/lib/QtGui/QPixmap/index.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import addon from "../../core/addon";
|
||||
import { Component, NativeElement } from "../../core/Component";
|
||||
|
||||
export class QPixmap extends Component {
|
||||
native: NativeElement;
|
||||
constructor(imageUrl?: string) {
|
||||
super();
|
||||
if (imageUrl) {
|
||||
this.native = new addon.QPixmap(imageUrl);
|
||||
} else {
|
||||
this.native = new addon.QPixmap();
|
||||
}
|
||||
}
|
||||
load = (imageUrl: string) => {
|
||||
return this.native.load(imageUrl);
|
||||
};
|
||||
}
|
||||
@ -2,6 +2,7 @@ import addon from "../../core/addon";
|
||||
import { NodeWidget } from "../../QtGui/QWidget";
|
||||
import { BaseWidgetEvents } from "../../core/EventWidget";
|
||||
import { NativeElement } from "../../core/Component";
|
||||
import { QPixmap } from "../../QtGui/QPixmap";
|
||||
|
||||
export const QLabelEvents = Object.freeze({
|
||||
...BaseWidgetEvents
|
||||
@ -32,4 +33,7 @@ export class QLabel extends NodeWidget {
|
||||
text() {
|
||||
return this.native.text();
|
||||
}
|
||||
setPixmap(pixMap: QPixmap) {
|
||||
this.native.setPixmap(pixMap.native);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
export { QApplication } from "./QtGui/QApplication";
|
||||
export { QWidget, QWidgetEvents } from "./QtGui/QWidget";
|
||||
export { QPixmap } from "./QtGui/QPixmap";
|
||||
// Abstract:
|
||||
export { NodeWidget } from "./QtGui/QWidget";
|
||||
export { NodeLayout } from "./QtWidgets/QLayout";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user