Add QTabBar (#451)
* fix issue #439 * Add QTabBar Co-authored-by: wuxiaofeng <wuxiaofeng@erayt.com>
This commit is contained in:
parent
50f43d955a
commit
d7060f3256
@ -90,6 +90,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QProgressBar/qprogressbar_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QRadioButton/qradiobutton_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QStackedWidget/qstackedwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QTabWidget/qtabwidget_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QLineEdit/qlineedit_wrap.cpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QPlainTextEdit/qplaintextedit_wrap.cpp"
|
||||
@ -141,6 +142,7 @@ add_library(${CORE_WIDGETS_ADDON} SHARED
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QScrollArea/nscrollarea.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QScrollBar/nscrollbar.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QStackedWidget/nstackedwidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTabBar/ntabbar.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QTabWidget/ntabwidget.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QSystemTrayIcon/nsystemtrayicon.hpp"
|
||||
"${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QAction/naction.hpp"
|
||||
|
||||
52
src/cpp/include/nodegui/QtWidgets/QTabBar/ntabbar.hpp
Normal file
52
src/cpp/include/nodegui/QtWidgets/QTabBar/ntabbar.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <QTabBar>
|
||||
|
||||
#include "Extras/Export/export.h"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
#include "core/NodeWidget/nodewidget.h"
|
||||
#include "napi.h"
|
||||
|
||||
class DLL_EXPORT NTabBar : public QTabBar, public NodeWidget {
|
||||
Q_OBJECT
|
||||
NODEWIDGET_IMPLEMENTATIONS(QTabBar)
|
||||
public:
|
||||
using QTabBar::QTabBar; // inherit all constructors of QTabBar
|
||||
|
||||
void connectSignalsToEventEmitter() {
|
||||
QWIDGET_SIGNALS
|
||||
// Qt Connects: Implement all signal connects here
|
||||
QObject::connect(this, &QTabBar::currentChanged, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "currentChanged"),
|
||||
Napi::Number::New(env, index)});
|
||||
});
|
||||
QObject::connect(this, &QTabBar::tabBarClicked, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "tabBarClicked"),
|
||||
Napi::Number::New(env, index)});
|
||||
});
|
||||
QObject::connect(this, &QTabBar::tabBarDoubleClicked, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "tabBarDoubleClicked"),
|
||||
Napi::Number::New(env, index)});
|
||||
});
|
||||
|
||||
QObject::connect(this, &QTabBar::tabCloseRequested, [=](int index) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "tabCloseRequested"),
|
||||
Napi::Number::New(env, index)});
|
||||
});
|
||||
QObject::connect(this, &QTabBar::tabMoved, [=](int from, int to) {
|
||||
Napi::Env env = this->emitOnNode.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
this->emitOnNode.Call({Napi::String::New(env, "tabMoved"),
|
||||
Napi::Number::New(env, from),
|
||||
Napi::Number::New(env, to)});
|
||||
});
|
||||
}
|
||||
};
|
||||
48
src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h
Normal file
48
src/cpp/include/nodegui/QtWidgets/QTabBar/qtabbar_wrap.h
Normal file
@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include <napi.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
#include "Extras/Export/export.h"
|
||||
#include "QtWidgets/QTabBar/ntabbar.hpp"
|
||||
#include "QtWidgets/QWidget/qwidget_macro.h"
|
||||
|
||||
class DLL_EXPORT QTabBarWrap : public Napi::ObjectWrap<QTabBarWrap> {
|
||||
QWIDGET_WRAPPED_METHODS_DECLARATION
|
||||
private:
|
||||
QPointer<NTabBar> instance;
|
||||
bool disableDeletion;
|
||||
|
||||
public:
|
||||
static Napi::Object init(Napi::Env env, Napi::Object exports);
|
||||
QTabBarWrap(const Napi::CallbackInfo& info);
|
||||
~QTabBarWrap();
|
||||
NTabBar* getInternalInstance();
|
||||
// class constructor
|
||||
static Napi::FunctionReference constructor;
|
||||
// wrapped methods
|
||||
Napi::Value setAccessibleTabName(const Napi::CallbackInfo& info);
|
||||
Napi::Value accessibleTabName(const Napi::CallbackInfo& info);
|
||||
Napi::Value addTab(const Napi::CallbackInfo& info);
|
||||
Napi::Value insertTab(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabEnabled(const Napi::CallbackInfo& info);
|
||||
Napi::Value isTabEnabled(const Napi::CallbackInfo& info);
|
||||
Napi::Value moveTab(const Napi::CallbackInfo& info);
|
||||
Napi::Value removeTab(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabButton(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabData(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabData(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabIcon(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabIcon(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabText(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabText(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabTextColor(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabTextColor(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabToolTip(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabToolTip(const Napi::CallbackInfo& info);
|
||||
Napi::Value setTabWhatsThis(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabWhatsThis(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabAt(const Napi::CallbackInfo& info);
|
||||
Napi::Value tabRect(const Napi::CallbackInfo& info);
|
||||
};
|
||||
346
src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp
Normal file
346
src/cpp/lib/QtWidgets/QTabBar/qtabbar_wrap.cpp
Normal file
@ -0,0 +1,346 @@
|
||||
#include "QtWidgets/QTabBar/qtabbar_wrap.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "Extras/Utils/nutils.h"
|
||||
#include "QtCore/QPoint/qpoint_wrap.h"
|
||||
#include "QtCore/QRect/qrect_wrap.h"
|
||||
#include "QtGui/QColor/qcolor_wrap.h"
|
||||
#include "QtGui/QIcon/qicon_wrap.h"
|
||||
#include "QtWidgets/QWidget/qwidget_wrap.h"
|
||||
|
||||
Napi::FunctionReference QTabBarWrap::constructor;
|
||||
|
||||
Napi::Object QTabBarWrap::init(Napi::Env env, Napi::Object exports) {
|
||||
Napi::HandleScope scope(env);
|
||||
char CLASSNAME[] = "QTabBar";
|
||||
Napi::Function func = DefineClass(
|
||||
env, CLASSNAME,
|
||||
{InstanceMethod("setAccessibleTabName",
|
||||
&QTabBarWrap::setAccessibleTabName),
|
||||
InstanceMethod("accessibleTabName", &QTabBarWrap::accessibleTabName),
|
||||
InstanceMethod("addTab", &QTabBarWrap::addTab),
|
||||
InstanceMethod("insertTab", &QTabBarWrap::insertTab),
|
||||
InstanceMethod("setTabEnabled", &QTabBarWrap::setTabEnabled),
|
||||
InstanceMethod("isTabEnabled", &QTabBarWrap::isTabEnabled),
|
||||
InstanceMethod("moveTab", &QTabBarWrap::moveTab),
|
||||
InstanceMethod("removeTab", &QTabBarWrap::removeTab),
|
||||
InstanceMethod("setTabButton", &QTabBarWrap::setTabButton),
|
||||
InstanceMethod("setTabData", &QTabBarWrap::setTabData),
|
||||
InstanceMethod("tabData", &QTabBarWrap::tabData),
|
||||
InstanceMethod("setTabIcon", &QTabBarWrap::setTabIcon),
|
||||
InstanceMethod("tabIcon", &QTabBarWrap::tabIcon),
|
||||
InstanceMethod("setTabText", &QTabBarWrap::setTabText),
|
||||
InstanceMethod("tabText", &QTabBarWrap::tabText),
|
||||
InstanceMethod("setTabTextColor", &QTabBarWrap::setTabTextColor),
|
||||
InstanceMethod("tabTextColor", &QTabBarWrap::tabTextColor),
|
||||
InstanceMethod("setTabToolTip", &QTabBarWrap::setTabToolTip),
|
||||
InstanceMethod("tabToolTip", &QTabBarWrap::tabToolTip),
|
||||
InstanceMethod("setTabWhatsThis", &QTabBarWrap::setTabWhatsThis),
|
||||
InstanceMethod("tabWhatsThis", &QTabBarWrap::tabWhatsThis),
|
||||
InstanceMethod("tabAt", &QTabBarWrap::tabAt),
|
||||
InstanceMethod("tabRect", &QTabBarWrap::tabRect),
|
||||
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QTabBarWrap)});
|
||||
constructor = Napi::Persistent(func);
|
||||
exports.Set(CLASSNAME, func);
|
||||
return exports;
|
||||
}
|
||||
|
||||
NTabBar* QTabBarWrap::getInternalInstance() { return this->instance; }
|
||||
|
||||
QTabBarWrap::~QTabBarWrap() {
|
||||
if (!this->disableDeletion) {
|
||||
extrautils::safeDelete(this->instance);
|
||||
}
|
||||
}
|
||||
|
||||
QTabBarWrap::QTabBarWrap(const Napi::CallbackInfo& info)
|
||||
: Napi::ObjectWrap<QTabBarWrap>(info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
if (info.Length() > 0 && info[0].IsExternal()) {
|
||||
// --- if external ---
|
||||
this->instance = info[0].As<Napi::External<NTabBar>>().Data();
|
||||
if (info.Length() == 2) {
|
||||
this->disableDeletion = info[1].As<Napi::Boolean>().Value();
|
||||
}
|
||||
} else {
|
||||
// --- regular cases ---
|
||||
if (info.Length() == 1) {
|
||||
Napi::Object parentObject = info[0].As<Napi::Object>();
|
||||
NodeWidgetWrap* parentWidgetWrap =
|
||||
Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(parentObject);
|
||||
this->instance = new NTabBar(parentWidgetWrap->getInternalInstance());
|
||||
} else if (info.Length() == 0) {
|
||||
this->instance = new NTabBar();
|
||||
} else {
|
||||
Napi::TypeError::New(env, "Wrong number of arguments")
|
||||
.ThrowAsJavaScriptException();
|
||||
}
|
||||
}
|
||||
this->rawData = extrautils::configureQWidget(
|
||||
this->getInternalInstance(), this->getInternalInstance()->getFlexNode(),
|
||||
true);
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setAccessibleTabName(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string napiName = info[1].As<Napi::String>().Utf8Value();
|
||||
QString name = QString::fromUtf8(napiName.c_str());
|
||||
this->instance->setAccessibleTabName(index, name);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::accessibleTabName(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QString tabName = this->instance->accessibleTabName(index);
|
||||
return Napi::String::New(env, tabName.toStdString());
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::addTab(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = 0;
|
||||
if (info.Length() == 2) {
|
||||
Napi::Object iconObject = info[0].As<Napi::Object>();
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
|
||||
std::string napiText = info[1].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
index = this->instance->addTab(*iconWrap->getInternalInstance(), text);
|
||||
} else {
|
||||
std::string napiText = info[0].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
index = this->instance->addTab(text);
|
||||
}
|
||||
return Napi::Number::New(env, index);
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::insertTab(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int result = 0;
|
||||
if (info.Length() == 3) {
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Object iconObject = info[1].As<Napi::Object>();
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
|
||||
std::string napiText = info[2].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
result = this->instance->insertTab(
|
||||
index, *iconWrap->getInternalInstance(), text);
|
||||
} else {
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string napiText = info[1].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
result = this->instance->insertTab(index, text);
|
||||
}
|
||||
return Napi::Number::New(env, result);
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabEnabled(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
bool enabled = info[1].As<Napi::Boolean>().Value();
|
||||
this->instance->setTabEnabled(index, enabled);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::isTabEnabled(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
bool enabled = this->instance->isTabEnabled(index);
|
||||
return Napi::Boolean::New(env, enabled);
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::moveTab(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int from = info[0].As<Napi::Number>().Int32Value();
|
||||
int to = info[1].As<Napi::Number>().Int32Value();
|
||||
this->instance->moveTab(from, to);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::removeTab(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
this->instance->removeTab(index);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabButton(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
int position = info[1].As<Napi::Number>().Int32Value();
|
||||
Napi::Object widgetObject = info[2].As<Napi::Object>();
|
||||
NodeWidgetWrap* widgetWrap = Napi::ObjectWrap<NodeWidgetWrap>::Unwrap(widgetObject);
|
||||
this->instance->setTabButton(index,
|
||||
static_cast<QTabBar::ButtonPosition>(position),
|
||||
widgetWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabData(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Object variantObject = info[1].As<Napi::Object>();
|
||||
QVariantWrap* variantWrap =
|
||||
Napi::ObjectWrap<QVariantWrap>::Unwrap(variantObject);
|
||||
this->instance->setTabData(index, *variantWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabData(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QVariant variant = this->instance->tabData(index);
|
||||
auto instance = QVariantWrap::constructor.New(
|
||||
{Napi::External<QVariant>::New(env, new QVariant(variant))});
|
||||
return instance;
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabIcon(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Object iconObject = info[1].As<Napi::Object>();
|
||||
QIconWrap* iconWrap = Napi::ObjectWrap<QIconWrap>::Unwrap(iconObject);
|
||||
this->instance->setTabIcon(index, *iconWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabIcon(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QIcon icon = this->instance->tabIcon(index);
|
||||
auto instance = QIconWrap::constructor.New(
|
||||
{Napi::External<QIcon>::New(env, new QIcon(icon))});
|
||||
return instance;
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string napiText = info[1].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
this->instance->setTabText(index, text);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabText(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QString text = this->instance->tabText(index);
|
||||
return Napi::String::New(env, text.toStdString());
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabTextColor(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
Napi::Object colorObject = info[1].As<Napi::Object>();
|
||||
QColorWrap* colorWrap = Napi::ObjectWrap<QColorWrap>::Unwrap(colorObject);
|
||||
this->instance->setTabTextColor(index, *colorWrap->getInternalInstance());
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabTextColor(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QColor color = this->instance->tabTextColor(index);
|
||||
auto instance = QColorWrap::constructor.New(
|
||||
{Napi::External<QColor>::New(env, new QColor(color))});
|
||||
return instance;
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabToolTip(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string napiTip = info[1].As<Napi::String>().Utf8Value();
|
||||
QString tip = QString::fromUtf8(napiTip.c_str());
|
||||
this->instance->setTabToolTip(index, tip);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabToolTip(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QString tip = this->instance->tabToolTip(index);
|
||||
return Napi::String::New(env, tip.toStdString());
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::setTabWhatsThis(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
std::string napiText = info[1].As<Napi::String>().Utf8Value();
|
||||
QString text = QString::fromUtf8(napiText.c_str());
|
||||
this->instance->setTabWhatsThis(index, text);
|
||||
return env.Null();
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabWhatsThis(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QString text = this->instance->tabWhatsThis(index);
|
||||
return Napi::String::New(env, text.toStdString());
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabAt(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
Napi::Object pointObject = info[0].As<Napi::Object>();
|
||||
QPointWrap* pointWrap = Napi::ObjectWrap<QPointWrap>::Unwrap(pointObject);
|
||||
int index = this->instance->tabAt(*pointWrap->getInternalInstance());
|
||||
return Napi::Number::New(env, index);
|
||||
}
|
||||
|
||||
Napi::Value QTabBarWrap::tabRect(const Napi::CallbackInfo& info) {
|
||||
Napi::Env env = info.Env();
|
||||
Napi::HandleScope scope(env);
|
||||
|
||||
int index = info[0].As<Napi::Number>().Int32Value();
|
||||
QRect rect = this->instance->tabRect(index);
|
||||
auto instance = QRectWrap::constructor.New({Napi::External<QRect>::New(
|
||||
env, new QRect(rect.x(), rect.y(), rect.width(), rect.height()))});
|
||||
return instance;
|
||||
}
|
||||
@ -63,6 +63,7 @@
|
||||
#include "QtWidgets/QStackedWidget/qstackedwidget_wrap.h"
|
||||
#include "QtWidgets/QStatusBar/qstatusbar_wrap.h"
|
||||
#include "QtWidgets/QSystemTrayIcon/qsystemtrayicon_wrap.h"
|
||||
#include "QtWidgets/QTabBar/qtabbar_wrap.h"
|
||||
#include "QtWidgets/QTabWidget/qtabwidget_wrap.h"
|
||||
#include "QtWidgets/QTableView/qtableview_wrap.h"
|
||||
#include "QtWidgets/QTableWidget/qtablewidget_wrap.h"
|
||||
@ -133,6 +134,7 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) {
|
||||
QProgressBarWrap::init(env, exports);
|
||||
QRadioButtonWrap::init(env, exports);
|
||||
QStackedWidgetWrap::init(env, exports);
|
||||
QTabBarWrap::init(env, exports);
|
||||
QTabWidgetWrap::init(env, exports);
|
||||
QLineEditWrap::init(env, exports);
|
||||
QKeyEventWrap::init(env, exports);
|
||||
|
||||
@ -53,6 +53,7 @@ export { QRadioButton, QRadioButtonSignals } from './lib/QtWidgets/QRadioButton'
|
||||
export { QStackedWidget, QStackedWidgetSignals } from './lib/QtWidgets/QStackedWidget';
|
||||
export { QListWidget, QListWidgetSignals } from './lib/QtWidgets/QListWidget';
|
||||
export { QListWidgetItem } from './lib/QtWidgets/QListWidgetItem';
|
||||
export { QTabBar, QTabBarSignals, ButtonPosition, SelectionBehavior, TabBarShape } from './lib/QtWidgets/QTabBar';
|
||||
export { QTabWidget, QTabWidgetSignals } from './lib/QtWidgets/QTabWidget';
|
||||
export { QTableView, QTableViewSignals } from './lib/QtWidgets/QTableView';
|
||||
export { QTableWidget, QTableWidgetSignals } from './lib/QtWidgets/QTableWidget';
|
||||
|
||||
233
src/lib/QtWidgets/QTabBar.ts
Normal file
233
src/lib/QtWidgets/QTabBar.ts
Normal file
@ -0,0 +1,233 @@
|
||||
import addon from '../utils/addon';
|
||||
import { NodeWidget, QWidgetSignals } from './QWidget';
|
||||
import { NativeElement } from '../core/Component';
|
||||
import { QIcon } from '../QtGui/QIcon';
|
||||
import { TextElideMode } from '../QtEnums';
|
||||
import { QSize } from '../QtCore/QSize';
|
||||
import { QVariant } from '../QtCore/QVariant';
|
||||
import { QColor } from '../QtGui/QColor';
|
||||
import { QPoint } from '../QtCore/QPoint';
|
||||
import { QRect } from '../QtCore/QRect';
|
||||
|
||||
/**
|
||||
|
||||
> Create and control tabbar.
|
||||
|
||||
* **This class is a JS wrapper around Qt's [QTabBar class](https://doc.qt.io/qt-5/qtabbar.html)**
|
||||
|
||||
The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs.
|
||||
|
||||
### Example
|
||||
|
||||
```javascript
|
||||
const { QTabBar } = require("@nodegui/nodegui");
|
||||
|
||||
const tabBar = new QTabBar();
|
||||
|
||||
```
|
||||
*/
|
||||
export class QTabBar extends NodeWidget<QTabBarSignals> {
|
||||
native: NativeElement;
|
||||
constructor();
|
||||
constructor(parent: NodeWidget<any>);
|
||||
constructor(parent?: NodeWidget<any>) {
|
||||
let native;
|
||||
if (parent) {
|
||||
native = new addon.QTabBar(parent.native);
|
||||
} else {
|
||||
native = new addon.QTabBar();
|
||||
}
|
||||
super(native);
|
||||
this.native = native;
|
||||
parent && this.setNodeParent(parent);
|
||||
}
|
||||
setAutoHide(hide: boolean): void {
|
||||
this.setProperty('autoHide', hide);
|
||||
}
|
||||
autoHide(): boolean {
|
||||
return this.property('autoHide').toBool();
|
||||
}
|
||||
setChangeCurrentOnDrag(change: boolean): void {
|
||||
this.setProperty('changeCurrentOnDrag', change);
|
||||
}
|
||||
changeCurrentOnDrag(): boolean {
|
||||
return this.property('changeCurrentOnDrag').toBool();
|
||||
}
|
||||
count(): number {
|
||||
return this.property('count').toInt();
|
||||
}
|
||||
setCurrentIndex(index: number): void {
|
||||
this.setProperty('currentIndex', index);
|
||||
}
|
||||
currentIndex(): number {
|
||||
return this.property('currentIndex').toInt();
|
||||
}
|
||||
setDocumentMode(set: boolean): void {
|
||||
this.setProperty('documentMode', set);
|
||||
}
|
||||
documentMode(): boolean {
|
||||
return this.property('documentMode').toBool();
|
||||
}
|
||||
setDrawBase(drawTheBase: boolean): void {
|
||||
this.setProperty('drawBase', drawTheBase);
|
||||
}
|
||||
drawBase(): boolean {
|
||||
return this.property('drawBase').toBool();
|
||||
}
|
||||
setElideMode(mode: TextElideMode): void {
|
||||
this.setProperty('elideMode', mode);
|
||||
}
|
||||
elideMode(): TextElideMode {
|
||||
return this.property('elideMode').toInt();
|
||||
}
|
||||
setExpanding(enabled: boolean): void {
|
||||
this.setProperty('expanding', enabled);
|
||||
}
|
||||
expanding(): boolean {
|
||||
return this.property('expanding').toBool();
|
||||
}
|
||||
setIconSize(size: QSize): void {
|
||||
this.setProperty('iconSize', size.native);
|
||||
}
|
||||
iconSize(): QSize {
|
||||
const size = this.property('iconSize');
|
||||
return QSize.fromQVariant(size);
|
||||
}
|
||||
setMovable(movable: boolean): void {
|
||||
this.setProperty('movable', movable);
|
||||
}
|
||||
isMovable(): boolean {
|
||||
return this.property('movable').toBool();
|
||||
}
|
||||
setSelectionBehaviorOnRemove(behavior: SelectionBehavior): void {
|
||||
this.setProperty('selectionBehaviorOnRemove', behavior);
|
||||
}
|
||||
selectionBehaviorOnRemove(): SelectionBehavior {
|
||||
return this.property('selectionBehaviorOnRemove').toInt();
|
||||
}
|
||||
setShape(shape: TabBarShape): void {
|
||||
this.setProperty('shape', shape);
|
||||
}
|
||||
shape(): TabBarShape {
|
||||
return this.property('shape').toInt();
|
||||
}
|
||||
setTabsClosable(closeable: boolean): void {
|
||||
this.setProperty('tabsClosable', closeable);
|
||||
}
|
||||
tabsClosable(): boolean {
|
||||
return this.property('tabsClosable').toBool();
|
||||
}
|
||||
setUsesScrollButtons(useButtons: boolean): void {
|
||||
this.setProperty('usesScrollButtons', useButtons);
|
||||
}
|
||||
usesScrollButtons(): boolean {
|
||||
return this.property('usesScrollButtons').toBool();
|
||||
}
|
||||
setAccessibleTabName(index: number, name: string): void {
|
||||
this.native.setAccessibleTabName(index, name);
|
||||
}
|
||||
accessibleTabName(index: number): string {
|
||||
return this.native.accessibleTabName(index);
|
||||
}
|
||||
addTab(icon: QIcon | undefined, text: string): number {
|
||||
if (icon) {
|
||||
return this.native.addTab(icon.native, text);
|
||||
} else {
|
||||
return this.native.addTab(text);
|
||||
}
|
||||
}
|
||||
insertTab(index: number, icon: QIcon | undefined, text: string): number {
|
||||
if (icon) {
|
||||
return this.native.insertTab(index, icon.native, text);
|
||||
} else {
|
||||
return this.native.insertTab(index, text);
|
||||
}
|
||||
}
|
||||
setTabEnabled(index: number, enabled: boolean): void {
|
||||
this.native.setTabEnabled(index, enabled);
|
||||
}
|
||||
isTabEnabled(index: number): boolean {
|
||||
return this.native.isTabEnabled(index);
|
||||
}
|
||||
moveTab(from: number, to: number): void {
|
||||
this.native.moveTab(from, to);
|
||||
}
|
||||
removeTab(index: number): void {
|
||||
this.native.removeTab(index);
|
||||
}
|
||||
setTabButton(index: number, position: ButtonPosition, widget: NodeWidget<any>): void {
|
||||
this.native.setTabButton(index, position, widget.native);
|
||||
}
|
||||
setTabData(index: number, data: QVariant): void {
|
||||
this.native.setTabData(index, data.native);
|
||||
}
|
||||
tabData(index: number): QVariant {
|
||||
return new QVariant(this.native.tabData(index));
|
||||
}
|
||||
setTabIcon(index: number, icon: QIcon): void {
|
||||
this.native.setTabIcon(index, icon.native);
|
||||
}
|
||||
tabIcon(index: number): QIcon {
|
||||
return new QIcon(this.native.tabIcon(index));
|
||||
}
|
||||
setTabText(index: number, text: string): void {
|
||||
this.native.setTabText(index, text);
|
||||
}
|
||||
tabText(index: number): string {
|
||||
return this.native.tabText(index);
|
||||
}
|
||||
setTabTextColor(index: number, color: QColor): void {
|
||||
this.native.setTabTextColor(index, color.native);
|
||||
}
|
||||
tabTextColor(index: number): QColor {
|
||||
return new QColor(this.native.tabTextColor(index));
|
||||
}
|
||||
setTabToolTip(index: number, tip: string): void {
|
||||
this.native.setTabToolTip(index, tip);
|
||||
}
|
||||
tabToolTip(index: number): string {
|
||||
return this.native.tabToolTip(index);
|
||||
}
|
||||
setTabWhatsThis(index: number, text: string): void {
|
||||
this.native.setTabWhatsThis(index, text);
|
||||
}
|
||||
tabWhatsThis(index: number): string {
|
||||
return this.native.tabWhatsThis(index);
|
||||
}
|
||||
tabAt(position: QPoint): number {
|
||||
return this.native.tabAt(position.native);
|
||||
}
|
||||
tabRect(index: number): QRect {
|
||||
return new QRect(this.native.tabRect(index));
|
||||
}
|
||||
}
|
||||
|
||||
export enum ButtonPosition {
|
||||
LeftSide = 0,
|
||||
RightSide = 1,
|
||||
}
|
||||
|
||||
export enum SelectionBehavior {
|
||||
SelectLeftTab = 0,
|
||||
SelectRightTab = 1,
|
||||
SelectPreviousTab = 2,
|
||||
}
|
||||
|
||||
export enum TabBarShape {
|
||||
RoundedNorth = 0,
|
||||
RoundedSouth = 1,
|
||||
RoundedWest = 2,
|
||||
RoundedEast = 3,
|
||||
TriangularNorth = 4,
|
||||
TriangularSouth = 5,
|
||||
TriangularWest = 6,
|
||||
TriangularEast = 7,
|
||||
}
|
||||
|
||||
export interface QTabBarSignals extends QWidgetSignals {
|
||||
currentChanged: (index: number) => void;
|
||||
tabBarClicked: (index: number) => void;
|
||||
tabBarDoubleClicked: (index: number) => void;
|
||||
tabCloseRequested: (index: number) => void;
|
||||
tabMoved: (from: number, to: number) => void;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user