From 527a18a1e511a743762a47e844bb4c04f83064f2 Mon Sep 17 00:00:00 2001 From: feng8848 <40539968+feng8848@users.noreply.github.com> Date: Wed, 15 Apr 2020 01:10:34 +0800 Subject: [PATCH] fix issue #503 (#519) * fix issue #481 * fix lint * Add QTextEdit and QTextBrowser * Add QGraphicsBlurEffect * Add QGraphicsDropShadowEffect Co-authored-by: wuxiaofeng --- CMakeLists.txt | 4 ++ .../ngraphicsblureffect.hpp | 36 ++++++++++ .../qgraphicsblureffect_wrap.h | 25 +++++++ .../ngraphicsdropshadoweffect.hpp | 29 ++++++++ .../qgraphicsdropshadoweffect_wrap.h | 25 +++++++ .../QGraphicsEffect/qgraphicseffect_macro.h | 47 ++++++++++++ .../nodegui/QtWidgets/QWidget/qwidget_macro.h | 17 ++++- .../qgraphicsblureffect_wrap.cpp | 46 ++++++++++++ .../qgraphicsdropshadoweffect_wrap.cpp | 49 +++++++++++++ src/cpp/main.cpp | 4 ++ src/index.ts | 3 + src/lib/QtWidgets/QGraphicsBlurEffect.ts | 66 +++++++++++++++++ .../QtWidgets/QGraphicsDropShadowEffect.ts | 72 +++++++++++++++++++ src/lib/QtWidgets/QGraphicsEffect.ts | 24 +++++++ src/lib/QtWidgets/QWidget.ts | 6 ++ 15 files changed, 451 insertions(+), 2 deletions(-) create mode 100644 src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/ngraphicsblureffect.hpp create mode 100644 src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h create mode 100644 src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/ngraphicsdropshadoweffect.hpp create mode 100644 src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h create mode 100644 src/cpp/include/nodegui/QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h create mode 100644 src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp create mode 100644 src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp create mode 100644 src/lib/QtWidgets/QGraphicsBlurEffect.ts create mode 100644 src/lib/QtWidgets/QGraphicsDropShadowEffect.ts create mode 100644 src/lib/QtWidgets/QGraphicsEffect.ts diff --git a/CMakeLists.txt b/CMakeLists.txt index d61376c5c..8ce13f6e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,8 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QFileDialog/qfiledialog_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QFontDialog/qfontdialog_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QFrame/qframe_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp" + "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListView/qlistview_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidget/qlistwidget_wrap.cpp" "${PROJECT_SOURCE_DIR}/src/cpp/lib/QtWidgets/QListWidgetItem/qlistwidgetitem_wrap.cpp" @@ -142,6 +144,8 @@ add_library(${CORE_WIDGETS_ADDON} SHARED "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QFileDialog/nfiledialog.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QFontDialog/nfontdialog.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QFrame/nframe.hpp" + "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/ngraphicsblureffect.hpp" + "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/ngraphicsdropshadoweffect.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QLCDNumber/nlcdnumber.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QListView/nlistview.hpp" "${PROJECT_SOURCE_DIR}/src/cpp/include/nodegui/QtWidgets/QListWidget/nlistwidget.hpp" diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/ngraphicsblureffect.hpp b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/ngraphicsblureffect.hpp new file mode 100644 index 000000000..54677f42b --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/ngraphicsblureffect.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include "Extras/Export/export.h" +#include "QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h" +#include "core/Events/eventwidget.h" +#include "core/Events/eventwidget_macro.h" + +class DLL_EXPORT NGraphicsBlurEffect : public QGraphicsBlurEffect, + public EventWidget { + Q_OBJECT + EVENTWIDGET_IMPLEMENTATIONS(QGraphicsBlurEffect) + public: + using QGraphicsBlurEffect::QGraphicsBlurEffect; + + void connectSignalsToEventEmitter() { + QGRAPHICSEFFECT_SIGNALS + // Qt Connects: Implement all signal connects here + QObject::connect(this, &QGraphicsBlurEffect::blurHintsChanged, + [=](QGraphicsBlurEffect::BlurHints hints) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call( + {Napi::String::New(env, "blurHintsChanged"), + Napi::Number::New(env, static_cast(hints))}); + }); + QObject::connect( + this, &QGraphicsBlurEffect::blurRadiusChanged, [=](qreal radius) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({Napi::String::New(env, "blurRadiusChanged"), + Napi::Number::New(env, radius)}); + }); + } +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h new file mode 100644 index 000000000..483526296 --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +#include "Extras/Export/export.h" +#include "QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h" +#include "ngraphicsblureffect.hpp" + +class DLL_EXPORT QGraphicsBlurEffectWrap + : public Napi::ObjectWrap { + QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION + private: + QPointer instance; + + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QGraphicsBlurEffectWrap(const Napi::CallbackInfo& info); + ~QGraphicsBlurEffectWrap(); + NGraphicsBlurEffect* getInternalInstance(); + // class constructor + static Napi::FunctionReference constructor; + // wrapped methods +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/ngraphicsdropshadoweffect.hpp b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/ngraphicsdropshadoweffect.hpp new file mode 100644 index 000000000..1b17870aa --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/ngraphicsdropshadoweffect.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "Extras/Export/export.h" +#include "QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h" +#include "core/Events/eventwidget.h" +#include "core/Events/eventwidget_macro.h" + +class DLL_EXPORT NGraphicsDropShadowEffect : public QGraphicsDropShadowEffect, + public EventWidget { + Q_OBJECT + EVENTWIDGET_IMPLEMENTATIONS(QGraphicsDropShadowEffect) + public: + using QGraphicsDropShadowEffect::QGraphicsDropShadowEffect; + + void connectSignalsToEventEmitter() { + QGRAPHICSEFFECT_SIGNALS + // Qt Connects: Implement all signal connects here + QObject::connect( + this, &QGraphicsDropShadowEffect::blurRadiusChanged, + [=](qreal blurRadius) { + Napi::Env env = this->emitOnNode.Env(); + Napi::HandleScope scope(env); + this->emitOnNode.Call({Napi::String::New(env, "blurRadiusChanged"), + Napi::Number::New(env, blurRadius)}); + }); + } +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h new file mode 100644 index 000000000..0eee0eaee --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +#include + +#include "Extras/Export/export.h" +#include "QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h" +#include "ngraphicsdropshadoweffect.hpp" + +class DLL_EXPORT QGraphicsDropShadowEffectWrap + : public Napi::ObjectWrap { + QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION + private: + QPointer instance; + + public: + static Napi::Object init(Napi::Env env, Napi::Object exports); + QGraphicsDropShadowEffectWrap(const Napi::CallbackInfo& info); + ~QGraphicsDropShadowEffectWrap(); + NGraphicsDropShadowEffect* getInternalInstance(); + // class constructor + static Napi::FunctionReference constructor; + // wrapped methods +}; diff --git a/src/cpp/include/nodegui/QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h b/src/cpp/include/nodegui/QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h new file mode 100644 index 000000000..a75c8c546 --- /dev/null +++ b/src/cpp/include/nodegui/QtWidgets/QGraphicsEffect/qgraphicseffect_macro.h @@ -0,0 +1,47 @@ +#pragma once + +#include "QtCore/QObject/qobject_macro.h" + +/* + + This macro adds common QGraphicsEffect exported methods + The exported methods are taken into this macro to avoid writing them in each + and every graphicseffect we export. + */ + +#ifndef QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION +#define QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION \ + \ + QOBJECT_WRAPPED_METHODS_DECLARATION \ + \ + Napi::Value update(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + this->instance->update(); \ + return env.Null(); \ + } + +#endif // QGRAPHICSEFFECT_WRAPPED_METHODS_DECLARATION + +#ifndef QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE +#define QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE(GraphicsEffectWrapName) \ + \ + QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(GraphicsEffectWrapName) \ + \ + InstanceMethod("update", &GraphicsEffectWrapName::update), + +#endif // QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE + +#ifndef QGRAPHICSEFFECT_SIGNALS +#define QGRAPHICSEFFECT_SIGNALS \ + \ + QOBJECT_SIGNALS \ + \ + QObject::connect(this, &QGraphicsEffect::enabledChanged, [=](bool enabled) { \ + Napi::Env env = this->emitOnNode.Env(); \ + Napi::HandleScope scope(env); \ + this->emitOnNode.Call({Napi::String::New(env, "enabledChanged"), \ + Napi::Boolean::New(env, enabled)}); \ + }); + +#endif // QGRAPHICSEFFECT_SIGNALS diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index a80a85e89..bd8a738e3 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -1,9 +1,10 @@ #pragma once +#include #include #include -#include "QtCore/QObject/qobject_macro.h" +#include "QtCore/QObject/qobject_wrap.h" #include "QtCore/QPoint/qpoint_wrap.h" #include "QtCore/QSize/qsize_wrap.h" #include "QtGui/QCursor/qcursor_wrap.h" @@ -383,6 +384,17 @@ this->instance->style()->unpolish(this->instance); \ this->instance->style()->polish(this->instance); \ return env.Null(); \ + } \ + Napi::Value setGraphicsEffect(const Napi::CallbackInfo& info) { \ + Napi::Env env = info.Env(); \ + Napi::HandleScope scope(env); \ + Napi::Object effectObject = info[0].As(); \ + QObjectWrap* effectWrap = \ + Napi::ObjectWrap::Unwrap(effectObject); \ + QGraphicsEffect* effect = \ + qobject_cast(effectWrap->getInternalInstance()); \ + this->instance->setGraphicsEffect(effect); \ + return env.Null(); \ } #endif // QWIDGET_WRAPPED_METHODS_DECLARATION @@ -438,7 +450,8 @@ InstanceMethod("showMinimized", &WidgetWrapName::showMinimized), \ InstanceMethod("showNormal", &WidgetWrapName::showNormal), \ InstanceMethod("addAction", &WidgetWrapName::addAction), \ - InstanceMethod("repolish", &WidgetWrapName::repolish), + InstanceMethod("repolish", &WidgetWrapName::repolish), \ + InstanceMethod("setGraphicsEffect", &WidgetWrapName::setGraphicsEffect), #endif // QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE diff --git a/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp b/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp new file mode 100644 index 000000000..27539cfd8 --- /dev/null +++ b/src/cpp/lib/QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.cpp @@ -0,0 +1,46 @@ +#include "QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h" + +#include "Extras/Utils/nutils.h" +#include "QtCore/QObject/qobject_wrap.h" + +Napi::FunctionReference QGraphicsBlurEffectWrap::constructor; + +Napi::Object QGraphicsBlurEffectWrap::init(Napi::Env env, + Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QGraphicsBlurEffect"; + Napi::Function func = DefineClass( + env, CLASSNAME, + {QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE(QGraphicsBlurEffectWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +NGraphicsBlurEffect* QGraphicsBlurEffectWrap::getInternalInstance() { + return this->instance; +} + +QGraphicsBlurEffectWrap::~QGraphicsBlurEffectWrap() { + extrautils::safeDelete(this->instance); +} + +QGraphicsBlurEffectWrap::QGraphicsBlurEffectWrap(const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + if (info.Length() == 1) { + Napi::Object parentObject = info[0].As(); + QObjectWrap* parentObjectWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NGraphicsBlurEffect(parentObjectWrap->getInternalInstance()); + } else if (info.Length() == 0) { + this->instance = new NGraphicsBlurEffect(); + } else { + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureQObject(this->getInternalInstance()); +} diff --git a/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp b/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp new file mode 100644 index 000000000..6a58c3964 --- /dev/null +++ b/src/cpp/lib/QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.cpp @@ -0,0 +1,49 @@ +#include "QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h" + +#include "Extras/Utils/nutils.h" +#include "QtCore/QObject/qobject_wrap.h" + +Napi::FunctionReference QGraphicsDropShadowEffectWrap::constructor; + +Napi::Object QGraphicsDropShadowEffectWrap::init(Napi::Env env, + Napi::Object exports) { + Napi::HandleScope scope(env); + char CLASSNAME[] = "QGraphicsDropShadowEffect"; + Napi::Function func = + DefineClass(env, CLASSNAME, + {QGRAPHICSEFFECT_WRAPPED_METHODS_EXPORT_DEFINE( + QGraphicsDropShadowEffectWrap)}); + constructor = Napi::Persistent(func); + exports.Set(CLASSNAME, func); + return exports; +} + +NGraphicsDropShadowEffect* +QGraphicsDropShadowEffectWrap::getInternalInstance() { + return this->instance; +} + +QGraphicsDropShadowEffectWrap::~QGraphicsDropShadowEffectWrap() { + extrautils::safeDelete(this->instance); +} + +QGraphicsDropShadowEffectWrap::QGraphicsDropShadowEffectWrap( + const Napi::CallbackInfo& info) + : Napi::ObjectWrap(info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + if (info.Length() == 1) { + Napi::Object parentObject = info[0].As(); + QObjectWrap* parentObjectWrap = + Napi::ObjectWrap::Unwrap(parentObject); + this->instance = + new NGraphicsDropShadowEffect(parentObjectWrap->getInternalInstance()); + } else if (info.Length() == 0) { + this->instance = new NGraphicsDropShadowEffect(); + } else { + Napi::TypeError::New(env, "Wrong number of arguments") + .ThrowAsJavaScriptException(); + } + this->rawData = extrautils::configureQObject(this->getInternalInstance()); +} diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index f0bf4f872..5ecb754a6 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -43,6 +43,8 @@ #include "QtWidgets/QFileDialog/qfiledialog_wrap.h" #include "QtWidgets/QFontDialog/qfontdialog_wrap.h" #include "QtWidgets/QFrame/qframe_wrap.h" +#include "QtWidgets/QGraphicsBlurEffect/qgraphicsblureffect_wrap.h" +#include "QtWidgets/QGraphicsDropShadowEffect/qgraphicsdropshadoweffect_wrap.h" #include "QtWidgets/QGridLayout/qgridlayout_wrap.h" #include "QtWidgets/QGroupBox/qgroupbox_wrap.h" #include "QtWidgets/QInputDialog/qinputdialog_wrap.h" @@ -132,6 +134,8 @@ Napi::Object Main(Napi::Env env, Napi::Object exports) { QFileDialogWrap::init(env, exports); QFontDialogWrap::init(env, exports); QFrameWrap::init(env, exports); + QGraphicsBlurEffectWrap::init(env, exports); + QGraphicsDropShadowEffectWrap::init(env, exports); QListViewWrap::init(env, exports); QListWidgetWrap::init(env, exports); QListWidgetItemWrap::init(env, exports); diff --git a/src/index.ts b/src/index.ts index b9f50414e..25cfc442f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,6 +48,9 @@ export { QErrorMessage, QErrorMessageSignals } from './lib/QtWidgets/QErrorMessa export { QFileDialog, QFileDialogSignals } from './lib/QtWidgets/QFileDialog'; export { QFontDialog, QFontDialogSignals, FontDialogOption } from './lib/QtWidgets/QFontDialog'; export { QFrame, QFrameSignals, Shadow, Shape } from './lib/QtWidgets/QFrame'; +export { QGraphicsEffect, QGraphicsEffectSignals } from './lib/QtWidgets/QGraphicsEffect'; +export { QGraphicsBlurEffect, QGraphicsBlurEffectSignals } from './lib/QtWidgets/QGraphicsBlurEffect'; +export { QGraphicsDropShadowEffect, QGraphicsDropShadowEffectSignals } from './lib/QtWidgets/QGraphicsDropShadowEffect'; export { QLineEdit, QLineEditSignals, EchoMode } from './lib/QtWidgets/QLineEdit'; export { QMainWindow, QMainWindowSignals } from './lib/QtWidgets/QMainWindow'; export { QProgressBar, QProgressBarSignals, QProgressBarDirection } from './lib/QtWidgets/QProgressBar'; diff --git a/src/lib/QtWidgets/QGraphicsBlurEffect.ts b/src/lib/QtWidgets/QGraphicsBlurEffect.ts new file mode 100644 index 000000000..2a5c18a24 --- /dev/null +++ b/src/lib/QtWidgets/QGraphicsBlurEffect.ts @@ -0,0 +1,66 @@ +import addon from '../utils/addon'; +import { NativeElement } from '../core/Component'; +import { checkIfNativeElement } from '../utils/helpers'; +import { NodeObject } from '../QtCore/QObject'; +import { QGraphicsEffect, QGraphicsEffectSignals } from './QGraphicsEffect'; + +/** + +> The QGraphicsBlurEffect class provides a blur effect. + +* **This class is a JS wrapper around Qt's [QGraphicsBlurEffect class](https://doc.qt.io/qt-5/qgraphicsblureffect.html)** + +A blur effect blurs the source. This effect is useful for reducing details, such as when the source loses focus and you want to draw attention to other elements. + +### Example + +```javascript +const { QGraphicsBlurEffect } = require("@nodegui/nodegui"); + +const blur = new QGraphicsBlurEffect(); +blur.setBlurRadius(8); +``` + */ +export class QGraphicsBlurEffect extends QGraphicsEffect { + native: NativeElement; + constructor(); + constructor(native: NativeElement); + constructor(parent: NodeObject); + constructor(arg?: NodeObject | NativeElement) { + let native: NativeElement; + if (arg) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else { + native = new addon.QGraphicsBlurEffect(arg.native); + } + } else { + native = new addon.QGraphicsBlurEffect(); + } + super(native); + this.native = native; + } + setBlurHints(hints: BlurHint): void { + this.setProperty('blurHints', hints); + } + blurHints(): BlurHint { + return this.property('blurHints').toInt(); + } + setBlurRadius(blurRadius: number): void { + this.setProperty('blurRadius', blurRadius); + } + blurRadius(): number { + return this.property('blurRadius').toDouble(); + } +} + +export enum BlurHint { + PerformanceHint = 0x00, + QualityHint = 0x01, + AnimationHint = 0x02, +} + +export interface QGraphicsBlurEffectSignals extends QGraphicsEffectSignals { + blurHintsChanged: (hints: BlurHint) => void; + blurRadiusChanged: (radius: number) => void; +} diff --git a/src/lib/QtWidgets/QGraphicsDropShadowEffect.ts b/src/lib/QtWidgets/QGraphicsDropShadowEffect.ts new file mode 100644 index 000000000..c75c09dd9 --- /dev/null +++ b/src/lib/QtWidgets/QGraphicsDropShadowEffect.ts @@ -0,0 +1,72 @@ +import addon from '../utils/addon'; +import { NativeElement } from '../core/Component'; +import { checkIfNativeElement } from '../utils/helpers'; +import { NodeObject } from '../QtCore/QObject'; +import { QGraphicsEffect, QGraphicsEffectSignals } from './QGraphicsEffect'; +import { QColor } from '../QtGui/QColor'; + +/** + +> The QGraphicsDropShadowEffect class provides a drop shadow effect. + +* **This class is a JS wrapper around Qt's [QGraphicsDropShadowEffect class](https://doc.qt.io/qt-5/qgraphicsdropshadoweffect.html)** + +A drop shadow effect renders the source with a drop shadow. + +### Example + +```javascript +const { QGraphicsDropShadowEffect } = require("@nodegui/nodegui"); + +const shadow = new QGraphicsDropShadowEffect(); +shadow.setBlurRadius(8); +``` + */ +export class QGraphicsDropShadowEffect extends QGraphicsEffect { + native: NativeElement; + constructor(); + constructor(native: NativeElement); + constructor(parent: NodeObject); + constructor(arg?: NodeObject | NativeElement) { + let native: NativeElement; + if (arg) { + if (checkIfNativeElement(arg)) { + native = arg as NativeElement; + } else { + native = new addon.QGraphicsDropShadowEffect(arg.native); + } + } else { + native = new addon.QGraphicsDropShadowEffect(); + } + super(native); + this.native = native; + } + setBlurRadius(blurRadius: number): void { + this.setProperty('blurRadius', blurRadius); + } + blurRadius(): number { + return this.property('blurRadius').toDouble(); + } + setColor(color: QColor): void { + this.setProperty('color', color.native); + } + color(): QColor { + return QColor.fromQVariant(this.property('color')); + } + setXOffset(dx: number): void { + this.setProperty('xOffset', dx); + } + xOffset(): number { + return this.property('xOffset').toDouble(); + } + setYOffset(dy: number): void { + this.setProperty('yOffset', dy); + } + yOffset(): number { + return this.property('yOffset').toDouble(); + } +} + +export interface QGraphicsDropShadowEffectSignals extends QGraphicsEffectSignals { + blurRadiusChanged: (blurRadius: number) => void; +} diff --git a/src/lib/QtWidgets/QGraphicsEffect.ts b/src/lib/QtWidgets/QGraphicsEffect.ts new file mode 100644 index 000000000..0703e839f --- /dev/null +++ b/src/lib/QtWidgets/QGraphicsEffect.ts @@ -0,0 +1,24 @@ +import { NodeObject, QObjectSignals } from '../QtCore/QObject'; + +/** + +> This is the abstract base class of graphicseffect, providing their functionality. + +* **This class is a JS wrapper around Qt's [QGraphicsEffect class](https://doc.qt.io/qt-5/qgraphicseffect.html)** + +The QGraphicsEffect class is an abstract class and therefore, technically, no further instances actually have to be created. +It is inherited by QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffect, and QGraphicsOpacityEffect. + + */ +export abstract class QGraphicsEffect extends NodeObject { + setEnabled(enable: boolean): void { + this.setProperty('enabled', enable); + } + isEnabled(): boolean { + return this.property('enabled').toBool(); + } +} + +export interface QGraphicsEffectSignals extends QObjectSignals { + enabledChanged: (enabled: boolean) => void; +} diff --git a/src/lib/QtWidgets/QWidget.ts b/src/lib/QtWidgets/QWidget.ts index f201afc7b..b7f94bbc2 100644 --- a/src/lib/QtWidgets/QWidget.ts +++ b/src/lib/QtWidgets/QWidget.ts @@ -16,6 +16,7 @@ import { QObjectSignals } from '../QtCore/QObject'; import { QFont } from '../QtGui/QFont'; import { QAction } from './QAction'; import memoizeOne from 'memoize-one'; +import { QGraphicsEffect } from './QGraphicsEffect'; /** @@ -55,6 +56,7 @@ export abstract class NodeWidget extends YogaWid actions: Set; _rawInlineStyle = ''; type = 'widget'; + private _effect?: QGraphicsEffect | null; constructor(native: NativeElement) { super(native); this.actions = new Set(); @@ -255,6 +257,10 @@ export abstract class NodeWidget extends YogaWid repolish(): void { this.native.repolish(); } + setGraphicsEffect(effect: QGraphicsEffect): void { + this._effect = effect; + this.native.setGraphicsEffect(effect.native); + } } export interface QWidgetSignals extends QObjectSignals {