diff --git a/src/plugins/lua/bindings/layout.cpp b/src/plugins/lua/bindings/layout.cpp index bd99b80d9be..0ba62be101b 100644 --- a/src/plugins/lua/bindings/layout.cpp +++ b/src/plugins/lua/bindings/layout.cpp @@ -137,12 +137,52 @@ std::unique_ptr constructWidgetType(const sol::table &children, QObject *guar return item; } +std::unique_ptr constructTabFromTable(const sol::table &children) +{ + if (children.size() != 2) + throw sol::error("Tab must have exactly two children"); + + auto tabName = children[1]; + if (tabName.get_type() != sol::type::string) + throw sol::error("Tab name (first argument) must be a string"); + + const auto &layout = children[2]; + if (!layout.is()) + throw sol::error("Tab child (second argument) must be a Layout"); + + std::unique_ptr item = std::make_unique(tabName, *layout.get()); + return item; +} + std::unique_ptr constructTab(const QString &tabName, const Layout &layout) { std::unique_ptr item = std::make_unique(tabName, layout); return item; } +std::unique_ptr constructSpanFromTable(const sol::table &children) +{ + if (children.size() != 2) + throw sol::error("Span must have exactly two children"); + + auto spanSize = children[1]; + if (spanSize.get_type() != sol::type::number) + throw sol::error("Span size (first argument) must be a number"); + + const auto &layout = children[2]; + if (!layout.is()) + throw sol::error("Span child (second argument) must be a Layout"); + + std::unique_ptr item = std::make_unique(spanSize, *layout.get()); + return item; +} + +std::unique_ptr constructSpan(int n, const Layout &layout) +{ + std::unique_ptr item = std::make_unique(n, layout); + return item; +} + std::unique_ptr constructTabWidget(const sol::table &children, QObject *guard) { std::unique_ptr item(new TabWidget({})); @@ -183,7 +223,7 @@ void addLayoutModule() sol::table layout = l.create_table(); layout.new_usertype( - "Span", sol::call_constructor, sol::constructors()); + "Span", sol::call_constructor, sol::factories(&constructSpan, &constructSpanFromTable)); layout.new_usertype("Space", sol::call_constructor, sol::constructors()); @@ -268,7 +308,7 @@ void addLayoutModule() layout.new_usertype( "Tab", sol::call_constructor, - sol::factories(&constructTab), + sol::factories(&constructTab, &constructTabFromTable), sol::base_classes, sol::bases()); @@ -327,6 +367,8 @@ void addLayoutModule() layout["hr"] = &hr; layout["noMargin"] = &noMargin; layout["normalMargin"] = &normalMargin; + layout["withFormAlignment"] = &withFormAlignment; + layout["spacing"] = &spacing; return layout; }); diff --git a/src/plugins/lua/meta/layout.lua b/src/plugins/lua/meta/layout.lua index fb255027809..90c44322405 100644 --- a/src/plugins/lua/meta/layout.lua +++ b/src/plugins/lua/meta/layout.lua @@ -2,98 +2,99 @@ local layout = {} ----The base class of all layout items ----@class LayoutItem -layout.LayoutItem = { - ---Attaches the layout to the specified widget - ---@param widget QWidget - attachTo = function(widget) end -} +---The base class of all layout classes +---@class Object +layout.Layout = {} + +---The base class of all layout classes +---@class Layout : Object +layout.Layout = {} + +---The base class of all widget classes, an empty widget itself. +---@class Widget : Object +Widget = {} + +---@param children Layout +---@return Widget +function layout.Widget(children) end ---Column layout ----@class Column : LayoutItem +---@class Column : Layout local column = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Column function layout.Column(children) end ---A group box with a title ----@class Group : LayoutItem +---@class Group : Widget local group = {} ---@return Group function layout.Group(children) end ---Row layout ----@class Row : LayoutItem +---@class Row : Layout local row = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Row function layout.Row(children) end ---Flow layout ----@class Flow : LayoutItem +---@class Flow : Layout local flow = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Flow function layout.Flow(children) end ---Grid layout ----@class Grid : LayoutItem +---@class Grid : Layout local grid = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Grid function layout.Grid(children) end ---Form layout ----@class Form : LayoutItem +---@class Form : Layout local form = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Form function layout.Form(children) end ----An empty widget ----@class Widget : LayoutItem -local widget = {} - ----@param children LayoutItem|string|BaseAspect|function ----@return Widget -function layout.Widget(children) end ---A stack of multiple widgets ----@class Stack : LayoutItem +---@class Stack : Widget local stack = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Stack function layout.Stack(children) end ---A Tab widget ----@class Tab : LayoutItem +---@class Tab : Widget local tab = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Tab function layout.Tab(children) end ---A Multiline text edit ----@class TextEdit : LayoutItem +---@class TextEdit : Widget local textEdit = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return TextEdit function layout.TextEdit(children) end ---A PushButton ----@class PushButton : LayoutItem +---@class PushButton : Widget local pushButton = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return PushButton function layout.PushButton(children) end @@ -106,37 +107,41 @@ local label = {} function layout.Label(children) end ---A SpinBox ----@class SpinBox : LayoutItem +---@class SpinBox : Widget local spinBox = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return SpinBox function layout.SpinBox(children) end ---A Splitter ----@class Splitter : LayoutItem +---@class Splitter : Widget local splitter = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return Splitter function layout.Splitter(children) end ---A Toolbar ----@class ToolBar : LayoutItem +---@class ToolBar : Widget local toolBar = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return ToolBar function layout.ToolBar(children) end ---A TabWidget ----@class TabWidget : LayoutItem +---@class TabWidget : Widget local tabWidget = {} ----@param children LayoutItem|string|BaseAspect|function +---@param children Layout|string|BaseAspect|function ---@return TabWidget function layout.TabWidget(children) end +---@param name string +---@param child Layout|string|BaseAspect|function +---@return TabWidget +function layout.TabWidget(name, child) end ---A "Line break" in the layout function layout.br() end @@ -155,33 +160,15 @@ function layout.noMargin() end ---Sets the margin of the layout to the default value function layout.normalMargin() end ----Sets the margin of the layout to a custom value -function layout.customMargin(left, top, right, bottom) end - ---Sets the alignment of the layout to "Form" function layout.withFormAlignment() end ----Sets the title of the parent object if possible -function layout.title(text) end - ----Sets the text of the parent object if possible -function layout.text(text) end - ----Sets the tooltip of the parent object if possible -function layout.tooltip(text) end - ---Sets the size of the parent object if possible function layout.resize(width, height) end ----Sets the stretch of the column at `index` -function layout.columnStretch(index, stretch) end - ---Sets the spacing of the layout function layout.spacing(spacing) end ----Sets the window title of the parent object if possible -function layout.windowTitle(text) end - ---Sets the field growth policy of the layout function layout.fieldGrowthPolicy(policy) end