File indexing completed on 2024-05-12 04:33:22
0001 /* 0002 * SPDX-FileCopyrightText: 2007-2011 Kare Sars <kare.sars@iki .fi> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef LABELED_COMBO_H 0008 #define LABELED_COMBO_H 0009 0010 #include "ksaneoptionwidget.h" 0011 0012 #include <QVariant> 0013 0014 class QComboBox; 0015 0016 namespace KSaneIface 0017 { 0018 0019 /** 0020 * A label and a combobox. 0021 */ 0022 class LabeledCombo : public KSaneOptionWidget 0023 { 0024 Q_OBJECT 0025 0026 public: 0027 /** 0028 * create a label and combobox combination. 0029 * \param parent parent widget 0030 * \param label is the lext for the label 0031 * \param list a stringlist with values the list should contain. 0032 */ 0033 LabeledCombo(QWidget *parent, const QString &label, const QStringList &list = QStringList()); 0034 0035 LabeledCombo(QWidget *parent, KSaneCore::Option *option); 0036 0037 /** This function forwards the request to the QComboBox equivalent */ 0038 QVariant currentData(int role = Qt::UserRole) const; 0039 0040 /** This function forwards the request to the QComboBox equivalent */ 0041 void addItem(const QString &text, const QVariant &userData = QVariant()); 0042 0043 /** This function forwards the request to the QComboBox equivalent */ 0044 int count() const; 0045 0046 /** This function forwards the request to the QComboBox equivalent */ 0047 int currentIndex() const; 0048 0049 /** 0050 * This function is used to read the current string of the combobox 0051 */ 0052 QString currentText() const; 0053 0054 public Q_SLOTS: 0055 0056 /** 0057 * Add string entries to the combobox 0058 */ 0059 void addItems(const QStringList &list); 0060 0061 /** 0062 * Remove all string entries 0063 */ 0064 void clear(); 0065 0066 /** 0067 * If the given string can be found in the combobox, activate that entry. 0068 * If not, the entry is not changed. 0069 */ 0070 void setCurrentText(const QString &); 0071 0072 /** 0073 * set the current item of the combobox. 0074 */ 0075 void setCurrentIndex(int); 0076 0077 void setValue(const QVariant &val); 0078 0079 private Q_SLOTS: 0080 0081 void emitChangedValue(int index); 0082 0083 Q_SIGNALS: 0084 0085 void activated(int); 0086 0087 void valueChanged(const QVariant &value); 0088 0089 private: 0090 void initCombo(const QStringList &list); 0091 0092 QString getStringWithUnitForInteger(int iValue) const; 0093 0094 QString getStringWithUnitForFloat(float iValue) const; 0095 0096 QComboBox *m_combo; 0097 }; 0098 0099 } // NameSpace KSaneIface 0100 0101 #endif // LABELED_COMBO_H