1 | /* |
2 | SPDX-FileCopyrightText: 2014 Laurent Montel <montel@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-or-later |
5 | */ |
6 | |
7 | #include "kpluralhandlingspinbox.h" |
8 | |
9 | #if KTEXTWIDGETS_BUILD_DEPRECATED_SINCE(6, 6) |
10 | |
11 | class KPluralHandlingSpinBoxPrivate |
12 | { |
13 | public: |
14 | KPluralHandlingSpinBoxPrivate(QSpinBox *qq) |
15 | : q(qq) |
16 | { |
17 | QObject::connect(sender: q, signal: qOverload<int>(&QSpinBox::valueChanged), context: q, slot: [this](int value) { |
18 | updateSuffix(value); |
19 | }); |
20 | } |
21 | |
22 | void updateSuffix(int value) |
23 | { |
24 | if (!pluralSuffix.isEmpty()) { |
25 | KLocalizedString s = pluralSuffix; |
26 | q->setSuffix(s.subs(a: value).toString()); |
27 | } |
28 | } |
29 | |
30 | QSpinBox *const q; |
31 | KLocalizedString pluralSuffix; |
32 | }; |
33 | |
34 | KPluralHandlingSpinBox::KPluralHandlingSpinBox(QWidget *parent) |
35 | : QSpinBox(parent) |
36 | , d(new KPluralHandlingSpinBoxPrivate(this)) |
37 | { |
38 | } |
39 | |
40 | KPluralHandlingSpinBox::~KPluralHandlingSpinBox() = default; |
41 | |
42 | void KPluralHandlingSpinBox::setSuffix(const KLocalizedString &suffix) |
43 | { |
44 | d->pluralSuffix = suffix; |
45 | if (suffix.isEmpty()) { |
46 | QSpinBox::setSuffix(QString()); |
47 | } else { |
48 | d->updateSuffix(value: value()); |
49 | } |
50 | } |
51 | #include "moc_kpluralhandlingspinbox.cpp" |
52 | |
53 | #endif |
54 | |