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 | class KPluralHandlingSpinBoxPrivate |
10 | { |
11 | public: |
12 | KPluralHandlingSpinBoxPrivate(QSpinBox *qq) |
13 | : q(qq) |
14 | { |
15 | QObject::connect(sender: q, signal: qOverload<int>(&QSpinBox::valueChanged), context: q, slot: [this](int value) { |
16 | updateSuffix(value); |
17 | }); |
18 | } |
19 | |
20 | void updateSuffix(int value) |
21 | { |
22 | if (!pluralSuffix.isEmpty()) { |
23 | KLocalizedString s = pluralSuffix; |
24 | q->setSuffix(s.subs(a: value).toString()); |
25 | } |
26 | } |
27 | |
28 | QSpinBox *const q; |
29 | KLocalizedString pluralSuffix; |
30 | }; |
31 | |
32 | KPluralHandlingSpinBox::KPluralHandlingSpinBox(QWidget *parent) |
33 | : QSpinBox(parent) |
34 | , d(new KPluralHandlingSpinBoxPrivate(this)) |
35 | { |
36 | } |
37 | |
38 | KPluralHandlingSpinBox::~KPluralHandlingSpinBox() = default; |
39 | |
40 | void KPluralHandlingSpinBox::setSuffix(const KLocalizedString &suffix) |
41 | { |
42 | d->pluralSuffix = suffix; |
43 | if (suffix.isEmpty()) { |
44 | QSpinBox::setSuffix(QString()); |
45 | } else { |
46 | d->updateSuffix(value: value()); |
47 | } |
48 | } |
49 | #include "moc_kpluralhandlingspinbox.cpp" |
50 | |