diff --git a/includes/CMakeLists.txt b/includes/CMakeLists.txt index 477753a1..58d3b8a2 100644 --- a/includes/CMakeLists.txt +++ b/includes/CMakeLists.txt @@ -88,7 +88,6 @@ install( KFileWidget KDiskFreeSpaceInfo KDoubleNumInput - KDoubleValidator KEMail KEMailDialog KEMailSettings @@ -136,7 +135,6 @@ install( KInputDialog KComponentData KIntNumInput - KIntValidator KJob KJobTrackerInterface KJobUiDelegate diff --git a/includes/KDoubleValidator b/includes/KDoubleValidator deleted file mode 100644 index 2dbfcb20..00000000 --- a/includes/KDoubleValidator +++ /dev/null @@ -1 +0,0 @@ -#include "../knumvalidator.h" diff --git a/includes/KIntValidator b/includes/KIntValidator deleted file mode 100644 index 2dbfcb20..00000000 --- a/includes/KIntValidator +++ /dev/null @@ -1 +0,0 @@ -#include "../knumvalidator.h" diff --git a/kdeui/CMakeLists.txt b/kdeui/CMakeLists.txt index 1017446f..3fd00eee 100644 --- a/kdeui/CMakeLists.txt +++ b/kdeui/CMakeLists.txt @@ -155,7 +155,6 @@ set(kdeui_LIB_SRCS util/kguiitem.cpp util/kkeyserver.cpp util/kselectionowner.cpp - util/knumvalidator.cpp util/kpassivepopup.cpp util/kstandardguiitem.cpp util/kxerrorhandler.cpp @@ -403,7 +402,6 @@ install( util/kkeyboardlayout.h util/kdebugger.h util/kselectionowner.h - util/knumvalidator.h util/kpassivepopup.h util/kstandardguiitem.h util/kxerrorhandler.h diff --git a/kdeui/util/knumvalidator.cpp b/kdeui/util/knumvalidator.cpp deleted file mode 100644 index 82880c8e..00000000 --- a/kdeui/util/knumvalidator.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - This file is part of the KDE libraries - Copyright (C) 2024 Ivailo Monev - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "knumvalidator.h" -#include "klocale.h" -#include "kglobal.h" -#include "kdebug.h" - -static void kAcceptLocalizedNumbers(QValidator *validator, const bool accept) -{ - if (accept) { - validator->setLocale(KGlobal::locale()->toLocale()); - } else { - validator->setLocale(QLocale::c()); - } -} - -class KIntValidator::KIntValidatorPrivate -{ -public: - KIntValidatorPrivate() - : acceptLocalizedNumbers(true) - { - } - - bool acceptLocalizedNumbers; -}; - -KIntValidator::KIntValidator(QObject *parent) - : QIntValidator(parent), - d(new KIntValidatorPrivate()) -{ - kAcceptLocalizedNumbers(this, true); -} - -KIntValidator::KIntValidator(int bottom, int top, QObject *parent) - : QIntValidator(bottom, top, parent), - d(new KIntValidatorPrivate()) -{ - kAcceptLocalizedNumbers(this, true); -} - -KIntValidator::~KIntValidator() -{ - delete d; -} - -bool KIntValidator::acceptLocalizedNumbers() const -{ - return d->acceptLocalizedNumbers; -} - -void KIntValidator::setAcceptLocalizedNumbers(bool accept) -{ - d->acceptLocalizedNumbers = accept; - kAcceptLocalizedNumbers(this, accept); -} - - -class KDoubleValidator::KDoubleValidatorPrivate -{ -public: - KDoubleValidatorPrivate() - : acceptLocalizedNumbers(true) - { - } - - bool acceptLocalizedNumbers; -}; - -KDoubleValidator::KDoubleValidator(QObject *parent) - : QDoubleValidator(parent), - d(new KDoubleValidatorPrivate()) -{ - kAcceptLocalizedNumbers(this, true); -} - -KDoubleValidator::KDoubleValidator(double bottom, double top, int decimals, QObject *parent) - : QDoubleValidator(bottom, top, decimals, parent), - d(new KDoubleValidatorPrivate()) -{ - kAcceptLocalizedNumbers(this, true); -} - -KDoubleValidator::~KDoubleValidator() -{ - delete d; -} - -bool KDoubleValidator::acceptLocalizedNumbers() const -{ - return d->acceptLocalizedNumbers; -} - -void KDoubleValidator::setAcceptLocalizedNumbers(bool accept) -{ - d->acceptLocalizedNumbers = accept; - kAcceptLocalizedNumbers(this, accept); -} - -#include "moc_knumvalidator.cpp" diff --git a/kdeui/util/knumvalidator.h b/kdeui/util/knumvalidator.h deleted file mode 100644 index 34fc4b54..00000000 --- a/kdeui/util/knumvalidator.h +++ /dev/null @@ -1,103 +0,0 @@ -/* - This file is part of the KDE libraries - Copyright (C) 2024 Ivailo Monev - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2, as published by the Free Software Foundation. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KNUMVALIDATOR_H -#define KNUMVALIDATOR_H - -#include - -#include - -/** - * @short A locale-aware QIntValidator - * - * QIntValidator extends QIntValidator to be locale-aware. That means that - subject to not being - * disabled - the system locale thousand separator, positive and negative sign are used for - * validation. - * - * @author Ivailo Monev - * @see KDoubleValidator - **/ -class KDEUI_EXPORT KIntValidator : public QIntValidator -{ - Q_OBJECT - Q_PROPERTY(bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers) -public: - /** - * Constuct a locale-aware KIntValidator with default range - */ - explicit KIntValidator(QObject *parent); - - /** - * Constuct a locale-aware KIntValidator for the speicified range and decimals - */ - KIntValidator(int bottom, int top, QObject *parent); - - virtual ~KIntValidator(); - - /** @return whether localized numbers are accepted, enabled by default */ - bool acceptLocalizedNumbers() const; - - /** Sets whether to accept localized numbers, enabled by default */ - void setAcceptLocalizedNumbers(bool accept); - -private: - class KIntValidatorPrivate; - KIntValidatorPrivate* const d; -}; - -/** - * @short A locale-aware QDoubleValidator - * - * KDoubleValidator extends QDoubleValidator to be locale-aware. That means that - subject to not - * being disabled - the system locale decimal point, thousand separator, positive and negative sign - * are used for validation. - * - * @author Ivailo Monev - * @see KIntValidator - **/ -class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator -{ - Q_OBJECT - Q_PROPERTY(bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers) -public: - /** - * Constuct a locale-aware KDoubleValidator with default range - */ - explicit KDoubleValidator(QObject *parent); - - /** - * Constuct a locale-aware KDoubleValidator for the speicified range and decimals - */ - KDoubleValidator(double bottom, double top, int decimals, QObject *parent); - - virtual ~KDoubleValidator(); - - /** @return whether localized numbers are accepted, enabled by default */ - bool acceptLocalizedNumbers() const; - - /** Sets whether to accept localized numbers, enabled by default */ - void setAcceptLocalizedNumbers(bool accept); - -private: - class KDoubleValidatorPrivate; - KDoubleValidatorPrivate* const d; -}; - -#endif diff --git a/kdeui/widgets/knuminput.cpp b/kdeui/widgets/knuminput.cpp index c188774b..74909dbf 100644 --- a/kdeui/widgets/knuminput.cpp +++ b/kdeui/widgets/knuminput.cpp @@ -18,20 +18,33 @@ */ #include "knuminput.h" -#include "knumvalidator.h" +#include "kglobal.h" +#include "klocale.h" #include "kdebug.h" #include #include #include #include +#include + +static void setupSpinBox(QSpinBox *spinbox, const int value) +{ + spinbox->setLocale(KGlobal::locale()->toLocale()); + spinbox->setValue(value); +} + +static void setupDoubleSpinBox(QDoubleSpinBox *spinbox, const double value) +{ + spinbox->setLocale(KGlobal::locale()->toLocale()); + spinbox->setValue(value); +} class KIntNumInputPrivate { public: KIntNumInputPrivate() - : validator(nullptr), - slider(nullptr), + : slider(nullptr), spinbox(nullptr) { } @@ -46,7 +59,6 @@ public: slider->setValue(value); } - KIntValidator* validator; QSlider* slider; QSpinBox* spinbox; KLocalizedString suffix; @@ -56,7 +68,6 @@ KIntNumInput::KIntNumInput(QWidget* parent) : QWidget(parent), d(new KIntNumInputPrivate()) { - d->validator = new KIntValidator(this); QHBoxLayout* hboxlayout = new QHBoxLayout(this); hboxlayout->setMargin(0); d->slider = new QSlider(Qt::Horizontal, this); @@ -83,6 +94,9 @@ KIntNumInput::KIntNumInput(QWidget* parent) setLayout(hboxlayout); setFocusProxy(d->spinbox); + + setupSpinBox(d->spinbox, d->spinbox->value()); + setRange(INT_MIN, INT_MAX); setSingleStep(1); setValue(0); @@ -95,7 +109,6 @@ KIntNumInput::~KIntNumInput() void KIntNumInput::setRange(int min, int max) { - d->validator->setRange(min, max); d->slider->setRange(min, max); d->spinbox->setRange(min, max); } @@ -112,7 +125,6 @@ int KIntNumInput::minimum() const void KIntNumInput::setMinimum(int min) { - d->validator->setRange(min, maximum()); d->slider->setMinimum(min); d->spinbox->setMinimum(min); } @@ -124,7 +136,6 @@ int KIntNumInput::maximum() const void KIntNumInput::setMaximum(int max) { - d->validator->setRange(minimum(), max); d->slider->setMaximum(max); d->spinbox->setMaximum(max); } @@ -187,16 +198,6 @@ void KIntNumInput::setSteps(int single, int page) d->slider->setPageStep(page); } -QValidator::State KIntNumInput::validate(QString &input, int &pos) const -{ - return d->validator->validate(input, pos); -} - -void KIntNumInput::fixup(QString &input) const -{ - d->validator->fixup(input); -} - void KIntNumInput::setValue(int value) { d->spinbox->setValue(value); @@ -219,13 +220,25 @@ void KIntNumInput::setPrefix(const QString &prefix) d->spinbox->setPrefix(prefix); } +void KIntNumInput::changeEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::LocaleChange: + case QEvent::LanguageChange: { + setupSpinBox(d->spinbox, d->spinbox->value()); + break; + } + default: { + break; + } + } +} class KDoubleNumInputPrivate { public: KDoubleNumInputPrivate() - : validator(nullptr), - slider(nullptr), + : slider(nullptr), spinbox(nullptr) { } @@ -245,7 +258,6 @@ public: spinbox->setValue(value); } - KDoubleValidator* validator; QSlider* slider; QDoubleSpinBox* spinbox; KLocalizedString suffix; @@ -255,7 +267,6 @@ KDoubleNumInput::KDoubleNumInput(QWidget *parent) : QWidget(parent), d(new KDoubleNumInputPrivate()) { - d->validator = new KDoubleValidator(this); QHBoxLayout* hboxlayout = new QHBoxLayout(this); hboxlayout->setMargin(0); d->slider = new QSlider(Qt::Horizontal, this); @@ -282,6 +293,9 @@ KDoubleNumInput::KDoubleNumInput(QWidget *parent) setLayout(hboxlayout); setFocusProxy(d->spinbox); + + setupDoubleSpinBox(d->spinbox, d->spinbox->value()); + setRange(0.0, 9999.0); setSingleStep(0.01); setDecimals(2); @@ -295,7 +309,6 @@ KDoubleNumInput::~KDoubleNumInput() void KDoubleNumInput::setRange(double min, double max) { - d->validator->setRange(min, max, decimals()); d->slider->setRange(qRound(min), qRound(max)); d->spinbox->setRange(min, max); } @@ -312,7 +325,6 @@ double KDoubleNumInput::minimum() const void KDoubleNumInput::setMinimum(double min) { - d->validator->setRange(min, maximum(), decimals()); d->slider->setMinimum(min); d->spinbox->setMinimum(min); } @@ -324,7 +336,6 @@ double KDoubleNumInput::maximum() const void KDoubleNumInput::setMaximum(double max) { - d->validator->setRange(minimum(), max, decimals()); d->slider->setMaximum(max); d->spinbox->setMaximum(max); } @@ -398,16 +409,6 @@ void KDoubleNumInput::setSteps(int single, int page) d->slider->setPageStep(page); } -QValidator::State KDoubleNumInput::validate(QString &input, int &pos) const -{ - return d->validator->validate(input, pos); -} - -void KDoubleNumInput::fixup(QString &input) const -{ - d->validator->fixup(input); -} - void KDoubleNumInput::setValue(double value) { d->spinbox->setValue(value); @@ -430,4 +431,18 @@ void KDoubleNumInput::setPrefix(const QString &prefix) d->spinbox->setPrefix(prefix); } +void KDoubleNumInput::changeEvent(QEvent *event) +{ + switch (event->type()) { + case QEvent::LocaleChange: + case QEvent::LanguageChange: { + setupDoubleSpinBox(d->spinbox, d->spinbox->value()); + break; + } + default: { + break; + } + } +} + #include "moc_knuminput.cpp" diff --git a/kdeui/widgets/knuminput.h b/kdeui/widgets/knuminput.h index 12fd7eb8..90ed5f57 100644 --- a/kdeui/widgets/knuminput.h +++ b/kdeui/widgets/knuminput.h @@ -24,7 +24,6 @@ #include #include -#include class KIntNumInputPrivate; class KDoubleNumInputPrivate; @@ -96,12 +95,6 @@ public: */ void setSteps(int single, int page); - /** - * Validation overrides - */ - virtual QValidator::State validate(QString &input, int &pos) const; - virtual void fixup(QString &input) const; - public Q_SLOTS: /** * Spin box and slider proxies @@ -115,6 +108,10 @@ Q_SIGNALS: void valueChanged(int); void editingFinished(); +protected: + // QWidget reimplementation + virtual void changeEvent(QEvent *event); + private: friend KIntNumInputPrivate; KIntNumInputPrivate* const d; @@ -201,12 +198,6 @@ public: */ void setSteps(int single, int page); - /** - * Validation overrides - */ - virtual QValidator::State validate(QString &input, int &pos) const; - virtual void fixup(QString &input) const; - public Q_SLOTS: /** * Spin box and slider proxies @@ -220,6 +211,10 @@ Q_SIGNALS: void valueChanged(double); void editingFinished(); +protected: + // QWidget reimplementation + virtual void changeEvent(QEvent *event); + private: friend KDoubleNumInputPrivate; KDoubleNumInputPrivate* const d;