File indexing completed on 2025-01-12 03:46:20
0001 // Copyright (C) 2002 Jason Katz-Brown <jason@katzbrown.com> 0002 // Copyright (C) 2002 Neil Stevens <neil@qualityassistant.com> 0003 // 0004 // Permission is hereby granted, free of charge, to any person obtaining a copy 0005 // of this software and associated documentation files (the "Software"), to deal 0006 // in the Software without restriction, including without limitation the rights 0007 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0008 // copies of the Software, and to permit persons to whom the Software is 0009 // furnished to do so, subject to the following conditions: 0010 // 0011 // The above copyright notice and this permission notice shall be included in 0012 // all copies or substantial portions of the Software. 0013 // 0014 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0015 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0016 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0017 // THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 0018 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 0019 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0020 // 0021 // Except as contained in this notice, the name(s) of the author(s) shall not be 0022 // used in advertising or otherwise to promote the sale, use or other dealings 0023 // in this Software without prior written authorization from the author(s). 0024 0025 #ifndef KCOMBOBOX_DIALOG_H 0026 #define KCOMBOBOX_DIALOG_H 0027 0028 #include <QDialog> 0029 #include <KConfig> 0030 #include <KSharedConfig> 0031 0032 class QCheckBox; 0033 class KHistoryComboBox; 0034 0035 ///Dialog for user to choose an item from a QStringList. 0036 class KComboBoxDialog : public QDialog 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 /** 0042 * Create a dialog that asks for a single line of text. _value is 0043 * the initial value of the line. _text appears as the current text 0044 * of the combobox. 0045 * 0046 * @param _items Items in the combobox 0047 * @param _text Text of the label 0048 * @param _value Initial value of the combobox 0049 */ 0050 KComboBoxDialog( const QString &_text, const QStringList& _items, const QString& _value = QString(), bool showDontAskAgain = false, QWidget *parent = nullptr ); 0051 ~KComboBoxDialog() override; 0052 0053 ///@return the value the user chose 0054 QString text() const; 0055 0056 ///@return the line edit widget 0057 KHistoryComboBox *comboBox() const { return combo; } 0058 0059 /** 0060 * Static convenience function to get input from the user. 0061 * 0062 * @param _text Text of the label 0063 * @param _items Items in the combobox 0064 * @param _value Initial value of the inputline 0065 * @param dontAskAgainName Name for saving whether the user doesn't want to be asked again; use QString() to disable 0066 */ 0067 static QString getItem( const QString &_text, const QStringList &_items, const QString& _value = QString(), const QString &dontAskAgainName = QString(), QWidget *parent = nullptr ); 0068 0069 /** 0070 * Static convenience function to get input from the user. 0071 * This method includes a caption. 0072 * 0073 * @param _caption Caption of the dialog 0074 * @param _text Text of the label 0075 * @param _items Items in the combobox 0076 * @param _value Initial value of the inputline 0077 * @param dontAskAgainName Name for saving whether the user doesn't want to be asked again; use QString() to disable 0078 */ 0079 static QString getItem( const QString &_text, const QString &_caption, const QStringList &_items, const QString& _value = QString(), const QString &dontAskAgainName = QString(), QWidget *parent = nullptr ); 0080 0081 /** 0082 * Static convenience method. 0083 * This method is meant as a replacement for KLineEditDlg::getText() for cases 0084 * when a history and autocompletion are desired. 0085 * 0086 * @param _caption Caption of the dialog 0087 * @param _text Text of the label 0088 * @param _value Initial value of the inputline 0089 * @param ok Variable to store whether the user hit OK 0090 * @param parent Parent widget for the dialog 0091 * @param configName Name of the dialog for saving the completion and history 0092 * @param config KConfig for saving the completion and history 0093 */ 0094 static QString getText(const QString &_caption, const QString &_text, 0095 const QString &_value = QString(), 0096 bool *ok = nullptr, QWidget *parent = nullptr, 0097 const QString &configName = QString(), 0098 KSharedConfigPtr config = KSharedConfig::openConfig()); 0099 0100 protected: 0101 KHistoryComboBox *combo; 0102 QCheckBox *dontAskAgainCheckBox; 0103 bool dontAskAgainChecked(); 0104 }; 0105 0106 #endif