kdeui: reimplement KIntNumInput and KDoubleNumInput

work-in-progress, the slider is not connected currently and code in many
places needs adjustments

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-20 14:07:12 +03:00
parent 92ff7de73c
commit 7b9b0eee9e
14 changed files with 459 additions and 1660 deletions

View file

@ -136,7 +136,6 @@ install(
KInputDialog KInputDialog
KComponentData KComponentData
KIntNumInput KIntNumInput
KIntSpinBox
KIntValidator KIntValidator
KJob KJob
KJobTrackerInterface KJobTrackerInterface

View file

@ -1 +0,0 @@
#include "../knuminput.h"

View file

@ -141,7 +141,6 @@ void KConfigDialogManager::initMaps()
s_changedMap->insert( "KUrlComboRequester", SIGNAL(textChanged(QString))); s_changedMap->insert( "KUrlComboRequester", SIGNAL(textChanged(QString)));
s_changedMap->insert( "KUrlComboBox", SIGNAL(urlActivated(KUrl))); s_changedMap->insert( "KUrlComboBox", SIGNAL(urlActivated(KUrl)));
s_changedMap->insert( "KIntNumInput", SIGNAL(valueChanged(int))); s_changedMap->insert( "KIntNumInput", SIGNAL(valueChanged(int)));
s_changedMap->insert( "KIntSpinBox", SIGNAL(valueChanged(int)));
s_changedMap->insert( "KDoubleNumInput", SIGNAL(valueChanged(double))); s_changedMap->insert( "KDoubleNumInput", SIGNAL(valueChanged(double)));
s_changedMap->insert( "KButtonGroup", SIGNAL(changed(int))); s_changedMap->insert( "KButtonGroup", SIGNAL(changed(int)));
} }

View file

@ -127,7 +127,11 @@ KInputDialogHelper::KInputDialogHelper( const QString &caption, const QString &l
m_label->setAlignment(Qt::AlignTop); m_label->setAlignment(Qt::AlignTop);
layout->addWidget(m_label); layout->addWidget(m_label);
m_intSpinBox = new KIntSpinBox(minValue, maxValue, step, value, frame, base); m_intSpinBox = new KIntNumInput(frame);
m_intSpinBox->setRange(minValue, maxValue);
m_intSpinBox->setSingleStep(step);
m_intSpinBox->setValue(value);
m_intSpinBox->setBase(base);
layout->addWidget(m_intSpinBox); layout->addWidget(m_intSpinBox);
layout->setMargin(0); layout->setMargin(0);
@ -156,7 +160,7 @@ KInputDialogHelper::KInputDialogHelper( const QString &caption, const QString &l
m_label->setAlignment(Qt::AlignTop); m_label->setAlignment(Qt::AlignTop);
layout->addWidget(m_label); layout->addWidget(m_label);
m_doubleSpinBox = new QDoubleSpinBox(frame); m_doubleSpinBox = new KDoubleNumInput(frame);
m_doubleSpinBox->setRange(minValue, maxValue); m_doubleSpinBox->setRange(minValue, maxValue);
m_doubleSpinBox->setSingleStep(step); m_doubleSpinBox->setSingleStep(step);
m_doubleSpinBox->setValue(value); m_doubleSpinBox->setValue(value);
@ -297,12 +301,12 @@ KLineEdit *KInputDialogHelper::lineEdit() const
return m_lineEdit; return m_lineEdit;
} }
KIntSpinBox *KInputDialogHelper::intSpinBox() const KIntNumInput *KInputDialogHelper::intSpinBox() const
{ {
return m_intSpinBox; return m_intSpinBox;
} }
QDoubleSpinBox *KInputDialogHelper::doubleSpinBox() const KDoubleNumInput *KInputDialogHelper::doubleSpinBox() const
{ {
return m_doubleSpinBox; return m_doubleSpinBox;
} }

View file

