File indexing completed on 2024-04-14 14:20:19
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEDITLISTBOX_H 0021 #define KEDITLISTBOX_H 0022 0023 #include <kdelibs4support_export.h> 0024 0025 #include <QGroupBox> 0026 #include <QStringListModel> 0027 0028 class KLineEdit; 0029 class KComboBox; 0030 class QListView; 0031 class QPushButton; 0032 class QItemSelection; 0033 0034 class KEditListBoxPrivate; 0035 /** 0036 * @brief An editable listbox 0037 * 0038 * @deprecated since 5.0 in favor of KEditListWidget embedded in a QGroupBox. 0039 */ 0040 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KEditListBox : public QGroupBox 0041 { 0042 Q_OBJECT 0043 0044 Q_FLAGS(Buttons) 0045 Q_PROPERTY(Buttons buttons READ buttons WRITE setButtons) 0046 Q_PROPERTY(QStringList items READ items WRITE setItems NOTIFY changed USER true) 0047 0048 public: 0049 class CustomEditorPrivate; 0050 0051 /** 0052 * Custom editor class 0053 **/ 0054 class KDELIBS4SUPPORT_DEPRECATED_EXPORT CustomEditor 0055 { 0056 public: 0057 CustomEditor(); 0058 CustomEditor(QWidget *repWidget, KLineEdit *edit); 0059 CustomEditor(KComboBox *combo); 0060 virtual ~CustomEditor(); 0061 0062 void setRepresentationWidget(QWidget *repWidget); 0063 void setLineEdit(KLineEdit *edit); 0064 0065 virtual QWidget *representationWidget() const; 0066 virtual KLineEdit *lineEdit() const; 0067 0068 private: 0069 friend class CustomEditorPrivate; 0070 CustomEditorPrivate *const d; 0071 0072 Q_DISABLE_COPY(CustomEditor) 0073 }; 0074 0075 public: 0076 0077 /** 0078 * Enumeration of the buttons, the listbox offers. Specify them in the 0079 * constructor in the buttons parameter, or in setButtons. 0080 */ 0081 enum Button { 0082 Add = 0x0001, 0083 Remove = 0x0002, 0084 UpDown = 0x0004, 0085 All = Add | Remove | UpDown 0086 }; 0087 0088 Q_DECLARE_FLAGS(Buttons, Button) 0089 0090 /** 0091 * Create an editable listbox. 0092 */ 0093 KDELIBS4SUPPORT_DEPRECATED explicit KEditListBox(QWidget *parent = nullptr); 0094 0095 /** 0096 * Create an editable listbox. 0097 * 0098 * The same as the other constructor, additionally it takes 0099 * @p title, which will be the title of the groupbox around the listbox. 0100 */ 0101 KDELIBS4SUPPORT_DEPRECATED explicit KEditListBox(const QString &title, QWidget *parent = nullptr); 0102 0103 // ### KDE5: remove name arguments and simplify (merge?!) constructors 0104 0105 /** 0106 * Create an editable listbox. 0107 * 0108 * \deprecated 0109 * 0110 * If @p checkAtEntering is true, after every character you type 0111 * in the line edit KEditListBox will enable or disable 0112 * the Add-button, depending whether the current content of the 0113 * line edit is already in the listbox. Maybe this can become a 0114 * performance hit with large lists on slow machines. 0115 * If @p checkAtEntering is false, 0116 * it will be checked if you press the Add-button. It is not 0117 * possible to enter items twice into the listbox. 0118 */ 0119 KDELIBS4SUPPORT_DEPRECATED explicit KEditListBox(QWidget *parent, const char *name, 0120 bool checkAtEntering = false, Buttons buttons = All); 0121 /** 0122 * Create an editable listbox. 0123 * 0124 * \deprecated 0125 * 0126 * The same as the other constructor, additionally it takes 0127 * @p title, which will be the title of the frame around the listbox. 0128 */ 0129 KDELIBS4SUPPORT_DEPRECATED explicit KEditListBox(const QString &title, QWidget *parent, 0130 const char *name, bool checkAtEntering = false, 0131 Buttons buttons = All); 0132 0133 /** 0134 * Another constructor, which allows to use a custom editing widget 0135 * instead of the standard KLineEdit widget. E.g. you can use a 0136 * KUrlRequester or a KComboBox as input widget. The custom 0137 * editor must consist of a lineedit and optionally another widget that 0138 * is used as representation. A KComboBox or a KUrlRequester have a 0139 * KLineEdit as child-widget for example, so the KComboBox is used as 0140 * the representation widget. 0141 * 0142 * @see KUrlRequester::customEditor(), setCustomEditor 0143 */ 0144 KEditListBox(const QString &title, 0145 const CustomEditor &customEditor, 0146 QWidget *parent = nullptr, const char *name = nullptr, 0147 bool checkAtEntering = false, Buttons buttons = All); 0148 0149 ~KEditListBox() override; 0150 0151 /** 0152 * Return a pointer to the embedded QListView. 0153 */ 0154 QListView *listView() const; 0155 /** 0156 * Return a pointer to the embedded KLineEdit. 0157 */ 0158 KLineEdit *lineEdit() const; 0159 /** 0160 * Return a pointer to the Add button 0161 */ 0162 QPushButton *addButton() const; 0163 /** 0164 * Return a pointer to the Remove button 0165 */ 0166 QPushButton *removeButton() const; 0167 /** 0168 * Return a pointer to the Up button 0169 */ 0170 QPushButton *upButton() const; 0171 /** 0172 * Return a pointer to the Down button 0173 */ 0174 QPushButton *downButton() const; 0175 0176 /** 0177 * See Q3ListBox::count() 0178 */ 0179 int count() const; 0180 /** 0181 * See Q3ListBox::insertStringList() 0182 */ 0183 void insertStringList(const QStringList &list, int index = -1); 0184 /** 0185 * See Q3ListBox::insertItem() 0186 */ 0187 void insertItem(const QString &text, int index = -1); 0188 /** 0189 * Clears both the listbox and the line edit. 0190 */ 0191 void clear(); 0192 /** 0193 * See Q3ListBox::text() 0194 */ 0195 QString text(int index) const; 0196 /** 0197 * See Q3ListBox::currentItem() 0198 */ 0199 int currentItem() const; 0200 /** 0201 * See Q3ListBox::currentText() 0202 */ 0203 QString currentText() const; 0204 0205 /** 0206 * @returns a stringlist of all items in the listbox 0207 */ 0208 QStringList items() const; 0209 0210 /** 0211 * Clears the listbox and sets the contents to @p items 0212 */ 0213 void setItems(const QStringList &items); 0214 0215 /** 0216 * Returns which buttons are visible 0217 */ 0218 Buttons buttons() const; 0219 0220 /** 0221 * Specifies which buttons should be visible 0222 */ 0223 void setButtons(Buttons buttons); 0224 0225 /** 0226 * If @p check is true, after every character you type 0227 * in the line edit KEditListBox will enable or disable 0228 * the Add-button, depending whether the current content of the 0229 * line edit is already in the listbox. Maybe this can become a 0230 * performance hit with large lists on slow machines. 0231 * If @p check is false, 0232 * it will be checked if you press the Add-button. It is not 0233 * possible to enter items twice into the listbox. 0234 * Default is false. 0235 */ 0236 void setCheckAtEntering(bool check); 0237 0238 /** 0239 * Returns true if check at entering is enabled. 0240 */ 0241 bool checkAtEntering(); 0242 0243 /** 0244 * Allows to use a custom editing widget 0245 * instead of the standard KLineEdit widget. E.g. you can use a 0246 * KUrlRequester or a KComboBox as input widget. The custom 0247 * editor must consist of a lineedit and optionally another widget that 0248 * is used as representation. A KComboBox or a KUrlRequester have a 0249 * KLineEdit as child-widget for example, so the KComboBox is used as 0250 * the representation widget. 0251 * 0252 * @since 4.1 0253 */ 0254 void setCustomEditor(const CustomEditor &editor); 0255 0256 /** 0257 * Reimplented for interal reasons. The API is not affected. 0258 */ 0259 bool eventFilter(QObject *o, QEvent *e) override; 0260 0261 Q_SIGNALS: 0262 void changed(); 0263 0264 /** 0265 * This signal is emitted when the user adds a new string to the list, 0266 * the parameter is the added string. 0267 */ 0268 void added(const QString &text); 0269 0270 /** 0271 * This signal is emitted when the user removes a string from the list, 0272 * the parameter is the removed string. 0273 */ 0274 void removed(const QString &text); 0275 0276 protected Q_SLOTS: // KDE5: make private? 0277 void moveItemUp(); 0278 void moveItemDown(); 0279 void addItem(); 0280 void removeItem(); 0281 void enableMoveButtons(const QModelIndex &, const QModelIndex &); 0282 void typedSomething(const QString &text); 0283 0284 private Q_SLOTS: 0285 void slotSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); 0286 0287 private: 0288 friend class KEditListBoxPrivate; 0289 KEditListBoxPrivate *const d; 0290 0291 Q_DISABLE_COPY(KEditListBox) 0292 }; 0293 0294 Q_DECLARE_OPERATORS_FOR_FLAGS(KEditListBox::Buttons) 0295 0296 #endif