-rw-r--r-- | microkde/keditlistbox.h | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/microkde/keditlistbox.h b/microkde/keditlistbox.h new file mode 100644 index 0000000..130d933 --- a/dev/null +++ b/microkde/keditlistbox.h | |||
@@ -0,0 +1,226 @@ | |||
1 | /* This file is part of the KDE libraries | ||
2 | Copyright (C) 2000 David Faure <faure@kde.org>, Alexander Neundorf <neundorf@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Library General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2 of the License, or (at your option) any later version. | ||
8 | |||
9 | This library is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | Library General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
17 | Boston, MA 02111-1307, USA. | ||
18 | */ | ||
19 | |||
20 | #ifndef KEDITLISTBOX_H | ||
21 | #define KEDITLISTBOX_H | ||
22 | |||
23 | #include <qgroupbox.h> | ||
24 | #include <qlistbox.h> | ||
25 | |||
26 | class KLineEdit; | ||
27 | class KComboBox; | ||
28 | class QPushButton; | ||
29 | |||
30 | class KEditListBoxPrivate; | ||
31 | /** | ||
32 | * An editable listbox | ||
33 | * | ||
34 | * This class provides a editable listbox ;-), this means | ||
35 | * a listbox which is accompanied by a line edit to enter new | ||
36 | * items into the listbox and pushbuttons to add and remove | ||
37 | * items from the listbox and two buttons to move items up and down. | ||
38 | */ | ||
39 | class KEditListBox : public QGroupBox | ||
40 | { | ||
41 | Q_OBJECT | ||
42 | |||
43 | public: | ||
44 | /// @since 3.1 | ||
45 | class CustomEditor | ||
46 | { | ||
47 | public: | ||
48 | CustomEditor() | ||
49 | : m_representationWidget( 0L ), | ||
50 | m_lineEdit( 0L ) {} | ||
51 | CustomEditor( QWidget *repWidget, KLineEdit *edit ) | ||
52 | : m_representationWidget( repWidget ), | ||
53 | m_lineEdit( edit ) {} | ||
54 | CustomEditor( KComboBox *combo ); | ||
55 | |||
56 | void setRepresentationWidget( QWidget *repWidget ) { | ||
57 | m_representationWidget = repWidget; | ||
58 | } | ||
59 | void setLineEdit( KLineEdit *edit ) { | ||
60 | m_lineEdit = edit; | ||
61 | } | ||
62 | |||
63 | virtual QWidget *representationWidget() const { | ||
64 | return m_representationWidget; | ||
65 | } | ||
66 | virtual KLineEdit *lineEdit() const { | ||
67 | return m_lineEdit; | ||
68 | } | ||
69 | |||
70 | protected: | ||
71 | QWidget *m_representationWidget; | ||
72 | KLineEdit *m_lineEdit; | ||
73 | }; | ||
74 | |||
75 | public: | ||
76 | |||
77 | /** | ||
78 | * Enumeration of the buttons, the listbox offers. Specify them in the | ||
79 | * constructor in the buttons parameter. | ||
80 | */ | ||
81 | enum Button { Add = 1, Remove = 2, UpDown = 4, All = Add|Remove|UpDown }; | ||
82 | |||
83 | /** | ||
84 | * Create an editable listbox. | ||
85 | * | ||
86 | * If @p checkAtEntering is true, after every character you type | ||
87 | * in the line edit KEditListBox will enable or disable | ||
88 | * the Add-button, depending whether the current content of the | ||
89 | * line edit is already in the listbox. Maybe this can become a | ||
90 | * performance hit with large lists on slow machines. | ||
91 | * If @p checkAtEntering is false, | ||
92 | * it will be checked if you press the Add-button. It is not | ||
93 | * possible to enter items twice into the listbox. | ||
94 | */ | ||
95 | KEditListBox(QWidget *parent = 0, const char *name = 0, | ||
96 | bool checkAtEntering=false, int buttons = All ); | ||
97 | /** | ||
98 | * Create an editable listbox. | ||
99 | * | ||
100 | * The same as the other constructor, additionally it takes | ||
101 | * @title, which will be the title of the frame around the listbox. | ||
102 | */ | ||
103 | KEditListBox(const QString& title, QWidget *parent = 0, | ||
104 | const char *name = 0, bool checkAtEntering=false, | ||
105 | int buttons = All ); | ||
106 | |||
107 | /** | ||
108 | * Another constructor, which allows to use a custom editing widget | ||
109 | * instead of the standard KLineEdit widget. E.g. you can use a | ||
110 | * @ref KURLRequester or a @ref KComboBox as input widget. The custom | ||
111 | * editor must consist of a lineedit and optionally another widget that | ||
112 | * is used as representation. A KComboBox or a KURLRequester have a | ||
113 | * KLineEdit as child-widget for example, so the KComboBox is used as | ||
114 | * the representation widget. | ||
115 | * | ||
116 | * @see KURLRequester::customEditor() | ||
117 | * @since 3.1 | ||
118 | */ | ||
119 | KEditListBox( const QString& title, | ||
120 | const CustomEditor &customEditor, | ||
121 | QWidget *parent = 0, const char *name = 0, | ||
122 | bool checkAtEntering = false, int buttons = All ); | ||
123 | |||
124 | virtual ~KEditListBox(); | ||
125 | |||
126 | /** | ||
127 | * Return a pointer to the embedded QListBox. | ||
128 | */ | ||
129 | QListBox* listBox() const { return m_listBox; } | ||
130 | /** | ||
131 | * Return a pointer to the embedded QLineEdit. | ||
132 | */ | ||
133 | KLineEdit* lineEdit() const { return m_lineEdit; } | ||
134 | /** | ||
135 | * Return a pointer to the Add button | ||
136 | */ | ||
137 | QPushButton* addButton() const { return servNewButton; } | ||
138 | /** | ||
139 | * Return a pointer to the Remove button | ||
140 | */ | ||
141 | QPushButton* removeButton() const { return servRemoveButton; } | ||
142 | /** | ||
143 | * Return a pointer to the Up button | ||
144 | */ | ||
145 | QPushButton* upButton() const { return servUpButton; } | ||
146 | /** | ||
147 | * Return a pointer to the Down button | ||
148 | */ | ||
149 | QPushButton* downButton() const { return servDownButton; } | ||
150 | |||
151 | /** | ||
152 | * See @ref QListBox::count() | ||
153 | */ | ||
154 | int count() const { return int(m_listBox->count()); } | ||
155 | /** | ||
156 | * See @ref QListBox::insertStringList() | ||
157 | */ | ||
158 | void insertStringList(const QStringList& list, int index=-1); | ||
159 | /** | ||
160 | * See @ref QListBox::insertStringList() | ||
161 | */ | ||
162 | void insertStrList(const QStrList* list, int index=-1); | ||
163 | /** | ||
164 | * See @ref QListBox::insertStrList() | ||
165 | */ | ||
166 | void insertStrList(const QStrList& list, int index=-1); | ||
167 | /** | ||
168 | * See @ref QListBox::insertStrList() | ||
169 | */ | ||
170 | void insertStrList(const char ** list, int numStrings=-1, int index=-1); | ||
171 | /** | ||
172 | * See @ref QListBox::insertItem() | ||
173 | */ | ||
174 | void insertItem(const QString& text, int index=-1) {m_listBox->insertItem(text,index);} | ||
175 | /** | ||
176 | * Clears both the listbox and the line edit. | ||
177 | */ | ||
178 | void clear(); | ||
179 | /** | ||
180 | * See @ref QListBox::text() | ||
181 | */ | ||
182 | QString text(int index) const { return m_listBox->text(index); } | ||
183 | /** | ||
184 | * See @ref QListBox::currentItem() | ||
185 | */ | ||
186 | int currentItem() const; | ||
187 | /** | ||
188 | * See @ref QListBox::currentText() | ||
189 | */ | ||
190 | QString currentText() const { return m_listBox->currentText(); } | ||
191 | |||
192 | /** | ||
193 | * @returns a stringlist of all items in the listbox | ||
194 | */ | ||
195 | QStringList items() const; | ||
196 | |||
197 | signals: | ||
198 | void changed(); | ||
199 | |||
200 | protected slots: | ||
201 | //the names should be self-explaining | ||
202 | void moveItemUp(); | ||
203 | void moveItemDown(); | ||
204 | void addItem(); | ||
205 | void removeItem(); | ||
206 | void enableMoveButtons(int index); | ||
207 | void typedSomething(const QString& text); | ||
208 | |||
209 | private: | ||
210 | QListBox *m_listBox; | ||
211 | QPushButton *servUpButton, *servDownButton; | ||
212 | QPushButton *servNewButton, *servRemoveButton; | ||
213 | KLineEdit *m_lineEdit; | ||
214 | |||
215 | //this is called in both ctors, to avoid code duplication | ||
216 | void init( bool checkAtEntering, int buttons, | ||
217 | QWidget *representationWidget = 0L ); | ||
218 | |||
219 | protected: | ||
220 | virtual void virtual_hook( int id, void* data ); | ||
221 | private: | ||
222 | //our lovely private d-pointer | ||
223 | KEditListBoxPrivate *d; | ||
224 | }; | ||
225 | |||
226 | #endif | ||