@ -20,18 +20,17 @@
#ifndef KINPUTDIALOG_P_H #ifndef KINPUTDIALOG_P_H
#define KINPUTDIALOG_P_H #define KINPUTDIALOG_P_H
#include "kdialog.h"
#include "knuminput.h"
#include <QLabel> #include <QLabel>
#include <QValidator> #include <QValidator>
class KComboBox; class KComboBox;
#include <QDoubleSpinBox>
class KIntSpinBox;
class KLineEdit; class KLineEdit;
class KListWidget; class KListWidget;
class KTextEdit; class KTextEdit;
#include <kdialog.h>
/** /**
* @author Nadeem Hasan <nhasan@kde.org> * @author Nadeem Hasan <nhasan@kde.org>
*/ */
@ -60,8 +59,8 @@ class KInputDialogHelper : public KDialog
~KInputDialogHelper(); ~KInputDialogHelper();
KLineEdit *lineEdit() const; KLineEdit *lineEdit() const;
KIntSpinBox *intSpinBox() const; KIntNumInput *intSpinBox() const;
QDoubleSpinBox *doubleSpinBox() const; KDoubleNumInput *doubleSpinBox() const;
KComboBox *comboBox() const; KComboBox *comboBox() const;
KListWidget *listBox() const; KListWidget *listBox() const;
KTextEdit *textEdit() const; KTextEdit *textEdit() const;
@ -73,8 +72,8 @@ class KInputDialogHelper : public KDialog
private: private:
QLabel *m_label; QLabel *m_label;
KLineEdit *m_lineEdit; KLineEdit *m_lineEdit;
KIntSpinBox *m_intSpinBox; KIntNumInput *m_intSpinBox;
QDoubleSpinBox *m_doubleSpinBox; KDoubleNumInput *m_doubleSpinBox;
KComboBox *m_comboBox; KComboBox *m_comboBox;
KListWidget *m_listBox; KListWidget *m_listBox;
KTextEdit *m_textEdit; KTextEdit *m_textEdit;

View file

