forked from qt-creator/qt-creator
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:
@@ -957,6 +957,10 @@ public:
|
|||||||
bool m_autoApplyOnEditingFinished = false;
|
bool m_autoApplyOnEditingFinished = false;
|
||||||
bool m_validatePlaceHolder = false;
|
bool m_validatePlaceHolder = false;
|
||||||
|
|
||||||
|
FilePath m_rightSideIconPath;
|
||||||
|
int m_minimumHeight = 0;
|
||||||
|
QPointer<QCompleter> m_completer;
|
||||||
|
|
||||||
UndoableValue<QString> undoable;
|
UndoableValue<QString> undoable;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1205,6 +1209,20 @@ void StringAspect::addToLayoutImpl(Layout &parent)
|
|||||||
auto lineEditDisplay = createSubWidget<FancyLineEdit>();
|
auto lineEditDisplay = createSubWidget<FancyLineEdit>();
|
||||||
addMacroExpansion(lineEditDisplay);
|
addMacroExpansion(lineEditDisplay);
|
||||||
lineEditDisplay->setPlaceholderText(d->m_placeHolderText);
|
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())
|
if (!d->m_historyCompleterKey.isEmpty())
|
||||||
lineEditDisplay->setHistoryCompleter(d->m_historyCompleterKey);
|
lineEditDisplay->setHistoryCompleter(d->m_historyCompleterKey);
|
||||||
|
|
||||||
@@ -1418,6 +1436,27 @@ void StringAspect::setChecked(bool checked)
|
|||||||
return d->m_checkerImpl.setChecked(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
|
\class Utils::FilePathAspect
|
||||||
|
@@ -633,6 +633,11 @@ public:
|
|||||||
bool isChecked() const;
|
bool isChecked() const;
|
||||||
void setChecked(bool checked);
|
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 {
|
enum DisplayStyle {
|
||||||
LabelDisplay,
|
LabelDisplay,
|
||||||
LineEditDisplay,
|
LineEditDisplay,
|
||||||
@@ -652,6 +657,7 @@ signals:
|
|||||||
void acceptRichTextChanged(bool acceptRichText);
|
void acceptRichTextChanged(bool acceptRichText);
|
||||||
void validationFunctionChanged(const FancyLineEdit::ValidationFunction &validator);
|
void validationFunctionChanged(const FancyLineEdit::ValidationFunction &validator);
|
||||||
void placeholderTextChanged(const QString &placeholderText);
|
void placeholderTextChanged(const QString &placeholderText);
|
||||||
|
void rightSideIconClicked();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void addToLayoutImpl(Layouting::Layout &parent) override;
|
void addToLayoutImpl(Layouting::Layout &parent) override;
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QSize>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QSpinBox>
|
#include <QSpinBox>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
@@ -897,6 +898,11 @@ void PushButton::setIconPath(const Utils::FilePath &iconPath)
|
|||||||
access(this)->setIcon(icon.icon());
|
access(this)->setIcon(icon.icon());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PushButton::setIconSize(const QSize &size)
|
||||||
|
{
|
||||||
|
access(this)->setIconSize(size);
|
||||||
|
}
|
||||||
|
|
||||||
void PushButton::setFlat(bool flat)
|
void PushButton::setFlat(bool flat)
|
||||||
{
|
{
|
||||||
access(this)->setFlat(flat);
|
access(this)->setFlat(flat);
|
||||||
|
@@ -28,6 +28,7 @@ class QLabel;
|
|||||||
class QLayout;
|
class QLayout;
|
||||||
class QObject;
|
class QObject;
|
||||||
class QPushButton;
|
class QPushButton;
|
||||||
|
class QSize;
|
||||||
class QSpinBox;
|
class QSpinBox;
|
||||||
class QSplitter;
|
class QSplitter;
|
||||||
class QStackedWidget;
|
class QStackedWidget;
|
||||||
@@ -295,6 +296,7 @@ public:
|
|||||||
|
|
||||||
void setText(const QString &);
|
void setText(const QString &);
|
||||||
void setIconPath(const Utils::FilePath &);
|
void setIconPath(const Utils::FilePath &);
|
||||||
|
void setIconSize(const QSize &);
|
||||||
void setFlat(bool);
|
void setFlat(bool);
|
||||||
void onClicked(const std::function<void()> &, QObject *guard);
|
void onClicked(const std::function<void()> &, QObject *guard);
|
||||||
};
|
};
|
||||||
|
@@ -106,6 +106,7 @@ HAS_MEM_FUNC(setAutoFillBackground, hasSetAutoFillBackground);
|
|||||||
HAS_MEM_FUNC(setIconPath, hasSetIconPath);
|
HAS_MEM_FUNC(setIconPath, hasSetIconPath);
|
||||||
HAS_MEM_FUNC(setFlat, hasSetFlat);
|
HAS_MEM_FUNC(setFlat, hasSetFlat);
|
||||||
HAS_MEM_FUNC(setOpenExternalLinks, hasSetOpenExternalLinks);
|
HAS_MEM_FUNC(setOpenExternalLinks, hasSetOpenExternalLinks);
|
||||||
|
HAS_MEM_FUNC(setIconSize, hasSetIconSize);
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void setProperties(std::unique_ptr<T> &item, const sol::table &children, QObject *guard) {
|
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);
|
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) {
|
if constexpr (hasSetWindowFlags<T, void (T::*)(Qt::WindowFlags)>::value) {
|
||||||
sol::optional<sol::table> windowFlags = children.get<sol::optional<sol::table>>(
|
sol::optional<sol::table> windowFlags = children.get<sol::optional<sol::table>>(
|
||||||
"windowFlags");
|
"windowFlags");
|
||||||
|
@@ -164,6 +164,17 @@ void typedAspectCreate(StringAspect *aspect, const std::string &key, const sol::
|
|||||||
aspect->setAutoApplyOnEditingFinished(value.as<bool>());
|
aspect->setAutoApplyOnEditingFinished(value.as<bool>());
|
||||||
else if (key == "elideMode")
|
else if (key == "elideMode")
|
||||||
aspect->setElideMode((Qt::TextElideMode) value.as<int>());
|
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
|
else
|
||||||
typedAspectCreate(static_cast<TypedAspect<QString> *>(aspect), key, value);
|
typedAspectCreate(static_cast<TypedAspect<QString> *>(aspect), key, value);
|
||||||
}
|
}
|
||||||
|
@@ -126,6 +126,9 @@ settings.StringDisplayStyle = {
|
|||||||
---@field acceptRichText? boolean
|
---@field acceptRichText? boolean
|
||||||
---@field autoApplyOnEditingFinished? boolean
|
---@field autoApplyOnEditingFinished? boolean
|
||||||
---@field elideMode? Qt.TextElideMode The elide mode of the aspect.
|
---@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 = {}
|
StringAspectCreate = {}
|
||||||
|
|
||||||
---@class StringAspect : TypedAspect<string>
|
---@class StringAspect : TypedAspect<string>
|
||||||
|
Reference in New Issue
Block a user