// SPDX-FileCopyrightText: 2024 PCSX2 Dev Team // SPDX-License-Identifier: GPL-3.0+ #pragma once #include #include /// layout->setRowVisible but compatible with older Qt static inline void setFormRowVisible(QFormLayout* layout, int idx, bool visible) { #if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) layout->setRowVisible(idx, visible); #else if (QLayoutItem* item = layout->itemAt(idx, QFormLayout::LabelRole)) item->widget()->setVisible(visible); if (QLayoutItem* item = layout->itemAt(idx, QFormLayout::FieldRole)) item->widget()->setVisible(visible); #endif } #if QT_VERSION < QT_VERSION_CHECK(6, 7, 0) template static inline void connectCheckStateChanged(QCheckBox* check, const Ctx *context, void (Ctx::*slot)(T)) { static_assert(std::is_same_v || std::is_same_v); check->connect(check, &QCheckBox::stateChanged, context, reinterpret_cast(slot)); } template static inline void connectCheckStateChanged(QCheckBox* check, const Ctx *context, void (Ctx::*slot)()) { check->connect(check, &QCheckBox::stateChanged, context, slot); } template static inline void connectCheckStateChanged(QCheckBox* check, QObject *context, Func&& slot) { if constexpr (std::is_invocable_v || std::is_invocable_v) { check->connect(check, &QCheckBox::stateChanged, context, std::forward(slot)); } else { check->connect(check, &QCheckBox::stateChanged, context, [slot = std::forward(slot)](int state){ slot(static_cast(state)); }); } } #else template static inline void connectCheckStateChanged(QCheckBox* check, const typename QtPrivate::ContextTypeForFunctor::ContextType *context, Func&& slot) { check->connect(check, &QCheckBox::checkStateChanged, context, std::forward(slot)); } #endif