@ -47,7 +47,7 @@ public:
int _max; int _max;
}; };
KIntValidator::KIntValidator ( QWidget *parent, int base) KIntValidator::KIntValidator(QWidget *parent, int base)
: QValidator(parent), : QValidator(parent),
d(new KIntValidatorPrivate()) d(new KIntValidatorPrivate())
{ {

View file

@ -39,52 +39,56 @@
@author Glen Parker <glenebob@nwlink.com> @author Glen Parker <glenebob@nwlink.com>
@version 0.0.1 @version 0.0.1
*/ */
class KDEUI_EXPORT KIntValidator : public QValidator { class KDEUI_EXPORT KIntValidator : public QValidator
{
public: public:
/** /**
* Constructor. Also sets the base value. * Constructor. Also sets the base value.
*/ */
explicit KIntValidator ( QWidget * parent, int base = 10 ); explicit KIntValidator(QWidget * parent, int base = 10);
/** /**
* Constructor. Also sets the minimum, maximum, and numeric base values. * Constructor. Also sets the minimum, maximum, and numeric base values.
*/ */
KIntValidator ( int bottom, int top, QWidget * parent, int base = 10 ); KIntValidator(int bottom, int top, QWidget *parent, int base = 10);
/**
* Destructs the validator. virtual ~KIntValidator();
*/
virtual ~KIntValidator ();
/** /**
* Validates the text, and return the result. Does not modify the parameters. * Validates the text, and return the result. Does not modify the parameters.
*/ */
virtual State validate ( QString &, int & ) const; virtual QValidator::State validate(QString &, int &) const;
/** /**
* Fixes the text if possible, providing a valid string. The parameter may be modified. * Fixes the text if possible, providing a valid string. The parameter may be modified.
*/ */
virtual void fixup ( QString & ) const; virtual void fixup(QString &) const;
/** /**
* Sets the minimum and maximum values allowed. * Sets the minimum and maximum values allowed.
* If @p top is greater than @p bottom, it is set to the value of @p bottom. * If @p top is greater than @p bottom, it is set to the value of @p bottom.
*/ */
virtual void setRange ( int bottom, int top ); virtual void setRange(int bottom, int top);
/** /**
* Sets the numeric base value. @p base must be between 2 and 36. * Sets the numeric base value. @p base must be between 2 and 36.
*/ */
virtual void setBase ( int base ); virtual void setBase(int base);
/** /**
* Returns the current minimum value allowed. * Returns the current minimum value allowed.
*/ */
virtual int bottom () const; virtual int bottom() const;
/** /**
* Returns the current maximum value allowed. * Returns the current maximum value allowed.
*/ */
virtual int top () const; virtual int top() const;
/** /**
* Returns the current numeric base. * Returns the current numeric base.
*/ */
virtual int base () const; virtual int base() const;
private: private:
class KIntValidatorPrivate; class KIntValidatorPrivate;
KIntValidatorPrivate * const d; KIntValidatorPrivate * const d;
}; };
@ -100,32 +104,36 @@ class KDEUI_EXPORT KIntValidator : public QValidator {
@author Marc Mutz <mutz@kde.org> @author Marc Mutz <mutz@kde.org>
@see KIntValidator @see KIntValidator
**/ **/
class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator
class KDEUI_EXPORT KDoubleValidator : public QDoubleValidator { {
Q_OBJECT Q_OBJECT
Q_PROPERTY( bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers ) Q_PROPERTY(bool acceptLocalizedNumbers READ acceptLocalizedNumbers WRITE setAcceptLocalizedNumbers)
public: public:
/** Constuct a locale-aware KDoubleValidator with default range /**
(whatever QDoubleValidator uses for that) and parent @p Constuct a locale-aware KDoubleValidator with default range
parent */ (whatever QDoubleValidator uses for that) and parent @p
explicit KDoubleValidator( QObject * parent ); parent
/** Constuct a locale-aware KDoubleValidator for range [@p bottom,@p */
top] and a precision of @p decimals decimals after the decimal explicit KDoubleValidator(QObject *parent);
point. */
KDoubleValidator( double bottom, double top, int decimals,
QObject * parent );
/** Destructs the validator.
*/
virtual ~KDoubleValidator();
/** @return whether localized numbers are accepted (default: true) */ /**
bool acceptLocalizedNumbers() const; Constuct a locale-aware KDoubleValidator for range [@p bottom,@p
/** Sets whether to accept localized numbers (default: true) */ top] and a precision of @p decimals decimals after the decimal
void setAcceptLocalizedNumbers( bool accept ); point.
*/
KDoubleValidator(double bottom, double top, int decimals, QObject *parent);
virtual ~KDoubleValidator();
/** @return whether localized numbers are accepted (default: true) */
bool acceptLocalizedNumbers() const;
/** Sets whether to accept localized numbers (default: true) */
void setAcceptLocalizedNumbers(bool accept);
private: private:
class KDoubleValidatorPrivate; class KDoubleValidatorPrivate;
KDoubleValidatorPrivate * const d; KDoubleValidatorPrivate * const d;
}; };
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -1,729 +1,222 @@
/* This file is part of the KDE libraries /*
* Copyright (c) 1997 Patrick Dowler <dowler@morgul.fsh.uvic.ca> This file is part of the KDE libraries
* Copyright (c) 2000 Dirk Mueller <mueller@kde.org> Copyright (C) 2024 Ivailo Monev <xakepa10@gmail.com>
* Copyright (c) 2002 Marc Mutz <mutz@kde.org>
* This library is free software; you can redistribute it and/or
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
* modify it under the terms of the GNU Library General Public License version 2, as published by the Free Software Foundation.
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* This library is distributed in the hope that it will be useful, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* but WITHOUT ANY WARRANTY; without even the implied warranty of Library General Public License for more details.
* 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
* You should have received a copy of the GNU Library General Public License the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* along with this library; see the file COPYING.LIB. If not, write to Boston, MA 02110-1301, USA.
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, */
* Boston, MA 02110-1301, USA.
*/
#ifndef K_NUMINPUT_H #ifndef K_NUMINPUT_H
#define K_NUMINPUT_H #define K_NUMINPUT_H
#include <kdeui_export.h> #include <kdeui_export.h>
#include <klocalizedstring.h>
#include <QtGui/QWidget> #include <QWidget>
#include <QtGui/QSpinBox>
#include <QSlider>
#include <QSpinBox>
#include <QValidator> #include <QValidator>
class KIntSpinBox; class KIntNumInputPrivate;
class KNumInputPrivate; class KDoubleNumInputPrivate;
class KLocalizedString;
/** /**
* You need to inherit from this class if you want to implement K*NumInput * @short An input control for numbers with different base.
* for a different variable type
*
*/
class KDEUI_EXPORT KNumInput : public QWidget
{
Q_OBJECT
Q_PROPERTY( QString label READ label WRITE setLabel )
public:
/**
* Default constructor
* @param parent If parent is 0, the new widget becomes a top-level
* window. If parent is another widget, this widget becomes a child
* window inside parent. The new widget is deleted when its parent is deleted.
*/
explicit KNumInput(QWidget* parent=0);
/**
* Destructor
*/
~KNumInput();
/**
* Sets the text and alignment of the main description label.
*
* @param label The text of the label.
* Use QString() to remove an existing one.
*
* @param a The alignment of the label (Qt::Alignment).
* Default is @p Qt:AlignLeft | @p Qt:AlignTop.
*
* The vertical alignment flags have special meaning with this
* widget:
*
* @li @p Qt:AlignTop The label is placed above the edit/slider
* @li @p Qt:AlignVCenter The label is placed left beside the edit
* @li @p Qt:AlignBottom The label is placed below the edit/slider
*
*/
virtual void setLabel(const QString & label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop);
/**
* @return the text of the label.
*/
QString label() const;
/**
* @return if the num input has a slider.
*/
bool showSlider() const;
/**
* Sets the spacing of tickmarks for the slider.
*
* @param minor Minor tickmark separation.
* @param major Major tickmark separation.
*/
void setSteps(int minor, int major);
/**
* Returns a size which fits the contents of the control.
*
* @return the preferred size necessary to show the control
*/
virtual QSize sizeHint() const;
protected:
/**
* @return the slider widget.
* @internal
*/
QSlider *slider() const;
/**
* Call this function whenever you change something in the geometry
* of your KNumInput child.
*
*/
void layout(bool deep);
/**
* You need to overwrite this method and implement your layout
* calculations there.
*
* See KIntNumInput::doLayout and KDoubleNumInput::doLayout implementation
* for details.
*
*/
virtual void doLayout() = 0;
private:
friend class KNumInputPrivate;
KNumInputPrivate * const d;
Q_DISABLE_COPY(KNumInput)
};
/* ------------------------------------------------------------------------ */
/**
* @short An input widget for integer numbers, consisting of a spinbox and a slider.
* *
* KIntNumInput combines a QSpinBox and optionally a QSlider * KIntNumInput combines a QSpinBox and optionally a QSlider
* with a label to make an easy to use control for setting some integer * with a label to make an easy to use control for setting some float
* parameter. This is especially nice for configuration dialogs, * parameter.
* which can have many such combinated controls.
* *
* The slider is created only when the user specifies a range * @see KDoubleNumInput
* for the control using the setRange function or when the user
* calls setSliderEnabled.
*
* A special feature of KIntNumInput, designed specifically for
* the situation when there are several KIntNumInputs in a column,
* is that you can specify what portion of the control is taken by the
* QSpinBox (the remaining portion is used by the slider). This makes
* it very simple to have all the sliders in a column be the same size.
*
* It uses KIntValidator validator class. KIntNumInput enforces the
* value to be in the given range, and can display it in any base
* between 2 and 36.
*
* \image html kintnuminput.png "KDE Int Number Input Spinbox"
*/ */
class KDEUI_EXPORT KIntNumInput : public QWidget
class KDEUI_EXPORT KIntNumInput : public KNumInput
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( int value READ value WRITE setValue NOTIFY valueChanged ) Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY( int minimum READ minimum WRITE setMinimum ) Q_PROPERTY(int minimum READ minimum WRITE setMinimum)
Q_PROPERTY( int maximum READ maximum WRITE setMaximum ) Q_PROPERTY(int maximum READ maximum WRITE setMaximum)
Q_PROPERTY( int singleStep READ singleStep WRITE setSingleStep ) Q_PROPERTY(int singleStep READ singleStep WRITE setSingleStep)
Q_PROPERTY( int referencePoint READ referencePoint WRITE setReferencePoint ) Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
Q_PROPERTY( double relativeValue READ relativeValue WRITE setRelativeValue ) Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText)
Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) Q_PROPERTY(int base READ base WRITE setBase)
Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) Q_PROPERTY(bool sliderEnabled READ sliderEnabled WRITE setSliderEnabled)
Q_PROPERTY( bool sliderEnabled READ showSlider WRITE setSliderEnabled )
public: public:
/** /**
* Constructs an input control for integer values * Constructs an input control for integer values with initial value 0.
* with base 10 and initial value 0.
*/ */
explicit KIntNumInput(QWidget *parent=0); explicit KIntNumInput(QWidget *parent = nullptr);
/**
* Constructor
* It constructs a QSpinBox that allows the input of integer numbers
* in the range of -INT_MAX to +INT_MAX. To set a descriptive label,
* use setLabel(). To enforce the value being in a range and optionally to
* attach a slider to it, use setRange().
*
* @param value initial value for the control
* @param base numeric base used for display
* @param parent parent QWidget
*/
explicit KIntNumInput(int value, QWidget *parent=0,int base = 10);
/**
* Destructor
*
*
*/
virtual ~KIntNumInput(); virtual ~KIntNumInput();
/** /**
* @return the current value. * Spin box proxies
*/ */
void setRange(int min, int max);
int value() const; int value() const;
/**
* @return the curent value in units of the referencePoint.
*/
double relativeValue() const;
/**
* @return the current reference point
*/
int referencePoint() const;
/**
* @return the suffix displayed behind the value.
* @see setSuffix()
*/
QString suffix() const;
/**
* @return the prefix displayed in front of the value.
* @see setPrefix()
*/
QString prefix() const;
/**
* @return the string displayed for a special value.
* @see setSpecialValueText()
*/
QString specialValueText() const;
/**
* Sets the allowed input range and the step size for the slider and the
* spin box.
*
* @param min minimum value
* @param max maximum value
* @param step step size
*/
void setRange(int min, int max, int singleStep=1);
/**
* @param enabled Show the slider
* @default enabled
*/
void setSliderEnabled(bool enabled=true);
/**
* Sets the minimum value.
*/
void setMinimum(int min);
/**
* @return the minimum value.
*/
int minimum() const; int minimum() const;
/** void setMinimum(int min);
* Sets the maximum value.
*/
void setMaximum(int max);
/**
* @return the maximum value.
*/
int maximum() const; int maximum() const;
void setMaximum(int max);
/**
* @return the step of the spin box
*/
int singleStep() const; int singleStep() const;
void setSingleStep(int singleStep);
QString suffix() const;
QString prefix() const;
QString specialValueText() const;
void setSpecialValueText(const QString &text);
/** /**
* @return the step of the spin box * @return the base in which numbers in the spin box are represented.
*/ */
void setSingleStep(int step); int base() const;
/**
* Sets the base in which the numbers in the spin box are represented.
*/
void setBase(int base);
/** /**
* Sets the special value text. If set, the SpinBox will display * @return if slider is enabled.
* this text instead of the numeric value whenever the current * @see setSliderEnabled()
* value is equal to minVal(). Typically this is used for indicating
* that the choice has a special (default) meaning.
*/ */
void setSpecialValueText(const QString& text); bool sliderEnabled() const;
virtual void setLabel(const QString & label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop);
/** /**
* This method returns the minimum size necessary to display the * @param enabled Show the slider
* control. The minimum size is enough to show all the labels * @default enabled
* in the current font (font change may invalidate the return value).
*
* @return the minimum size necessary to show the control
*/ */
virtual QSize minimumSizeHint() const; void setSliderEnabled(bool enabled);
/**
* Validation overrides
*/
virtual QValidator::State validate(QString &input, int &pos) const;
virtual void fixup(QString &input) const;
public Q_SLOTS: public Q_SLOTS:
/** /**
* Sets the value of the control. * Spin box proxies
*/
void setValue(int);
/**
* Sets the value in units of the referencePoint
*/
void setRelativeValue(double);
/**
* Sets the reference point for relativeValue.
*/
void setReferencePoint(int);
/**
* Sets the suffix to @p suffix.
* Use QString() to disable this feature.
* Formatting has to be provided (e.g. a space separator between the
* prepended @p value and the suffix's text has to be provided
* as the first character in the suffix).
*
* @see QSpinBox::setSuffix(), #setPrefix()
*/
void setSuffix(const QString &suffix);
/**
* Sets the suffix to @p suffix.
* Use this to add a plural-aware suffix, e.g. by using ki18np("singular", "plural").
*
* @since 4.3
*/ */
void setValue(int value);
void setSuffix(const KLocalizedString &suffix); void setSuffix(const KLocalizedString &suffix);
void setSuffix(const QString &suffix);
/**
* Sets the prefix to @p prefix.
* Use QString() to disable this feature.
* Formatting has to be provided (see above).
*
* @see QSpinBox::setPrefix(), #setSuffix()
*/
void setPrefix(const QString &prefix); void setPrefix(const QString &prefix);
/**
* sets focus to the edit widget and marks all text in if mark == true
*
*/
void setEditFocus( bool mark = true );
Q_SIGNALS: Q_SIGNALS:
/**
* Emitted every time the value changes (by calling setValue() or
* by user interaction).
*/
void valueChanged(int); void valueChanged(int);
void editingFinished();
/**
* Emitted whenever valueChanged is. Contains the change
* relative to the referencePoint.
*/
void relativeValueChanged(double);
private Q_SLOTS:
void spinValueChanged(int);
void slotEmitRelativeValueChanged(int);
protected:
/**
* @return the spin box widget.
* @internal
*/
QSpinBox *spinBox() const;
virtual void doLayout();
void resizeEvent ( QResizeEvent * );
private: private:
void init(int value, int _base); friend KIntNumInputPrivate;
KIntNumInputPrivate* const d;
private:
class KIntNumInputPrivate; Q_PRIVATE_SLOT(d, void _k_updateSuffix(int value));
friend class KIntNumInputPrivate;
KIntNumInputPrivate * const d;
Q_DISABLE_COPY(KIntNumInput) Q_DISABLE_COPY(KIntNumInput)
}; };
/* ------------------------------------------------------------------------ */
/** /**
* @short An input control for real numbers, consisting of a spinbox and a slider. * @short An input control for real numbers.
* *
* KDoubleNumInput combines a QSpinBox and optionally a QSlider * KDoubleNumInput combines a QSpinBox and optionally a QSlider
* with a label to make an easy to use control for setting some float * with a label to make an easy to use control for setting some float
* parameter. This is especially nice for configuration dialogs, * parameter.
* which can have many such combinated controls.
*
* The slider is created only when the user specifies a range
* for the control using the setRange function with the slider
* parameter set to "true".
*
* A special feature of KDoubleNumInput, designed specifically for
* the situation when there are several instances in a column,
* is that you can specify what portion of the control is taken by the
* QSpinBox (the remaining portion is used by the slider). This makes
* it very simple to have all the sliders in a column be the same size.
*
* \image html kdoublenuminput.png "KDE Double Number Input Spinbox"
* *
* @see KIntNumInput * @see KIntNumInput
*/ */
class KDEUI_EXPORT KDoubleNumInput : public KNumInput class KDEUI_EXPORT KDoubleNumInput : public QWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY( double value READ value WRITE setValue NOTIFY valueChanged ) Q_PROPERTY(double value READ value WRITE setValue NOTIFY valueChanged)
Q_PROPERTY( double minimum READ minimum WRITE setMinimum ) Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
Q_PROPERTY( double maximum READ maximum WRITE setMaximum ) Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
Q_PROPERTY( double singleStep READ singleStep WRITE setSingleStep ) Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep)
Q_PROPERTY( QString suffix READ suffix WRITE setSuffix ) Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
Q_PROPERTY( QString prefix READ prefix WRITE setPrefix ) Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
Q_PROPERTY( QString specialValueText READ specialValueText WRITE setSpecialValueText ) Q_PROPERTY(QString specialValueText READ specialValueText WRITE setSpecialValueText)
Q_PROPERTY( int decimals READ decimals WRITE setDecimals ) Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
Q_PROPERTY( double referencePoint READ referencePoint WRITE setReferencePoint ) Q_PROPERTY(bool sliderEnabled READ sliderEnabled WRITE setSliderEnabled)
Q_PROPERTY( double relativeValue READ relativeValue WRITE setRelativeValue )
Q_PROPERTY( bool sliderEnabled READ showSlider WRITE setSliderEnabled )
Q_PROPERTY( double exponentRatio READ exponentRatio WRITE setExponentRatio )
public: public:
/** /**
* Constructs an input control for double values * Constructs an input control for double values with initial value 0.00.
* with initial value 0.00.
*/ */
explicit KDoubleNumInput(QWidget *parent = 0); explicit KDoubleNumInput(QWidget *parent = nullptr);
/**
* Constructor
*
* @param lower lower boundary value
* @param upper upper boundary value
* @param value initial value for the control
* @param singleStep step size to use for up/down arrow clicks
* @param precision number of digits after the decimal point
* @param parent parent QWidget
*/
KDoubleNumInput(double lower, double upper, double value, QWidget *parent=0,double singleStep=0.01,
int precision=2);
/**
* destructor
*/
virtual ~KDoubleNumInput(); virtual ~KDoubleNumInput();
/** /**
* @return the current value. * Spin box proxies
*/ */
void setRange(double min, double max);
double value() const; double value() const;
double minimum() const;
/** void setMinimum(double min);
* @return the suffix. double maximum() const;
* @see setSuffix() void setMaximum(double max);
*/ double singleStep() const;
void setSingleStep(double singleStep);
QString suffix() const; QString suffix() const;
/**
* @return the prefix.
* @see setPrefix()
*/
QString prefix() const; QString prefix() const;
QString specialValueText() const;
void setSpecialValueText(const QString &text);
/** /**
* @return number of decimals. * @return number of decimals.
* @see setDecimals() * @see setDecimals()
*/ */
int decimals() const; int decimals() const;
/**
* @return the string displayed for a special value.
* @see setSpecialValueText()
*/
QString specialValueText() const;
/**
* @param min minimum value
* @param max maximum value
* @param singleStep step size for the QSlider
* @param slider whether the slider is created or not
*/
void setRange(double min, double max, double singleStep=1, bool slider=true);
/**
* @param enabled Show the slider
* @default enabled
*/
void setSliderEnabled(bool enabled);
/**
* Sets the minimum value.
*/
void setMinimum(double min);
/**
* @return the minimum value.
*/
double minimum() const;
/**
* Sets the maximum value.
*/
void setMaximum(double max);
/**
* @return the maximum value.
*/
double maximum() const;
/**
* @return the step of the spin box
*/
double singleStep() const;
/**
* @return the step of the spin box
*/
void setSingleStep(double singleStep);
/** /**
* Specifies the number of digits to use. * Specifies the number of digits to use.
*/ */
void setDecimals(int decimals); void setDecimals(int decimals);
/**
* @return if slider is enabled.
* @see setSliderEnabled()
*/
bool sliderEnabled() const;
/** /**
* @return the reference point for relativeValue calculation * @param enabled Show the slider
* @default enabled
*/ */
double referencePoint() const; void setSliderEnabled(bool enabled);
/** /**
* @return the current value in units of referencePoint. * Validation overrides
*/ */
double relativeValue() const; virtual QValidator::State validate(QString &input, int &pos) const;
virtual void fixup(QString &input) const;
/**
* Sets the special value text. If set, the spin box will display
* this text instead of the numeric value whenever the current
* value is equal to minVal(). Typically this is used for indicating
* that the choice has a special (default) meaning.
*/
void setSpecialValueText(const QString& text);
virtual void setLabel(const QString & label, Qt::Alignment a = Qt::AlignLeft | Qt::AlignTop);
virtual QSize minimumSizeHint() const;
/**
* @return the value of the exponent use to map the slider to the
* spin box.
*/
double exponentRatio() const;
/**
* @param dbl the value of the exponent use to map the slider to the
* spin box (dbl need to be strictly positive).
*/
void setExponentRatio(double dbl);
public Q_SLOTS: public Q_SLOTS:
/** /**
* Sets the value of the control. * Spin box proxies
*/
void setValue(double);
/**
* Sets the value in units of referencePoint.
*/
void setRelativeValue(double);
/**
* Sets the reference Point to @p ref. It @p ref == 0, emitting of
* relativeValueChanged is blocked and relativeValue
* just returns 0.
*/
void setReferencePoint(double ref);
/**
* Sets the suffix to be displayed to @p suffix. Use QString() to disable
* this feature. Note that the suffix is attached to the value without any
* spacing. So if you prefer to display a space separator, set suffix
* to something like " cm".
* @see setSuffix()
*/ */
void setValue(double value);
void setSuffix(const KLocalizedString &suffix);
void setSuffix(const QString &suffix); void setSuffix(const QString &suffix);
/**
* Sets the prefix to be displayed to @p prefix. Use QString() to disable
* this feature. Note that the prefix is attached to the value without any
* spacing.
* @see setPrefix()
*/
void setPrefix(const QString &prefix); void setPrefix(const QString &prefix);
Q_SIGNALS: Q_SIGNALS:
/**
* Emitted every time the value changes (by calling setValue() or
* by user interaction).
*/
void valueChanged(double); void valueChanged(double);
/** void editingFinished();
* This is an overloaded member function, provided for
* convenience. It essentially behaves like the above function.
*
* Contains the value in units of referencePoint.
*/
void relativeValueChanged(double);
private Q_SLOTS:
void sliderMoved(int);
void spinBoxChanged(double);
void slotEmitRelativeValueChanged(double);
protected:
virtual void doLayout();
void resizeEvent ( QResizeEvent * );
private: private:
void init(double value, double lower, double upper, friend KDoubleNumInputPrivate;
double singleStep, int precision); KDoubleNumInputPrivate* const d;
double mapSliderToSpin(int) const;
void updateLegacyMembers();
private: Q_PRIVATE_SLOT(d, void _k_updateSuffix(double value));
class KDoubleNumInputPrivate;
friend class KDoubleNumInputPrivate;
KDoubleNumInputPrivate * const d;
Q_DISABLE_COPY(KDoubleNumInput) Q_DISABLE_COPY(KDoubleNumInput)
}; };
/* ------------------------------------------------------------------------ */
/**
* @short A QSpinBox with support for arbitrary base numbers.
*
* A QSpinBox with support for arbitrary base numbers
* (e.g. hexadecimal).
*
* The class provides an easy interface to use other
* numeric systems than the decimal.
*
* \image html kintspinbox.png "KDE Integer Input Spinboxes with hexadecimal and binary input"
*/
class KDEUI_EXPORT KIntSpinBox : public QSpinBox
{
Q_OBJECT
Q_PROPERTY( int base READ base WRITE setBase )
public:
/**
* Constructor.
*
* Constructs a widget with an integer inputline with a little scrollbar
* and a slider, with minimal value 0, maximal value 99, step 1, base 10
* and initial value 0.
*/
explicit KIntSpinBox( QWidget *parent = 0 );
/**
* Constructor.
*
* Constructs a widget with an integer inputline with a little scrollbar
* and a slider.
*
* @param lower The lowest valid value.
* @param upper The greatest valid value.
* @param singleStep The step size of the scrollbar.
* @param value The actual value.
* @param base The base of the used number system.
* @param parent The parent of the widget.
*/
KIntSpinBox(int lower, int upper, int singleStep, int value, QWidget *parent,int base = 10);
/**
* Destructor.
*/
virtual ~KIntSpinBox();
/**
* Sets the base in which the numbers in the spin box are represented.
*/
void setBase(int base);
/**
* @return the base in which numbers in the spin box are represented.
*/
int base() const;
/**
* sets focus and optionally marks all text
*
*/
void setEditFocus(bool mark);
/**
* Sets the suffix to @p suffix.
* Use this to add a plural-aware suffix, e.g. by using ki18np("singular", "plural").
*
* @since 4.3
*/
void setSuffix(const KLocalizedString &suffix);
using QSpinBox::setSuffix;
protected:
/**
* Overloaded the method in QSpinBox
* to make use of the base given in the constructor.
*/
virtual QString textFromValue(int) const;
/**
* Overloaded the method in QSpinBox
* to make use of the base given in the constructor.
*/
virtual int valueFromText(const QString &text) const;
private:
class KIntSpinBoxPrivate;
friend class KIntSpinBoxPrivate;
KIntSpinBoxPrivate *const d;
Q_DISABLE_COPY(KIntSpinBox)
Q_PRIVATE_SLOT(d, void updateSuffix(int))
};
#endif // K_NUMINPUT_H #endif // K_NUMINPUT_H

