Lua: Expose extra properties from StringAspect

Change-Id: Ia50ce5df53c155bfcad8df84d7af5f2ac65b28fd
Reviewed-by: <lie@spyro-soft.com>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Artur Twardy
2024-09-27 16:55:19 +02:00
parent c7a0fee1fd
commit 6e4e60f54e
7 changed files with 74 additions and 0 deletions

View File

@@ -957,6 +957,10 @@ public:
bool m_autoApplyOnEditingFinished = false;
bool m_validatePlaceHolder = false;
FilePath m_rightSideIconPath;
int m_minimumHeight = 0;
QPointer<QCompleter> m_completer;
UndoableValue<QString> undoable;
};
@@ -1205,6 +1209,20 @@ void StringAspect::addToLayoutImpl(Layout &parent)
auto lineEditDisplay = createSubWidget<FancyLineEdit>();
addMacroExpansion(lineEditDisplay);
lineEditDisplay->setPlaceholderText(d->m_placeHolderText);
lineEditDisplay->setMinimumHeight(d->m_minimumHeight);
if (d->m_completer)
lineEditDisplay->setSpecialCompleter(d->m_completer);
if (!d->m_rightSideIconPath.isEmpty()) {
QIcon icon(d->m_rightSideIconPath.toFSPathString());
QTC_CHECK(!icon.isNull());
lineEditDisplay->setButtonIcon(FancyLineEdit::Right, icon);
lineEditDisplay->setButtonVisible(FancyLineEdit::Right, true);
connect(lineEditDisplay, &FancyLineEdit::rightButtonClicked,
this, &StringAspect::rightSideIconClicked);
}
if (!d->m_historyCompleterKey.isEmpty())
lineEditDisplay->setHistoryCompleter(d->m_historyCompleterKey);
@@ -1418,6 +1436,27 @@ void StringAspect::setChecked(bool checked)
return d->m_checkerImpl.setChecked(checked);
}
void StringAspect::addOnRightSideIconClicked(QObject *guard,
const std::function<void ()> &callback)
{
connect(this, &StringAspect::rightSideIconClicked, guard, callback);
}
void StringAspect::setMinimumHeight(int height)
{
d->m_minimumHeight = height;
}
void StringAspect::setCompleter(QCompleter *completer)
{
d->m_completer = completer;
}
void StringAspect::setRightSideIconPath(const FilePath &path)
{
d->m_rightSideIconPath = path;
}
/*!
\class Utils::FilePathAspect

View File

@@ -633,6 +633,11 @@ public:
bool isChecked() const;
void setChecked(bool checked);
void setRightSideIconPath(const FilePath &path);
void addOnRightSideIconClicked(QObject *guard, const std::function<void()> &);
void setMinimumHeight(int);
void setCompleter(QCompleter *completer);
enum DisplayStyle {
LabelDisplay,
LineEditDisplay,
@@ -652,6 +657,7 @@ signals:
void acceptRichTextChanged(bool acceptRichText);
void validationFunctionChanged(const FancyLineEdit::ValidationFunction &validator);
void placeholderTextChanged(const QString &placeholderText);
void rightSideIconClicked();
protected:
void addToLayoutImpl(Layouting::Layout &parent) override;

View File

@@ -13,6 +13,7 @@
#include <QGroupBox>
#include <QLabel>
#include <QPushButton>
#include <QSize>
#include <QSpacerItem>
#include <QSpinBox>
#include <QSplitter>
@@ -897,6 +898,11 @@ void PushButton::setIconPath(const Utils::FilePath &iconPath)
access(this)->setIcon(icon.icon());
}
void PushButton::setIconSize(const QSize &size)
{
access(this)->setIconSize(size);
}
void PushButton::setFlat(bool flat)
{
access(this)->setFlat(flat);

View File

@@ -28,6 +28,7 @@ class QLabel;
class QLayout;
class QObject;
class QPushButton;
class QSize;
class QSpinBox;
class QSplitter;
class QStackedWidget;
@@ -295,6 +296,7 @@ public:
void setText(const QString &);
void setIconPath(const Utils::FilePath &);
void setIconSize(const QSize &);
void setFlat(bool);
void onClicked(const std::function<void()> &, QObject *guard);
};

View File

@@ -106,6 +106,7 @@ HAS_MEM_FUNC(setAutoFillBackground, hasSetAutoFillBackground);
HAS_MEM_FUNC(setIconPath, hasSetIconPath);
HAS_MEM_FUNC(setFlat, hasSetFlat);
HAS_MEM_FUNC(setOpenExternalLinks, hasSetOpenExternalLinks);
HAS_MEM_FUNC(setIconSize, hasSetIconSize);
template<class T>
void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject *guard) {
@@ -121,6 +122,12 @@ void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject
item->setIconPath(*iconPath);
}
if constexpr (hasSetIconSize<T, void (T::*)(const QSize &)>::value) {
const auto iconSize = children.get<sol::optional<QSize>>("iconSize");
if (iconSize)
item->setIconSize(*iconSize);
}
if constexpr (hasSetWindowFlags<T, void (T::*)(Qt::WindowFlags)>::value) {
sol::optional<sol::table> windowFlags = children.get<sol::optional<sol::table>>(
"windowFlags");

View File

@@ -164,6 +164,17 @@ void typedAspectCreate(StringAspect *aspect, const std::string &key, const sol::
aspect->setAutoApplyOnEditingFinished(value.as<bool>());
else if (key == "elideMode")
aspect->setElideMode((Qt::TextElideMode) value.as<int>());
else if (key == "rightSideIconPath")
aspect->setRightSideIconPath(value.as<FilePath>());
else if (key == "minimumHeight")
aspect->setMinimumHeight(value.as<int>());
else if (key == "completer")
aspect->setCompleter(value.as<QCompleter*>());
else if (key == "addOnRightSideIconClicked") {
aspect->addOnRightSideIconClicked(aspect, [func = value.as<sol::function>()]() {
void_safe_call(func);
});
}
else
typedAspectCreate(static_cast<TypedAspect<QString> *>(aspect), key, value);
}

View File

@@ -126,6 +126,9 @@ settings.StringDisplayStyle = {
---@field acceptRichText? boolean
---@field autoApplyOnEditingFinished? boolean
---@field elideMode? Qt.TextElideMode The elide mode of the aspect.
---@field rightSideIconPath? string Path to the icon
---@field minimumHeight? int
---@field completer QCompleter? A QCompleter object.
StringAspectCreate = {}
---@class StringAspect : TypedAspect<string>