File indexing completed on 2024-04-14 04:36:10
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) 2006-2015 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_BOOLEDIT_H 0023 #define KPROPERTY_BOOLEDIT_H 0024 0025 #include "combobox.h" 0026 #include "KPropertyFactory.h" 0027 0028 #include <QEvent> 0029 #include <QResizeEvent> 0030 #include <QToolButton> 0031 0032 //! A bool editor supporting two states: true and false. 0033 /*! For null values, false is displayed. 0034 */ 0035 class KPROPERTYWIDGETS_EXPORT KPropertyBoolEditor : public QToolButton 0036 { 0037 Q_OBJECT 0038 Q_PROPERTY(QVariant value READ value WRITE setValue USER true) 0039 0040 public: 0041 explicit KPropertyBoolEditor(const KProperty *prop, QWidget *parent = nullptr); 0042 0043 ~KPropertyBoolEditor() override; 0044 0045 QVariant value() const; 0046 0047 static void draw(QPainter *p, const QRect &r, const QVariant &value, 0048 const QString& text, bool threeState); 0049 Q_SIGNALS: 0050 void commitData(QWidget* editor); 0051 0052 public Q_SLOTS: 0053 void setValue(const QVariant &value); 0054 0055 protected Q_SLOTS: 0056 void slotValueChanged(bool state); 0057 0058 protected: 0059 void paintEvent( QPaintEvent * event ) override; 0060 bool eventFilter(QObject* watched, QEvent* e) override; 0061 0062 private: 0063 Q_DISABLE_COPY(KPropertyBoolEditor) 0064 class Private; 0065 Private * const d; 0066 }; 0067 0068 //! A bool editor supporting three states: true, false and null. 0069 /*! The editor is implemented as a drop-down list. 0070 */ 0071 class KPROPERTYWIDGETS_EXPORT KPropertyThreeStateBoolEditor : public KPropertyComboBoxEditor 0072 { 0073 Q_OBJECT 0074 0075 public: 0076 explicit KPropertyThreeStateBoolEditor(const KPropertyListData& listData, QWidget *parent = nullptr); 0077 ~KPropertyThreeStateBoolEditor() override; 0078 0079 QVariant value() const override; 0080 void setValue(const QVariant &value) override; 0081 0082 private: 0083 Q_DISABLE_COPY(KPropertyThreeStateBoolEditor) 0084 class Private; 0085 Private * const d; 0086 }; 0087 0088 class KPROPERTYWIDGETS_EXPORT KPropertyBoolDelegate : public KPropertyEditorCreatorInterface, 0089 public KPropertyValuePainterInterface, 0090 public KPropertyValueDisplayInterface 0091 { 0092 public: 0093 KPropertyBoolDelegate(); 0094 0095 QWidget *createEditor(int type, QWidget *parent, const QStyleOptionViewItem &option, 0096 const QModelIndex &index) const override; 0097 0098 void paint(QPainter *painter, const QStyleOptionViewItem &option, 0099 const QModelIndex &index) const override; 0100 0101 QString propertyValueToString(const KProperty *prop, const QLocale &locale) const override; 0102 0103 QString valueToString(const QVariant &value, const QLocale &locale) const override; 0104 }; 0105 0106 #endif