View file

@ -60,12 +60,6 @@ IncludeFile=kdialogbuttonbox.h
Group=Buttons (KDE) Group=Buttons (KDE)
DomXML=<ui><widget class="KDialogButtonBox"><property name="standardButtons"><set>QDialogButtonBox::Ok|QDialogButtonBox::Cancel</set></property></widget></ui> DomXML=<ui><widget class="KDialogButtonBox"><property name="standardButtons"><set>QDialogButtonBox::Ok|QDialogButtonBox::Cancel</set></property></widget></ui>
[KDoubleNumInput]
ToolTip=Floating Point Number Input Widget (KDE)
WhatsThis=An input widget for floating point numbers, consisting of a spinbox and a slider.
IncludeFile=knuminput.h
Group=Input (KDE)
[KEditListWidget] [KEditListWidget]
ToolTip=Fullfeatured edit box with buttons (KDE) ToolTip=Fullfeatured edit box with buttons (KDE)
Group=Views (KDE) Group=Views (KDE)
@ -111,9 +105,10 @@ WhatsThis=An input widget for integer numbers, consisting of a spinbox and a sli
IncludeFile=knuminput.h IncludeFile=knuminput.h
Group=Input (KDE) Group=Input (KDE)
[KIntSpinBox] [KDoubleNumInput]
ToolTip=Floating Point Number Input Widget (KDE)
WhatsThis=An input widget for floating point numbers, consisting of a spinbox and a slider.
IncludeFile=knuminput.h IncludeFile=knuminput.h
ToolTip=Enhanced Spinbox for Integer Values (KDE)
Group=Input (KDE) Group=Input (KDE)
[KKeySequenceWidget] [KKeySequenceWidget]

