Add more tabwidgets methods (#422)
* add qtabwidget indexOf * Adds setTabIcon
This commit is contained in:
parent
57cf0d4836
commit
07d70e6321
@ -22,10 +22,12 @@ class DLL_EXPORT QTabWidgetWrap : public Napi::ObjectWrap<QTabWidgetWrap> {
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
Napi::Value addTab(const Napi::CallbackInfo &info);
|
||||
Napi::Value indexOf(const Napi::CallbackInfo &info);
|
||||
Napi::Value setTabPosition(const Napi::CallbackInfo &info);
|
||||
Napi::Value setCurrentIndex(const Napi::CallbackInfo &info);
|
||||
Napi::Value currentIndex(const Napi::CallbackInfo &info);
|
||||
Napi::Value removeTab(const Napi::CallbackInfo &info);
|
||||
Napi::Value setTabsClosable(const Napi::CallbackInfo &info);
|
||||
Napi::Value setTabText(const Napi::CallbackInfo &info);
|
||||
Napi::Value setTabIcon(const Napi::CallbackInfo &info);
|
||||
};
|
||||
|
||||
@ -15,7 +15,9 @@ Napi::Object QTabWidgetWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("addTab", &QTabWidgetWrap::addTab),
|
||||
InstanceMethod("setTabPosition", &QTabWidgetWrap::setTabPosition),
|
||||
InstanceMethod("indexOf", &QTabWidgetWrap::indexOf),
|
||||
InstanceMethod("setTabText", &QTabWidgetWrap::setTabText),
|
||||
InstanceMethod("setTabIcon", &QTabWidgetWrap::setTabIcon),
|
||||
InstanceMethod("setCurrentIndex", &QTabWidgetWrap::setCurrentIndex),
|
||||
InstanceMethod("currentIndex", &QTabWidgetWrap::currentIndex),
|
||||
InstanceMethod("removeTab", &QTabWidgetWrap::removeTab),
|
||||
@ -72,6 +74,19 @@ Napi::Value QTabWidgetWrap::addTab(const Napi::CallbackInfo& info) {
|
||||
return Napi::Number::New(env, index);
|
||||
}
|
||||
|
||||
Napi::Value QTabWidgetWrap::indexOf(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object widgetObject = info[0].As<Napi::Object>();
|
||||
|
||||
QWidgetWrap* widgetObjectWrap =
|
||||
Napi::ObjectWrap<QWidgetWrap>::Unwrap(widgetObject);
|
||||
|
||||
int index = this->instance->indexOf(widgetObjectWrap->getInternalInstance());
|
||||
return Napi::Number::New(env, index);
|
||||
}
|
||||
|
||||
Napi::Value QTabWidgetWrap::setTabPosition(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
@ -91,6 +106,17 @@ Napi::Value QTabWidgetWrap::setTabText(const Napi::CallbackInfo& info) {
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabWidgetWrap::setTabIcon(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int tabIndex = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Object iconObject = info[1].As<Napi::Object>();
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
|
||||
this->instance->setTabIcon(tabIndex, *iconWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabWidgetWrap::setCurrentIndex(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
61
src/demo.ts
61
src/demo.ts
@ -1,46 +1,21 @@
|
||||
import { QTableView } from './lib/QtWidgets/QTableView';
|
||||
import { QWidget } from './lib/QtWidgets/QWidget';
|
||||
import { FlexLayout } from './lib/core/FlexLayout';
|
||||
import { QTableWidget } from './lib/QtWidgets/QTableWidget';
|
||||
import { QFrame, Shape } from './lib/QtWidgets/QFrame';
|
||||
import { QMainWindow } from './lib/QtWidgets/QMainWindow';
|
||||
import { QTabWidget } from './lib/QtWidgets/QTabWidget';
|
||||
import { QLabel } from './lib/QtWidgets/QLabel';
|
||||
import { QIcon } from './lib/QtGui/QIcon';
|
||||
|
||||
const widget = new QWidget();
|
||||
const layout = new FlexLayout();
|
||||
const view = new QTableView();
|
||||
const table = new QTableWidget(5, 5);
|
||||
const frame = new QFrame();
|
||||
const win = new QMainWindow();
|
||||
const tab = new QTabWidget();
|
||||
const label = new QLabel();
|
||||
label.setText('Hello');
|
||||
const label2 = new QLabel();
|
||||
label2.setText('LABEL');
|
||||
|
||||
frame.setFrameShape(Shape.HLine);
|
||||
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());
|
||||
|
||||
view.setStyleSheet(`
|
||||
QTableView {
|
||||
min-width:300px;
|
||||
min-height:200px;
|
||||
}
|
||||
`);
|
||||
|
||||
table.setStyleSheet(`
|
||||
QTableView {
|
||||
min-width:300px;
|
||||
min-height:200px;
|
||||
}
|
||||
`);
|
||||
|
||||
frame.setStyleSheet(`
|
||||
QFrame{
|
||||
background: blue;
|
||||
border: none;
|
||||
height:15px;
|
||||
}
|
||||
`);
|
||||
|
||||
widget.setLayout(layout);
|
||||
layout.addWidget(view);
|
||||
layout.addWidget(frame);
|
||||
layout.addWidget(table);
|
||||
|
||||
widget.setInlineStyle('flex:1;');
|
||||
widget.resize(600, 400);
|
||||
widget.show();
|
||||
|
||||
(global as any).main = widget;
|
||||
win.show();
|
||||
(global as any).win = win;
|
||||
|
||||
@ -49,6 +49,10 @@ export class QTabWidget extends NodeWidget<QTabWidgetSignals> {
|
||||
return index;
|
||||
}
|
||||
|
||||
indexOf(widget: NodeWidget<any>): number {
|
||||
return this.native.indexOf(widget.native);
|
||||
}
|
||||
|
||||
setTabPosition(tabPosition: TabPosition): void {
|
||||
this.native.setTabPosition(tabPosition);
|
||||
}
|
||||
@ -57,6 +61,10 @@ export class QTabWidget extends NodeWidget<QTabWidgetSignals> {
|
||||
this.native.setTabText(tabIndex, tabText);
|
||||
}
|
||||
|
||||
setTabIcon(tabIndex: number, icon: QIcon): void {
|
||||
this.native.setTabIcon(tabIndex, icon.native);
|
||||
}
|
||||
|
||||
setCurrentIndex(index: number): void {
|
||||
this.native.setCurrentIndex(index);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user