Lua: Add Widget Attribute

Change-Id: Iede7d72eb56301980ca5f98c6877c69d240208a7
Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-08-22 14:48:09 +02:00
parent 1606544cca
commit 81212f8384
4 changed files with 135 additions and 78 deletions

View File

@@ -716,6 +716,11 @@ void Widget::setWindowFlags(Qt::WindowFlags flags)
access(this)->setWindowFlags(flags);
}
void Widget::setWidgetAttribute(Qt::WidgetAttribute attr, bool on)
{
access(this)->setAttribute(attr, on);
}
void Widget::setToolTip(const QString &title)
{
access(this)->setToolTip(title);

View File

@@ -225,6 +225,7 @@ public:
void setSize(int, int);
void setWindowTitle(const QString &);
void setWindowFlags(Qt::WindowFlags);
void setWidgetAttribute(Qt::WidgetAttribute, bool on);
void setToolTip(const QString &);
void setNoMargins(int = 0);
void setNormalMargins(int = 0);
@@ -425,6 +426,7 @@ QTC_DEFINE_BUILDER_SETTER(toolTip, setToolTip)
QTC_DEFINE_BUILDER_SETTER(windowTitle, setWindowTitle)
QTC_DEFINE_BUILDER_SETTER(wordWrap, setWordWrap);
QTC_DEFINE_BUILDER_SETTER(windowFlags, setWindowFlags);
QTC_DEFINE_BUILDER_SETTER(widgetAttribute, setWidgetAttribute);
// Nesting dispatchers

View File

@@ -8,6 +8,8 @@
#include <utils/aspects.h>
#include <utils/layoutbuilder.h>
#include <QMetaEnum>
using namespace Layouting;
using namespace Utils;
@@ -95,6 +97,7 @@ HAS_MEM_FUNC(setTitle, hasSetTitle);
HAS_MEM_FUNC(setValue, hasSetValue);
HAS_MEM_FUNC(setSize, hasSetSize);
HAS_MEM_FUNC(setWindowFlags, hasSetWindowFlags);
HAS_MEM_FUNC(setWidgetAttribute, hasSetWidgetAttribute);
template<class T>
void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject *guard)
@@ -116,6 +119,16 @@ void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject
item->setSize(size->width(), size->height());
}
if constexpr (hasSetWidgetAttribute<T, void (T::*)(Qt::WidgetAttribute, bool on)>::value) {
sol::optional<sol::table> widgetAttributes = children.get<sol::optional<sol::table>>(
"widgetAttributes");
if (widgetAttributes) {
for (const auto &kv : *widgetAttributes)
item->setWidgetAttribute(
static_cast<Qt::WidgetAttribute>(kv.first.as<int>()), kv.second.as<bool>());
}
}
if constexpr (hasOnTextChanged<T, void (T::*)(const QString &)>::value) {
sol::optional<sol::protected_function> onTextChanged
= children.get<sol::optional<sol::protected_function>>("onTextChanged");
@@ -369,85 +382,14 @@ void setupGuiModule()
sol::base_classes,
sol::bases<Object, Thing>());
gui["WindowType"] = l.create_table_with(
"Widget",
Qt::Widget,
"Window",
Qt::Window,
"Dialog",
Qt::Dialog,
"Sheet",
Qt::Sheet,
"Drawer",
Qt::Drawer,
"Popup",
Qt::Popup,
"Tool",
Qt::Tool,
"ToolTip",
Qt::ToolTip,
"SplashScreen",
Qt::SplashScreen,
"Desktop",
Qt::Desktop,
"SubWindow",
Qt::SubWindow,
"ForeignWindow",
Qt::ForeignWindow,
"CoverWindow",
Qt::CoverWindow,
auto mirrorEnum = [&gui](QMetaEnum metaEnum) {
sol::table widgetAttributes = gui.create(metaEnum.name());
for (int i = 0; i < metaEnum.keyCount(); ++i)
widgetAttributes.set(metaEnum.key(i), metaEnum.value(i));
};
"WindowType_Mask",
Qt::WindowType_Mask,
"MSWindowsFixedSizeDialogHint",
Qt::MSWindowsFixedSizeDialogHint,
"MSWindowsOwnDC",
Qt::MSWindowsOwnDC,
"BypassWindowManagerHint",
Qt::BypassWindowManagerHint,
"X11BypassWindowManagerHint",
Qt::X11BypassWindowManagerHint,
"FramelessWindowHint",
Qt::FramelessWindowHint,
"WindowTitleHint",
Qt::WindowTitleHint,
"WindowSystemMenuHint",
Qt::WindowSystemMenuHint,
"WindowMinimizeButtonHint",
Qt::WindowMinimizeButtonHint,
"WindowMaximizeButtonHint",
Qt::WindowMaximizeButtonHint,
"WindowMinMaxButtonsHint",
Qt::WindowMinMaxButtonsHint,
"WindowContextHelpButtonHint",
Qt::WindowContextHelpButtonHint,
"WindowShadeButtonHint",
Qt::WindowShadeButtonHint,
"WindowStaysOnTopHint",
Qt::WindowStaysOnTopHint,
"WindowTransparentForInput",
Qt::WindowTransparentForInput,
"WindowOverridesSystemGestures",
Qt::WindowOverridesSystemGestures,
"WindowDoesNotAcceptFocus",
Qt::WindowDoesNotAcceptFocus,
"MaximizeUsingFullscreenGeometryHint",
Qt::MaximizeUsingFullscreenGeometryHint,
"CustomizeWindowHint",
Qt::CustomizeWindowHint,
"WindowStaysOnBottomHint",
Qt::WindowStaysOnBottomHint,
"WindowCloseButtonHint",
Qt::WindowCloseButtonHint,
"MacWindowToolBarButtonHint",
Qt::MacWindowToolBarButtonHint,
"BypassGraphicsProxyWidget",
Qt::BypassGraphicsProxyWidget,
"NoDropShadowWindowHint",
Qt::NoDropShadowWindowHint,
"WindowFullscreenButtonHint",
Qt::WindowFullscreenButtonHint);
mirrorEnum(QMetaEnum::fromType<Qt::WidgetAttribute>());
mirrorEnum(QMetaEnum::fromType<Qt::WindowType>());
gui.new_usertype<Stack>(
"Stack",

View File

@@ -17,9 +17,12 @@ gui.widget = {}
---@alias LayoutChild string|BaseAspect|Layout|Widget|function
---@alias LayoutChildren LayoutChild[]
---@class WidgetAttributeMapT<T>: { [WidgetAttribute]: T }
---@class (exact) BaseWidgetOptions
---@field size? integer[] Two integers, representing the width and height of the widget.
---@field windowFlags? WindowType[] The window flags of the widget.
---@field widgetAttributes? WidgetAttributeMapT<boolean> The widget attributes of the widget.
gui.baseWidgetOptions = {}
---@class (exact) WidgetOptions : BaseWidgetOptions
@@ -247,6 +250,111 @@ gui.WindowType = {
WindowFullscreenButtonHint = 0,
}
---@enum (key) WidgetAttribute
gui.WidgetAttribute = {
WA_Disabled = 0,
WA_UnderMouse = 0,
WA_MouseTracking = 0,
WA_OpaquePaintEvent = 0,
WA_StaticContents = 0,
WA_LaidOut = 0,
WA_PaintOnScreen = 0,
WA_NoSystemBackground = 0,
WA_UpdatesDisabled = 0,
WA_Mapped = 0,
WA_InputMethodEnabled = 0,
WA_WState_Visible = 0,
WA_WState_Hidden = 0,
WA_ForceDisabled = 0,
WA_KeyCompression = 0,
WA_PendingMoveEvent = 0,
WA_PendingResizeEvent = 0,
WA_SetPalette = 0,
WA_SetFont = 0,
WA_SetCursor = 0,
WA_NoChildEventsFromChildren = 0,
WA_WindowModified = 0,
WA_Resized = 0,
WA_Moved = 0,
WA_PendingUpdate = 0,
WA_InvalidSize = 0,
WA_CustomWhatsThis = 0,
WA_LayoutOnEntireRect = 0,
WA_OutsideWSRange = 0,
WA_GrabbedShortcut = 0,
WA_TransparentForMouseEvents = 0,
WA_PaintUnclipped = 0,
WA_SetWindowIcon = 0,
WA_NoMouseReplay = 0,
WA_DeleteOnClose = 0,
WA_RightToLeft = 0,
WA_SetLayoutDirection = 0,
WA_NoChildEventsForParent = 0,
WA_ForceUpdatesDisabled = 0,
WA_WState_Created = 0,
WA_WState_CompressKeys = 0,
WA_WState_InPaintEvent = 0,
WA_WState_Reparented = 0,
WA_WState_ConfigPending = 0,
WA_WState_Polished = 0,
WA_WState_OwnSizePolicy = 0,
WA_WState_ExplicitShowHide = 0,
WA_ShowModal = 0,
WA_MouseNoMask = 0,
WA_NoMousePropagation = 0,
WA_Hover = 0,
WA_InputMethodTransparent = 0,
WA_QuitOnClose = 0,
WA_KeyboardFocusChange = 0,
WA_AcceptDrops = 0,
WA_DropSiteRegistered = 0,
WA_WindowPropagation = 0,
WA_NoX11EventCompression = 0,
WA_TintedBackground = 0,
WA_X11OpenGLOverlay = 0,
WA_AlwaysShowToolTips = 0,
WA_MacOpaqueSizeGrip = 0,
WA_SetStyle = 0,
WA_SetLocale = 0,
WA_MacShowFocusRect = 0,
WA_MacNormalSize = 0,
WA_MacSmallSize = 0,
WA_MacMiniSize = 0,
WA_LayoutUsesWidgetRect = 0,
WA_StyledBackground = 0,
WA_CanHostQMdiSubWindowTitleBar = 0,
WA_MacAlwaysShowToolWindow = 0,
WA_StyleSheet = 0,
WA_ShowWithoutActivating = 0,
WA_X11BypassTransientForHint = 0,
WA_NativeWindow = 0,
WA_DontCreateNativeAncestors = 0,
WA_DontShowOnScreen = 0,
WA_X11NetWmWindowTypeDesktop = 0,
WA_X11NetWmWindowTypeDock = 0,
WA_X11NetWmWindowTypeToolBar = 0,
WA_X11NetWmWindowTypeMenu = 0,
WA_X11NetWmWindowTypeUtility = 0,
WA_X11NetWmWindowTypeSplash = 0,
WA_X11NetWmWindowTypeDialog = 0,
WA_X11NetWmWindowTypeDropDownMenu = 0,
WA_X11NetWmWindowTypePopupMenu = 0,
WA_X11NetWmWindowTypeToolTip = 0,
WA_X11NetWmWindowTypeNotification = 0,
WA_X11NetWmWindowTypeCombo = 0,
WA_X11NetWmWindowTypeDND = 0,
WA_SetWindowModality = 0,
WA_WState_WindowOpacitySet = 0,
WA_TranslucentBackground = 0,
WA_AcceptTouchEvents = 0,
WA_WState_AcceptedTouchBeginEvent = 0,
WA_TouchPadAcceptSingleTouchEvents = 0,
WA_X11DoNotAcceptFocus = 0,
WA_AlwaysStackOnTop = 0,
WA_TabletTracking = 0,
WA_ContentsMarginsRespectsSafeArea = 0,
WA_StyleSheetTarget = 0
}
---@class Space : Layout
gui.space = {}