author | mickeyl <mickeyl> | 2003-03-28 15:11:52 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-28 15:11:52 (UTC) |
commit | 11304d02942e9fa493e4e80943a828f9c65f6772 (patch) (unidiff) | |
tree | a0223c10c067e1afc70d15c2b82be3f3c15e41ae /libopie2/qt3/opieui/ocompletionbox.h | |
parent | b271d575fa05cf570a1a829136517761bd47e69b (diff) | |
download | opie-11304d02942e9fa493e4e80943a828f9c65f6772.zip opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.gz opie-11304d02942e9fa493e4e80943a828f9c65f6772.tar.bz2 |
skeleton and the start of libopie2, please read README, ROADMAP and STATUS and comment...
Diffstat (limited to 'libopie2/qt3/opieui/ocompletionbox.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/qt3/opieui/ocompletionbox.h | 232 |
1 files changed, 232 insertions, 0 deletions
diff --git a/libopie2/qt3/opieui/ocompletionbox.h b/libopie2/qt3/opieui/ocompletionbox.h new file mode 100644 index 0000000..54d9ef5 --- a/dev/null +++ b/libopie2/qt3/opieui/ocompletionbox.h | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
3 | is part of the Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org> | ||
4 | Opie Project Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | ||
5 | |||
6 | =. Originally part of the KDE Project | ||
7 | .=l. | ||
8 | .>+-= | ||
9 | _;:, .> :=|. This program is free software; you can | ||
10 | .> <`_, > . <= redistribute it and/or modify it under | ||
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
12 | .="- .-=="i, .._ License as published by the Free Software | ||
13 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
14 | ._= =} : or (at your option) any later version. | ||
15 | .%`+i> _;_. | ||
16 | .i_,=:_. -<s. This program is distributed in the hope that | ||
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
18 | : .. .:, . . . without even the implied warranty of | ||
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
21 | ..}^=.= = ; Library General Public License for more | ||
22 | ++= -. .` .: details. | ||
23 | : = ...= . :.=- | ||
24 | -. .:....=;==+<; You should have received a copy of the GNU | ||
25 | -_. . . )=. = Library General Public License along with | ||
26 | -- :-=` this library; see the file COPYING.LIB. | ||
27 | If not, write to the Free Software Foundation, | ||
28 | Inc., 59 Temple Place - Suite 330, | ||
29 | Boston, MA 02111-1307, USA. | ||
30 | |||
31 | */ | ||
32 | |||
33 | #ifndef OCOMPLETIONBOX_H | ||
34 | #define OCOMPLETIONBOX_H | ||
35 | |||
36 | class QEvent; | ||
37 | #include <qstringlist.h> | ||
38 | #include <qlistbox.h> | ||
39 | |||
40 | // ML: Until we don't have an own OListBox, we use the QListBox | ||
41 | #define OListBox QListBox | ||
42 | |||
43 | /** | ||
44 | * A little utility class for "completion-widgets", like @ref OLineEdit or | ||
45 | * @ref OComboBox. OCompletionBox is a listbox, displayed as a rectangle without | ||
46 | * any window decoration, usually directly under the lineedit or combobox. | ||
47 | * It is filled with all possible matches for a completion, so the user | ||
48 | * can select the one he wants. | ||
49 | * | ||
50 | * It is used when OGlobalSettings::Completion == CompletionPopup or CompletionPopupAuto. | ||
51 | * | ||
52 | * @short A helper widget for "completion-widgets" (OLineEdit, OComboBox)) | ||
53 | * @short Adapted for the Opie project by Michael Lauer <mickey@tm.informatik.uni-frankfurt.de> | ||
54 | * @author Carsten Pfeiffer <pfeiffer@kde.org> | ||
55 | * | ||
56 | */ | ||
57 | class OCompletionBox : public OListBox | ||
58 | { | ||
59 | Q_OBJECT | ||
60 | Q_PROPERTY( bool isTabHandling READ isTabHandling WRITE setTabHandling ) | ||
61 | Q_PROPERTY(QString cancelledText READ cancelledText WRITE setCancelledText) | ||
62 | |||
63 | public: | ||
64 | /** | ||
65 | * Constructs a OCompletionBox. | ||
66 | * | ||
67 | * Notice: the parent needs to be always 0L, | ||
68 | * so you can't specify it in the constructor. Because of that, Qt's | ||
69 | * auto-deletion does not take place, so you have to explicitly delete | ||
70 | * this widget when you don't need it anymore. | ||
71 | * | ||
72 | * The parent widget is used to give the focus back when pressing the | ||
73 | * up-button on the very first item. | ||
74 | */ | ||
75 | OCompletionBox( QWidget *parent, const char *name = 0 ); | ||
76 | |||
77 | /** | ||
78 | * Destroys the box | ||
79 | */ | ||
80 | ~OCompletionBox(); | ||
81 | |||
82 | virtual QSize sizeHint() const; | ||
83 | |||
84 | public slots: | ||
85 | /** | ||
86 | * Returns a list of all items currently in the box. | ||
87 | */ | ||
88 | QStringList items() const; | ||
89 | |||
90 | /** | ||
91 | * Inserts @p items into the box. Does not clear the items before. | ||
92 | * @p index determines at which position @p items will be inserted. | ||
93 | * (defaults to appending them at the end) | ||
94 | */ | ||
95 | void insertItems( const QStringList& items, int index = -1 ); | ||
96 | |||
97 | /** | ||
98 | * Clears the box and inserts @p items. | ||
99 | */ | ||
100 | void setItems( const QStringList& items ); | ||
101 | |||
102 | /** | ||
103 | * Adjusts the size of the box to fit the width of the parent given in the | ||
104 | * constructor and pops it up at the most appropriate place, relative to | ||
105 | * the parent. | ||
106 | * | ||
107 | * Depending on the screensize and the position of the parent, this may | ||
108 | * be a different place, however the default is to pop it up and the | ||
109 | * lower left corner of the parent. | ||
110 | * | ||
111 | * Make sure to hide() the box when appropriate. | ||
112 | */ | ||
113 | virtual void popup(); | ||
114 | |||
115 | /** | ||
116 | * Makes this widget (when visible) capture Tab-key events to traverse the | ||
117 | * items in the dropdown list. | ||
118 | * | ||
119 | * Default off, as it conflicts with the usual behavior of Tab to traverse | ||
120 | * widgets. It is useful for cases like Konqueror's Location Bar, though. | ||
121 | * | ||
122 | * @see #isTabHandling | ||
123 | */ | ||
124 | void setTabHandling( bool enable ); | ||
125 | |||
126 | /** | ||
127 | * @returns true if this widget is handling Tab-key events to traverse the | ||
128 | * items in the dropdown list, otherwise false. | ||
129 | * | ||
130 | * Default is false. | ||
131 | * | ||
132 | * @see #setTabHandling | ||
133 | */ | ||
134 | bool isTabHandling() const; | ||
135 | |||
136 | /** | ||
137 | * Sets the text to be emitted if the user chooses not to | ||
138 | * pick from the available matches. | ||
139 | * | ||
140 | * If the cancelled text is not set through this function, the | ||
141 | * @ref userCancelled signal will not be emitted. | ||
142 | * | ||
143 | * @see userCancelled( const QString& ) | ||
144 | * @param txt the text to be emitted if the user cancels this box | ||
145 | */ | ||
146 | void setCancelledText( const QString& ); | ||
147 | |||
148 | /** | ||
149 | * @returns the text set via @ref setCancelledText() or QString::null. | ||
150 | */ | ||
151 | QString cancelledText() const; | ||
152 | |||
153 | /** | ||
154 | * Moves the selection one line down or select the first item if nothing is selected yet. | ||
155 | */ | ||
156 | void down(); | ||
157 | |||
158 | /** | ||
159 | * Moves the selection one line up or select the first item if nothing is selected yet. | ||
160 | */ | ||
161 | void up(); | ||
162 | |||
163 | /** | ||
164 | * Moves the selection one page down. | ||
165 | */ | ||
166 | void pageDown(); | ||
167 | |||
168 | /** | ||
169 | * Moves the selection one page up. | ||
170 | */ | ||
171 | void pageUp(); | ||
172 | |||
173 | /** | ||
174 | * Moves the selection up to the first item. | ||
175 | */ | ||
176 | void home(); | ||
177 | |||
178 | /** | ||
179 | * Moves the selection down to the last item. | ||
180 | */ | ||
181 | void end(); | ||
182 | |||
183 | /** | ||
184 | * Re-implemented for internal reasons. API is unaffected. | ||
185 | */ | ||
186 | virtual void show(); | ||
187 | |||
188 | /** | ||
189 | * Re-implemented for internal reasons. API is unaffected. | ||
190 | */ | ||
191 | virtual void hide(); | ||
192 | |||
193 | signals: | ||
194 | /** | ||
195 | * Emitted when an item was selected, contains the text of | ||
196 | * the selected item. | ||
197 | */ | ||
198 | void activated( const QString& ); | ||
199 | |||
200 | /** | ||
201 | * Emitted whenever the user chooses to ignore the available | ||
202 | * selections and close the this box. | ||
203 | */ | ||
204 | void userCancelled( const QString& ); | ||
205 | |||
206 | protected: | ||
207 | /** | ||
208 | * Reimplemented from OListBox to get events from the viewport (to hide | ||
209 | * this widget on mouse-click, Escape-presses, etc. | ||
210 | */ | ||
211 | virtual bool eventFilter( QObject *, QEvent * ); | ||
212 | |||
213 | protected slots: | ||
214 | /** | ||
215 | * Called when an item was activated. Emits | ||
216 | * @ref activated() with the item. | ||
217 | */ | ||
218 | virtual void slotActivated( QListBoxItem * ); | ||
219 | |||
220 | private slots: | ||
221 | void slotSetCurrentItem( QListBoxItem *i ) { setCurrentItem( i ); } // grrr | ||
222 | void slotCurrentChanged(); | ||
223 | void cancelled(); | ||
224 | void slotItemClicked( QListBoxItem * ); | ||
225 | |||
226 | private: | ||
227 | class OCompletionBoxPrivate; | ||
228 | OCompletionBoxPrivate* d; | ||
229 | }; | ||
230 | |||
231 | |||
232 | #endif // OCOMPLETIONBOX_H | ||