#include "QtWidgets/QTabBar/qtabbar_wrap.h" #include #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(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); if (info.Length() > 0 && info[0].IsExternal()) { // --- if external --- this->instance = info[0].As>().Data(); if (info.Length() == 2) { this->disableDeletion = info[1].As().Value(); } } else { // --- regular cases --- if (info.Length() == 1) { Napi::Object parentObject = info[0].As(); NodeWidgetWrap* parentWidgetWrap = Napi::ObjectWrap::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().Int32Value(); std::string napiName = info[1].As().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().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(); QIconWrap* iconWrap = Napi::ObjectWrap::Unwrap(iconObject); std::string napiText = info[1].As().Utf8Value(); QString text = QString::fromUtf8(napiText.c_str()); index = this->instance->addTab(*iconWrap->getInternalInstance(), text); } else { std::string napiText = info[0].As().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().Int32Value(); Napi::Object iconObject = info[1].As(); QIconWrap* iconWrap = Napi::ObjectWrap::Unwrap(iconObject); std::string napiText = info[2].As().Utf8Value(); QString text = QString::fromUtf8(napiText.c_str()); result = this->instance->insertTab(index, *iconWrap->getInternalInstance(), text); } else { int index = info[0].As().Int32Value(); std::string napiText = info[1].As().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().Int32Value(); bool enabled = info[1].As().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().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().Int32Value(); int to = info[1].As().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().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().Int32Value(); int position = info[1].As().Int32Value(); Napi::Object widgetObject = info[2].As(); NodeWidgetWrap* widgetWrap = Napi::ObjectWrap::Unwrap(widgetObject); this->instance->setTabButton(index, static_cast(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().Int32Value(); Napi::Object variantObject = info[1].As(); QVariantWrap* variantWrap = Napi::ObjectWrap::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().Int32Value(); QVariant variant = this->instance->tabData(index); auto instance = QVariantWrap::constructor.New( {Napi::External::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().Int32Value(); Napi::Object iconObject = info[1].As(); QIconWrap* iconWrap = Napi::ObjectWrap::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().Int32Value(); QIcon icon = this->instance->tabIcon(index); auto instance = QIconWrap::constructor.New( {Napi::External::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().Int32Value(); std::string napiText = info[1].As().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().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().Int32Value(); Napi::Object colorObject = info[1].As(); QColorWrap* colorWrap = Napi::ObjectWrap::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().Int32Value(); QColor color = this->instance->tabTextColor(index); auto instance = QColorWrap::constructor.New( {Napi::External::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().Int32Value(); std::string napiTip = info[1].As().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().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().Int32Value(); std::string napiText = info[1].As().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().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(); QPointWrap* pointWrap = Napi::ObjectWrap::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().Int32Value(); QRect rect = this->instance->tabRect(index); auto instance = QRectWrap::constructor.New({Napi::External::New( env, new QRect(rect.x(), rect.y(), rect.width(), rect.height()))}); return instance; }