forked from qt-creator/qt-creator
Lua: Expose LineEdit type to lua
Change-Id: Icd74bd5c9af12bbf737fca29417d011f9c58de81 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "filepath.h"
|
||||
#include "icon.h"
|
||||
#include "qtcassert.h"
|
||||
#include "fancylineedit.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QFormLayout>
|
||||
@@ -1096,6 +1097,52 @@ void addToLayout(Layout *layout, const Stretch &inner)
|
||||
lt->addStretch(inner.stretch);
|
||||
}
|
||||
|
||||
LineEdit::LineEdit(std::initializer_list<I> ps)
|
||||
{
|
||||
ptr = new Implementation;
|
||||
apply(this, ps);
|
||||
}
|
||||
|
||||
QString LineEdit::text() const
|
||||
{
|
||||
return access(this)->text();
|
||||
}
|
||||
|
||||
void LineEdit::setRightSideIconPath(const Utils::FilePath &path)
|
||||
{
|
||||
if (!path.isEmpty()) {
|
||||
QIcon icon(path.toFSPathString());
|
||||
QTC_CHECK(!icon.isNull());
|
||||
access(this)->setButtonIcon(Utils::FancyLineEdit::Right, icon);
|
||||
access(this)->setButtonVisible(Utils::FancyLineEdit::Right, !icon.isNull());
|
||||
}
|
||||
}
|
||||
|
||||
void LineEdit::setPlaceHolderText(const QString &text)
|
||||
{
|
||||
access(this)->setPlaceholderText(text);
|
||||
}
|
||||
|
||||
void LineEdit::setCompleter(QCompleter *completer)
|
||||
{
|
||||
access(this)->setSpecialCompleter(completer);
|
||||
}
|
||||
|
||||
void LineEdit::setMinimumHeight(int height)
|
||||
{
|
||||
access(this)->setMinimumHeight(height);
|
||||
}
|
||||
|
||||
void LineEdit::onReturnPressed(const std::function<void ()> &func)
|
||||
{
|
||||
QObject::connect(access(this), &Utils::FancyLineEdit::returnPressed, func);
|
||||
}
|
||||
|
||||
void LineEdit::onRightSideIconClicked(const std::function<void ()> &func)
|
||||
{
|
||||
QObject::connect(access(this), &Utils::FancyLineEdit::rightButtonClicked, func);
|
||||
}
|
||||
|
||||
// void createItem(LayoutItem *item, QWidget *t)
|
||||
// {
|
||||
// if (auto l = qobject_cast<QLabel *>(t))
|
||||
|
@@ -20,6 +20,7 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QBoxLayout;
|
||||
class QCompleter;
|
||||
class QFormLayout;
|
||||
class QGridLayout;
|
||||
class QGroupBox;
|
||||
@@ -41,6 +42,7 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
class FancyLineEdit;
|
||||
class FilePath;
|
||||
} // Utils
|
||||
|
||||
@@ -322,6 +324,24 @@ public:
|
||||
void setReadOnly(bool);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT LineEdit : public Widget
|
||||
{
|
||||
public:
|
||||
using Implementation = Utils::FancyLineEdit;
|
||||
using I = Building::BuilderItem<LineEdit>;
|
||||
using Id = Implementation *;
|
||||
|
||||
LineEdit(std::initializer_list<I> ps);
|
||||
|
||||
QString text() const;
|
||||
void setRightSideIconPath(const Utils::FilePath &path);
|
||||
void setPlaceHolderText(const QString &text);
|
||||
void setCompleter(QCompleter *completer);
|
||||
void setMinimumHeight(int height);
|
||||
void onReturnPressed(const std::function<void()> &);
|
||||
void onRightSideIconClicked(const std::function<void()> &);
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT Splitter : public Widget
|
||||
{
|
||||
public:
|
||||
|
@@ -107,9 +107,54 @@ HAS_MEM_FUNC(setIconPath, hasSetIconPath);
|
||||
HAS_MEM_FUNC(setFlat, hasSetFlat);
|
||||
HAS_MEM_FUNC(setOpenExternalLinks, hasSetOpenExternalLinks);
|
||||
HAS_MEM_FUNC(setIconSize, hasSetIconSize);
|
||||
HAS_MEM_FUNC(setRightSideIconPath, hasSetRightSideIconPath);
|
||||
HAS_MEM_FUNC(setPlaceHolderText, hasSetPlaceHolderText);
|
||||
HAS_MEM_FUNC(setCompleter, hasSetCompleter);
|
||||
HAS_MEM_FUNC(setMinimumHeight, hasSetMinimumHeight);
|
||||
HAS_MEM_FUNC(onReturnPressed, hasOnReturnPressed);
|
||||
HAS_MEM_FUNC(onRightSideIconClicked, hasOnRightSideIconClicked);
|
||||
|
||||
|
||||
template<class T>
|
||||
void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject *guard) {
|
||||
if constexpr (hasSetRightSideIconPath<T, void (T::*)(const Utils::FilePath &)>::value) {
|
||||
const auto path = children.get<sol::optional<Utils::FilePath>>("rightSideIconPath");
|
||||
if (path)
|
||||
item->setRightSideIconPath(*path);
|
||||
}
|
||||
|
||||
if constexpr (hasSetPlaceHolderText<T, void (T::*)(const QString &)>::value) {
|
||||
const auto text = children.get<sol::optional<QString>>("placeHolderText");
|
||||
if (text)
|
||||
item->setPlaceHolderText(*text);
|
||||
}
|
||||
|
||||
if constexpr (hasSetCompleter<T, void (T::*)(QCompleter *)>::value) {
|
||||
const auto completer = children.get<QCompleter *>("completer");
|
||||
if (completer)
|
||||
item->setCompleter(completer);
|
||||
}
|
||||
|
||||
if constexpr (hasSetMinimumHeight<T, void (T::*)(int)>::value) {
|
||||
const auto minHeight = children.get<sol::optional<int>>("minimumHeight");
|
||||
if (minHeight)
|
||||
item->setMinimumHeight(*minHeight);
|
||||
}
|
||||
|
||||
if constexpr (hasOnReturnPressed<T, void (T::*)(const std::function<void()> &)>::value) {
|
||||
const auto callback = children.get<sol::optional<sol::function>>("onReturnPressed");
|
||||
if (callback)
|
||||
{
|
||||
item->onReturnPressed([func = *callback]() { void_safe_call(func); });
|
||||
}
|
||||
}
|
||||
|
||||
if constexpr (hasOnRightSideIconClicked<T, void (T::*)(const std::function<void()> &)>::value) {
|
||||
const auto callback = children.get<sol::optional<sol::function>>("onRightSideIconClicked");
|
||||
if (callback)
|
||||
item->onRightSideIconClicked([func = *callback]() { void_safe_call(func); });
|
||||
}
|
||||
|
||||
if constexpr (hasSetFlat<T, void (T::*)(bool)>::value) {
|
||||
const auto flat = children.get<sol::optional<bool>>("flat");
|
||||
if (flat)
|
||||
@@ -467,6 +512,17 @@ void setupGuiModule()
|
||||
sol::base_classes,
|
||||
sol::bases<Widget, Object, Thing>());
|
||||
|
||||
gui.new_usertype<LineEdit>(
|
||||
"LineEdit",
|
||||
sol::call_constructor,
|
||||
sol::factories([guard](const sol::table &children) {
|
||||
return constructWidgetType<LineEdit>(children, guard);
|
||||
}),
|
||||
"text",
|
||||
sol::property(&LineEdit::text),
|
||||
sol::base_classes,
|
||||
sol::bases<Widget, Object, Thing>());
|
||||
|
||||
gui.new_usertype<SpinBox>(
|
||||
"SpinBox",
|
||||
sol::call_constructor,
|
||||
|
@@ -137,6 +137,18 @@ function textEdit:markdown() end
|
||||
---@return TextEdit
|
||||
function gui.TextEdit(options) end
|
||||
|
||||
---A Single line text edit
|
||||
---@class LineEdit : Widget
|
||||
---@field rightSideIconPath? FilePath A path to icon
|
||||
---@field placeHolderText? string A placeholder text for intput
|
||||
---@field completer? QCompleter A QCompleter object.
|
||||
---@field minimumHeight? int Minimum height of input
|
||||
---@field onReturnPressed? function The function to be called when Enter is pressed
|
||||
---@field onRightSideIconClicked? function The function to be called when right side icon is clicked
|
||||
---@field text string Current text
|
||||
|
||||
local lineEdit = {}
|
||||
|
||||
---@class PushButton : Widget
|
||||
local pushButton = {}
|
||||
|
||||
|
Reference in New Issue
Block a user