View file

@ -7,7 +7,6 @@ install(
kfontrequester.png kfontrequester.png
kurlrequester.png kurlrequester.png
kcombobox.png kcombobox.png
kintspinbox.png
kled.png kled.png
ksqueezedtextlabel.png ksqueezedtextlabel.png
kurllabel.png kurllabel.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -24,10 +24,10 @@
#include "private/style_p.h" #include "private/style_p.h"
#include "private/themedwidgetinterface_p.h" #include "private/themedwidgetinterface_p.h"
#include "theme.h" #include "theme.h"
#include "kmimetype.h"
#include "knuminput.h"
#include <QGraphicsView> #include <QGraphicsView>
#include <kmimetype.h>
#include <knuminput.h>
namespace Plasma namespace Plasma
{ {
@ -48,7 +48,7 @@ SpinBox::SpinBox(QGraphicsWidget *parent)
: QGraphicsProxyWidget(parent), : QGraphicsProxyWidget(parent),
d(new SpinBoxPrivate(this)) d(new SpinBoxPrivate(this))
{ {
QDoubleSpinBox *native = new QDoubleSpinBox(); KDoubleNumInput *native = new KDoubleNumInput();
connect(native, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double))); connect(native, SIGNAL(valueChanged(double)), this, SIGNAL(valueChanged(double)));
connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished())); connect(native, SIGNAL(editingFinished()), this, SIGNAL(editingFinished()));
@ -104,9 +104,9 @@ double SpinBox::value() const
return nativeWidget()->value(); return nativeWidget()->value();
} }
QDoubleSpinBox *SpinBox::nativeWidget() const KDoubleNumInput *SpinBox::nativeWidget() const
{ {
return static_cast<QDoubleSpinBox*>(widget()); return static_cast<KDoubleNumInput*>(widget());
} }
void SpinBox::changeEvent(QEvent *event) void SpinBox::changeEvent(QEvent *event)

View file

@ -21,11 +21,12 @@
#ifndef PLASMA_SPINBOX_H #ifndef PLASMA_SPINBOX_H
#define PLASMA_SPINBOX_H #define PLASMA_SPINBOX_H
#include <QDoubleSpinBox>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
class KDoubleNumInput;
namespace Plasma namespace Plasma
{ {
@ -65,7 +66,7 @@ public:
/** /**
* @return the native widget wrapped by this SpinBox * @return the native widget wrapped by this SpinBox
*/ */
QDoubleSpinBox *nativeWidget() const; KDoubleNumInput *nativeWidget() const;
protected: protected:
void changeEvent(QEvent *event); void changeEvent(QEvent *event);
@ -96,15 +97,6 @@ public Q_SLOTS:
void setValue(double value); void setValue(double value);
Q_SIGNALS: Q_SIGNALS:
/**
* This signal is emitted when the user drags the slider.
*
* In fact, it is emitted whenever the sliderMoved(double) signal
* of KIntSpinBox would be emitted. See the Qt documentation for
* more information.
*/
void sliderMoved(double value);
/** /**
* This signal is emitted when the slider value has changed, * This signal is emitted when the slider value has changed,
* with the new slider value as argument. * with the new slider value as argument.