summaryrefslogtreecommitdiff
path: root/libopie2/qt3/opieui/oeditlistbox.h
Unidiff
Diffstat (limited to 'libopie2/qt3/opieui/oeditlistbox.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opieui/oeditlistbox.h250
1 files changed, 250 insertions, 0 deletions
diff --git a/libopie2/qt3/opieui/oeditlistbox.h b/libopie2/qt3/opieui/oeditlistbox.h
new file mode 100644
index 0000000..63fab11
--- a/dev/null
+++ b/libopie2/qt3/opieui/oeditlistbox.h
@@ -0,0 +1,250 @@
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 OEDITLISTBOX_H
21#define OEDITLISTBOX_H
22
23#include <qgroupbox.h>
24#include <qlistbox.h>
25
26class OLineEdit;
27class OComboBox;
28class QPushButton;
29
30#if QT_VERSION < 300
31 enum StringComparisonMode {
32 CaseSensitive = 0x00001, // 0 0001
33 BeginsWith = 0x00002, // 0 0010
34 EndsWith = 0x00004, // 0 0100
35 Contains = 0x00008, // 0 1000
36 ExactMatch = 0x00010 // 1 0000
37 };
38#endif
39
40class OEditListBoxPrivate;
41/**
42 * An editable listbox
43 *
44 * This class provides a editable listbox ;-), this means
45 * a listbox which is accompanied by a line edit to enter new
46 * items into the listbox and pushbuttons to add and remove
47 * items from the listbox and two buttons to move items up and down.
48 */
49class OEditListBox : public QGroupBox
50{
51 Q_OBJECT
52
53public:
54 /// @since 3.1
55 class CustomEditor
56 {
57 public:
58 CustomEditor()
59 : m_representationWidget( 0L ),
60 m_lineEdit( 0L ) {}
61 CustomEditor( QWidget *repWidget, OLineEdit *edit )
62 : m_representationWidget( repWidget ),
63 m_lineEdit( edit ) {}
64 CustomEditor( OComboBox *combo );
65
66 void setRepresentationWidget( QWidget *repWidget ) {
67 m_representationWidget = repWidget;
68 }
69 void setLineEdit( OLineEdit *edit ) {
70 m_lineEdit = edit;
71 }
72
73 virtual QWidget *representationWidget() const {
74 return m_representationWidget;
75 }
76 virtual OLineEdit *lineEdit() const {
77 return m_lineEdit;
78 }
79
80 protected:
81 QWidget *m_representationWidget;
82 OLineEdit *m_lineEdit;
83 };
84
85 public:
86
87 /**
88 * Enumeration of the buttons, the listbox offers. Specify them in the
89 * constructor in the buttons parameter.
90 */
91 enum Button { Add = 1, Remove = 2, UpDown = 4, All = Add|Remove|UpDown };
92
93 /**
94 * Create an editable listbox.
95 *
96 * If @p checkAtEntering is true, after every character you type
97 * in the line edit OEditListBox will enable or disable
98 * the Add-button, depending whether the current content of the
99 * line edit is already in the listbox. Maybe this can become a
100 * performance hit with large lists on slow machines.
101 * If @p checkAtEntering is false,
102 * it will be checked if you press the Add-button. It is not
103 * possible to enter items twice into the listbox.
104 */
105 OEditListBox(QWidget *parent = 0, const char *name = 0,
106 bool checkAtEntering=false, int buttons = All );
107 /**
108 * Create an editable listbox.
109 *
110 * The same as the other constructor, additionally it takes
111 * @title, which will be the title of the frame around the listbox.
112 */
113 OEditListBox(const QString& title, QWidget *parent = 0,
114 const char *name = 0, bool checkAtEntering=false,
115 int buttons = All );
116
117 /**
118 * Another constructor, which allows to use a custom editing widget
119 * instead of the standard OLineEdit widget. E.g. you can use a
120 * @ref OURLRequester or a @ref OComboBox as input widget. The custom
121 * editor must consist of a lineedit and optionally another widget that
122 * is used as representation. A OComboBox or a OURLRequester have a
123 * OLineEdit as child-widget for example, so the OComboBox is used as
124 * the representation widget.
125 *
126 * @see OURLRequester::customEditor()
127 * @since 3.1
128 */
129 OEditListBox( const QString& title,
130 const CustomEditor &customEditor,
131 QWidget *parent = 0, const char *name = 0,
132 bool checkAtEntering = false, int buttons = All );
133
134 virtual ~OEditListBox();
135
136 /**
137 * Return a pointer to the embedded QListBox.
138 */
139 QListBox* listBox() const { return m_listBox; }
140 /**
141 * Return a pointer to the embedded QLineEdit.
142 */
143 OLineEdit* lineEdit() const { return m_lineEdit; }
144 /**
145 * Return a pointer to the Add button
146 */
147 QPushButton* addButton() const { return servNewButton; }
148 /**
149 * Return a pointer to the Remove button
150 */
151 QPushButton* removeButton() const { return servRemoveButton; }
152 /**
153 * Return a pointer to the Up button
154 */
155 QPushButton* upButton() const { return servUpButton; }
156 /**
157 * Return a pointer to the Down button
158 */
159 QPushButton* downButton() const { return servDownButton; }
160
161 /**
162 * See @ref QListBox::count()
163 */
164 int count() const { return int(m_listBox->count()); }
165 /**
166 * See @ref QListBox::insertStringList()
167 */
168 void insertStringList(const QStringList& list, int index=-1);
169 /**
170 * See @ref QListBox::insertStringList()
171 */
172 void insertStrList(const QStrList* list, int index=-1);
173 /**
174 * See @ref QListBox::insertStrList()
175 */
176 void insertStrList(const QStrList& list, int index=-1);
177 /**
178 * See @ref QListBox::insertStrList()
179 */
180 void insertStrList(const char ** list, int numStrings=-1, int index=-1);
181 /**
182 * See @ref QListBox::insertItem()
183 */
184 void insertItem(const QString& text, int index=-1) {m_listBox->insertItem(text,index);}
185 /**
186 * Clears both the listbox and the line edit.
187 */
188 void clear();
189 /**
190 * See @ref QListBox::text()
191 */
192 QString text(int index) const { return m_listBox->text(index); }
193 /**
194 * See @ref QListBox::currentItem()
195 */
196 int currentItem() const;
197 /**
198 * See @ref QListBox::currentText()
199 */
200 QString currentText() const { return m_listBox->currentText(); }
201
202 /**
203 * @returns a stringlist of all items in the listbox
204 */
205 QStringList items() const;
206
207 signals:
208 void changed();
209
210 /**
211 * This signal is emitted when the user adds a new string to the list,
212 * the parameter is the added string.
213 * @since 3.2
214 */
215 void added( const QString & text );
216
217 /**
218 * This signal is emitted when the user removes a string from the list,
219 * the parameter is the removed string.
220 * @since 3.2
221 */
222 void removed( const QString & text );
223
224 protected slots:
225 //the names should be self-explaining
226 void moveItemUp();
227 void moveItemDown();
228 void addItem();
229 void removeItem();
230 void enableMoveButtons(int index);
231 void typedSomething(const QString& text);
232
233 private:
234 QListBox *m_listBox;
235 QPushButton *servUpButton, *servDownButton;
236 QPushButton *servNewButton, *servRemoveButton;
237 OLineEdit *m_lineEdit;
238
239 //this is called in both ctors, to avoid code duplication
240 void init( bool checkAtEntering, int buttons,
241 QWidget *representationWidget = 0L );
242
243 protected:
244 virtual void virtual_hook( int id, void* data );
245 private:
246 //our lovely private d-pointer
247 OEditListBoxPrivate *d;
248};
249
250#endif // OEDITLISTBOX