16 const char *
const HANDLER_PROPERTY_NAME =
"_kis_KisSpinBoxI18nHelper_handler";
24 explicit HandlerWrapper(std::function<
void(
int)> handler)
37 void install(QSpinBox *spinBox, std::function<QString(
int)> messageFn)
39 const auto changeHandler = [messageFn, spinBox](
int value) {
43 changeHandler(spinBox->value());
44 QObject::connect(spinBox, QOverload<int>::of(&QSpinBox::valueChanged), changeHandler);
45 spinBox->setProperty(HANDLER_PROPERTY_NAME, QVariant::fromValue(HandlerWrapper(changeHandler)));
50 const QVariant handlerVariant = spinBox->property(HANDLER_PROPERTY_NAME);
51 if (!handlerVariant.isValid()) {
52 qWarning() <<
"KisSpinBoxI18nHelper::update called with" << spinBox
53 <<
"but it does not have the property" << HANDLER_PROPERTY_NAME;
56 if (!handlerVariant.canConvert<HandlerWrapper>()) {
57 qWarning() <<
"KisSpinBoxI18nHelper::update called with" << spinBox
58 <<
"but its property" << HANDLER_PROPERTY_NAME <<
"is invalid";
61 const HandlerWrapper handler = handlerVariant.value<HandlerWrapper>();
62 handler.m_handler(spinBox->value());
66 template<
typename TSpinBox>
67 static void setTextGeneric(TSpinBox *spinBox,
const QStringView textTemplate)
69 const QLatin1String placeholder{
"{n}"};
70 const qsizetype idx = textTemplate.indexOf(placeholder);
72 spinBox->setPrefix(textTemplate.left(idx).toString());
73 spinBox->setSuffix(textTemplate.mid(idx + placeholder.size()).toString());
75 spinBox->setPrefix(QString());
76 spinBox->setSuffix(textTemplate.toString());
80 void setText(QSpinBox *spinBox,
const QStringView textTemplate)
85 void setText(QDoubleSpinBox *spinBox,
const QStringView textTemplate)
float value(const T *src, size_t ch)
std::function< void(int)> m_handler
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
void setText(QSpinBox *spinBox, const QStringView textTemplate)
void install(QSpinBox *spinBox, std::function< QString(int)> messageFn)
static void setTextGeneric(TSpinBox *spinBox, const QStringView textTemplate)
bool update(QSpinBox *spinBox)