forked from qt-creator/qt-creator
Lua: Add Icon binding
Change-Id: I9f796f997463a8aa30be6b055f0abdce8f0131d5 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -55,8 +55,8 @@ void setupActionModule()
|
|||||||
cmd->m_contextAction->setText(text);
|
cmd->m_contextAction->setText(text);
|
||||||
}),
|
}),
|
||||||
"icon",
|
"icon",
|
||||||
sol::property([](ScriptCommand *cmd, const FilePathOrString &&icon) {
|
sol::property([](ScriptCommand *cmd, const IconFilePathOrString &&icon) {
|
||||||
cmd->m_contextAction->setIcon(QIcon(toFilePath(icon).toFSPathString()));
|
cmd->m_contextAction->setIcon(toIcon(icon)->icon());
|
||||||
}));
|
}));
|
||||||
|
|
||||||
result["create"] = [parent = std::make_unique<QObject>()](
|
result["create"] = [parent = std::make_unique<QObject>()](
|
||||||
@@ -100,7 +100,7 @@ void setupActionModule()
|
|||||||
"asMode needs an integer argument for the priority");
|
"asMode needs an integer argument for the priority");
|
||||||
}
|
}
|
||||||
} else if (key == "icon") {
|
} else if (key == "icon") {
|
||||||
b.setIcon(QIcon(toFilePath(v.as<FilePathOrString>()).toFSPathString()));
|
b.setIcon(toIcon(v.as<IconFilePathOrString>())->icon());
|
||||||
} else
|
} else
|
||||||
throw std::runtime_error("Unknown key: " + key.toStdString());
|
throw std::runtime_error("Unknown key: " + key.toStdString());
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
#include "../luaengine.h"
|
#include "../luaengine.h"
|
||||||
|
|
||||||
#include "inheritance.h"
|
#include "inheritance.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <utils/aspects.h>
|
#include <utils/aspects.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
@@ -418,14 +419,8 @@ void setupGuiModule()
|
|||||||
sol::base_classes,
|
sol::base_classes,
|
||||||
sol::bases<Object, Thing>());
|
sol::bases<Object, Thing>());
|
||||||
|
|
||||||
auto mirrorEnum = [&gui](QMetaEnum metaEnum) {
|
mirrorEnum(gui, QMetaEnum::fromType<Qt::WidgetAttribute>());
|
||||||
sol::table widgetAttributes = gui.create(metaEnum.name());
|
mirrorEnum(gui, QMetaEnum::fromType<Qt::WindowType>());
|
||||||
for (int i = 0; i < metaEnum.keyCount(); ++i)
|
|
||||||
widgetAttributes.set(metaEnum.key(i), metaEnum.value(i));
|
|
||||||
};
|
|
||||||
|
|
||||||
mirrorEnum(QMetaEnum::fromType<Qt::WidgetAttribute>());
|
|
||||||
mirrorEnum(QMetaEnum::fromType<Qt::WindowType>());
|
|
||||||
|
|
||||||
gui.new_usertype<Stack>(
|
gui.new_usertype<Stack>(
|
||||||
"Stack",
|
"Stack",
|
||||||
|
@@ -4,10 +4,13 @@
|
|||||||
#include "../luaengine.h"
|
#include "../luaengine.h"
|
||||||
#include "../luaqttypes.h"
|
#include "../luaqttypes.h"
|
||||||
|
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <utils/async.h>
|
#include <utils/async.h>
|
||||||
#include <utils/commandline.h>
|
#include <utils/commandline.h>
|
||||||
#include <utils/futuresynchronizer.h>
|
#include <utils/futuresynchronizer.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
#include <utils/icon.h>
|
||||||
#include <utils/processinterface.h>
|
#include <utils/processinterface.h>
|
||||||
|
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@@ -244,6 +247,33 @@ void setupUtilsModule()
|
|||||||
return QString::fromUtf8(QByteArray::fromBase64(data));
|
return QString::fromUtf8(QByteArray::fromBase64(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
utils.new_enum<Icon::IconStyleOption>(
|
||||||
|
"IconStyleOption",
|
||||||
|
{{"None", Icon::None},
|
||||||
|
{"Tint", Icon::Tint},
|
||||||
|
{"DropShadow", Icon::DropShadow},
|
||||||
|
{"PunchEdges", Icon::PunchEdges},
|
||||||
|
{"ToolBarStyle", Icon::ToolBarStyle},
|
||||||
|
{"MenuTintedStyle", Icon::MenuTintedStyle}});
|
||||||
|
|
||||||
|
mirrorEnum(utils, QMetaEnum::fromType<Theme::Color>(), "ThemeColor");
|
||||||
|
|
||||||
|
auto iconType = utils.new_usertype<Icon>(
|
||||||
|
"Icon",
|
||||||
|
"create",
|
||||||
|
sol::factories(
|
||||||
|
[](FilePathOrString path) { return std::make_shared<Icon>(toFilePath(path)); },
|
||||||
|
[](const sol::table &maskAndColor, Icon::IconStyleOption style) {
|
||||||
|
QList<IconMaskAndColor> args;
|
||||||
|
for (const auto &it : maskAndColor) {
|
||||||
|
auto pair = it.second.as<sol::table>();
|
||||||
|
args.append(qMakePair(
|
||||||
|
toFilePath(pair.get<FilePathOrString>(1)),
|
||||||
|
pair.get<Theme::Color>(2)));
|
||||||
|
}
|
||||||
|
return std::make_shared<Icon>(args, Icon::IconStyleOptions::fromInt(style));
|
||||||
|
}));
|
||||||
|
|
||||||
return utils;
|
return utils;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../luaengine.h"
|
||||||
|
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
|
#include <utils/icon.h>
|
||||||
|
|
||||||
|
#include <QMetaEnum>
|
||||||
|
|
||||||
namespace Lua::Internal {
|
namespace Lua::Internal {
|
||||||
|
|
||||||
@@ -22,4 +27,27 @@ inline Utils::FilePath toFilePath(const FilePathOrString &v)
|
|||||||
v);
|
v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
using IconFilePathOrString = std::variant<std::shared_ptr<Utils::Icon>, Utils::FilePath, QString>;
|
||||||
|
|
||||||
|
inline std::shared_ptr<Utils::Icon> toIcon(const IconFilePathOrString &v)
|
||||||
|
{
|
||||||
|
return std::visit(
|
||||||
|
[](auto &&arg) -> std::shared_ptr<Utils::Icon> {
|
||||||
|
using T = std::decay_t<decltype(arg)>;
|
||||||
|
if constexpr (std::is_same_v<T, std::shared_ptr<Utils::Icon>>)
|
||||||
|
return arg;
|
||||||
|
else
|
||||||
|
return std::make_shared<Utils::Icon>(toFilePath(arg));
|
||||||
|
},
|
||||||
|
v);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void mirrorEnum(sol::table &target, QMetaEnum metaEnum, const QString &name = {})
|
||||||
|
{
|
||||||
|
sol::table widgetAttributes = target.create(
|
||||||
|
name.isEmpty() ? QString::fromUtf8(metaEnum.name()) : name, metaEnum.keyCount());
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); ++i)
|
||||||
|
widgetAttributes.set(metaEnum.key(i), metaEnum.value(i));
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace Lua::Internal
|
} // namespace Lua::Internal
|
||||||
|
Reference in New Issue
Block a user