Merge pull request #118 from soonoo/add-qsystemtrayicon
Adds basic support for QSystemTrayIcon
This commit is contained in:
commit
5080c84e3d
@ -56,6 +56,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QScrollArea/qscrollarea_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/core/FlexLayout/flexlayout_wrap.cpp"
|
||||
# Custom widgets (include them for automoc since they contain Q_OBJECT)
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QWidget/nwidget.hpp"
|
||||
@ -71,6 +72,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QPlainTextEdit/nplaintextedit.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTabWidget/ntabwidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/nsystemtrayicon.hpp"
|
||||
)
|
||||
|
||||
AddCommonConfig(${CORE_WIDGETS_ADDON})
|
||||
|
||||
BIN
extras/assets/nodegui_white.png
Normal file
BIN
extras/assets/nodegui_white.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSystemTrayIcon>
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
class NSystemTrayIcon: public QSystemTrayIcon, public EventWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
EVENTWIDGET_IMPLEMENTATIONS(QSystemTrayIcon)
|
||||
public:
|
||||
using QSystemTrayIcon::QSystemTrayIcon; //inherit all constructors of QSystemTrayIcon
|
||||
void connectWidgetSignalsToEventEmitter() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
#include "nsystemtrayicon.hpp"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
|
||||
class QSystemTrayIconWrap : public Napi::ObjectWrap<QSystemTrayIconWrap>{
|
||||
private:
|
||||
NSystemTrayIcon* instance;
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QSystemTrayIconWrap(const Napi::CallbackInfo& info);
|
||||
~QSystemTrayIconWrap();
|
||||
NSystemTrayIcon* getInternalInstance();
|
||||
//class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
//wrapped methods
|
||||
Napi::Value show(const Napi::CallbackInfo& info);
|
||||
Napi::Value hide(const Napi::CallbackInfo& info);
|
||||
Napi::Value setIcon(const Napi::CallbackInfo& info);
|
||||
Napi::Value isVisible(const Napi::CallbackInfo& info);
|
||||
|
||||
EVENTWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
};
|
||||
|
||||
@ -0,0 +1,83 @@
|
||||
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include <QWidget>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
Napi::FunctionReference QSystemTrayIconWrap::constructor;
|
||||
|
||||
Napi::Object QSystemTrayIconWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QSystemTrayIcon";
|
||||
Napi::Function func = DefineClass(env, CLASSNAME, {
|
||||
InstanceMethod("show", &QSystemTrayIconWrap::show),
|
||||
InstanceMethod("hide", &QSystemTrayIconWrap::hide),
|
||||
InstanceMethod("setIcon", &QSystemTrayIconWrap::setIcon),
|
||||
InstanceMethod("isVisible", &QSystemTrayIconWrap::isVisible),
|
||||
|
||||
COMPONENT_WRAPPED_METHODS_EXPORT_DEFINE
|
||||
EVENTWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QSystemTrayIconWrap)
|
||||
});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NSystemTrayIcon* QSystemTrayIconWrap::getInternalInstance() {
|
||||
return this->instance;
|
||||
}
|
||||
|
||||
QSystemTrayIconWrap::QSystemTrayIconWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap<QSystemTrayIconWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if(info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
QWidgetWrap* parentWidgetWrap = Napi::ObjectWrap<QWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NSystemTrayIcon(parentWidgetWrap->getInternalInstance()); //this sets the parent to current widget
|
||||
}else if (info.Length() == 0){
|
||||
this->instance = new NSystemTrayIcon();
|
||||
}else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
|
||||
QSystemTrayIconWrap::~QSystemTrayIconWrap() {
|
||||
delete this->instance;
|
||||
}
|
||||
|
||||
Napi::Value QSystemTrayIconWrap::show(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->show();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QSystemTrayIconWrap::hide(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
this->instance->hide();
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QSystemTrayIconWrap::setIcon(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>();
|
||||
QIconWrap *iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
|
||||
this->instance->setIcon(*iconWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QSystemTrayIconWrap::isVisible(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
bool visibility = this->instance->isVisible();
|
||||
return Napi::Boolean::New(env, visibility);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@
|
||||
#include "core/FlexLayout/flexlayout_wrap.h"
|
||||
#include "QtGui/QEvent/QKeyEvent/qkeyevent_wrap.h"
|
||||
#include "QtWidgets/QScrollArea/qscrollarea_wrap.h"
|
||||
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
|
||||
#include <napi.h>
|
||||
// These cant be instantiated in JS Side
|
||||
void InitPrivateHelpers(Napi::Env env){
|
||||
@ -49,6 +50,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QDialWrap::init(env, exports);
|
||||
QLabelWrap::init(env, exports);
|
||||
QScrollAreaWrap::init(env, exports);
|
||||
QSystemTrayIconWrap::init(env, exports);
|
||||
return exports;
|
||||
}
|
||||
|
||||
|
||||
11
src/demo.ts
11
src/demo.ts
@ -18,7 +18,8 @@ import {
|
||||
CursorShape,
|
||||
WindowState,
|
||||
QTextOptionWrapMode,
|
||||
QCheckBoxEvents
|
||||
QCheckBoxEvents,
|
||||
QSystemTrayIcon,
|
||||
} from "./index";
|
||||
|
||||
const path = require("path");
|
||||
@ -105,6 +106,13 @@ const pixmap = new QPixmap(
|
||||
imageLabel.setPixmap(pixmap);
|
||||
scrollArea.setWidget(imageLabel);
|
||||
|
||||
const trayIcon = new QIcon(
|
||||
path.resolve(__dirname, "../extras/assets/nodegui_white.png")
|
||||
);
|
||||
const tray = new QSystemTrayIcon();
|
||||
tray.setIcon(trayIcon);
|
||||
tray.show()
|
||||
|
||||
if (rootView.layout) {
|
||||
rootView.layout.addWidget(tabs);
|
||||
rootView.layout.addWidget(checkbox);
|
||||
@ -134,3 +142,4 @@ win.show();
|
||||
win.setWindowState(WindowState.WindowActive);
|
||||
|
||||
(global as any).win = win; // To prevent win from being garbage collected.
|
||||
(global as any).systemTray = tray; // To prevent system tray from being garbage collected.
|
||||
|
||||
@ -35,6 +35,7 @@ export {
|
||||
LineWrapMode
|
||||
} from "./lib/QtWidgets/QPlainTextEdit";
|
||||
export { QScrollArea, QScrollAreaEvents } from "./lib/QtWidgets/QScrollArea";
|
||||
export { QSystemTrayIcon, QSystemTrayIconEvents } from './lib/QtWidgets/QSystemTrayIcon';
|
||||
// Layouts:
|
||||
export { QGridLayout } from "./lib/QtWidgets/QGridLayout";
|
||||
export { FlexLayout } from "./lib/core/FlexLayout";
|
||||
|
||||
39
src/lib/QtWidgets/QSystemTrayIcon/index.ts
Normal file
39
src/lib/QtWidgets/QSystemTrayIcon/index.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import addon from "../../utils/addon";
|
||||
import { NodeWidget } from "../QWidget";
|
||||
import { EventWidget, BaseWidgetEvents } from "../../core/EventWidget";
|
||||
import { NativeElement } from "../../core/Component";
|
||||
import { QIcon } from "../../QtGui/QIcon";
|
||||
|
||||
export const QSystemTrayIconEvents = Object.freeze({
|
||||
...BaseWidgetEvents,
|
||||
});
|
||||
export class QSystemTrayIcon extends EventWidget {
|
||||
native: NativeElement;
|
||||
constructor(parent?: NodeWidget) {
|
||||
let native;
|
||||
if (parent) {
|
||||
native = new addon.QSystemTrayIcon(parent.native);
|
||||
} else {
|
||||
native = new addon.QSystemTrayIcon();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
// bind member functions
|
||||
this.show = this.show.bind(this);
|
||||
this.hide = this.hide.bind(this);
|
||||
this.setIcon = this.setIcon.bind(this);
|
||||
this.isVisible = this.isVisible.bind(this);
|
||||
}
|
||||
show() {
|
||||
this.native.show();
|
||||
}
|
||||
hide() {
|
||||
this.native.hide();
|
||||
}
|
||||
setIcon(icon: QIcon) {
|
||||
this.native.setIcon(icon.native);
|
||||
}
|
||||
isVisible(): boolean {
|
||||
return this.native.isVisible();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user