#pragma once #include "property.hh" #include #include #include #include #include namespace creeper::common { template struct Token { void apply(auto& self) const { const auto self_name = typeid(self).name(); const auto prop_name = typeid(this).name(); qDebug() << "Unimplemented" << prop_name << "is called by" << self_name; } }; namespace pro { // 设置组建透明度 template using Opacity = SetterProp; // 设置圆角(NXNY) template using RadiusNxNy = SetterProp; // 设置圆角(PXPY) template using RadiusPxPy = SetterProp; // 设置圆角(NXPY) template using RadiusNxPy = SetterProp; // 设置圆角(PXNY) template using RadiusPxNy = SetterProp; // 设置圆角(X方向) template using RadiusX = SetterProp; // 设置圆角(Y方向) template using RadiusY = SetterProp; // 设置通用圆角 template using Radius = SetterProp; // 通用边界宽度 template using BorderWidth = SetterProp; // 通用边界颜色 template using BorderColor = SetterProp; // 通用文字颜色 template using TextColor = SetterProp; // 通用背景颜色 template using Background = SetterProp; // 通用水波纹颜色 template using WaterColor = SetterProp; // 通用禁止属性 template using Disabled = SetterProp; // 通用 Checked 属性 template using Checked = SetterProp; // 通用文本属性 template struct String : public QString, Token { using QString::QString; explicit String(const QString& text) noexcept : QString { text } { } explicit String(const std::string& text) noexcept : QString { QString::fromStdString(text) } { } auto operator=(const QString& text) noexcept { QString::operator=(text); return *this; } auto operator=(QString&& text) noexcept { QString::operator=(std::move(text)); return *this; } void apply(auto& self) const requires requires { setter(self, *this); } { setter(self, *this); } }; template struct Vector : public QVector, Token { using QVector::QVector; explicit Vector(const QVector& vec) noexcept : QVector { vec } { } explicit Vector(const std::vector& vec) noexcept : QVector { vec } { } void apply(auto& self) const requires requires {setter(self, *this); } { setter(self, *this); } }; template struct Array : public std::array, Token { using std::array::array; explicit Array(const std::array& arr) noexcept : std::array { arr } { } template requires (sizeof...(Args) == N) explicit Array(Args&&... args) noexcept : std::array { std::forward(args)...} {} void apply(auto& self) const requires requires {setter(self, *this);} { setter(self, *this); } }; // template // Vector::Vector(const QVector &vec) noexcept:QVector { vec } { } template using Text = String; // 通用指针绑定 template struct Bind : Token { Final*& widget; explicit Bind(Final*& p) : widget(p) { }; void apply(Final& self) const { widget = &self; } }; // 通用点击事件 template struct Clickable : Token { Callback callback; explicit Clickable(Callback callback) noexcept : callback { std::move(callback) } { } auto apply(auto& self) const noexcept -> void requires std::invocable || std::invocable { using widget_t = std::remove_cvref_t; QObject::connect(&self, &widget_t::clicked, [function = callback, &self] { if constexpr (std::invocable) function(self); if constexpr (std::invocable) function(); }); } }; template struct IndexChanged : Token { Callback callback; explicit IndexChanged(Callback callback) noexcept : callback {std::move(callback)} {} auto apply(auto& self) const noexcept -> void requires std::invocable || std::invocable { using widget_t = std::remove_cvref_t; QObject::connect(&self, &widget_t::currentIndexChanged, [function = callback, &self] { if constexpr (std::invocable) function(self); }); } }; // 自定义信号回调注册 namespace internal { template struct FunctionArgs; template struct FunctionArgsR> { using type = std::tuple; }; template struct FunctionArgsR> { using type = std::tuple; }; template concept tuple_invocable_trait = requires(F&& f, Tuple&& t) { std::apply(std::forward(f), std::forward(t)); // }; } template struct SignalInjection : Token { F f; using SignalArgs = typename internal::FunctionArgs::type; explicit SignalInjection(F f) noexcept requires internal::tuple_invocable_trait : f { std::forward(f) } { } auto apply(auto& self) const noexcept { QObject::connect(&self, signal, f); } }; } }