File indexing completed on 2024-04-21 04:41:02

0001 /* This file is part of the KDE project
0002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
0003    Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
0004    Copyright (C) 2008-2017 Jarosław Staniek <staniek@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License as published by the Free Software Foundation; either
0009    version 2 of the License, or (at your option) any later version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019  * Boston, MA 02110-1301, USA.
0020 */
0021 
0022 #ifndef KPROPERTY_SPINBOX_H
0023 #define KPROPERTY_SPINBOX_H
0024 
0025 #include "KPropertyWidgetsFactory.h"
0026 
0027 #include <QSpinBox>
0028 #include <QDoubleSpinBox>
0029 
0030 //! A delegate supporting Int and UInt types
0031 /*! Note that due to KIntNumInput limitations, for UInt the maximum value
0032     is INT_MAX, not UINT_MAX.
0033 */
0034 class KPROPERTYWIDGETS_EXPORT KPropertyIntSpinBox : public QSpinBox
0035 {
0036     Q_OBJECT
0037     Q_PROPERTY(QVariant value READ value WRITE setValue USER true)
0038 
0039 public:
0040     KPropertyIntSpinBox(const KProperty& prop, QWidget *parent, int itemHeight);
0041     ~KPropertyIntSpinBox() override;
0042 
0043     QVariant value() const;
0044 
0045 Q_SIGNALS:
0046     void commitData(QWidget* editor);
0047 
0048 public Q_SLOTS:
0049     void setValue(const QVariant& value);
0050 
0051 protected Q_SLOTS:
0052     void slotValueChanged(int value);
0053 
0054 private:
0055     Q_DISABLE_COPY(KPropertyIntSpinBox)
0056     class Private;
0057     Private * const d;
0058 };
0059 
0060 //! Double editor
0061 class KPROPERTYWIDGETS_EXPORT KPropertyDoubleSpinBox : public QDoubleSpinBox
0062 {
0063     Q_OBJECT
0064     Q_PROPERTY(double value READ value WRITE setValue USER true)
0065 
0066 public:
0067     KPropertyDoubleSpinBox(const KProperty &prop, QWidget *parent, int itemHeight);
0068     ~KPropertyDoubleSpinBox() override;
0069 
0070 Q_SIGNALS:
0071     void commitData(QWidget* editor);
0072 
0073 public Q_SLOTS:
0074     void setValue(const QVariant& value);
0075 
0076 protected Q_SLOTS:
0077     void slotValueChanged(double value);
0078 
0079 protected:
0080     // keep this until the next ABI break
0081     void resizeEvent( QResizeEvent * event ) override;
0082 
0083     Q_DISABLE_COPY(KPropertyDoubleSpinBox)
0084     class Private;
0085     Private * const d;
0086 };
0087 
0088 //! A delegate supporting Int, UInt, LongLong and ULongLong types
0089 class KPROPERTYWIDGETS_EXPORT KPropertyIntSpinBoxDelegate : public KPropertyEditorCreatorInterface,
0090                                                             public KPropertyValueDisplayInterface
0091 {
0092 public:
0093     KPropertyIntSpinBoxDelegate();
0094 
0095     QString propertyValueToString(const KProperty *prop, const QLocale &locale) const override;
0096 
0097     QString valueToString(const QVariant &value, const QLocale &locale) const override;
0098 
0099     QWidget *createEditor(int type, QWidget *parent, const QStyleOptionViewItem &option,
0100                           const QModelIndex &index) const override;
0101 };
0102 
0103 class KPROPERTYWIDGETS_EXPORT KPropertyDoubleSpinBoxDelegate : public KPropertyEditorCreatorInterface,
0104                                                                public KPropertyValueDisplayInterface
0105 {
0106 public:
0107     KPropertyDoubleSpinBoxDelegate();
0108 
0109     QString propertyValueToString(const KProperty *prop, const QLocale &locale) const override;
0110 
0111     QString valueToString(const QVariant &value, const QLocale &locale) const override;
0112 
0113     QWidget *createEditor(int type, QWidget *parent, const QStyleOptionViewItem &option,
0114                           const QModelIndex &index) const override;
0115 };
0116 
0117 #endif