forked from qt-creator/qt-creator
Lua: Export sizePolicy parameter for Widgets
Extend lua bindings to support horizontal and vertical size policies. Change-Id: I663b17bd11086efd2cbf430aace800fde55b6c0d Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
committed by
Marcus Tillmanns
parent
08870178bb
commit
91fcdcce2d
@@ -20,6 +20,7 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QSize>
|
#include <QSize>
|
||||||
|
#include <QSizePolicy>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
@@ -791,6 +792,11 @@ void Widget::setCursor(Qt::CursorShape shape)
|
|||||||
access(this)->setCursor(shape);
|
access(this)->setCursor(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::setSizePolicy(const QSizePolicy &policy)
|
||||||
|
{
|
||||||
|
access(this)->setSizePolicy(policy);
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::activateWindow()
|
void Widget::activateWindow()
|
||||||
{
|
{
|
||||||
access(this)->activateWindow();
|
access(this)->activateWindow();
|
||||||
|
@@ -31,6 +31,7 @@ class QObject;
|
|||||||
class QPushButton;
|
class QPushButton;
|
||||||
class QScrollArea;
|
class QScrollArea;
|
||||||
class QSize;
|
class QSize;
|
||||||
|
class QSizePolicy;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
@@ -250,6 +251,7 @@ public:
|
|||||||
void setAutoFillBackground(bool);
|
void setAutoFillBackground(bool);
|
||||||
void setLayout(const Layout &layout);
|
void setLayout(const Layout &layout);
|
||||||
void setSize(int, int);
|
void setSize(int, int);
|
||||||
|
void setSizePolicy(const QSizePolicy &policy);
|
||||||
void setFixedSize(const QSize &);
|
void setFixedSize(const QSize &);
|
||||||
void setWindowTitle(const QString &);
|
void setWindowTitle(const QString &);
|
||||||
void setWindowFlags(Qt::WindowFlags);
|
void setWindowFlags(Qt::WindowFlags);
|
||||||
@@ -537,6 +539,7 @@ QTC_DEFINE_BUILDER_SETTER(widgetAttribute, setWidgetAttribute);
|
|||||||
QTC_DEFINE_BUILDER_SETTER(autoFillBackground, setAutoFillBackground);
|
QTC_DEFINE_BUILDER_SETTER(autoFillBackground, setAutoFillBackground);
|
||||||
QTC_DEFINE_BUILDER_SETTER(readOnly, setReadOnly);
|
QTC_DEFINE_BUILDER_SETTER(readOnly, setReadOnly);
|
||||||
QTC_DEFINE_BUILDER_SETTER(markdown, setMarkdown);
|
QTC_DEFINE_BUILDER_SETTER(markdown, setMarkdown);
|
||||||
|
QTC_DEFINE_BUILDER_SETTER(sizePolicy, setSizePolicy);
|
||||||
QTC_DEFINE_BUILDER_SETTER(basePath, setBasePath);
|
QTC_DEFINE_BUILDER_SETTER(basePath, setBasePath);
|
||||||
QTC_DEFINE_BUILDER_SETTER(fixedSize, setFixedSize);
|
QTC_DEFINE_BUILDER_SETTER(fixedSize, setFixedSize);
|
||||||
|
|
||||||
|
@@ -88,6 +88,7 @@ CREATE_HAS_FUNC(onTextChanged, nullptr, nullptr)
|
|||||||
CREATE_HAS_FUNC(onClicked, nullptr, nullptr)
|
CREATE_HAS_FUNC(onClicked, nullptr, nullptr)
|
||||||
CREATE_HAS_FUNC(setText, QString())
|
CREATE_HAS_FUNC(setText, QString())
|
||||||
CREATE_HAS_FUNC(setMarkdown, QString())
|
CREATE_HAS_FUNC(setMarkdown, QString())
|
||||||
|
CREATE_HAS_FUNC(setSizePolicy, QSizePolicy())
|
||||||
CREATE_HAS_FUNC(setReadOnly, bool())
|
CREATE_HAS_FUNC(setReadOnly, bool())
|
||||||
CREATE_HAS_FUNC(setTitle, QString())
|
CREATE_HAS_FUNC(setTitle, QString())
|
||||||
CREATE_HAS_FUNC(setValue, int())
|
CREATE_HAS_FUNC(setValue, int())
|
||||||
@@ -290,6 +291,19 @@ void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject
|
|||||||
if (markdown)
|
if (markdown)
|
||||||
item->setMarkdown(*markdown);
|
item->setMarkdown(*markdown);
|
||||||
}
|
}
|
||||||
|
if constexpr (has_setSizePolicy<T>) {
|
||||||
|
auto sizePolicy = children.get<sol::optional<sol::table>>("sizePolicy");
|
||||||
|
if (sizePolicy) {
|
||||||
|
QTC_ASSERT(
|
||||||
|
sizePolicy->size() == 2,
|
||||||
|
throw sol::error(
|
||||||
|
"sizePolicy must be array of 2 elements: horizontalPolicy, verticalPolicy.")
|
||||||
|
);
|
||||||
|
auto horizontalPolicy = sizePolicy->get<QSizePolicy::Policy>(1);
|
||||||
|
auto verticalPolicy = sizePolicy->get<QSizePolicy::Policy>(2);
|
||||||
|
item->setSizePolicy(QSizePolicy(horizontalPolicy, verticalPolicy));
|
||||||
|
}
|
||||||
|
}
|
||||||
if constexpr (has_setTitle<T>) {
|
if constexpr (has_setTitle<T>) {
|
||||||
item->setTitle(children.get_or<QString>("title", ""));
|
item->setTitle(children.get_or<QString>("title", ""));
|
||||||
}
|
}
|
||||||
@@ -552,6 +566,9 @@ void setupGuiModule()
|
|||||||
mirrorEnum(gui, QMetaEnum::fromType<Qt::TextInteractionFlag>());
|
mirrorEnum(gui, QMetaEnum::fromType<Qt::TextInteractionFlag>());
|
||||||
mirrorEnum(gui, QMetaEnum::fromType<Qt::CursorShape>());
|
mirrorEnum(gui, QMetaEnum::fromType<Qt::CursorShape>());
|
||||||
|
|
||||||
|
auto sizePolicy = gui.create_named("QSizePolicy");
|
||||||
|
mirrorEnum(sizePolicy, QMetaEnum::fromType<QSizePolicy::Policy>());
|
||||||
|
|
||||||
gui.new_usertype<Stack>(
|
gui.new_usertype<Stack>(
|
||||||
"Stack",
|
"Stack",
|
||||||
sol::call_constructor,
|
sol::call_constructor,
|
||||||
|
@@ -26,6 +26,7 @@ gui.widget = {}
|
|||||||
---@field windowFlags? WindowType[] The window flags of the widget.
|
---@field windowFlags? WindowType[] The window flags of the widget.
|
||||||
---@field widgetAttributes? WidgetAttributeMapT<boolean> The widget attributes of the widget.
|
---@field widgetAttributes? WidgetAttributeMapT<boolean> The widget attributes of the widget.
|
||||||
---@field autoFillBackground? boolean A boolean, representing whether the widget should automatically fill its background.
|
---@field autoFillBackground? boolean A boolean, representing whether the widget should automatically fill its background.
|
||||||
|
---@field sizePolicy? SizePolicy.Policy[] Two size policies of the widget, horizontal and vertical.
|
||||||
gui.baseWidgetOptions = {}
|
gui.baseWidgetOptions = {}
|
||||||
|
|
||||||
---@class (exact) WidgetOptions : BaseWidgetOptions
|
---@class (exact) WidgetOptions : BaseWidgetOptions
|
||||||
@@ -460,6 +461,20 @@ gui.CursorShape = {
|
|||||||
CustomCursor = 0
|
CustomCursor = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.SizePolicy = {
|
||||||
|
--- Enum representing size policy.
|
||||||
|
---@enum Policy
|
||||||
|
Policy = {
|
||||||
|
Fixed = 0,
|
||||||
|
Minimum = 0,
|
||||||
|
Maximum = 0,
|
||||||
|
Preferred = 0,
|
||||||
|
MinimumExpanding = 0,
|
||||||
|
Expanding = 0,
|
||||||
|
Ignored = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
---@class Space : Layout
|
---@class Space : Layout
|
||||||
gui.space = {}
|
gui.space = {}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user