File indexing completed on 2024-04-21 04:41:00
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-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_COMBOBOX_H 0023 #define KPROPERTY_COMBOBOX_H 0024 0025 #include "KPropertyWidgetsFactory.h" 0026 0027 #include <QComboBox> 0028 0029 class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxEditorIconProviderInterface 0030 { 0031 public: 0032 KPropertyComboBoxEditorIconProviderInterface() {} 0033 virtual ~KPropertyComboBoxEditorIconProviderInterface() {} 0034 virtual QIcon icon(int index) const = 0; 0035 virtual KPropertyComboBoxEditorIconProviderInterface* clone() const = 0; 0036 }; 0037 0038 class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxEditorOptions 0039 { 0040 public: 0041 KPropertyComboBoxEditorOptions(); 0042 KPropertyComboBoxEditorOptions(const KPropertyComboBoxEditorOptions& other); 0043 ~KPropertyComboBoxEditorOptions(); 0044 0045 KPropertyComboBoxEditorOptions& operator=(const KPropertyComboBoxEditorOptions &other); 0046 0047 KPropertyComboBoxEditorIconProviderInterface *iconProvider = nullptr; 0048 bool extraValueAllowed; 0049 }; 0050 0051 class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxEditor : public QComboBox 0052 { 0053 Q_OBJECT 0054 Q_PROPERTY(QVariant value READ value WRITE setValue USER true) 0055 0056 public: 0057 KPropertyComboBoxEditor(const KPropertyListData &listData, 0058 const KPropertyComboBoxEditorOptions &options, 0059 QWidget *parent = nullptr); 0060 0061 ~KPropertyComboBoxEditor() override; 0062 0063 virtual QVariant value() const; 0064 0065 static QString borderSheet(const QWidget *widget); 0066 0067 Q_SIGNALS: 0068 void commitData( QWidget * editor ); 0069 0070 public Q_SLOTS: 0071 void setListData(const KPropertyListData & listData); 0072 0073 virtual void setValue(const QVariant &value); 0074 0075 protected Q_SLOTS: 0076 void slotValueChanged(int value); 0077 0078 protected: 0079 void paintEvent(QPaintEvent *event) override; 0080 0081 QString keyForValue(const QVariant &value); 0082 0083 void fillValues(); 0084 0085 bool listDataKeysAvailable() const; 0086 0087 private: 0088 Q_DISABLE_COPY(KPropertyComboBoxEditor) 0089 class Private; 0090 Private * const d; 0091 }; 0092 0093 class KPROPERTYWIDGETS_EXPORT KPropertyComboBoxDelegate : public KPropertyEditorCreatorInterface, 0094 public KPropertyValueDisplayInterface 0095 { 0096 public: 0097 KPropertyComboBoxDelegate(); 0098 0099 QString propertyValueToString(const KProperty *property, const QLocale &locale) const override; 0100 0101 QString valueToString(const QVariant &value, const QLocale &locale) const override; 0102 0103 QWidget *createEditor(int type, QWidget *parent, const QStyleOptionViewItem &option, 0104 const QModelIndex &index) const override; 0105 }; 0106 0107 #endif