-rw-r--r-- | libopie2/qt3/opieui/ocombobox.cpp | 20 | ||||
-rw-r--r-- | libopie2/qt3/opieui/ocompletionbox.cpp | 10 | ||||
-rw-r--r-- | libopie2/qt3/opieui/ojanuswidget.cpp | 10 | ||||
-rw-r--r-- | libopie2/qt3/opieui/olineedit.cpp | 24 |
4 files changed, 32 insertions, 32 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp index 8dbda8f..bd330e0 100644 --- a/libopie2/qt3/opieui/ocombobox.cpp +++ b/libopie2/qt3/opieui/ocombobox.cpp | |||
@@ -1,669 +1,669 @@ | |||
1 | /* | 1 | /* |
2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 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> | 3 | is part of the Copyright (C) 2000 Carsten Pfeiffer <pfeiffer@kde.org> |
4 | Opie Project Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org> | 4 | Opie Project Copyright (C) 2000 Dawit Alemayehu <adawit@kde.org> |
5 | 5 | ||
6 | =. Originally part of the KDE Project | 6 | =. Originally part of the KDE Project |
7 | .=l. | 7 | .=l. |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* QT */ | 33 | /* QT */ |
34 | 34 | ||
35 | #include <qclipboard.h> | 35 | #include <qclipboard.h> |
36 | #include <qlistbox.h> | 36 | #include <qlistbox.h> |
37 | #include <qpopupmenu.h> | 37 | #include <qpopupmenu.h> |
38 | 38 | ||
39 | /* OPIE */ | 39 | /* OPIE */ |
40 | 40 | ||
41 | #include <opie2/ocompletionbox.h> | 41 | #include <opie2/ocompletionbox.h> |
42 | #include <opie2/olineedit.h> | 42 | #include <opie2/olineedit.h> |
43 | #include <opie2/opixmapprovider.h> | 43 | #include <opie2/opixmapprovider.h> |
44 | #include <opie2/ocombobox.h> | 44 | #include <opie2/ocombobox.h> |
45 | 45 | ||
46 | /*====================================================================================== | 46 | /*====================================================================================== |
47 | * OComboBoxPrivate | 47 | * OComboBoxPrivate |
48 | *======================================================================================*/ | 48 | *======================================================================================*/ |
49 | 49 | ||
50 | class OComboBox::OComboBoxPrivate | 50 | class OComboBox::OComboBoxPrivate |
51 | { | 51 | { |
52 | public: | 52 | public: |
53 | OComboBoxPrivate() | 53 | OComboBoxPrivate() |
54 | { | 54 | { |
55 | olineEdit = 0L; | 55 | olineEdit = 0L; |
56 | } | 56 | } |
57 | ~OComboBoxPrivate() | 57 | ~OComboBoxPrivate() |
58 | { | 58 | { |
59 | } | 59 | } |
60 | 60 | ||
61 | OLineEdit *olineEdit; | 61 | OLineEdit *olineEdit; |
62 | }; | 62 | }; |
63 | 63 | ||
64 | /*====================================================================================== | 64 | /*====================================================================================== |
65 | * OComboBox | 65 | * OComboBox |
66 | *======================================================================================*/ | 66 | *======================================================================================*/ |
67 | 67 | ||
68 | OComboBox::OComboBox( QWidget *parent, const char *name ) | 68 | OComboBox::OComboBox( QWidget *parent, const char *name ) |
69 | : QComboBox( parent, name ) | 69 | : QComboBox( parent, name ) |
70 | { | 70 | { |
71 | init(); | 71 | init(); |
72 | } | 72 | } |
73 | 73 | ||
74 | OComboBox::OComboBox( bool rw, QWidget *parent, const char *name ) | 74 | OComboBox::OComboBox( bool rw, QWidget *parent, const char *name ) |
75 | : QComboBox( rw, parent, name ) | 75 | : QComboBox( rw, parent, name ) |
76 | { | 76 | { |
77 | init(); | 77 | init(); |
78 | 78 | ||
79 | if ( rw ) | 79 | if ( rw ) |
80 | { | 80 | { |
81 | OLineEdit *edit = new OLineEdit( this, "combo lineedit" ); | 81 | OLineEdit *edit = new OLineEdit( this, "combo lineedit" ); |
82 | setLineEdit( edit ); | 82 | setLineEdit( edit ); |
83 | } | 83 | } |
84 | } | 84 | } |
85 | 85 | ||
86 | OComboBox::~OComboBox() | 86 | OComboBox::~OComboBox() |
87 | { | 87 | { |
88 | delete d; | 88 | delete d; |
89 | } | 89 | } |
90 | 90 | ||
91 | void OComboBox::init() | 91 | void OComboBox::init() |
92 | { | 92 | { |
93 | d = new OComboBoxPrivate; | 93 | d = new OComboBoxPrivate; |
94 | 94 | ||
95 | // Permanently set some parameters in the parent object. | 95 | // Permanently set some parameters in the parent object. |
96 | QComboBox::setAutoCompletion( false ); | 96 | QComboBox::setAutoCompletion( false ); |
97 | 97 | ||
98 | // Initialize enable popup menu to false. | 98 | // Initialize enable popup menu to false. |
99 | // Below it will be enabled if the widget | 99 | // Below it will be enabled if the widget |
100 | // is editable. | 100 | // is editable. |
101 | m_bEnableMenu = false; | 101 | m_bEnableMenu = false; |
102 | 102 | ||
103 | m_trapReturnKey = false; | 103 | m_trapReturnKey = false; |
104 | 104 | ||
105 | // Enable context menu by default if widget | 105 | // Enable context menu by default if widget |
106 | // is editable. | 106 | // is editable. |
107 | setContextMenuEnabled( true ); | 107 | setContextMenuEnabled( true ); |
108 | 108 | ||
109 | // for wheelscrolling | 109 | // for wheelscrolling |
110 | installEventFilter( this ); | 110 | installEventFilter( this ); |
111 | if ( lineEdit() ) | 111 | if ( lineEdit() ) |
112 | lineEdit()->installEventFilter( this ); | 112 | lineEdit()->installEventFilter( this ); |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | bool OComboBox::contains( const QString& _text ) const | 116 | bool OComboBox::contains( const QString& _text ) const |
117 | { | 117 | { |
118 | if ( _text.isEmpty() ) | 118 | if ( _text.isEmpty() ) |
119 | return false; | 119 | return false; |
120 | 120 | ||
121 | for (int i = 0; i < count(); i++ ) { | 121 | for (int i = 0; i < count(); i++ ) { |
122 | if ( text(i) == _text ) | 122 | if ( text(i) == _text ) |
123 | return true; | 123 | return true; |
124 | } | 124 | } |
125 | return false; | 125 | return false; |
126 | } | 126 | } |
127 | 127 | ||
128 | void OComboBox::setAutoCompletion( bool autocomplete ) | 128 | void OComboBox::setAutoCompletion( bool autocomplete ) |
129 | { | 129 | { |
130 | if ( d->olineEdit ) | 130 | if ( d->olineEdit ) |
131 | { | 131 | { |
132 | if ( autocomplete ) | 132 | if ( autocomplete ) |
133 | { | 133 | { |
134 | d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto ); | 134 | d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto ); |
135 | setCompletionMode( OGlobalSettings::CompletionAuto ); | 135 | setCompletionMode( OGlobalSettings::CompletionAuto ); |
136 | } | 136 | } |
137 | else | 137 | else |
138 | { | 138 | { |
139 | d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() ); | 139 | d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() ); |
140 | setCompletionMode( OGlobalSettings::completionMode() ); | 140 | setCompletionMode( OGlobalSettings::completionMode() ); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | void OComboBox::setContextMenuEnabled( bool showMenu ) | 145 | void OComboBox::setContextMenuEnabled( bool showMenu ) |
146 | { | 146 | { |
147 | if( d->olineEdit ) | 147 | if( d->olineEdit ) |
148 | { | 148 | { |
149 | d->olineEdit->setContextMenuEnabled( showMenu ); | 149 | d->olineEdit->setContextMenuEnabled( showMenu ); |
150 | m_bEnableMenu = showMenu; | 150 | m_bEnableMenu = showMenu; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | /* | 154 | /* |
155 | void OComboBox::setURLDropsEnabled( bool enable ) | 155 | void OComboBox::setURLDropsEnabled( bool enable ) |
156 | { | 156 | { |
157 | if ( d->olineEdit ) | 157 | if ( d->olineEdit ) |
158 | d->olineEdit->setURLDropsEnabled( enable ); | 158 | d->olineEdit->setURLDropsEnabled( enable ); |
159 | } | 159 | } |
160 | 160 | ||
161 | bool OComboBox::isURLDropsEnabled() const | 161 | bool OComboBox::isURLDropsEnabled() const |
162 | { | 162 | { |
163 | return d->olineEdit && d->olineEdit->isURLDropsEnabled(); | 163 | return d->olineEdit && d->olineEdit->isURLDropsEnabled(); |
164 | } | 164 | } |
165 | */ | 165 | */ |
166 | 166 | ||
167 | void OComboBox::setCompletedText( const QString& text, bool marked ) | 167 | void OComboBox::setCompletedText( const QString& text, bool marked ) |
168 | { | 168 | { |
169 | if ( d->olineEdit ) | 169 | if ( d->olineEdit ) |
170 | d->olineEdit->setCompletedText( text, marked ); | 170 | d->olineEdit->setCompletedText( text, marked ); |
171 | } | 171 | } |
172 | 172 | ||
173 | void OComboBox::setCompletedText( const QString& text ) | 173 | void OComboBox::setCompletedText( const QString& text ) |
174 | { | 174 | { |
175 | if ( d->olineEdit ) | 175 | if ( d->olineEdit ) |
176 | d->olineEdit->setCompletedText( text ); | 176 | d->olineEdit->setCompletedText( text ); |
177 | } | 177 | } |
178 | 178 | ||
179 | void OComboBox::makeCompletion( const QString& text ) | 179 | void OComboBox::makeCompletion( const QString& text ) |
180 | { | 180 | { |
181 | if( d->olineEdit ) | 181 | if( d->olineEdit ) |
182 | d->olineEdit->makeCompletion( text ); | 182 | d->olineEdit->makeCompletion( text ); |
183 | 183 | ||
184 | else // read-only combo completion | 184 | else // read-only combo completion |
185 | { | 185 | { |
186 | if( text.isNull() || !listBox() ) | 186 | if( text.isNull() || !listBox() ) |
187 | return; | 187 | return; |
188 | 188 | ||
189 | int index = listBox()->index( listBox()->findItem( text ) ); | 189 | int index = listBox()->index( listBox()->findItem( text ) ); |
190 | if( index >= 0 ) { | 190 | if( index >= 0 ) { |
191 | setCurrentItem( index ); | 191 | setCurrentItem( index ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | } | 194 | } |
195 | 195 | ||
196 | void OComboBox::rotateText( OCompletionBase::KeyBindingType type ) | 196 | void OComboBox::rotateText( OCompletionBase::KeyBindingType type ) |
197 | { | 197 | { |
198 | if ( d->olineEdit ) | 198 | if ( d->olineEdit ) |
199 | d->olineEdit->rotateText( type ); | 199 | d->olineEdit->rotateText( type ); |
200 | } | 200 | } |
201 | 201 | ||
202 | bool OComboBox::eventFilter( QObject* o, QEvent* ev ) | 202 | bool OComboBox::eventFilter( QObject* o, QEvent* ev ) |
203 | { | 203 | { |
204 | QLineEdit *edit = lineEdit(); | 204 | QLineEdit *edit = lineEdit(); |
205 | 205 | ||
206 | int type = ev->type(); | 206 | int type = ev->type(); |
207 | 207 | ||
208 | if ( o == edit ) | 208 | if ( o == edit ) |
209 | { | 209 | { |
210 | //OCursor::autoHideEventFilter( edit, ev ); | 210 | //OCursor::autoHideEventFilter( edit, ev ); |
211 | 211 | ||
212 | if ( type == QEvent::KeyPress ) | 212 | if ( type == QEvent::KeyPress ) |
213 | { | 213 | { |
214 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 214 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
215 | 215 | ||
216 | if ( e->key() == Key_Return || e->key() == Key_Enter) | 216 | if ( e->key() == Key_Return || e->key() == Key_Enter) |
217 | { | 217 | { |
218 | // On Return pressed event, emit both | 218 | // On Return pressed event, emit both |
219 | // returnPressed(const QString&) and returnPressed() signals | 219 | // returnPressed(const QString&) and returnPressed() signals |
220 | emit returnPressed(); | 220 | emit returnPressed(); |
221 | emit returnPressed( currentText() ); | 221 | emit returnPressed( currentText() ); |
222 | if ( d->olineEdit && d->olineEdit->completionBox(false) && | 222 | if ( d->olineEdit && d->olineEdit->completionBox(false) && |
223 | d->olineEdit->completionBox()->isVisible() ) | 223 | d->olineEdit->completionBox()->isVisible() ) |
224 | d->olineEdit->completionBox()->hide(); | 224 | d->olineEdit->completionBox()->hide(); |
225 | 225 | ||
226 | return m_trapReturnKey; | 226 | return m_trapReturnKey; |
227 | } | 227 | } |
228 | } | 228 | } |
229 | } | 229 | } |
230 | 230 | ||
231 | 231 | ||
232 | // wheel-scrolling changes the current item | 232 | // wheel-scrolling changes the current item |
233 | if ( type == QEvent::Wheel ) { | 233 | if ( type == QEvent::Wheel ) { |
234 | if ( !listBox() || listBox()->isHidden() ) { | 234 | if ( !listBox() || listBox()->isHidden() ) { |
235 | QWheelEvent *e = static_cast<QWheelEvent*>( ev ); | 235 | QWheelEvent *e = static_cast<QWheelEvent*>( ev ); |
236 | static const int WHEEL_DELTA = 120; | 236 | static const int WHEEL_DELTA = 120; |
237 | int skipItems = e->delta() / WHEEL_DELTA; | 237 | int skipItems = e->delta() / WHEEL_DELTA; |
238 | if ( e->state() & ControlButton ) // fast skipping | 238 | if ( e->state() & ControlButton ) // fast skipping |
239 | skipItems *= 10; | 239 | skipItems *= 10; |
240 | 240 | ||
241 | int newItem = currentItem() - skipItems; | 241 | int newItem = currentItem() - skipItems; |
242 | 242 | ||
243 | if ( newItem < 0 ) | 243 | if ( newItem < 0 ) |
244 | newItem = 0; | 244 | newItem = 0; |
245 | else if ( newItem >= count() ) | 245 | else if ( newItem >= count() ) |
246 | newItem = count() -1; | 246 | newItem = count() -1; |
247 | 247 | ||
248 | setCurrentItem( newItem ); | 248 | setCurrentItem( newItem ); |
249 | if ( !text( newItem ).isNull() ) | 249 | if ( !text( newItem ).isNull() ) |
250 | emit activated( text( newItem ) ); | 250 | emit activated( text( newItem ) ); |
251 | emit activated( newItem ); | 251 | emit activated( newItem ); |
252 | e->accept(); | 252 | e->accept(); |
253 | return true; | 253 | return true; |
254 | } | 254 | } |
255 | } | 255 | } |
256 | 256 | ||
257 | return QComboBox::eventFilter( o, ev ); | 257 | return QComboBox::eventFilter( o, ev ); |
258 | } | 258 | } |
259 | 259 | ||
260 | void OComboBox::setTrapReturnKey( bool grab ) | 260 | void OComboBox::setTrapReturnKey( bool grab ) |
261 | { | 261 | { |
262 | m_trapReturnKey = grab; | 262 | m_trapReturnKey = grab; |
263 | } | 263 | } |
264 | 264 | ||
265 | bool OComboBox::trapReturnKey() const | 265 | bool OComboBox::trapReturnKey() const |
266 | { | 266 | { |
267 | return m_trapReturnKey; | 267 | return m_trapReturnKey; |
268 | } | 268 | } |
269 | 269 | ||
270 | /* | 270 | /* |
271 | void OComboBox::setEditURL( const OURL& url ) | 271 | void OComboBox::setEditURL( const OURL& url ) |
272 | { | 272 | { |
273 | QComboBox::setEditText( url.prettyURL() ); | 273 | QComboBox::setEditText( url.prettyURL() ); |
274 | } | 274 | } |
275 | 275 | ||
276 | void OComboBox::insertURL( const OURL& url, int index ) | 276 | void OComboBox::insertURL( const OURL& url, int index ) |
277 | { | 277 | { |
278 | QComboBox::insertItem( url.prettyURL(), index ); | 278 | QComboBox::insertItem( url.prettyURL(), index ); |
279 | } | 279 | } |
280 | 280 | ||
281 | void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index ) | 281 | void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index ) |
282 | { | 282 | { |
283 | QComboBox::insertItem( pixmap, url.prettyURL(), index ); | 283 | QComboBox::insertItem( pixmap, url.prettyURL(), index ); |
284 | } | 284 | } |
285 | 285 | ||
286 | void OComboBox::changeURL( const OURL& url, int index ) | 286 | void OComboBox::changeURL( const OURL& url, int index ) |
287 | { | 287 | { |
288 | QComboBox::changeItem( url.prettyURL(), index ); | 288 | QComboBox::changeItem( url.prettyURL(), index ); |
289 | } | 289 | } |
290 | 290 | ||
291 | void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index ) | 291 | void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index ) |
292 | { | 292 | { |
293 | QComboBox::changeItem( pixmap, url.prettyURL(), index ); | 293 | QComboBox::changeItem( pixmap, url.prettyURL(), index ); |
294 | } | 294 | } |
295 | */ | 295 | */ |
296 | 296 | ||
297 | 297 | ||
298 | void OComboBox::setCompletedItems( const QStringList& items ) | 298 | void OComboBox::setCompletedItems( const QStringList& items ) |
299 | { | 299 | { |
300 | if ( d->olineEdit ) | 300 | if ( d->olineEdit ) |
301 | d->olineEdit->setCompletedItems( items ); | 301 | d->olineEdit->setCompletedItems( items ); |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | OCompletionBox * OComboBox::completionBox( bool create ) | 305 | OCompletionBox * OComboBox::completionBox( bool create ) |
306 | { | 306 | { |
307 | if ( d->olineEdit ) | 307 | if ( d->olineEdit ) |
308 | return d->olineEdit->completionBox( create ); | 308 | return d->olineEdit->completionBox( create ); |
309 | return 0; | 309 | return 0; |
310 | } | 310 | } |
311 | 311 | ||
312 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding | 312 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding |
313 | void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow ) | 313 | void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow ) |
314 | { | 314 | { |
315 | QComboBox::create( id, initializeWindow, destroyOldWindow ); | 315 | QComboBox::create( id, initializeWindow, destroyOldWindow ); |
316 | //OCursor::setAutoHideCursor( lineEdit(), true, true ); | 316 | //OCursor::setAutoHideCursor( lineEdit(), true, true ); |
317 | } | 317 | } |
318 | 318 | ||
319 | void OComboBox::setLineEdit( OLineEdit *edit ) | 319 | void OComboBox::setLineEdit( OLineEdit *edit ) |
320 | { | 320 | { |
321 | #if QT_VERSION > 290 | 321 | #if QT_VERSION > 290 |
322 | QComboBox::setLineEdit( edit ); | 322 | QComboBox::setLineEdit( edit ); |
323 | if ( !edit->inherits( "OLineEdit" ) ) | 323 | if ( !edit->inherits( "OLineEdit" ) ) |
324 | d->olineEdit = 0; | 324 | d->olineEdit = 0; |
325 | else | 325 | else |
326 | d->olineEdit = static_cast<OLineEdit*>( edit ); | 326 | d->olineEdit = static_cast<OLineEdit*>( edit ); |
327 | setDelegate( d->olineEdit ); | 327 | setDelegate( d->olineEdit ); |
328 | 328 | ||
329 | // forward some signals. We only emit returnPressed() ourselves. | 329 | // forward some signals. We only emit returnPressed() ourselves. |
330 | if ( d->olineEdit ) { | 330 | if ( d->olineEdit ) { |
331 | connect( d->olineEdit, SIGNAL( completion( const QString& )), | 331 | connect( d->olineEdit, SIGNAL( completion(const QString&)), |
332 | SIGNAL( completion( const QString& )) ); | 332 | SIGNAL( completion(const QString&)) ); |
333 | connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )), | 333 | connect( d->olineEdit, SIGNAL( substringCompletion(const QString&)), |
334 | SIGNAL( substringCompletion( const QString& )) ); | 334 | SIGNAL( substringCompletion(const QString&)) ); |
335 | connect( d->olineEdit, | 335 | connect( d->olineEdit, |
336 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )), | 336 | SIGNAL( textRotation(OCompletionBase::KeyBindingType)), |
337 | SIGNAL( textRotation( OCompletionBase::KeyBindingType )) ); | 337 | SIGNAL( textRotation(OCompletionBase::KeyBindingType)) ); |
338 | connect( d->olineEdit, | 338 | connect( d->olineEdit, |
339 | SIGNAL( completionModeChanged( OGlobalSettings::Completion )), | 339 | SIGNAL( completionModeChanged(OGlobalSettings::Completion)), |
340 | SIGNAL( completionModeChanged( OGlobalSettings::Completion))); | 340 | SIGNAL( completionModeChanged(OGlobalSettings::Completion))); |
341 | 341 | ||
342 | connect( d->olineEdit, | 342 | connect( d->olineEdit, |
343 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )), | 343 | SIGNAL( aboutToShowContextMenu(QPopupMenu*)), |
344 | SIGNAL( aboutToShowContextMenu( QPopupMenu * )) ); | 344 | SIGNAL( aboutToShowContextMenu(QPopupMenu*)) ); |
345 | } | 345 | } |
346 | #else | 346 | #else |
347 | #warning OComboBox is not fully functional with Qt2 | 347 | #warning OComboBox is not fully functional with Qt2 |
348 | #endif | 348 | #endif |
349 | } | 349 | } |
350 | 350 | ||
351 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 | 351 | // Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 |
352 | void OComboBox::deleteWordForward() | 352 | void OComboBox::deleteWordForward() |
353 | { | 353 | { |
354 | lineEdit()->cursorWordForward(TRUE); | 354 | lineEdit()->cursorWordForward(TRUE); |
355 | #if QT_VERSION > 290 | 355 | #if QT_VERSION > 290 |
356 | if ( lineEdit()->hasSelectedText() ) | 356 | if ( lineEdit()->hasSelectedText() ) |
357 | #else | 357 | #else |
358 | if ( lineEdit()->hasMarkedText() ) | 358 | if ( lineEdit()->hasMarkedText() ) |
359 | #endif | 359 | #endif |
360 | { | 360 | { |
361 | lineEdit()->del(); | 361 | lineEdit()->del(); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | 364 | ||
365 | void OComboBox::deleteWordBack() | 365 | void OComboBox::deleteWordBack() |
366 | { | 366 | { |
367 | lineEdit()->cursorWordBackward(TRUE); | 367 | lineEdit()->cursorWordBackward(TRUE); |
368 | #if QT_VERSION > 290 | 368 | #if QT_VERSION > 290 |
369 | if ( lineEdit()->hasSelectedText() ) | 369 | if ( lineEdit()->hasSelectedText() ) |
370 | #else | 370 | #else |
371 | if ( lineEdit()->hasMarkedText() ) | 371 | if ( lineEdit()->hasMarkedText() ) |
372 | #endif | 372 | #endif |
373 | { | 373 | { |
374 | lineEdit()->del(); | 374 | lineEdit()->del(); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) | 378 | void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) |
379 | { | 379 | { |
380 | int sel = -1; | 380 | int sel = -1; |
381 | for (int i = 0; i < count(); ++i) | 381 | for (int i = 0; i < count(); ++i) |
382 | if (text(i) == item) | 382 | if (text(i) == item) |
383 | { | 383 | { |
384 | sel = i; | 384 | sel = i; |
385 | break; | 385 | break; |
386 | } | 386 | } |
387 | if (sel == -1 && insert) | 387 | if (sel == -1 && insert) |
388 | { | 388 | { |
389 | insertItem(item, index); | 389 | insertItem(item, index); |
390 | if (index >= 0) | 390 | if (index >= 0) |
391 | sel = index; | 391 | sel = index; |
392 | else | 392 | else |
393 | sel = count() - 1; | 393 | sel = count() - 1; |
394 | } | 394 | } |
395 | setCurrentItem(sel); | 395 | setCurrentItem(sel); |
396 | } | 396 | } |
397 | 397 | ||
398 | void OComboBox::setCurrentItem(int index) | 398 | void OComboBox::setCurrentItem(int index) |
399 | { | 399 | { |
400 | QComboBox::setCurrentItem(index); | 400 | QComboBox::setCurrentItem(index); |
401 | } | 401 | } |
402 | 402 | ||
403 | 403 | ||
404 | /*====================================================================================== | 404 | /*====================================================================================== |
405 | * OHistoryCombo | 405 | * OHistoryCombo |
406 | *======================================================================================*/ | 406 | *======================================================================================*/ |
407 | 407 | ||
408 | // we are always read-write | 408 | // we are always read-write |
409 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) | 409 | OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) |
410 | : OComboBox( true, parent, name ) | 410 | : OComboBox( true, parent, name ) |
411 | { | 411 | { |
412 | init( true ); // using completion | 412 | init( true ); // using completion |
413 | } | 413 | } |
414 | 414 | ||
415 | // we are always read-write | 415 | // we are always read-write |
416 | OHistoryCombo::OHistoryCombo( bool useCompletion, | 416 | OHistoryCombo::OHistoryCombo( bool useCompletion, |
417 | QWidget *parent, const char *name ) | 417 | QWidget *parent, const char *name ) |
418 | : OComboBox( true, parent, name ) | 418 | : OComboBox( true, parent, name ) |
419 | { | 419 | { |
420 | init( useCompletion ); | 420 | init( useCompletion ); |
421 | } | 421 | } |
422 | 422 | ||
423 | void OHistoryCombo::init( bool useCompletion ) | 423 | void OHistoryCombo::init( bool useCompletion ) |
424 | { | 424 | { |
425 | if ( useCompletion ) | 425 | if ( useCompletion ) |
426 | completionObject()->setOrder( OCompletion::Weighted ); | 426 | completionObject()->setOrder( OCompletion::Weighted ); |
427 | 427 | ||
428 | setInsertionPolicy( NoInsertion ); | 428 | setInsertionPolicy( NoInsertion ); |
429 | myIterateIndex = -1; | 429 | myIterateIndex = -1; |
430 | myRotated = false; | 430 | myRotated = false; |
431 | myPixProvider = 0L; | 431 | myPixProvider = 0L; |
432 | 432 | ||
433 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), | 433 | connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), |
434 | SLOT(addContextMenuItems(QPopupMenu*)) ); | 434 | SLOT(addContextMenuItems(QPopupMenu*)) ); |
435 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); | 435 | connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); |
436 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); | 436 | connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); |
437 | } | 437 | } |
438 | 438 | ||
439 | OHistoryCombo::~OHistoryCombo() | 439 | OHistoryCombo::~OHistoryCombo() |
440 | { | 440 | { |
441 | delete myPixProvider; | 441 | delete myPixProvider; |
442 | } | 442 | } |
443 | 443 | ||
444 | void OHistoryCombo::setHistoryItems( QStringList items, | 444 | void OHistoryCombo::setHistoryItems( QStringList items, |
445 | bool setCompletionList ) | 445 | bool setCompletionList ) |
446 | { | 446 | { |
447 | OComboBox::clear(); | 447 | OComboBox::clear(); |
448 | 448 | ||
449 | // limit to maxCount() | 449 | // limit to maxCount() |
450 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) | 450 | while ( (int) items.count() > maxCount() && !items.isEmpty() ) |
451 | items.remove( items.begin() ); | 451 | items.remove( items.begin() ); |
452 | 452 | ||
453 | insertItems( items ); | 453 | insertItems( items ); |
454 | 454 | ||
455 | if ( setCompletionList && useCompletion() ) { | 455 | if ( setCompletionList && useCompletion() ) { |
456 | // we don't have any weighting information here ;( | 456 | // we don't have any weighting information here ;( |
457 | OCompletion *comp = completionObject(); | 457 | OCompletion *comp = completionObject(); |
458 | comp->setOrder( OCompletion::Insertion ); | 458 | comp->setOrder( OCompletion::Insertion ); |
459 | comp->setItems( items ); | 459 | comp->setItems( items ); |
460 | comp->setOrder( OCompletion::Weighted ); | 460 | comp->setOrder( OCompletion::Weighted ); |
461 | } | 461 | } |
462 | 462 | ||
463 | clearEdit(); | 463 | clearEdit(); |
464 | } | 464 | } |
465 | 465 | ||
466 | QStringList OHistoryCombo::historyItems() const | 466 | QStringList OHistoryCombo::historyItems() const |
467 | { | 467 | { |
468 | QStringList list; | 468 | QStringList list; |
469 | for ( int i = 0; i < count(); i++ ) | 469 | for ( int i = 0; i < count(); i++ ) |
470 | list.append( text( i ) ); | 470 | list.append( text( i ) ); |
471 | 471 | ||
472 | return list; | 472 | return list; |
473 | } | 473 | } |
474 | 474 | ||
475 | void OHistoryCombo::clearHistory() | 475 | void OHistoryCombo::clearHistory() |
476 | { | 476 | { |
477 | OComboBox::clear(); | 477 | OComboBox::clear(); |
478 | if ( useCompletion() ) | 478 | if ( useCompletion() ) |
479 | completionObject()->clear(); | 479 | completionObject()->clear(); |
480 | } | 480 | } |
481 | 481 | ||
482 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) | 482 | void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) |
483 | { | 483 | { |
484 | if ( menu &&!lineEdit()->text().isEmpty()) | 484 | if ( menu &&!lineEdit()->text().isEmpty()) |
485 | { | 485 | { |
486 | menu->insertSeparator(); | 486 | menu->insertSeparator(); |
487 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); | 487 | menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); |
488 | } | 488 | } |
489 | } | 489 | } |
490 | 490 | ||
491 | void OHistoryCombo::addToHistory( const QString& item ) | 491 | void OHistoryCombo::addToHistory( const QString& item ) |
492 | { | 492 | { |
493 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) | 493 | if ( item.isEmpty() || (count() > 0 && item == text(0) )) |
494 | return; | 494 | return; |
495 | 495 | ||
496 | // remove all existing items before adding | 496 | // remove all existing items before adding |
497 | if ( !duplicatesEnabled() ) { | 497 | if ( !duplicatesEnabled() ) { |
498 | for ( int i = 0; i < count(); i++ ) { | 498 | for ( int i = 0; i < count(); i++ ) { |
499 | if ( text( i ) == item ) | 499 | if ( text( i ) == item ) |
500 | removeItem( i ); | 500 | removeItem( i ); |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | // now add the item | 504 | // now add the item |
505 | if ( myPixProvider ) | 505 | if ( myPixProvider ) |
506 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); | 506 | //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); |
507 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); | 507 | insertItem( myPixProvider->pixmapFor(item, 16), item, 0); |
508 | else | 508 | else |
509 | insertItem( item, 0 ); | 509 | insertItem( item, 0 ); |
510 | 510 | ||
511 | int last; | 511 | int last; |
512 | QString rmItem; | 512 | QString rmItem; |
513 | 513 | ||
514 | bool useComp = useCompletion(); | 514 | bool useComp = useCompletion(); |
515 | while ( count() > maxCount() && count() > 0 ) { | 515 | while ( count() > maxCount() && count() > 0 ) { |
516 | // remove the last item, as long as we are longer than maxCount() | 516 | // remove the last item, as long as we are longer than maxCount() |
517 | // remove the removed item from the completionObject if it isn't | 517 | // remove the removed item from the completionObject if it isn't |
518 | // anymore available at all in the combobox. | 518 | // anymore available at all in the combobox. |
519 | last = count() - 1; | 519 | last = count() - 1; |
520 | rmItem = text( last ); | 520 | rmItem = text( last ); |
521 | removeItem( last ); | 521 | removeItem( last ); |
522 | if ( useComp && !contains( rmItem ) ) | 522 | if ( useComp && !contains( rmItem ) ) |
523 | completionObject()->removeItem( rmItem ); | 523 | completionObject()->removeItem( rmItem ); |
524 | } | 524 | } |
525 | 525 | ||
526 | if ( useComp ) | 526 | if ( useComp ) |
527 | completionObject()->addItem( item ); | 527 | completionObject()->addItem( item ); |
528 | } | 528 | } |
529 | 529 | ||
530 | bool OHistoryCombo::removeFromHistory( const QString& item ) | 530 | bool OHistoryCombo::removeFromHistory( const QString& item ) |
531 | { | 531 | { |
532 | if ( item.isEmpty() ) | 532 | if ( item.isEmpty() ) |
533 | return false; | 533 | return false; |
534 | 534 | ||
535 | bool removed = false; | 535 | bool removed = false; |
536 | QString temp = currentText(); | 536 | QString temp = currentText(); |
537 | for ( int i = 0; i < count(); i++ ) { | 537 | for ( int i = 0; i < count(); i++ ) { |
538 | while ( item == text( i ) ) { | 538 | while ( item == text( i ) ) { |
539 | removed = true; | 539 | removed = true; |
540 | removeItem( i ); | 540 | removeItem( i ); |
541 | } | 541 | } |
542 | } | 542 | } |
543 | 543 | ||
544 | if ( removed && useCompletion() ) | 544 | if ( removed && useCompletion() ) |
545 | completionObject()->removeItem( item ); | 545 | completionObject()->removeItem( item ); |
546 | 546 | ||
547 | setEditText( temp ); | 547 | setEditText( temp ); |
548 | return removed; | 548 | return removed; |
549 | } | 549 | } |
550 | 550 | ||
551 | void OHistoryCombo::keyPressEvent( QKeyEvent *e ) | 551 | void OHistoryCombo::keyPressEvent( QKeyEvent *e ) |
552 | { | 552 | { |
553 | // save the current text in the lineedit | 553 | // save the current text in the lineedit |
554 | if ( myIterateIndex == -1 ) | 554 | if ( myIterateIndex == -1 ) |
555 | myText = currentText(); | 555 | myText = currentText(); |
556 | 556 | ||
557 | // going up in the history, rotating when reaching QListBox::count() | 557 | // going up in the history, rotating when reaching QListBox::count() |
558 | //if ( OStdAccel::isEqual( e, OStdAccel::rotateUp() ) ) { | 558 | //if ( OStdAccel::isEqual( e, OStdAccel::rotateUp() ) ) { |
559 | if ( e->key() == Qt::Key_Up ) { | 559 | if ( e->key() == Qt::Key_Up ) { |
560 | myIterateIndex++; | 560 | myIterateIndex++; |
561 | 561 | ||
562 | // skip duplicates/empty items | 562 | // skip duplicates/empty items |
563 | while ( myIterateIndex < count()-1 && | 563 | while ( myIterateIndex < count()-1 && |
564 | (currentText() == text( myIterateIndex ) || | 564 | (currentText() == text( myIterateIndex ) || |
565 | text( myIterateIndex ).isEmpty()) ) | 565 | text( myIterateIndex ).isEmpty()) ) |
566 | myIterateIndex++; | 566 | myIterateIndex++; |
567 | 567 | ||
568 | if ( myIterateIndex >= count() ) { | 568 | if ( myIterateIndex >= count() ) { |
569 | myRotated = true; | 569 | myRotated = true; |
570 | myIterateIndex = -1; | 570 | myIterateIndex = -1; |
571 | 571 | ||
572 | // if the typed text is the same as the first item, skip the first | 572 | // if the typed text is the same as the first item, skip the first |
573 | if ( myText == text(0) ) | 573 | if ( myText == text(0) ) |
574 | myIterateIndex = 0; | 574 | myIterateIndex = 0; |
575 | 575 | ||
576 | setEditText( myText ); | 576 | setEditText( myText ); |
577 | } | 577 | } |
578 | else | 578 | else |
579 | setEditText( text( myIterateIndex )); | 579 | setEditText( text( myIterateIndex )); |
580 | } | 580 | } |
581 | 581 | ||
582 | 582 | ||
583 | // going down in the history, no rotation possible. Last item will be | 583 | // going down in the history, no rotation possible. Last item will be |
584 | // the text that was in the lineedit before Up was called. | 584 | // the text that was in the lineedit before Up was called. |
585 | //else if ( OStdAccel::isEqual( e, OStdAccel::rotateDown() ) ) { | 585 | //else if ( OStdAccel::isEqual( e, OStdAccel::rotateDown() ) ) { |
586 | else if ( e->key() == Qt::Key_Down ) { | 586 | else if ( e->key() == Qt::Key_Down ) { |
587 | myIterateIndex--; | 587 | myIterateIndex--; |
588 | 588 | ||
589 | // skip duplicates/empty items | 589 | // skip duplicates/empty items |
590 | while ( myIterateIndex >= 0 && | 590 | while ( myIterateIndex >= 0 && |
591 | (currentText() == text( myIterateIndex ) || | 591 | (currentText() == text( myIterateIndex ) || |
592 | text( myIterateIndex ).isEmpty()) ) | 592 | text( myIterateIndex ).isEmpty()) ) |
593 | myIterateIndex--; | 593 | myIterateIndex--; |
594 | 594 | ||
595 | 595 | ||
596 | if ( myIterateIndex < 0 ) { | 596 | if ( myIterateIndex < 0 ) { |
597 | if ( myRotated && myIterateIndex == -2 ) { | 597 | if ( myRotated && myIterateIndex == -2 ) { |
598 | myRotated = false; | 598 | myRotated = false; |
599 | myIterateIndex = count() - 1; | 599 | myIterateIndex = count() - 1; |
600 | setEditText( text(myIterateIndex) ); | 600 | setEditText( text(myIterateIndex) ); |
601 | } | 601 | } |
602 | else { // bottom of history | 602 | else { // bottom of history |
603 | if ( myIterateIndex == -2 ) { | 603 | if ( myIterateIndex == -2 ) { |
604 | qDebug( "ONotifyClient is not implemented yet." ); | 604 | qDebug( "ONotifyClient is not implemented yet." ); |
605 | //ONotifyClient::event( ONotifyClient::notification, | 605 | //ONotifyClient::event( ONotifyClient::notification, |
606 | // i18n("No further item in the history.")); | 606 | // i18n("No further item in the history.")); |
607 | } | 607 | } |
608 | 608 | ||
609 | myIterateIndex = -1; | 609 | myIterateIndex = -1; |
610 | if ( currentText() != myText ) | 610 | if ( currentText() != myText ) |
611 | setEditText( myText ); | 611 | setEditText( myText ); |
612 | } | 612 | } |
613 | } | 613 | } |
614 | else | 614 | else |
615 | setEditText( text( myIterateIndex )); | 615 | setEditText( text( myIterateIndex )); |
616 | } | 616 | } |
617 | 617 | ||
618 | else | 618 | else |
619 | OComboBox::keyPressEvent( e ); | 619 | OComboBox::keyPressEvent( e ); |
620 | } | 620 | } |
621 | 621 | ||
622 | void OHistoryCombo::slotReset() | 622 | void OHistoryCombo::slotReset() |
623 | { | 623 | { |
624 | myIterateIndex = -1; | 624 | myIterateIndex = -1; |
625 | myRotated = false; | 625 | myRotated = false; |
626 | } | 626 | } |
627 | 627 | ||
628 | 628 | ||
629 | void OHistoryCombo::setPixmapProvider( OPixmapProvider *prov ) | 629 | void OHistoryCombo::setPixmapProvider( OPixmapProvider *prov ) |
630 | { | 630 | { |
631 | if ( myPixProvider == prov ) | 631 | if ( myPixProvider == prov ) |
632 | return; | 632 | return; |
633 | 633 | ||
634 | delete myPixProvider; | 634 | delete myPixProvider; |
635 | myPixProvider = prov; | 635 | myPixProvider = prov; |
636 | 636 | ||
637 | // re-insert all the items with/without pixmap | 637 | // re-insert all the items with/without pixmap |
638 | // I would prefer to use changeItem(), but that doesn't honour the pixmap | 638 | // I would prefer to use changeItem(), but that doesn't honour the pixmap |
639 | // when using an editable combobox (what we do) | 639 | // when using an editable combobox (what we do) |
640 | if ( count() > 0 ) { | 640 | if ( count() > 0 ) { |
641 | QStringList items( historyItems() ); | 641 | QStringList items( historyItems() ); |
642 | clear(); | 642 | clear(); |
643 | insertItems( items ); | 643 | insertItems( items ); |
644 | } | 644 | } |
645 | } | 645 | } |
646 | 646 | ||
647 | void OHistoryCombo::insertItems( const QStringList& items ) | 647 | void OHistoryCombo::insertItems( const QStringList& items ) |
648 | { | 648 | { |
649 | QStringList::ConstIterator it = items.begin(); | 649 | QStringList::ConstIterator it = items.begin(); |
650 | QString item; | 650 | QString item; |
651 | while ( it != items.end() ) { | 651 | while ( it != items.end() ) { |
652 | item = *it; | 652 | item = *it; |
653 | if ( !item.isEmpty() ) { // only insert non-empty items | 653 | if ( !item.isEmpty() ) { // only insert non-empty items |
654 | if ( myPixProvider ) | 654 | if ( myPixProvider ) |
655 | // insertItem( myPixProvider->pixmapFor(item, OIcon::SizeSmall), item ); | 655 | // insertItem( myPixProvider->pixmapFor(item, OIcon::SizeSmall), item ); |
656 | insertItem( myPixProvider->pixmapFor(item, 16), item ); | 656 | insertItem( myPixProvider->pixmapFor(item, 16), item ); |
657 | else | 657 | else |
658 | insertItem( item ); | 658 | insertItem( item ); |
659 | } | 659 | } |
660 | ++it; | 660 | ++it; |
661 | } | 661 | } |
662 | } | 662 | } |
663 | 663 | ||
664 | void OHistoryCombo::slotClear() | 664 | void OHistoryCombo::slotClear() |
665 | { | 665 | { |
666 | clearHistory(); | 666 | clearHistory(); |
667 | emit cleared(); | 667 | emit cleared(); |
668 | } | 668 | } |
669 | 669 | ||
diff --git a/libopie2/qt3/opieui/ocompletionbox.cpp b/libopie2/qt3/opieui/ocompletionbox.cpp index b594b8e..b36123e 100644 --- a/libopie2/qt3/opieui/ocompletionbox.cpp +++ b/libopie2/qt3/opieui/ocompletionbox.cpp | |||
@@ -1,408 +1,408 @@ | |||
1 | /* | 1 | /* |
2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
3 | is part of the Copyright (C) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> | 3 | is part of the Copyright (C) 2000,2001 Carsten Pfeiffer <pfeiffer@kde.org> |
4 | Opie Project Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> | 4 | Opie Project Copyright (C) 2000 Stefan Schimanski <1Stein@gmx.de> |
5 | Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org> | 5 | Copyright (C) 2000,2001 Dawit Alemayehu <adawit@kde.org> |
6 | =. | 6 | =. |
7 | .=l. Originally part of the KDE Project | 7 | .=l. Originally part of the KDE Project |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | #include <qapplication.h> | 33 | #include <qapplication.h> |
34 | #include <qevent.h> | 34 | #include <qevent.h> |
35 | #include <qstyle.h> | 35 | #include <qstyle.h> |
36 | 36 | ||
37 | #include <opie2/ocompletionbox.h> | 37 | #include <opie2/ocompletionbox.h> |
38 | 38 | ||
39 | #define OListBox QListBox | 39 | #define OListBox QListBox |
40 | 40 | ||
41 | class OCompletionBox::OCompletionBoxPrivate | 41 | class OCompletionBox::OCompletionBoxPrivate |
42 | { | 42 | { |
43 | public: | 43 | public: |
44 | QWidget *m_parent; // necessary to set the focus back | 44 | QWidget *m_parent; // necessary to set the focus back |
45 | QString cancelText; | 45 | QString cancelText; |
46 | bool tabHandling; | 46 | bool tabHandling; |
47 | bool down_workaround; | 47 | bool down_workaround; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | OCompletionBox::OCompletionBox( QWidget *parent, const char *name ) | 50 | OCompletionBox::OCompletionBox( QWidget *parent, const char *name ) |
51 | :OListBox( parent, name, WType_Popup ) | 51 | :OListBox( parent, name, WType_Popup ) |
52 | { | 52 | { |
53 | d = new OCompletionBoxPrivate; | 53 | d = new OCompletionBoxPrivate; |
54 | d->m_parent = parent; | 54 | d->m_parent = parent; |
55 | d->tabHandling = true; | 55 | d->tabHandling = true; |
56 | d->down_workaround = false; | 56 | d->down_workaround = false; |
57 | 57 | ||
58 | setColumnMode( 1 ); | 58 | setColumnMode( 1 ); |
59 | setLineWidth( 1 ); | 59 | setLineWidth( 1 ); |
60 | setFrameStyle( QFrame::Box | QFrame::Plain ); | 60 | setFrameStyle( QFrame::Box | QFrame::Plain ); |
61 | 61 | ||
62 | if ( parent ) | 62 | if ( parent ) |
63 | setFocusProxy( parent ); | 63 | setFocusProxy( parent ); |
64 | else | 64 | else |
65 | setFocusPolicy( NoFocus ); | 65 | setFocusPolicy( NoFocus ); |
66 | 66 | ||
67 | setVScrollBarMode( Auto ); | 67 | setVScrollBarMode( Auto ); |
68 | setHScrollBarMode( AlwaysOff ); | 68 | setHScrollBarMode( AlwaysOff ); |
69 | 69 | ||
70 | connect( this, SIGNAL( doubleClicked( QListBoxItem * )), | 70 | connect( this, SIGNAL( doubleClicked(QListBoxItem*)), |
71 | SLOT( slotActivated( QListBoxItem * )) ); | 71 | SLOT( slotActivated(QListBoxItem*)) ); |
72 | 72 | ||
73 | // grmbl, just QListBox workarounds :[ Thanks Volker. | 73 | // grmbl, just QListBox workarounds :[ Thanks Volker. |
74 | connect( this, SIGNAL( currentChanged( QListBoxItem * )), | 74 | connect( this, SIGNAL( currentChanged(QListBoxItem*)), |
75 | SLOT( slotCurrentChanged() )); | 75 | SLOT( slotCurrentChanged() )); |
76 | connect( this, SIGNAL( clicked( QListBoxItem * )), | 76 | connect( this, SIGNAL( clicked(QListBoxItem*)), |
77 | SLOT( slotItemClicked( QListBoxItem * )) ); | 77 | SLOT( slotItemClicked(QListBoxItem*)) ); |
78 | } | 78 | } |
79 | 79 | ||
80 | OCompletionBox::~OCompletionBox() | 80 | OCompletionBox::~OCompletionBox() |
81 | { | 81 | { |
82 | d->m_parent = 0L; | 82 | d->m_parent = 0L; |
83 | delete d; | 83 | delete d; |
84 | } | 84 | } |
85 | 85 | ||
86 | QStringList OCompletionBox::items() const | 86 | QStringList OCompletionBox::items() const |
87 | { | 87 | { |
88 | QStringList list; | 88 | QStringList list; |
89 | for ( uint i = 0; i < count(); i++ ) { | 89 | for ( uint i = 0; i < count(); i++ ) { |
90 | list.append( text( i ) ); | 90 | list.append( text( i ) ); |
91 | } | 91 | } |
92 | return list; | 92 | return list; |
93 | } | 93 | } |
94 | 94 | ||
95 | void OCompletionBox::slotActivated( QListBoxItem *item ) | 95 | void OCompletionBox::slotActivated( QListBoxItem *item ) |
96 | { | 96 | { |
97 | if ( !item ) | 97 | if ( !item ) |
98 | return; | 98 | return; |
99 | 99 | ||
100 | hide(); | 100 | hide(); |
101 | emit activated( item->text() ); | 101 | emit activated( item->text() ); |
102 | } | 102 | } |
103 | 103 | ||
104 | bool OCompletionBox::eventFilter( QObject *o, QEvent *e ) | 104 | bool OCompletionBox::eventFilter( QObject *o, QEvent *e ) |
105 | { | 105 | { |
106 | int type = e->type(); | 106 | int type = e->type(); |
107 | 107 | ||
108 | if ( o == d->m_parent ) { | 108 | if ( o == d->m_parent ) { |
109 | if ( isVisible() ) { | 109 | if ( isVisible() ) { |
110 | if ( type == QEvent::KeyPress ) { | 110 | if ( type == QEvent::KeyPress ) { |
111 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); | 111 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); |
112 | switch ( ev->key() ) { | 112 | switch ( ev->key() ) { |
113 | case Key_BackTab: | 113 | case Key_BackTab: |
114 | if ( d->tabHandling ) { | 114 | if ( d->tabHandling ) { |
115 | up(); | 115 | up(); |
116 | ev->accept(); | 116 | ev->accept(); |
117 | return true; | 117 | return true; |
118 | } | 118 | } |
119 | break; | 119 | break; |
120 | case Key_Tab: | 120 | case Key_Tab: |
121 | if ( d->tabHandling ) { | 121 | if ( d->tabHandling ) { |
122 | down(); // Only on TAB!! | 122 | down(); // Only on TAB!! |
123 | ev->accept(); | 123 | ev->accept(); |
124 | return true; | 124 | return true; |
125 | } | 125 | } |
126 | break; | 126 | break; |
127 | case Key_Down: | 127 | case Key_Down: |
128 | down(); | 128 | down(); |
129 | ev->accept(); | 129 | ev->accept(); |
130 | return true; | 130 | return true; |
131 | case Key_Up: | 131 | case Key_Up: |
132 | up(); | 132 | up(); |
133 | ev->accept(); | 133 | ev->accept(); |
134 | return true; | 134 | return true; |
135 | case Key_Prior: | 135 | case Key_Prior: |
136 | pageUp(); | 136 | pageUp(); |
137 | ev->accept(); | 137 | ev->accept(); |
138 | return true; | 138 | return true; |
139 | case Key_Next: | 139 | case Key_Next: |
140 | pageDown(); | 140 | pageDown(); |
141 | ev->accept(); | 141 | ev->accept(); |
142 | return true; | 142 | return true; |
143 | case Key_Escape: | 143 | case Key_Escape: |
144 | cancelled(); | 144 | cancelled(); |
145 | ev->accept(); | 145 | ev->accept(); |
146 | return true; | 146 | return true; |
147 | case Key_Enter: | 147 | case Key_Enter: |
148 | case Key_Return: | 148 | case Key_Return: |
149 | if ( ev->state() & ShiftButton ) { | 149 | if ( ev->state() & ShiftButton ) { |
150 | hide(); | 150 | hide(); |
151 | ev->accept(); // Consume the Enter event | 151 | ev->accept(); // Consume the Enter event |
152 | return true; | 152 | return true; |
153 | } | 153 | } |
154 | break; | 154 | break; |
155 | default: | 155 | default: |
156 | break; | 156 | break; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | else if ( type == QEvent::AccelOverride ) { | 159 | else if ( type == QEvent::AccelOverride ) { |
160 | // Override any acceleartors that match | 160 | // Override any acceleartors that match |
161 | // the key sequences we use here... | 161 | // the key sequences we use here... |
162 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); | 162 | QKeyEvent *ev = static_cast<QKeyEvent *>( e ); |
163 | switch ( ev->key() ) { | 163 | switch ( ev->key() ) { |
164 | case Key_Tab: | 164 | case Key_Tab: |
165 | case Key_BackTab: | 165 | case Key_BackTab: |
166 | case Key_Down: | 166 | case Key_Down: |
167 | case Key_Up: | 167 | case Key_Up: |
168 | case Key_Prior: | 168 | case Key_Prior: |
169 | case Key_Next: | 169 | case Key_Next: |
170 | case Key_Escape: | 170 | case Key_Escape: |
171 | case Key_Enter: | 171 | case Key_Enter: |
172 | case Key_Return: | 172 | case Key_Return: |
173 | ev->accept(); | 173 | ev->accept(); |
174 | return true; | 174 | return true; |
175 | break; | 175 | break; |
176 | default: | 176 | default: |
177 | break; | 177 | break; |
178 | } | 178 | } |
179 | } | 179 | } |
180 | 180 | ||
181 | // parent loses focus or gets a click -> we hide | 181 | // parent loses focus or gets a click -> we hide |
182 | else if ( type == QEvent::FocusOut || type == QEvent::Resize || | 182 | else if ( type == QEvent::FocusOut || type == QEvent::Resize || |
183 | type == QEvent::Close || type == QEvent::Hide || | 183 | type == QEvent::Close || type == QEvent::Hide || |
184 | type == QEvent::Move ) { | 184 | type == QEvent::Move ) { |
185 | hide(); | 185 | hide(); |
186 | } | 186 | } |
187 | else if ( type == QEvent::Move ) | 187 | else if ( type == QEvent::Move ) |
188 | move( d->m_parent->mapToGlobal(QPoint(0, d->m_parent->height()))); | 188 | move( d->m_parent->mapToGlobal(QPoint(0, d->m_parent->height()))); |
189 | else if ( type == QEvent::Resize ) | 189 | else if ( type == QEvent::Resize ) |
190 | resize( sizeHint() ); | 190 | resize( sizeHint() ); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | // any mouse-click on something else than "this" makes us hide | 194 | // any mouse-click on something else than "this" makes us hide |
195 | else if ( type == QEvent::MouseButtonPress ) { | 195 | else if ( type == QEvent::MouseButtonPress ) { |
196 | QMouseEvent *ev = static_cast<QMouseEvent *>( e ); | 196 | QMouseEvent *ev = static_cast<QMouseEvent *>( e ); |
197 | if ( !rect().contains( ev->pos() )) // this widget | 197 | if ( !rect().contains( ev->pos() )) // this widget |
198 | hide(); | 198 | hide(); |
199 | } | 199 | } |
200 | 200 | ||
201 | return OListBox::eventFilter( o, e ); | 201 | return OListBox::eventFilter( o, e ); |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | void OCompletionBox::popup() | 205 | void OCompletionBox::popup() |
206 | { | 206 | { |
207 | if ( count() == 0 ) | 207 | if ( count() == 0 ) |
208 | hide(); | 208 | hide(); |
209 | else { | 209 | else { |
210 | ensureCurrentVisible(); | 210 | ensureCurrentVisible(); |
211 | bool block = signalsBlocked(); | 211 | bool block = signalsBlocked(); |
212 | blockSignals( true ); | 212 | blockSignals( true ); |
213 | setCurrentItem( 0 ); | 213 | setCurrentItem( 0 ); |
214 | blockSignals( block ); | 214 | blockSignals( block ); |
215 | clearSelection(); | 215 | clearSelection(); |
216 | if ( !isVisible() ) | 216 | if ( !isVisible() ) |
217 | show(); | 217 | show(); |
218 | else if ( size().height() < sizeHint().height() ) | 218 | else if ( size().height() < sizeHint().height() ) |
219 | resize( sizeHint() ); | 219 | resize( sizeHint() ); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | void OCompletionBox::show() | 223 | void OCompletionBox::show() |
224 | { | 224 | { |
225 | resize( sizeHint() ); | 225 | resize( sizeHint() ); |
226 | 226 | ||
227 | if ( d->m_parent ) | 227 | if ( d->m_parent ) |
228 | { | 228 | { |
229 | //QDesktopWidget *screen = QApplication::desktop(); | 229 | //QDesktopWidget *screen = QApplication::desktop(); |
230 | QWidget *screen = QApplication::desktop(); | 230 | QWidget *screen = QApplication::desktop(); |
231 | 231 | ||
232 | QPoint orig = d->m_parent->mapToGlobal( QPoint(0, d->m_parent->height()) ); | 232 | QPoint orig = d->m_parent->mapToGlobal( QPoint(0, d->m_parent->height()) ); |
233 | int x = orig.x(); | 233 | int x = orig.x(); |
234 | int y = orig.y(); | 234 | int y = orig.y(); |
235 | 235 | ||
236 | if ( x + width() > screen->width() ) | 236 | if ( x + width() > screen->width() ) |
237 | x = screen->width() - width(); | 237 | x = screen->width() - width(); |
238 | if (y + height() > screen->height() ) | 238 | if (y + height() > screen->height() ) |
239 | y = y - height() - d->m_parent->height(); | 239 | y = y - height() - d->m_parent->height(); |
240 | 240 | ||
241 | move( x, y); | 241 | move( x, y); |
242 | qApp->installEventFilter( this ); | 242 | qApp->installEventFilter( this ); |
243 | } | 243 | } |
244 | 244 | ||
245 | // ### we shouldn't need to call this, but without this, the scrollbars | 245 | // ### we shouldn't need to call this, but without this, the scrollbars |
246 | // are pretty b0rked. | 246 | // are pretty b0rked. |
247 | //triggerUpdate( true ); | 247 | //triggerUpdate( true ); |
248 | 248 | ||
249 | OListBox::show(); | 249 | OListBox::show(); |
250 | } | 250 | } |
251 | 251 | ||
252 | void OCompletionBox::hide() | 252 | void OCompletionBox::hide() |
253 | { | 253 | { |
254 | if ( d->m_parent ) | 254 | if ( d->m_parent ) |
255 | qApp->removeEventFilter( this ); | 255 | qApp->removeEventFilter( this ); |
256 | d->cancelText = QString::null; | 256 | d->cancelText = QString::null; |
257 | OListBox::hide(); | 257 | OListBox::hide(); |
258 | } | 258 | } |
259 | 259 | ||
260 | QSize OCompletionBox::sizeHint() const | 260 | QSize OCompletionBox::sizeHint() const |
261 | { | 261 | { |
262 | int ih = itemHeight(); | 262 | int ih = itemHeight(); |
263 | int h = QMIN( 15 * ih, (int) count() * ih ) +1; | 263 | int h = QMIN( 15 * ih, (int) count() * ih ) +1; |
264 | h = QMAX( h, OListBox::minimumSizeHint().height() ); | 264 | h = QMAX( h, OListBox::minimumSizeHint().height() ); |
265 | 265 | ||
266 | int w = (d->m_parent) ? d->m_parent->width() : OListBox::minimumSizeHint().width(); | 266 | int w = (d->m_parent) ? d->m_parent->width() : OListBox::minimumSizeHint().width(); |
267 | w = QMAX( OListBox::minimumSizeHint().width(), w ); | 267 | w = QMAX( OListBox::minimumSizeHint().width(), w ); |
268 | return QSize( w, h ); | 268 | return QSize( w, h ); |
269 | } | 269 | } |
270 | 270 | ||
271 | void OCompletionBox::down() | 271 | void OCompletionBox::down() |
272 | { | 272 | { |
273 | int i = currentItem(); | 273 | int i = currentItem(); |
274 | 274 | ||
275 | if ( i == 0 && d->down_workaround ) { | 275 | if ( i == 0 && d->down_workaround ) { |
276 | d->down_workaround = false; | 276 | d->down_workaround = false; |
277 | setCurrentItem( 0 ); | 277 | setCurrentItem( 0 ); |
278 | setSelected( 0, true ); | 278 | setSelected( 0, true ); |
279 | emit highlighted( currentText() ); | 279 | emit highlighted( currentText() ); |
280 | } | 280 | } |
281 | 281 | ||
282 | else if ( i < (int) count() - 1 ) | 282 | else if ( i < (int) count() - 1 ) |
283 | setCurrentItem( i + 1 ); | 283 | setCurrentItem( i + 1 ); |
284 | } | 284 | } |
285 | 285 | ||
286 | void OCompletionBox::up() | 286 | void OCompletionBox::up() |
287 | { | 287 | { |
288 | if ( currentItem() > 0 ) | 288 | if ( currentItem() > 0 ) |
289 | setCurrentItem( currentItem() - 1 ); | 289 | setCurrentItem( currentItem() - 1 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | void OCompletionBox::pageDown() | 292 | void OCompletionBox::pageDown() |
293 | { | 293 | { |
294 | int i = currentItem() + numItemsVisible(); | 294 | int i = currentItem() + numItemsVisible(); |
295 | i = i > (int)count() - 1 ? (int)count() - 1 : i; | 295 | i = i > (int)count() - 1 ? (int)count() - 1 : i; |
296 | setCurrentItem( i ); | 296 | setCurrentItem( i ); |
297 | } | 297 | } |
298 | 298 | ||
299 | void OCompletionBox::pageUp() | 299 | void OCompletionBox::pageUp() |
300 | { | 300 | { |
301 | int i = currentItem() - numItemsVisible(); | 301 | int i = currentItem() - numItemsVisible(); |
302 | i = i < 0 ? 0 : i; | 302 | i = i < 0 ? 0 : i; |
303 | setCurrentItem( i ); | 303 | setCurrentItem( i ); |
304 | } | 304 | } |
305 | 305 | ||
306 | void OCompletionBox::home() | 306 | void OCompletionBox::home() |
307 | { | 307 | { |
308 | setCurrentItem( 0 ); | 308 | setCurrentItem( 0 ); |
309 | } | 309 | } |
310 | 310 | ||
311 | void OCompletionBox::end() | 311 | void OCompletionBox::end() |
312 | { | 312 | { |
313 | setCurrentItem( count() -1 ); | 313 | setCurrentItem( count() -1 ); |
314 | } | 314 | } |
315 | 315 | ||
316 | void OCompletionBox::setTabHandling( bool enable ) | 316 | void OCompletionBox::setTabHandling( bool enable ) |
317 | { | 317 | { |
318 | d->tabHandling = enable; | 318 | d->tabHandling = enable; |
319 | } | 319 | } |
320 | 320 | ||
321 | bool OCompletionBox::isTabHandling() const | 321 | bool OCompletionBox::isTabHandling() const |
322 | { | 322 | { |
323 | return d->tabHandling; | 323 | return d->tabHandling; |
324 | } | 324 | } |
325 | 325 | ||
326 | void OCompletionBox::setCancelledText( const QString& text ) | 326 | void OCompletionBox::setCancelledText( const QString& text ) |
327 | { | 327 | { |
328 | d->cancelText = text; | 328 | d->cancelText = text; |
329 | } | 329 | } |
330 | 330 | ||
331 | QString OCompletionBox::cancelledText() const | 331 | QString OCompletionBox::cancelledText() const |
332 | { | 332 | { |
333 | return d->cancelText; | 333 | return d->cancelText; |
334 | } | 334 | } |
335 | 335 | ||
336 | void OCompletionBox::cancelled() | 336 | void OCompletionBox::cancelled() |
337 | { | 337 | { |
338 | if ( !d->cancelText.isNull() ) | 338 | if ( !d->cancelText.isNull() ) |
339 | emit userCancelled( d->cancelText ); | 339 | emit userCancelled( d->cancelText ); |
340 | if ( isVisible() ) | 340 | if ( isVisible() ) |
341 | hide(); | 341 | hide(); |
342 | } | 342 | } |
343 | 343 | ||
344 | class OCompletionBoxItem : public QListBoxItem | 344 | class OCompletionBoxItem : public QListBoxItem |
345 | { | 345 | { |
346 | public: | 346 | public: |
347 | void reuse( const QString &text ) { setText( text ); } | 347 | void reuse( const QString &text ) { setText( text ); } |
348 | }; | 348 | }; |
349 | 349 | ||
350 | 350 | ||
351 | void OCompletionBox::insertItems( const QStringList& items, int index ) | 351 | void OCompletionBox::insertItems( const QStringList& items, int index ) |
352 | { | 352 | { |
353 | bool block = signalsBlocked(); | 353 | bool block = signalsBlocked(); |
354 | blockSignals( true ); | 354 | blockSignals( true ); |
355 | insertStringList( items, index ); | 355 | insertStringList( items, index ); |
356 | blockSignals( block ); | 356 | blockSignals( block ); |
357 | d->down_workaround = true; | 357 | d->down_workaround = true; |
358 | } | 358 | } |
359 | 359 | ||
360 | void OCompletionBox::setItems( const QStringList& items ) | 360 | void OCompletionBox::setItems( const QStringList& items ) |
361 | { | 361 | { |
362 | bool block = signalsBlocked(); | 362 | bool block = signalsBlocked(); |
363 | blockSignals( true ); | 363 | blockSignals( true ); |
364 | 364 | ||
365 | QListBoxItem* item = firstItem(); | 365 | QListBoxItem* item = firstItem(); |
366 | if ( !item ) { | 366 | if ( !item ) { |
367 | insertStringList( items ); | 367 | insertStringList( items ); |
368 | } | 368 | } |
369 | else { | 369 | else { |
370 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); it++) { | 370 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); it++) { |
371 | if ( item ) { | 371 | if ( item ) { |
372 | ((OCompletionBoxItem*)item)->reuse( *it ); | 372 | ((OCompletionBoxItem*)item)->reuse( *it ); |
373 | item = item->next(); | 373 | item = item->next(); |
374 | } | 374 | } |
375 | else { | 375 | else { |
376 | insertItem( new QListBoxText( *it ) ); | 376 | insertItem( new QListBoxText( *it ) ); |
377 | } | 377 | } |
378 | } | 378 | } |
379 | QListBoxItem* tmp = item; | 379 | QListBoxItem* tmp = item; |
380 | while ( (item = tmp ) ) { | 380 | while ( (item = tmp ) ) { |
381 | tmp = item->next(); | 381 | tmp = item->next(); |
382 | delete item; | 382 | delete item; |
383 | } | 383 | } |
384 | triggerUpdate( false ); | 384 | triggerUpdate( false ); |
385 | } | 385 | } |
386 | 386 | ||
387 | blockSignals( block ); | 387 | blockSignals( block ); |
388 | d->down_workaround = true; | 388 | d->down_workaround = true; |
389 | } | 389 | } |
390 | 390 | ||
391 | void OCompletionBox::slotCurrentChanged() | 391 | void OCompletionBox::slotCurrentChanged() |
392 | { | 392 | { |
393 | d->down_workaround = false; | 393 | d->down_workaround = false; |
394 | } | 394 | } |
395 | 395 | ||
396 | void OCompletionBox::slotItemClicked( QListBoxItem *item ) | 396 | void OCompletionBox::slotItemClicked( QListBoxItem *item ) |
397 | { | 397 | { |
398 | if ( item ) | 398 | if ( item ) |
399 | { | 399 | { |
400 | if ( d->down_workaround ) { | 400 | if ( d->down_workaround ) { |
401 | d->down_workaround = false; | 401 | d->down_workaround = false; |
402 | emit highlighted( item->text() ); | 402 | emit highlighted( item->text() ); |
403 | } | 403 | } |
404 | 404 | ||
405 | hide(); | 405 | hide(); |
406 | emit activated( item->text() ); | 406 | emit activated( item->text() ); |
407 | } | 407 | } |
408 | } | 408 | } |
diff --git a/libopie2/qt3/opieui/ojanuswidget.cpp b/libopie2/qt3/opieui/ojanuswidget.cpp index 0a037ff..063e393 100644 --- a/libopie2/qt3/opieui/ojanuswidget.cpp +++ b/libopie2/qt3/opieui/ojanuswidget.cpp | |||
@@ -1,1116 +1,1116 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Originally part of the KDE project | 4 | Originally part of the KDE project |
5 | (C) 1999-2000 Espen Sand (espensa@online.no) | 5 | (C) 1999-2000 Espen Sand (espensa@online.no) |
6 | =. | 6 | =. |
7 | .=l. | 7 | .=l. |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* QT */ | 33 | /* QT */ |
34 | 34 | ||
35 | #include <qbitmap.h> | 35 | #include <qbitmap.h> |
36 | #include <qgrid.h> | 36 | #include <qgrid.h> |
37 | #include <qhbox.h> | 37 | #include <qhbox.h> |
38 | #include <qheader.h> | 38 | #include <qheader.h> |
39 | #include <qlabel.h> | 39 | #include <qlabel.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qobjectlist.h> | 41 | #include <qobjectlist.h> |
42 | #include <qpixmap.h> | 42 | #include <qpixmap.h> |
43 | #include <qlistview.h> | 43 | #include <qlistview.h> |
44 | #include <qsplitter.h> | 44 | #include <qsplitter.h> |
45 | #include <qtabwidget.h> | 45 | #include <qtabwidget.h> |
46 | #include <qvbox.h> | 46 | #include <qvbox.h> |
47 | #include <qwidgetstack.h> | 47 | #include <qwidgetstack.h> |
48 | #include <qpainter.h> | 48 | #include <qpainter.h> |
49 | #include <qtimer.h> | 49 | #include <qtimer.h> |
50 | #include <qstyle.h> | 50 | #include <qstyle.h> |
51 | 51 | ||
52 | /* OPIE */ | 52 | /* OPIE */ |
53 | 53 | ||
54 | #include <opie2/odialog.h> | 54 | #include <opie2/odialog.h> |
55 | #include <opie2/oseparator.h> | 55 | #include <opie2/oseparator.h> |
56 | #include <opie2/ojanuswidget.h> | 56 | #include <opie2/ojanuswidget.h> |
57 | 57 | ||
58 | /*====================================================================================== | 58 | /*====================================================================================== |
59 | * IconListItem | 59 | * IconListItem |
60 | *======================================================================================*/ | 60 | *======================================================================================*/ |
61 | 61 | ||
62 | class OJanusWidget::IconListItem : public QListBoxItem | 62 | class OJanusWidget::IconListItem : public QListBoxItem |
63 | { | 63 | { |
64 | public: | 64 | public: |
65 | IconListItem( QListBox *listbox, const QPixmap &pixmap, | 65 | IconListItem( QListBox *listbox, const QPixmap &pixmap, |
66 | const QString &text ); | 66 | const QString &text ); |
67 | virtual int height( const QListBox *lb ) const; | 67 | virtual int height( const QListBox *lb ) const; |
68 | virtual int width( const QListBox *lb ) const; | 68 | virtual int width( const QListBox *lb ) const; |
69 | int expandMinimumWidth( int width ); | 69 | int expandMinimumWidth( int width ); |
70 | 70 | ||
71 | protected: | 71 | protected: |
72 | const QPixmap &defaultPixmap(); | 72 | const QPixmap &defaultPixmap(); |
73 | void paint( QPainter *painter ); | 73 | void paint( QPainter *painter ); |
74 | 74 | ||
75 | private: | 75 | private: |
76 | QPixmap mPixmap; | 76 | QPixmap mPixmap; |
77 | int mMinimumWidth; | 77 | int mMinimumWidth; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | template class QPtrList<QListViewItem>; | 80 | template class QPtrList<QListViewItem>; |
81 | 81 | ||
82 | /*====================================================================================== | 82 | /*====================================================================================== |
83 | * OJanusWidget | 83 | * OJanusWidget |
84 | *======================================================================================*/ | 84 | *======================================================================================*/ |
85 | 85 | ||
86 | OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) | 86 | OJanusWidget::OJanusWidget( QWidget *parent, const char *name, int face ) |
87 | : QWidget( parent, name, 0 ), | 87 | : QWidget( parent, name, 0 ), |
88 | mValid(false), mPageList(0), | 88 | mValid(false), mPageList(0), |
89 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), | 89 | mTitleList(0), mFace(face), mTitleLabel(0), mActivePageWidget(0), |
90 | mShowIconsInTreeList(false), d(0) | 90 | mShowIconsInTreeList(false), d(0) |
91 | { | 91 | { |
92 | QVBoxLayout *topLayout = new QVBoxLayout( this ); | 92 | QVBoxLayout *topLayout = new QVBoxLayout( this ); |
93 | 93 | ||
94 | if( mFace == TreeList || mFace == IconList ) | 94 | if( mFace == TreeList || mFace == IconList ) |
95 | { | 95 | { |
96 | mPageList = new QPtrList<QWidget>; | 96 | mPageList = new QPtrList<QWidget>; |
97 | mTitleList = new QStringList(); | 97 | mTitleList = new QStringList(); |
98 | 98 | ||
99 | QFrame *page; | 99 | QFrame *page; |
100 | if( mFace == TreeList ) | 100 | if( mFace == TreeList ) |
101 | { | 101 | { |
102 | QSplitter *splitter = new QSplitter( this ); | 102 | QSplitter *splitter = new QSplitter( this ); |
103 | topLayout->addWidget( splitter, 10 ); | 103 | topLayout->addWidget( splitter, 10 ); |
104 | mTreeListResizeMode = QSplitter::KeepSize; | 104 | mTreeListResizeMode = QSplitter::KeepSize; |
105 | 105 | ||
106 | mTreeList = new QListView( splitter ); | 106 | mTreeList = new QListView( splitter ); |
107 | mTreeList->addColumn( QString::fromLatin1("") ); | 107 | mTreeList->addColumn( QString::fromLatin1("") ); |
108 | mTreeList->header()->hide(); | 108 | mTreeList->header()->hide(); |
109 | mTreeList->setRootIsDecorated(true); | 109 | mTreeList->setRootIsDecorated(true); |
110 | mTreeList->setSorting( -1 ); | 110 | mTreeList->setSorting( -1 ); |
111 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); | 111 | connect( mTreeList, SIGNAL(selectionChanged()), SLOT(slotShowPage()) ); |
112 | connect( mTreeList, SIGNAL(clicked(QListViewItem *)), SLOT(slotItemClicked(QListViewItem *))); | 112 | connect( mTreeList, SIGNAL(clicked(QListViewItem*)), SLOT(slotItemClicked(QListViewItem*))); |
113 | 113 | ||
114 | // | 114 | // |
115 | // Page area. Title at top with a separator below and a pagestack using | 115 | // Page area. Title at top with a separator below and a pagestack using |
116 | // all available space at bottom. | 116 | // all available space at bottom. |
117 | // | 117 | // |
118 | QFrame *p = new QFrame( splitter ); | 118 | QFrame *p = new QFrame( splitter ); |
119 | 119 | ||
120 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); | 120 | QHBoxLayout *hbox = new QHBoxLayout( p, 0, 0 ); |
121 | hbox->addSpacing( ODialog::spacingHint() ); | 121 | hbox->addSpacing( ODialog::spacingHint() ); |
122 | 122 | ||
123 | page = new QFrame( p ); | 123 | page = new QFrame( p ); |
124 | hbox->addWidget( page, 10 ); | 124 | hbox->addWidget( page, 10 ); |
125 | } | 125 | } |
126 | else | 126 | else |
127 | { | 127 | { |
128 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); | 128 | QHBoxLayout *hbox = new QHBoxLayout( topLayout ); |
129 | mIconList = new IconListBox( this ); | 129 | mIconList = new IconListBox( this ); |
130 | 130 | ||
131 | QFont listFont( mIconList->font() ); | 131 | QFont listFont( mIconList->font() ); |
132 | listFont.setBold( true ); | 132 | listFont.setBold( true ); |
133 | mIconList->setFont( listFont ); | 133 | mIconList->setFont( listFont ); |
134 | 134 | ||
135 | mIconList->verticalScrollBar()->installEventFilter( this ); | 135 | mIconList->verticalScrollBar()->installEventFilter( this ); |
136 | hbox->addWidget( mIconList ); | 136 | hbox->addWidget( mIconList ); |
137 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); | 137 | connect( mIconList, SIGNAL(selectionChanged()), SLOT(slotShowPage())); |
138 | hbox->addSpacing( ODialog::spacingHint() ); | 138 | hbox->addSpacing( ODialog::spacingHint() ); |
139 | page = new QFrame( this ); | 139 | page = new QFrame( this ); |
140 | hbox->addWidget( page, 10 ); | 140 | hbox->addWidget( page, 10 ); |
141 | } | 141 | } |
142 | 142 | ||
143 | // | 143 | // |
144 | // Rest of page area. Title at top with a separator below and a | 144 | // Rest of page area. Title at top with a separator below and a |
145 | // pagestack using all available space at bottom. | 145 | // pagestack using all available space at bottom. |
146 | // | 146 | // |
147 | 147 | ||
148 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); | 148 | QVBoxLayout *vbox = new QVBoxLayout( page, 0, ODialog::spacingHint() ); |
149 | 149 | ||
150 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); | 150 | mTitleLabel = new QLabel( QString::fromLatin1("Empty page"), page, "OJanusWidgetTitleLabel" ); |
151 | vbox->addWidget( mTitleLabel ); | 151 | vbox->addWidget( mTitleLabel ); |
152 | 152 | ||
153 | QFont titleFont( mTitleLabel->font() ); | 153 | QFont titleFont( mTitleLabel->font() ); |
154 | titleFont.setBold( true ); | 154 | titleFont.setBold( true ); |
155 | mTitleLabel->setFont( titleFont ); | 155 | mTitleLabel->setFont( titleFont ); |
156 | 156 | ||
157 | mTitleSep = new OSeparator( page ); | 157 | mTitleSep = new OSeparator( page ); |
158 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); | 158 | mTitleSep->setFrameStyle( QFrame::HLine|QFrame::Plain ); |
159 | vbox->addWidget( mTitleSep ); | 159 | vbox->addWidget( mTitleSep ); |
160 | 160 | ||
161 | mPageStack = new QWidgetStack( page ); | 161 | mPageStack = new QWidgetStack( page ); |
162 | connect(mPageStack, SIGNAL(aboutToShow(QWidget *)), | 162 | connect(mPageStack, SIGNAL(aboutToShow(QWidget*)), |
163 | this, SIGNAL(aboutToShowPage(QWidget *))); | 163 | this, SIGNAL(aboutToShowPage(QWidget*))); |
164 | vbox->addWidget( mPageStack, 10 ); | 164 | vbox->addWidget( mPageStack, 10 ); |
165 | } | 165 | } |
166 | else if( mFace == Tabbed ) | 166 | else if( mFace == Tabbed ) |
167 | { | 167 | { |
168 | mPageList = new QPtrList<QWidget>; | 168 | mPageList = new QPtrList<QWidget>; |
169 | 169 | ||
170 | mTabControl = new QTabWidget( this ); | 170 | mTabControl = new QTabWidget( this ); |
171 | mTabControl->setMargin (ODialog::marginHint()); | 171 | mTabControl->setMargin (ODialog::marginHint()); |
172 | topLayout->addWidget( mTabControl, 10 ); | 172 | topLayout->addWidget( mTabControl, 10 ); |
173 | } | 173 | } |
174 | else if( mFace == Swallow ) | 174 | else if( mFace == Swallow ) |
175 | { | 175 | { |
176 | mSwallowPage = new QWidget( this ); | 176 | mSwallowPage = new QWidget( this ); |
177 | topLayout->addWidget( mSwallowPage, 10 ); | 177 | topLayout->addWidget( mSwallowPage, 10 ); |
178 | } | 178 | } |
179 | else | 179 | else |
180 | { | 180 | { |
181 | mFace = Plain; | 181 | mFace = Plain; |
182 | mPlainPage = new QFrame( this ); | 182 | mPlainPage = new QFrame( this ); |
183 | topLayout->addWidget( mPlainPage, 10 ); | 183 | topLayout->addWidget( mPlainPage, 10 ); |
184 | } | 184 | } |
185 | 185 | ||
186 | /* FIXME: Revise for Opie | 186 | /* FIXME: Revise for Opie |
187 | if ( kapp ) | 187 | if ( kapp ) |
188 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); | 188 | connect(kapp,SIGNAL(kdisplayFontChanged()),SLOT(slotFontChanged())); |
189 | */ | 189 | */ |
190 | 190 | ||
191 | mValid = true; | 191 | mValid = true; |
192 | 192 | ||
193 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. | 193 | setSwallowedWidget(0); // Set default size if 'mFace' is Swallow. |
194 | } | 194 | } |
195 | 195 | ||
196 | 196 | ||
197 | OJanusWidget::~OJanusWidget() | 197 | OJanusWidget::~OJanusWidget() |
198 | { | 198 | { |
199 | delete mPageList; | 199 | delete mPageList; |
200 | mPageList = 0; | 200 | mPageList = 0; |
201 | delete mTitleList; | 201 | delete mTitleList; |
202 | mTitleList = 0; | 202 | mTitleList = 0; |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | bool OJanusWidget::isValid() const | 206 | bool OJanusWidget::isValid() const |
207 | { | 207 | { |
208 | return( mValid ); | 208 | return( mValid ); |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | QFrame *OJanusWidget::plainPage() | 212 | QFrame *OJanusWidget::plainPage() |
213 | { | 213 | { |
214 | return( mPlainPage ); | 214 | return( mPlainPage ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | int OJanusWidget::face() const | 218 | int OJanusWidget::face() const |
219 | { | 219 | { |
220 | return( mFace ); | 220 | return( mFace ); |
221 | } | 221 | } |
222 | 222 | ||
223 | QWidget *OJanusWidget::FindParent() | 223 | QWidget *OJanusWidget::FindParent() |
224 | { | 224 | { |
225 | if( mFace == Tabbed ) { | 225 | if( mFace == Tabbed ) { |
226 | return mTabControl; | 226 | return mTabControl; |
227 | } | 227 | } |
228 | else { | 228 | else { |
229 | return this; | 229 | return this; |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, | 233 | QFrame *OJanusWidget::addPage( const QStringList &items, const QString &header, |
234 | const QPixmap &pixmap ) | 234 | const QPixmap &pixmap ) |
235 | { | 235 | { |
236 | if( mValid == false ) | 236 | if( mValid == false ) |
237 | { | 237 | { |
238 | qDebug( "addPage: Invalid object" ); | 238 | qDebug( "addPage: Invalid object" ); |
239 | return( 0 ); | 239 | return( 0 ); |
240 | } | 240 | } |
241 | 241 | ||
242 | QFrame *page = new QFrame( FindParent(), "page" ); | 242 | QFrame *page = new QFrame( FindParent(), "page" ); |
243 | addPageWidget( page, items, header, pixmap ); | 243 | addPageWidget( page, items, header, pixmap ); |
244 | 244 | ||
245 | return page; | 245 | return page; |
246 | } | 246 | } |
247 | 247 | ||
248 | void OJanusWidget::pageGone( QObject *obj ) | 248 | void OJanusWidget::pageGone( QObject *obj ) |
249 | { | 249 | { |
250 | removePage( static_cast<QWidget*>( obj ) ); | 250 | removePage( static_cast<QWidget*>( obj ) ); |
251 | } | 251 | } |
252 | 252 | ||
253 | void OJanusWidget::slotReopen( QListViewItem * item ) | 253 | void OJanusWidget::slotReopen( QListViewItem * item ) |
254 | { | 254 | { |
255 | if( item ) | 255 | if( item ) |
256 | item->setOpen( true ); | 256 | item->setOpen( true ); |
257 | } | 257 | } |
258 | 258 | ||
259 | QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, | 259 | QFrame *OJanusWidget::addPage( const QString &itemName, const QString &header, |
260 | const QPixmap &pixmap ) | 260 | const QPixmap &pixmap ) |
261 | { | 261 | { |
262 | QStringList items; | 262 | QStringList items; |
263 | items << itemName; | 263 | items << itemName; |
264 | return addPage(items, header, pixmap); | 264 | return addPage(items, header, pixmap); |
265 | } | 265 | } |
266 | 266 | ||
267 | 267 | ||
268 | 268 | ||
269 | QVBox *OJanusWidget::addVBoxPage( const QStringList &items, | 269 | QVBox *OJanusWidget::addVBoxPage( const QStringList &items, |
270 | const QString &header, | 270 | const QString &header, |
271 | const QPixmap &pixmap ) | 271 | const QPixmap &pixmap ) |
272 | { | 272 | { |
273 | if( mValid == false ) | 273 | if( mValid == false ) |
274 | { | 274 | { |
275 | qDebug( "addPage: Invalid object" ); | 275 | qDebug( "addPage: Invalid object" ); |
276 | return( 0 ); | 276 | return( 0 ); |
277 | } | 277 | } |
278 | 278 | ||
279 | QVBox *page = new QVBox(FindParent() , "page" ); | 279 | QVBox *page = new QVBox(FindParent() , "page" ); |
280 | page->setSpacing( ODialog::spacingHint() ); | 280 | page->setSpacing( ODialog::spacingHint() ); |
281 | addPageWidget( page, items, header, pixmap ); | 281 | addPageWidget( page, items, header, pixmap ); |
282 | 282 | ||
283 | return page; | 283 | return page; |
284 | } | 284 | } |
285 | 285 | ||
286 | QVBox *OJanusWidget::addVBoxPage( const QString &itemName, | 286 | QVBox *OJanusWidget::addVBoxPage( const QString &itemName, |
287 | const QString &header, | 287 | const QString &header, |
288 | const QPixmap &pixmap ) | 288 | const QPixmap &pixmap ) |
289 | { | 289 | { |
290 | QStringList items; | 290 | QStringList items; |
291 | items << itemName; | 291 | items << itemName; |
292 | return addVBoxPage(items, header, pixmap); | 292 | return addVBoxPage(items, header, pixmap); |
293 | } | 293 | } |
294 | 294 | ||
295 | QHBox *OJanusWidget::addHBoxPage( const QStringList &items, | 295 | QHBox *OJanusWidget::addHBoxPage( const QStringList &items, |
296 | const QString &header, | 296 | const QString &header, |
297 | const QPixmap &pixmap ) | 297 | const QPixmap &pixmap ) |
298 | { | 298 | { |
299 | if( mValid == false ) { | 299 | if( mValid == false ) { |
300 | qDebug( "addPage: Invalid object" ); | 300 | qDebug( "addPage: Invalid object" ); |
301 | return( 0 ); | 301 | return( 0 ); |
302 | } | 302 | } |
303 | 303 | ||
304 | QHBox *page = new QHBox(FindParent(), "page"); | 304 | QHBox *page = new QHBox(FindParent(), "page"); |
305 | page->setSpacing( ODialog::spacingHint() ); | 305 | page->setSpacing( ODialog::spacingHint() ); |
306 | addPageWidget( page, items, header, pixmap ); | 306 | addPageWidget( page, items, header, pixmap ); |
307 | 307 | ||
308 | return page; | 308 | return page; |
309 | } | 309 | } |
310 | 310 | ||
311 | QHBox *OJanusWidget::addHBoxPage( const QString &itemName, | 311 | QHBox *OJanusWidget::addHBoxPage( const QString &itemName, |
312 | const QString &header, | 312 | const QString &header, |
313 | const QPixmap &pixmap ) | 313 | const QPixmap &pixmap ) |
314 | { | 314 | { |
315 | QStringList items; | 315 | QStringList items; |
316 | items << itemName; | 316 | items << itemName; |
317 | return addHBoxPage(items, header, pixmap); | 317 | return addHBoxPage(items, header, pixmap); |
318 | } | 318 | } |
319 | 319 | ||
320 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, | 320 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, |
321 | const QStringList &items, | 321 | const QStringList &items, |
322 | const QString &header, | 322 | const QString &header, |
323 | const QPixmap &pixmap ) | 323 | const QPixmap &pixmap ) |
324 | { | 324 | { |
325 | if( mValid == false ) | 325 | if( mValid == false ) |
326 | { | 326 | { |
327 | qDebug( "addPage: Invalid object" ); | 327 | qDebug( "addPage: Invalid object" ); |
328 | return( 0 ); | 328 | return( 0 ); |
329 | } | 329 | } |
330 | 330 | ||
331 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); | 331 | QGrid *page = new QGrid( n, dir, FindParent(), "page" ); |
332 | page->setSpacing( ODialog::spacingHint() ); | 332 | page->setSpacing( ODialog::spacingHint() ); |
333 | addPageWidget( page, items, header, pixmap ); | 333 | addPageWidget( page, items, header, pixmap ); |
334 | 334 | ||
335 | return page; | 335 | return page; |
336 | } | 336 | } |
337 | 337 | ||
338 | 338 | ||
339 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, | 339 | QGrid *OJanusWidget::addGridPage( int n, Orientation dir, |
340 | const QString &itemName, | 340 | const QString &itemName, |
341 | const QString &header, | 341 | const QString &header, |
342 | const QPixmap &pixmap ) | 342 | const QPixmap &pixmap ) |
343 | { | 343 | { |
344 | QStringList items; | 344 | QStringList items; |
345 | items << itemName; | 345 | items << itemName; |
346 | return addGridPage(n, dir, items, header, pixmap); | 346 | return addGridPage(n, dir, items, header, pixmap); |
347 | } | 347 | } |
348 | 348 | ||
349 | void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) | 349 | void OJanusWidget::InsertTreeListItem(const QStringList &items, const QPixmap &pixmap, QFrame *page) |
350 | { | 350 | { |
351 | bool isTop = true; | 351 | bool isTop = true; |
352 | QListViewItem *curTop = 0, *child, *last, *newChild; | 352 | QListViewItem *curTop = 0, *child, *last, *newChild; |
353 | unsigned int index = 1; | 353 | unsigned int index = 1; |
354 | QStringList curPath; | 354 | QStringList curPath; |
355 | 355 | ||
356 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) { | 356 | for ( QStringList::ConstIterator it = items.begin(); it != items.end(); ++it, index++ ) { |
357 | QString name = (*it); | 357 | QString name = (*it); |
358 | bool isPath = ( index != items.count() ); | 358 | bool isPath = ( index != items.count() ); |
359 | 359 | ||
360 | // Find the first child. | 360 | // Find the first child. |
361 | if (isTop) { | 361 | if (isTop) { |
362 | child = mTreeList->firstChild(); | 362 | child = mTreeList->firstChild(); |
363 | } | 363 | } |
364 | else { | 364 | else { |
365 | child = curTop->firstChild(); | 365 | child = curTop->firstChild(); |
366 | } | 366 | } |
367 | 367 | ||
368 | // Now search for a child with the current Name, and if it we doesn't | 368 | // Now search for a child with the current Name, and if it we doesn't |
369 | // find it, then remember the location of the last child. | 369 | // find it, then remember the location of the last child. |
370 | for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling()); | 370 | for (last = 0; child && child->text(0) != name ; last = child, child = child->nextSibling()); |
371 | 371 | ||
372 | if (last == 0 && child == 0) { | 372 | if (last == 0 && child == 0) { |
373 | // This node didn't have any children at all, lets just insert the | 373 | // This node didn't have any children at all, lets just insert the |
374 | // new child. | 374 | // new child. |
375 | if (isTop) | 375 | if (isTop) |
376 | newChild = new QListViewItem(mTreeList, name); | 376 | newChild = new QListViewItem(mTreeList, name); |
377 | else | 377 | else |
378 | newChild = new QListViewItem(curTop, name); | 378 | newChild = new QListViewItem(curTop, name); |
379 | 379 | ||
380 | } | 380 | } |
381 | else if (child != 0) { | 381 | else if (child != 0) { |
382 | // we found the given name in this child. | 382 | // we found the given name in this child. |
383 | if (!isPath) { | 383 | if (!isPath) { |
384 | qDebug( "The element inserted was already in the TreeList box!" ); | 384 | qDebug( "The element inserted was already in the TreeList box!" ); |
385 | return; | 385 | return; |
386 | } | 386 | } |
387 | else { | 387 | else { |
388 | // Ok we found the folder | 388 | // Ok we found the folder |
389 | newChild = child; | 389 | newChild = child; |
390 | } | 390 | } |
391 | } | 391 | } |
392 | else { | 392 | else { |
393 | // the node had some children, but we didn't find the given name | 393 | // the node had some children, but we didn't find the given name |
394 | if (isTop) | 394 | if (isTop) |
395 | newChild = new QListViewItem(mTreeList, last, name); | 395 | newChild = new QListViewItem(mTreeList, last, name); |
396 | else | 396 | else |
397 | newChild = new QListViewItem(curTop, last, name); | 397 | newChild = new QListViewItem(curTop, last, name); |
398 | } | 398 | } |
399 | 399 | ||
400 | // Now make the element expandable if it is a path component, and make | 400 | // Now make the element expandable if it is a path component, and make |
401 | // ready for next loop | 401 | // ready for next loop |
402 | if (isPath) { | 402 | if (isPath) { |
403 | newChild->setExpandable(true); | 403 | newChild->setExpandable(true); |
404 | curTop = newChild; | 404 | curTop = newChild; |
405 | isTop = false; | 405 | isTop = false; |
406 | curPath << name; | 406 | curPath << name; |
407 | 407 | ||
408 | QString key = curPath.join("_/_"); | 408 | QString key = curPath.join("_/_"); |
409 | if (mFolderIconMap.contains(key)) { | 409 | if (mFolderIconMap.contains(key)) { |
410 | QPixmap p = mFolderIconMap[key]; | 410 | QPixmap p = mFolderIconMap[key]; |
411 | newChild->setPixmap(0,p); | 411 | newChild->setPixmap(0,p); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | else { | 414 | else { |
415 | if (mShowIconsInTreeList) { | 415 | if (mShowIconsInTreeList) { |
416 | newChild->setPixmap(0, pixmap); | 416 | newChild->setPixmap(0, pixmap); |
417 | } | 417 | } |
418 | mTreeListToPageStack.insert(newChild, page); | 418 | mTreeListToPageStack.insert(newChild, page); |
419 | } | 419 | } |
420 | } | 420 | } |
421 | } | 421 | } |
422 | 422 | ||
423 | void OJanusWidget::addPageWidget( QFrame *page, const QStringList &items, | 423 | void OJanusWidget::addPageWidget( QFrame *page, const QStringList &items, |
424 | const QString &header,const QPixmap &pixmap ) | 424 | const QString &header,const QPixmap &pixmap ) |
425 | { | 425 | { |
426 | connect(page, SIGNAL(destroyed(QObject*)), SLOT(pageGone(QObject*))); | 426 | connect(page, SIGNAL(destroyed(QObject*)), SLOT(pageGone(QObject*))); |
427 | 427 | ||
428 | if( mFace == Tabbed ) | 428 | if( mFace == Tabbed ) |
429 | { | 429 | { |
430 | mTabControl->addTab (page, items.last()); | 430 | mTabControl->addTab (page, items.last()); |
431 | mPageList->append (page); | 431 | mPageList->append (page); |
432 | } | 432 | } |
433 | else if( mFace == TreeList || mFace == IconList ) | 433 | else if( mFace == TreeList || mFace == IconList ) |
434 | { | 434 | { |
435 | mPageList->append( page ); | 435 | mPageList->append( page ); |
436 | mPageStack->addWidget( page, 0 ); | 436 | mPageStack->addWidget( page, 0 ); |
437 | 437 | ||
438 | if (items.count() == 0) { | 438 | if (items.count() == 0) { |
439 | qDebug( "Invalid QStringList, with zero items" ); | 439 | qDebug( "Invalid QStringList, with zero items" ); |
440 | return; | 440 | return; |
441 | } | 441 | } |
442 | 442 | ||
443 | if( mFace == TreeList ) | 443 | if( mFace == TreeList ) |
444 | { | 444 | { |
445 | InsertTreeListItem(items, pixmap, page); | 445 | InsertTreeListItem(items, pixmap, page); |
446 | } | 446 | } |
447 | else // mFace == IconList | 447 | else // mFace == IconList |
448 | { | 448 | { |
449 | QString itemName = items.last(); | 449 | QString itemName = items.last(); |
450 | IconListItem *item = new IconListItem( mIconList, pixmap, itemName ); | 450 | IconListItem *item = new IconListItem( mIconList, pixmap, itemName ); |
451 | // | 451 | // |
452 | // 2000-06-01 Espen Sand: If I do this with Qt 2.1.1 all sorts of | 452 | // 2000-06-01 Espen Sand: If I do this with Qt 2.1.1 all sorts of |
453 | // strange things happen. With Qt <= 2.1 it worked but now I must | 453 | // strange things happen. With Qt <= 2.1 it worked but now I must |
454 | // either specify the listbox in the constructor on the item | 454 | // either specify the listbox in the constructor on the item |
455 | // or as below, not both. | 455 | // or as below, not both. |
456 | // mIconList->insertItem( item ); | 456 | // mIconList->insertItem( item ); |
457 | // | 457 | // |
458 | mIconListToPageStack.insert(item, page); | 458 | mIconListToPageStack.insert(item, page); |
459 | mIconList->invalidateHeight(); | 459 | mIconList->invalidateHeight(); |
460 | mIconList->invalidateWidth(); | 460 | mIconList->invalidateWidth(); |
461 | 461 | ||
462 | if (mIconList->isVisible()) | 462 | if (mIconList->isVisible()) |
463 | mIconList->updateWidth(); | 463 | mIconList->updateWidth(); |
464 | } | 464 | } |
465 | 465 | ||
466 | // | 466 | // |
467 | // Make sure the title label is sufficiently wide | 467 | // Make sure the title label is sufficiently wide |
468 | // | 468 | // |
469 | QString lastName = items.last(); | 469 | QString lastName = items.last(); |
470 | const QString &title = (header != QString::null ? header : lastName); | 470 | const QString &title = (header != QString::null ? header : lastName); |
471 | QRect r = mTitleLabel->fontMetrics().boundingRect( title ); | 471 | QRect r = mTitleLabel->fontMetrics().boundingRect( title ); |
472 | if( mTitleLabel->minimumWidth() < r.width() ) | 472 | if( mTitleLabel->minimumWidth() < r.width() ) |
473 | { | 473 | { |
474 | mTitleLabel->setMinimumWidth( r.width() ); | 474 | mTitleLabel->setMinimumWidth( r.width() ); |
475 | } | 475 | } |
476 | mTitleList->append( title ); | 476 | mTitleList->append( title ); |
477 | 477 | ||
478 | if( mTitleList->count() == 1 ) | 478 | if( mTitleList->count() == 1 ) |
479 | { | 479 | { |
480 | showPage(0); | 480 | showPage(0); |
481 | } | 481 | } |
482 | } | 482 | } |
483 | else | 483 | else |
484 | { | 484 | { |
485 | qDebug( "OJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" ); | 485 | qDebug( "OJanusWidget::addPageWidget: can only add a page in Tabbed, TreeList or IconList modes" ); |
486 | } | 486 | } |
487 | 487 | ||
488 | } | 488 | } |
489 | 489 | ||
490 | void OJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap) | 490 | void OJanusWidget::setFolderIcon(const QStringList &path, const QPixmap &pixmap) |
491 | { | 491 | { |
492 | QString key = path.join("_/_"); | 492 | QString key = path.join("_/_"); |
493 | mFolderIconMap.insert(key,pixmap); | 493 | mFolderIconMap.insert(key,pixmap); |
494 | } | 494 | } |
495 | 495 | ||
496 | 496 | ||
497 | 497 | ||
498 | bool OJanusWidget::setSwallowedWidget( QWidget *widget ) | 498 | bool OJanusWidget::setSwallowedWidget( QWidget *widget ) |
499 | { | 499 | { |
500 | if( mFace != Swallow || mValid == false ) | 500 | if( mFace != Swallow || mValid == false ) |
501 | { | 501 | { |
502 | return( false ); | 502 | return( false ); |
503 | } | 503 | } |
504 | 504 | ||
505 | // | 505 | // |
506 | // Remove current layout and make a new. | 506 | // Remove current layout and make a new. |
507 | // | 507 | // |
508 | if( mSwallowPage->layout() != 0 ) | 508 | if( mSwallowPage->layout() != 0 ) |
509 | { | 509 | { |
510 | delete mSwallowPage->layout(); | 510 | delete mSwallowPage->layout(); |
511 | } | 511 | } |
512 | QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 ); | 512 | QGridLayout *gbox = new QGridLayout( mSwallowPage, 1, 1, 0 ); |
513 | 513 | ||
514 | // | 514 | // |
515 | // Hide old children | 515 | // Hide old children |
516 | // | 516 | // |
517 | QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please | 517 | QObjectList *l = (QObjectList*)mSwallowPage->children(); // silence please |
518 | for( uint i=0; i < l->count(); i++ ) | 518 | for( uint i=0; i < l->count(); i++ ) |
519 | { | 519 | { |
520 | QObject *o = l->at(i); | 520 | QObject *o = l->at(i); |
521 | if( o->isWidgetType() ) | 521 | if( o->isWidgetType() ) |
522 | { | 522 | { |
523 | ((QWidget*)o)->hide(); | 523 | ((QWidget*)o)->hide(); |
524 | } | 524 | } |
525 | } | 525 | } |
526 | 526 | ||
527 | // | 527 | // |
528 | // Add new child or make default size | 528 | // Add new child or make default size |
529 | // | 529 | // |
530 | if( widget == 0 ) | 530 | if( widget == 0 ) |
531 | { | 531 | { |
532 | gbox->addRowSpacing(0,100); | 532 | gbox->addRowSpacing(0,100); |
533 | gbox->addColSpacing(0,100); | 533 | gbox->addColSpacing(0,100); |
534 | mSwallowPage->setMinimumSize(100,100); | 534 | mSwallowPage->setMinimumSize(100,100); |
535 | } | 535 | } |
536 | else | 536 | else |
537 | { | 537 | { |
538 | if( widget->parent() != mSwallowPage ) | 538 | if( widget->parent() != mSwallowPage ) |
539 | { | 539 | { |
540 | widget->reparent( mSwallowPage, 0, QPoint(0,0) ); | 540 | widget->reparent( mSwallowPage, 0, QPoint(0,0) ); |
541 | } | 541 | } |
542 | gbox->addWidget(widget, 0, 0 ); | 542 | gbox->addWidget(widget, 0, 0 ); |
543 | gbox->activate(); | 543 | gbox->activate(); |
544 | mSwallowPage->setMinimumSize( widget->minimumSize() ); | 544 | mSwallowPage->setMinimumSize( widget->minimumSize() ); |
545 | } | 545 | } |
546 | 546 | ||
547 | return( true ); | 547 | return( true ); |
548 | } | 548 | } |
549 | 549 | ||
550 | bool OJanusWidget::slotShowPage() | 550 | bool OJanusWidget::slotShowPage() |
551 | { | 551 | { |
552 | if( mValid == false ) | 552 | if( mValid == false ) |
553 | { | 553 | { |
554 | return( false ); | 554 | return( false ); |
555 | } | 555 | } |
556 | 556 | ||
557 | if( mFace == TreeList ) | 557 | if( mFace == TreeList ) |
558 | { | 558 | { |
559 | QListViewItem *node = mTreeList->selectedItem(); | 559 | QListViewItem *node = mTreeList->selectedItem(); |
560 | if( node == 0 ) { return( false ); } | 560 | if( node == 0 ) { return( false ); } |
561 | 561 | ||
562 | QWidget *stackItem = mTreeListToPageStack[node]; | 562 | QWidget *stackItem = mTreeListToPageStack[node]; |
563 | return showPage(stackItem); | 563 | return showPage(stackItem); |
564 | } | 564 | } |
565 | else if( mFace == IconList ) | 565 | else if( mFace == IconList ) |
566 | { | 566 | { |
567 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); | 567 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); |
568 | if( node == 0 ) { return( false ); } | 568 | if( node == 0 ) { return( false ); } |
569 | QWidget *stackItem = mIconListToPageStack[node]; | 569 | QWidget *stackItem = mIconListToPageStack[node]; |
570 | return showPage(stackItem); | 570 | return showPage(stackItem); |
571 | } | 571 | } |
572 | 572 | ||
573 | return( false ); | 573 | return( false ); |
574 | } | 574 | } |
575 | 575 | ||
576 | 576 | ||
577 | bool OJanusWidget::showPage( int index ) | 577 | bool OJanusWidget::showPage( int index ) |
578 | { | 578 | { |
579 | if( mPageList == 0 || mValid == false ) | 579 | if( mPageList == 0 || mValid == false ) |
580 | { | 580 | { |
581 | return( false ); | 581 | return( false ); |
582 | } | 582 | } |
583 | else | 583 | else |
584 | { | 584 | { |
585 | return showPage(mPageList->at(index)); | 585 | return showPage(mPageList->at(index)); |
586 | } | 586 | } |
587 | } | 587 | } |
588 | 588 | ||
589 | 589 | ||
590 | bool OJanusWidget::showPage( QWidget *w ) | 590 | bool OJanusWidget::showPage( QWidget *w ) |
591 | { | 591 | { |
592 | if( w == 0 || mValid == false ) | 592 | if( w == 0 || mValid == false ) |
593 | { | 593 | { |
594 | return( false ); | 594 | return( false ); |
595 | } | 595 | } |
596 | 596 | ||
597 | if( mFace == TreeList || mFace == IconList ) | 597 | if( mFace == TreeList || mFace == IconList ) |
598 | { | 598 | { |
599 | mPageStack->raiseWidget( w ); | 599 | mPageStack->raiseWidget( w ); |
600 | mActivePageWidget = w; | 600 | mActivePageWidget = w; |
601 | 601 | ||
602 | int index = mPageList->findRef( w ); | 602 | int index = mPageList->findRef( w ); |
603 | mTitleLabel->setText( *mTitleList->at(index) ); | 603 | mTitleLabel->setText( *mTitleList->at(index) ); |
604 | if( mFace == TreeList ) | 604 | if( mFace == TreeList ) |
605 | { | 605 | { |
606 | QMap<QListViewItem *, QWidget *>::Iterator it; | 606 | QMap<QListViewItem *, QWidget *>::Iterator it; |
607 | for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){ | 607 | for (it = mTreeListToPageStack.begin(); it != mTreeListToPageStack.end(); ++it){ |
608 | QListViewItem *key = it.key(); | 608 | QListViewItem *key = it.key(); |
609 | QWidget *val = it.data(); | 609 | QWidget *val = it.data(); |
610 | if (val == w) { | 610 | if (val == w) { |
611 | mTreeList->setSelected(key, true ); | 611 | mTreeList->setSelected(key, true ); |
612 | break; | 612 | break; |
613 | } | 613 | } |
614 | } | 614 | } |
615 | } | 615 | } |
616 | else | 616 | else |
617 | { | 617 | { |
618 | QMap<QListBoxItem *, QWidget *>::Iterator it; | 618 | QMap<QListBoxItem *, QWidget *>::Iterator it; |
619 | for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){ | 619 | for (it = mIconListToPageStack.begin(); it != mIconListToPageStack.end(); ++it){ |
620 | QListBoxItem *key = it.key(); | 620 | QListBoxItem *key = it.key(); |
621 | QWidget *val = it.data(); | 621 | QWidget *val = it.data(); |
622 | if (val == w) { | 622 | if (val == w) { |
623 | mIconList->setSelected( key, true ); | 623 | mIconList->setSelected( key, true ); |
624 | break; | 624 | break; |
625 | } | 625 | } |
626 | } | 626 | } |
627 | 627 | ||
628 | // | 628 | // |
629 | // 2000-02-13 Espen Sand | 629 | // 2000-02-13 Espen Sand |
630 | // Don't ask me why (because I don't know). If I select a page | 630 | // Don't ask me why (because I don't know). If I select a page |
631 | // with the mouse the page is not updated until it receives an | 631 | // with the mouse the page is not updated until it receives an |
632 | // event. It seems this event get lost if the mouse is not moved | 632 | // event. It seems this event get lost if the mouse is not moved |
633 | // when released. The timer ensures the update | 633 | // when released. The timer ensures the update |
634 | // | 634 | // |
635 | QTimer::singleShot( 0, mActivePageWidget, SLOT(update()) ); | 635 | QTimer::singleShot( 0, mActivePageWidget, SLOT(update()) ); |
636 | } | 636 | } |
637 | } | 637 | } |
638 | else if( mFace == Tabbed ) | 638 | else if( mFace == Tabbed ) |
639 | { | 639 | { |
640 | mTabControl->showPage(w); | 640 | mTabControl->showPage(w); |
641 | mActivePageWidget = w; | 641 | mActivePageWidget = w; |
642 | } | 642 | } |
643 | else | 643 | else |
644 | { | 644 | { |
645 | return( false ); | 645 | return( false ); |
646 | } | 646 | } |
647 | 647 | ||
648 | return( true ); | 648 | return( true ); |
649 | } | 649 | } |
650 | 650 | ||
651 | 651 | ||
652 | int OJanusWidget::activePageIndex() const | 652 | int OJanusWidget::activePageIndex() const |
653 | { | 653 | { |
654 | if( mFace == TreeList) { | 654 | if( mFace == TreeList) { |
655 | QListViewItem *node = mTreeList->selectedItem(); | 655 | QListViewItem *node = mTreeList->selectedItem(); |
656 | if( node == 0 ) { return -1; } | 656 | if( node == 0 ) { return -1; } |
657 | QWidget *stackItem = mTreeListToPageStack[node]; | 657 | QWidget *stackItem = mTreeListToPageStack[node]; |
658 | return mPageList->findRef(stackItem); | 658 | return mPageList->findRef(stackItem); |
659 | } | 659 | } |
660 | else if (mFace == IconList) { | 660 | else if (mFace == IconList) { |
661 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); | 661 | QListBoxItem *node = mIconList->item( mIconList->currentItem() ); |
662 | if( node == 0 ) { return( false ); } | 662 | if( node == 0 ) { return( false ); } |
663 | QWidget *stackItem = mIconListToPageStack[node]; | 663 | QWidget *stackItem = mIconListToPageStack[node]; |
664 | return mPageList->findRef(stackItem); | 664 | return mPageList->findRef(stackItem); |
665 | } | 665 | } |
666 | else if( mFace == Tabbed ) { | 666 | else if( mFace == Tabbed ) { |
667 | QWidget *widget = mTabControl->currentPage(); | 667 | QWidget *widget = mTabControl->currentPage(); |
668 | return( widget == 0 ? -1 : mPageList->findRef( widget ) ); | 668 | return( widget == 0 ? -1 : mPageList->findRef( widget ) ); |
669 | } | 669 | } |
670 | else { | 670 | else { |
671 | return( -1 ); | 671 | return( -1 ); |
672 | } | 672 | } |
673 | } | 673 | } |
674 | 674 | ||
675 | 675 | ||
676 | int OJanusWidget::pageIndex( QWidget *widget ) const | 676 | int OJanusWidget::pageIndex( QWidget *widget ) const |
677 | { | 677 | { |
678 | if( widget == 0 ) | 678 | if( widget == 0 ) |
679 | { | 679 | { |
680 | return( -1 ); | 680 | return( -1 ); |
681 | } | 681 | } |
682 | else if( mFace == TreeList || mFace == IconList ) | 682 | else if( mFace == TreeList || mFace == IconList ) |
683 | { | 683 | { |
684 | return( mPageList->findRef( widget ) ); | 684 | return( mPageList->findRef( widget ) ); |
685 | } | 685 | } |
686 | else if( mFace == Tabbed ) | 686 | else if( mFace == Tabbed ) |
687 | { | 687 | { |
688 | // | 688 | // |
689 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() | 689 | // The user gets the real page widget with addVBoxPage(), addHBoxPage() |
690 | // and addGridPage() but not with addPage() which returns a child of | 690 | // and addGridPage() but not with addPage() which returns a child of |
691 | // the toplevel page. addPage() returns a QFrame so I check for that. | 691 | // the toplevel page. addPage() returns a QFrame so I check for that. |
692 | // | 692 | // |
693 | if( widget->isA("QFrame") ) | 693 | if( widget->isA("QFrame") ) |
694 | { | 694 | { |
695 | return( mPageList->findRef( widget->parentWidget() ) ); | 695 | return( mPageList->findRef( widget->parentWidget() ) ); |
696 | } | 696 | } |
697 | else | 697 | else |
698 | { | 698 | { |
699 | return( mPageList->findRef( widget ) ); | 699 | return( mPageList->findRef( widget ) ); |
700 | } | 700 | } |
701 | } | 701 | } |
702 | else | 702 | else |
703 | { | 703 | { |
704 | return( -1 ); | 704 | return( -1 ); |
705 | } | 705 | } |
706 | } | 706 | } |
707 | 707 | ||
708 | void OJanusWidget::slotFontChanged() | 708 | void OJanusWidget::slotFontChanged() |
709 | { | 709 | { |
710 | #ifdef FIXME | 710 | #ifdef FIXME |
711 | 711 | ||
712 | if ( mTitleLabel != 0 ) | 712 | if ( mTitleLabel != 0 ) |
713 | { | 713 | { |
714 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); | 714 | mTitleLabel->setFont( KGlobalSettings::generalFont() ); |
715 | QFont titleFont( mTitleLabel->font() ); | 715 | QFont titleFont( mTitleLabel->font() ); |
716 | titleFont.setBold( true ); | 716 | titleFont.setBold( true ); |
717 | mTitleLabel->setFont( titleFont ); | 717 | mTitleLabel->setFont( titleFont ); |
718 | } | 718 | } |
719 | #endif | 719 | #endif |
720 | 720 | ||
721 | if( mFace == IconList ) | 721 | if( mFace == IconList ) |
722 | { | 722 | { |
723 | QFont listFont( mIconList->font() ); | 723 | QFont listFont( mIconList->font() ); |
724 | listFont.setBold( true ); | 724 | listFont.setBold( true ); |
725 | mIconList->setFont( listFont ); | 725 | mIconList->setFont( listFont ); |
726 | mIconList->invalidateHeight(); | 726 | mIconList->invalidateHeight(); |
727 | mIconList->invalidateWidth(); | 727 | mIconList->invalidateWidth(); |
728 | } | 728 | } |
729 | } | 729 | } |
730 | 730 | ||
731 | // makes the treelist behave like the list of kcontrol | 731 | // makes the treelist behave like the list of kcontrol |
732 | void OJanusWidget::slotItemClicked(QListViewItem *it) | 732 | void OJanusWidget::slotItemClicked(QListViewItem *it) |
733 | { | 733 | { |
734 | if(it && (it->childCount()>0)) | 734 | if(it && (it->childCount()>0)) |
735 | it->setOpen(!it->isOpen()); | 735 | it->setOpen(!it->isOpen()); |
736 | } | 736 | } |
737 | 737 | ||
738 | void OJanusWidget::setFocus() | 738 | void OJanusWidget::setFocus() |
739 | { | 739 | { |
740 | if( mValid == false ) { return; } | 740 | if( mValid == false ) { return; } |
741 | if( mFace == TreeList ) | 741 | if( mFace == TreeList ) |
742 | { | 742 | { |
743 | mTreeList->setFocus(); | 743 | mTreeList->setFocus(); |
744 | } | 744 | } |
745 | if( mFace == IconList ) | 745 | if( mFace == IconList ) |
746 | { | 746 | { |
747 | mIconList->setFocus(); | 747 | mIconList->setFocus(); |
748 | } | 748 | } |
749 | else if( mFace == Tabbed ) | 749 | else if( mFace == Tabbed ) |
750 | { | 750 | { |
751 | mTabControl->setFocus(); | 751 | mTabControl->setFocus(); |
752 | } | 752 | } |
753 | else if( mFace == Swallow ) | 753 | else if( mFace == Swallow ) |
754 | { | 754 | { |
755 | mSwallowPage->setFocus(); | 755 | mSwallowPage->setFocus(); |
756 | } | 756 | } |
757 | else if( mFace == Plain ) | 757 | else if( mFace == Plain ) |
758 | { | 758 | { |
759 | mPlainPage->setFocus(); | 759 | mPlainPage->setFocus(); |
760 | } | 760 | } |
761 | } | 761 | } |
762 | 762 | ||
763 | 763 | ||
764 | QSize OJanusWidget::minimumSizeHint() const | 764 | QSize OJanusWidget::minimumSizeHint() const |
765 | { | 765 | { |
766 | if( mFace == TreeList || mFace == IconList ) | 766 | if( mFace == TreeList || mFace == IconList ) |
767 | { | 767 | { |
768 | QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); | 768 | QSize s1( ODialog::spacingHint(), ODialog::spacingHint()*2 ); |
769 | QSize s2(0,0); | 769 | QSize s2(0,0); |
770 | QSize s3(0,0); | 770 | QSize s3(0,0); |
771 | QSize s4( mPageStack->sizeHint() ); | 771 | QSize s4( mPageStack->sizeHint() ); |
772 | 772 | ||
773 | if( mFace == TreeList ) | 773 | if( mFace == TreeList ) |
774 | { | 774 | { |
775 | #if QT_VERSION < 300 | 775 | #if QT_VERSION < 300 |
776 | s1.rwidth() += style().splitterWidth(); | 776 | s1.rwidth() += style().splitterWidth(); |
777 | #else | 777 | #else |
778 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); | 778 | s1.rwidth() += style().pixelMetric( QStyle::PM_SplitterWidth ); |
779 | #endif | 779 | #endif |
780 | s2 = mTreeList->minimumSize(); | 780 | s2 = mTreeList->minimumSize(); |
781 | } | 781 | } |
782 | else | 782 | else |
783 | { | 783 | { |
784 | mIconList->updateMinimumHeight(); | 784 | mIconList->updateMinimumHeight(); |
785 | mIconList->updateWidth(); | 785 | mIconList->updateWidth(); |
786 | s2 = mIconList->minimumSize(); | 786 | s2 = mIconList->minimumSize(); |
787 | } | 787 | } |
788 | 788 | ||
789 | if( mTitleLabel->isVisible() == true ) | 789 | if( mTitleLabel->isVisible() == true ) |
790 | { | 790 | { |
791 | s3 += mTitleLabel->sizeHint(); | 791 | s3 += mTitleLabel->sizeHint(); |
792 | s3.rheight() += mTitleSep->minimumSize().height(); | 792 | s3.rheight() += mTitleSep->minimumSize().height(); |
793 | } | 793 | } |
794 | 794 | ||
795 | // | 795 | // |
796 | // Select the tallest item. It has only effect in IconList mode | 796 | // Select the tallest item. It has only effect in IconList mode |
797 | // | 797 | // |
798 | int h1 = s1.rheight() + s3.rheight() + s4.height(); | 798 | int h1 = s1.rheight() + s3.rheight() + s4.height(); |
799 | int h2 = QMAX( h1, s2.rheight() ); | 799 | int h2 = QMAX( h1, s2.rheight() ); |
800 | 800 | ||
801 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); | 801 | return( QSize( s1.width()+s2.width()+QMAX(s3.width(),s4.width()), h2 ) ); |
802 | } | 802 | } |
803 | else if( mFace == Tabbed ) | 803 | else if( mFace == Tabbed ) |
804 | { | 804 | { |
805 | return( mTabControl->sizeHint() ); | 805 | return( mTabControl->sizeHint() ); |
806 | } | 806 | } |
807 | else if( mFace == Swallow ) | 807 | else if( mFace == Swallow ) |
808 | { | 808 | { |
809 | return( mSwallowPage->minimumSize() ); | 809 | return( mSwallowPage->minimumSize() ); |
810 | } | 810 | } |
811 | else if( mFace == Plain ) | 811 | else if( mFace == Plain ) |
812 | { | 812 | { |
813 | return( mPlainPage->sizeHint() ); | 813 | return( mPlainPage->sizeHint() ); |
814 | } | 814 | } |
815 | else | 815 | else |
816 | { | 816 | { |
817 | return( QSize( 100, 100 ) ); // Should never happen though. | 817 | return( QSize( 100, 100 ) ); // Should never happen though. |
818 | } | 818 | } |
819 | 819 | ||
820 | } | 820 | } |
821 | 821 | ||
822 | 822 | ||
823 | QSize OJanusWidget::sizeHint() const | 823 | QSize OJanusWidget::sizeHint() const |
824 | { | 824 | { |
825 | return( minimumSizeHint() ); | 825 | return( minimumSizeHint() ); |
826 | } | 826 | } |
827 | 827 | ||
828 | 828 | ||
829 | void OJanusWidget::setTreeListAutoResize( bool state ) | 829 | void OJanusWidget::setTreeListAutoResize( bool state ) |
830 | { | 830 | { |
831 | if( mFace == TreeList ) | 831 | if( mFace == TreeList ) |
832 | { | 832 | { |
833 | mTreeListResizeMode = state == false ? | 833 | mTreeListResizeMode = state == false ? |
834 | QSplitter::KeepSize : QSplitter::Stretch; | 834 | QSplitter::KeepSize : QSplitter::Stretch; |
835 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 835 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
836 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 836 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
837 | } | 837 | } |
838 | } | 838 | } |
839 | 839 | ||
840 | 840 | ||
841 | void OJanusWidget::setIconListAllVisible( bool state ) | 841 | void OJanusWidget::setIconListAllVisible( bool state ) |
842 | { | 842 | { |
843 | if( mFace == IconList ) | 843 | if( mFace == IconList ) |
844 | { | 844 | { |
845 | mIconList->setShowAll( state ); | 845 | mIconList->setShowAll( state ); |
846 | } | 846 | } |
847 | } | 847 | } |
848 | 848 | ||
849 | void OJanusWidget::setShowIconsInTreeList( bool state ) | 849 | void OJanusWidget::setShowIconsInTreeList( bool state ) |
850 | { | 850 | { |
851 | mShowIconsInTreeList = state; | 851 | mShowIconsInTreeList = state; |
852 | } | 852 | } |
853 | 853 | ||
854 | void OJanusWidget::setRootIsDecorated( bool state ) | 854 | void OJanusWidget::setRootIsDecorated( bool state ) |
855 | { | 855 | { |
856 | if( mFace == TreeList ) { | 856 | if( mFace == TreeList ) { |
857 | mTreeList->setRootIsDecorated(state); | 857 | mTreeList->setRootIsDecorated(state); |
858 | } | 858 | } |
859 | } | 859 | } |
860 | 860 | ||
861 | void OJanusWidget::unfoldTreeList( bool persist ) | 861 | void OJanusWidget::unfoldTreeList( bool persist ) |
862 | { | 862 | { |
863 | if( mFace == TreeList ) | 863 | if( mFace == TreeList ) |
864 | { | 864 | { |
865 | if( persist ) | 865 | if( persist ) |
866 | connect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 866 | connect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); |
867 | else | 867 | else |
868 | disconnect( mTreeList, SIGNAL( collapsed( QListViewItem * ) ), this, SLOT( slotReopen( QListViewItem * ) ) ); | 868 | disconnect( mTreeList, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( slotReopen(QListViewItem*) ) ); |
869 | 869 | ||
870 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) | 870 | for( QListViewItem * item = mTreeList->firstChild(); item; item = item->itemBelow() ) |
871 | item->setOpen( true ); | 871 | item->setOpen( true ); |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | void OJanusWidget::showEvent( QShowEvent * ) | 875 | void OJanusWidget::showEvent( QShowEvent * ) |
876 | { | 876 | { |
877 | if( mFace == TreeList ) | 877 | if( mFace == TreeList ) |
878 | { | 878 | { |
879 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); | 879 | QSplitter *splitter = (QSplitter*)(mTreeList->parentWidget()); |
880 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); | 880 | splitter->setResizeMode( mTreeList, mTreeListResizeMode ); |
881 | } | 881 | } |
882 | } | 882 | } |
883 | 883 | ||
884 | 884 | ||
885 | // | 885 | // |
886 | // 2000-13-02 Espen Sand | 886 | // 2000-13-02 Espen Sand |
887 | // It should be obvious that this eventfilter must only be | 887 | // It should be obvious that this eventfilter must only be |
888 | // be installed on the vertical scrollbar of the mIconList. | 888 | // be installed on the vertical scrollbar of the mIconList. |
889 | // | 889 | // |
890 | bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) | 890 | bool OJanusWidget::eventFilter( QObject *o, QEvent *e ) |
891 | { | 891 | { |
892 | if( e->type() == QEvent::Show ) | 892 | if( e->type() == QEvent::Show ) |
893 | { | 893 | { |
894 | IconListItem *item = (IconListItem*)mIconList->item(0); | 894 | IconListItem *item = (IconListItem*)mIconList->item(0); |
895 | if( item != 0 ) | 895 | if( item != 0 ) |
896 | { | 896 | { |
897 | int lw = item->width( mIconList ); | 897 | int lw = item->width( mIconList ); |
898 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); | 898 | int sw = mIconList->verticalScrollBar()->sizeHint().width(); |
899 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); | 899 | mIconList->setFixedWidth( lw+sw+mIconList->frameWidth()*2 ); |
900 | } | 900 | } |
901 | } | 901 | } |
902 | else if( e->type() == QEvent::Hide ) | 902 | else if( e->type() == QEvent::Hide ) |
903 | { | 903 | { |
904 | IconListItem *item = (IconListItem*)mIconList->item(0); | 904 | IconListItem *item = (IconListItem*)mIconList->item(0); |
905 | if( item != 0 ) | 905 | if( item != 0 ) |
906 | { | 906 | { |
907 | int lw = item->width( mIconList ); | 907 | int lw = item->width( mIconList ); |
908 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); | 908 | mIconList->setFixedWidth( lw+mIconList->frameWidth()*2 ); |
909 | } | 909 | } |
910 | } | 910 | } |
911 | return QWidget::eventFilter( o, e ); | 911 | return QWidget::eventFilter( o, e ); |
912 | } | 912 | } |
913 | 913 | ||
914 | 914 | ||
915 | 915 | ||
916 | // | 916 | // |
917 | // Code for the icon list box | 917 | // Code for the icon list box |
918 | // | 918 | // |
919 | 919 | ||
920 | 920 | ||
921 | OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, | 921 | OJanusWidget::IconListBox::IconListBox( QWidget *parent, const char *name, |
922 | WFlags f ) | 922 | WFlags f ) |
923 | :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), | 923 | :QListBox( parent, name, f ), mShowAll(false), mHeightValid(false), |
924 | mWidthValid(false) | 924 | mWidthValid(false) |
925 | { | 925 | { |
926 | } | 926 | } |
927 | 927 | ||
928 | 928 | ||
929 | void OJanusWidget::IconListBox::updateMinimumHeight() | 929 | void OJanusWidget::IconListBox::updateMinimumHeight() |
930 | { | 930 | { |
931 | if( mShowAll == true && mHeightValid == false ) | 931 | if( mShowAll == true && mHeightValid == false ) |
932 | { | 932 | { |
933 | int h = frameWidth()*2; | 933 | int h = frameWidth()*2; |
934 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 934 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
935 | { | 935 | { |
936 | h += i->height( this ); | 936 | h += i->height( this ); |
937 | } | 937 | } |
938 | setMinimumHeight( h ); | 938 | setMinimumHeight( h ); |
939 | mHeightValid = true; | 939 | mHeightValid = true; |
940 | } | 940 | } |
941 | } | 941 | } |
942 | 942 | ||
943 | 943 | ||
944 | void OJanusWidget::IconListBox::updateWidth() | 944 | void OJanusWidget::IconListBox::updateWidth() |
945 | { | 945 | { |
946 | if( mWidthValid == false ) | 946 | if( mWidthValid == false ) |
947 | { | 947 | { |
948 | int maxWidth = 10; | 948 | int maxWidth = 10; |
949 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 949 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
950 | { | 950 | { |
951 | int w = ((IconListItem *)i)->width(this); | 951 | int w = ((IconListItem *)i)->width(this); |
952 | maxWidth = QMAX( w, maxWidth ); | 952 | maxWidth = QMAX( w, maxWidth ); |
953 | } | 953 | } |
954 | 954 | ||
955 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) | 955 | for( QListBoxItem *i = item(0); i != 0; i = i->next() ) |
956 | { | 956 | { |
957 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); | 957 | ((IconListItem *)i)->expandMinimumWidth( maxWidth ); |
958 | } | 958 | } |
959 | 959 | ||
960 | if( verticalScrollBar()->isVisible() ) | 960 | if( verticalScrollBar()->isVisible() ) |
961 | { | 961 | { |
962 | maxWidth += verticalScrollBar()->sizeHint().width(); | 962 | maxWidth += verticalScrollBar()->sizeHint().width(); |
963 | } | 963 | } |
964 | 964 | ||
965 | setFixedWidth( maxWidth + frameWidth()*2 ); | 965 | setFixedWidth( maxWidth + frameWidth()*2 ); |
966 | mWidthValid = true; | 966 | mWidthValid = true; |
967 | } | 967 | } |
968 | } | 968 | } |
969 | 969 | ||
970 | 970 | ||
971 | void OJanusWidget::IconListBox::invalidateHeight() | 971 | void OJanusWidget::IconListBox::invalidateHeight() |
972 | { | 972 | { |
973 | mHeightValid = false; | 973 | mHeightValid = false; |
974 | } | 974 | } |
975 | 975 | ||
976 | 976 | ||
977 | void OJanusWidget::IconListBox::invalidateWidth() | 977 | void OJanusWidget::IconListBox::invalidateWidth() |
978 | { | 978 | { |
979 | mWidthValid = false; | 979 | mWidthValid = false; |
980 | } | 980 | } |
981 | 981 | ||
982 | 982 | ||
983 | void OJanusWidget::IconListBox::setShowAll( bool showAll ) | 983 | void OJanusWidget::IconListBox::setShowAll( bool showAll ) |
984 | { | 984 | { |
985 | mShowAll = showAll; | 985 | mShowAll = showAll; |
986 | mHeightValid = false; | 986 | mHeightValid = false; |
987 | } | 987 | } |
988 | 988 | ||
989 | 989 | ||
990 | 990 | ||
991 | OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, | 991 | OJanusWidget::IconListItem::IconListItem( QListBox *listbox, const QPixmap &pixmap, |
992 | const QString &text ) | 992 | const QString &text ) |
993 | : QListBoxItem( listbox ) | 993 | : QListBoxItem( listbox ) |
994 | { | 994 | { |
995 | mPixmap = pixmap; | 995 | mPixmap = pixmap; |
996 | if( mPixmap.isNull() == true ) | 996 | if( mPixmap.isNull() == true ) |
997 | { | 997 | { |
998 | mPixmap = defaultPixmap(); | 998 | mPixmap = defaultPixmap(); |
999 | } | 999 | } |
1000 | setText( text ); | 1000 | setText( text ); |
1001 | mMinimumWidth = 0; | 1001 | mMinimumWidth = 0; |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | 1004 | ||
1005 | int OJanusWidget::IconListItem::expandMinimumWidth( int width ) | 1005 | int OJanusWidget::IconListItem::expandMinimumWidth( int width ) |
1006 | { | 1006 | { |
1007 | mMinimumWidth = QMAX( mMinimumWidth, width ); | 1007 | mMinimumWidth = QMAX( mMinimumWidth, width ); |
1008 | return( mMinimumWidth ); | 1008 | return( mMinimumWidth ); |
1009 | } | 1009 | } |
1010 | 1010 | ||
1011 | 1011 | ||
1012 | const QPixmap &OJanusWidget::IconListItem::defaultPixmap() | 1012 | const QPixmap &OJanusWidget::IconListItem::defaultPixmap() |
1013 | { | 1013 | { |
1014 | static QPixmap *pix=0; | 1014 | static QPixmap *pix=0; |
1015 | if( pix == 0 ) | 1015 | if( pix == 0 ) |
1016 | { | 1016 | { |
1017 | pix = new QPixmap( 32, 32 ); | 1017 | pix = new QPixmap( 32, 32 ); |
1018 | QPainter p( pix ); | 1018 | QPainter p( pix ); |
1019 | p.eraseRect( 0, 0, pix->width(), pix->height() ); | 1019 | p.eraseRect( 0, 0, pix->width(), pix->height() ); |
1020 | p.setPen( Qt::red ); | 1020 | p.setPen( Qt::red ); |
1021 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1021 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1022 | p.end(); | 1022 | p.end(); |
1023 | 1023 | ||
1024 | QBitmap mask( pix->width(), pix->height(), true ); | 1024 | QBitmap mask( pix->width(), pix->height(), true ); |
1025 | mask.fill( Qt::black ); | 1025 | mask.fill( Qt::black ); |
1026 | p.begin( &mask ); | 1026 | p.begin( &mask ); |
1027 | p.setPen( Qt::white ); | 1027 | p.setPen( Qt::white ); |
1028 | p.drawRect ( 0, 0, pix->width(), pix->height() ); | 1028 | p.drawRect ( 0, 0, pix->width(), pix->height() ); |
1029 | p.end(); | 1029 | p.end(); |
1030 | 1030 | ||
1031 | pix->setMask( mask ); | 1031 | pix->setMask( mask ); |
1032 | } | 1032 | } |
1033 | return( *pix ); | 1033 | return( *pix ); |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | 1036 | ||
1037 | void OJanusWidget::IconListItem::paint( QPainter *painter ) | 1037 | void OJanusWidget::IconListItem::paint( QPainter *painter ) |
1038 | { | 1038 | { |
1039 | QFontMetrics fm = painter->fontMetrics(); | 1039 | QFontMetrics fm = painter->fontMetrics(); |
1040 | //int wt = fm.boundingRect(text()).width(); | 1040 | //int wt = fm.boundingRect(text()).width(); |
1041 | int wp = mPixmap.width(); | 1041 | int wp = mPixmap.width(); |
1042 | int ht = fm.lineSpacing(); | 1042 | int ht = fm.lineSpacing(); |
1043 | int hp = mPixmap.height(); | 1043 | int hp = mPixmap.height(); |
1044 | 1044 | ||
1045 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); | 1045 | painter->drawPixmap( (mMinimumWidth-wp)/2, 5, mPixmap ); |
1046 | if( text().isEmpty() == false ) | 1046 | if( text().isEmpty() == false ) |
1047 | { | 1047 | { |
1048 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); | 1048 | painter->drawText( 0, hp+7, mMinimumWidth, ht, Qt::AlignCenter, text() ); |
1049 | } | 1049 | } |
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | int OJanusWidget::IconListItem::height( const QListBox *lb ) const | 1052 | int OJanusWidget::IconListItem::height( const QListBox *lb ) const |
1053 | { | 1053 | { |
1054 | if( text().isEmpty() == true ) | 1054 | if( text().isEmpty() == true ) |
1055 | { | 1055 | { |
1056 | return( mPixmap.height() ); | 1056 | return( mPixmap.height() ); |
1057 | } | 1057 | } |
1058 | else | 1058 | else |
1059 | { | 1059 | { |
1060 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); | 1060 | return( mPixmap.height() + lb->fontMetrics().lineSpacing()+10 ); |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | 1063 | ||
1064 | 1064 | ||
1065 | int OJanusWidget::IconListItem::width( const QListBox *lb ) const | 1065 | int OJanusWidget::IconListItem::width( const QListBox *lb ) const |
1066 | { | 1066 | { |
1067 | int wt = lb->fontMetrics().boundingRect(text()).width()+10; | 1067 | int wt = lb->fontMetrics().boundingRect(text()).width()+10; |
1068 | int wp = mPixmap.width() + 10; | 1068 | int wp = mPixmap.width() + 10; |
1069 | int w = QMAX( wt, wp ); | 1069 | int w = QMAX( wt, wp ); |
1070 | return( QMAX( w, mMinimumWidth ) ); | 1070 | return( QMAX( w, mMinimumWidth ) ); |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | // Just remove the page from our stack of widgets. Do not modify the given widget in | 1073 | // Just remove the page from our stack of widgets. Do not modify the given widget in |
1074 | // any way. No memory leak occurs as parent is not changed. | 1074 | // any way. No memory leak occurs as parent is not changed. |
1075 | // Make this virtual in KDE 4.0. | 1075 | // Make this virtual in KDE 4.0. |
1076 | // Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> | 1076 | // Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu> |
1077 | void OJanusWidget::removePage( QWidget *page ) | 1077 | void OJanusWidget::removePage( QWidget *page ) |
1078 | { | 1078 | { |
1079 | if (!mPageList || !mPageList->containsRef(page)) | 1079 | if (!mPageList || !mPageList->containsRef(page)) |
1080 | return; | 1080 | return; |
1081 | 1081 | ||
1082 | int index = mPageList->findRef( page ); | 1082 | int index = mPageList->findRef( page ); |
1083 | if ( mTitleList ) | 1083 | if ( mTitleList ) |
1084 | mTitleList->remove(mTitleList->at(index)); | 1084 | mTitleList->remove(mTitleList->at(index)); |
1085 | 1085 | ||
1086 | mPageList->removeRef(page); | 1086 | mPageList->removeRef(page); |
1087 | 1087 | ||
1088 | if ( mFace == TreeList ) | 1088 | if ( mFace == TreeList ) |
1089 | { | 1089 | { |
1090 | QMap<QListViewItem*, QWidget *>::Iterator i; | 1090 | QMap<QListViewItem*, QWidget *>::Iterator i; |
1091 | for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i ) | 1091 | for( i = mTreeListToPageStack.begin(); i != mTreeListToPageStack.end(); ++i ) |
1092 | if (i.data()==page) | 1092 | if (i.data()==page) |
1093 | { | 1093 | { |
1094 | delete i.key(); | 1094 | delete i.key(); |
1095 | mPageStack->removeWidget(page); | 1095 | mPageStack->removeWidget(page); |
1096 | mTreeListToPageStack.remove(i); | 1096 | mTreeListToPageStack.remove(i); |
1097 | break; | 1097 | break; |
1098 | } | 1098 | } |
1099 | } | 1099 | } |
1100 | else if ( mFace == IconList ) | 1100 | else if ( mFace == IconList ) |
1101 | { | 1101 | { |
1102 | QMap<QListBoxItem*, QWidget *>::Iterator i; | 1102 | QMap<QListBoxItem*, QWidget *>::Iterator i; |
1103 | for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i ) | 1103 | for( i = mIconListToPageStack.begin(); i != mIconListToPageStack.end(); ++i ) |
1104 | if (i.data()==page) | 1104 | if (i.data()==page) |
1105 | { | 1105 | { |
1106 | delete i.key(); | 1106 | delete i.key(); |
1107 | mPageStack->removeWidget(page); | 1107 | mPageStack->removeWidget(page); |
1108 | mIconListToPageStack.remove(i); | 1108 | mIconListToPageStack.remove(i); |
1109 | break; | 1109 | break; |
1110 | } | 1110 | } |
1111 | } | 1111 | } |
1112 | else // Tabbed | 1112 | else // Tabbed |
1113 | { | 1113 | { |
1114 | mTabControl->removePage(page); | 1114 | mTabControl->removePage(page); |
1115 | } | 1115 | } |
1116 | } | 1116 | } |
diff --git a/libopie2/qt3/opieui/olineedit.cpp b/libopie2/qt3/opieui/olineedit.cpp index 9cb0cff..6f66fc7 100644 --- a/libopie2/qt3/opieui/olineedit.cpp +++ b/libopie2/qt3/opieui/olineedit.cpp | |||
@@ -1,729 +1,729 @@ | |||
1 | /* | 1 | /* |
2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 2 | This file Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
3 | is part of the Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>, Dawit Alemayehu <adawit@kde.org> | 3 | is part of the Copyright (C) 2001 Carsten Pfeiffer <pfeiffer@kde.org>, Dawit Alemayehu <adawit@kde.org> |
4 | Opie Project Copyright (C) 1999 Preston Brown <pbrown@kde.org>, Patrick Ward <PAT_WARD@HP-USA-om5.om.hp.com> | 4 | Opie Project Copyright (C) 1999 Preston Brown <pbrown@kde.org>, Patrick Ward <PAT_WARD@HP-USA-om5.om.hp.com> |
5 | Copyright (C) 1997 Sven Radej (sven.radej@iname.com) | 5 | Copyright (C) 1997 Sven Radej (sven.radej@iname.com) |
6 | =. | 6 | =. |
7 | .=l. Originally part of the KDE Project | 7 | .=l. Originally part of the KDE Project |
8 | .>+-= | 8 | .>+-= |
9 | _;:, .> :=|. This program is free software; you can | 9 | _;:, .> :=|. This program is free software; you can |
10 | .> <`_, > . <= redistribute it and/or modify it under | 10 | .> <`_, > . <= redistribute it and/or modify it under |
11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 11 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
12 | .="- .-=="i, .._ License as published by the Free Software | 12 | .="- .-=="i, .._ License as published by the Free Software |
13 | - . .-<_> .<> Foundation; either version 2 of the License, | 13 | - . .-<_> .<> Foundation; either version 2 of the License, |
14 | ._= =} : or (at your option) any later version. | 14 | ._= =} : or (at your option) any later version. |
15 | .%`+i> _;_. | 15 | .%`+i> _;_. |
16 | .i_,=:_. -<s. This program is distributed in the hope that | 16 | .i_,=:_. -<s. This program is distributed in the hope that |
17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 17 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
18 | : .. .:, . . . without even the implied warranty of | 18 | : .. .:, . . . without even the implied warranty of |
19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 19 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 20 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
21 | ..}^=.= = ; Library General Public License for more | 21 | ..}^=.= = ; Library General Public License for more |
22 | ++= -. .` .: details. | 22 | ++= -. .` .: details. |
23 | : = ...= . :.=- | 23 | : = ...= . :.=- |
24 | -. .:....=;==+<; You should have received a copy of the GNU | 24 | -. .:....=;==+<; You should have received a copy of the GNU |
25 | -_. . . )=. = Library General Public License along with | 25 | -_. . . )=. = Library General Public License along with |
26 | -- :-=` this library; see the file COPYING.LIB. | 26 | -- :-=` this library; see the file COPYING.LIB. |
27 | If not, write to the Free Software Foundation, | 27 | If not, write to the Free Software Foundation, |
28 | Inc., 59 Temple Place - Suite 330, | 28 | Inc., 59 Temple Place - Suite 330, |
29 | Boston, MA 02111-1307, USA. | 29 | Boston, MA 02111-1307, USA. |
30 | 30 | ||
31 | */ | 31 | */ |
32 | 32 | ||
33 | /* QT */ | 33 | /* QT */ |
34 | 34 | ||
35 | #include <qapplication.h> | 35 | #include <qapplication.h> |
36 | #include <qclipboard.h> | 36 | #include <qclipboard.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | #include <qpopupmenu.h> | 38 | #include <qpopupmenu.h> |
39 | 39 | ||
40 | /* OPIE */ | 40 | /* OPIE */ |
41 | 41 | ||
42 | #include <opie2/ocompletionbox.h> | 42 | #include <opie2/ocompletionbox.h> |
43 | #include <opie2/olineedit.h> | 43 | #include <opie2/olineedit.h> |
44 | #include <opie2/oglobalsettings.h> | 44 | #include <opie2/oglobalsettings.h> |
45 | 45 | ||
46 | typedef QString KURL; //FIXME: Revise for Opie | 46 | typedef QString KURL; //FIXME: Revise for Opie |
47 | 47 | ||
48 | /*====================================================================================== | 48 | /*====================================================================================== |
49 | * OLineEditPrivate | 49 | * OLineEditPrivate |
50 | *======================================================================================*/ | 50 | *======================================================================================*/ |
51 | 51 | ||
52 | class OLineEdit::OLineEditPrivate | 52 | class OLineEdit::OLineEditPrivate |
53 | { | 53 | { |
54 | public: | 54 | public: |
55 | OLineEditPrivate() | 55 | OLineEditPrivate() |
56 | { | 56 | { |
57 | grabReturnKeyEvents = false; | 57 | grabReturnKeyEvents = false; |
58 | handleURLDrops = true; | 58 | handleURLDrops = true; |
59 | completionBox = 0L; | 59 | completionBox = 0L; |
60 | } | 60 | } |
61 | ~OLineEditPrivate() | 61 | ~OLineEditPrivate() |
62 | { | 62 | { |
63 | delete completionBox; | 63 | delete completionBox; |
64 | } | 64 | } |
65 | 65 | ||
66 | bool grabReturnKeyEvents; | 66 | bool grabReturnKeyEvents; |
67 | bool handleURLDrops; | 67 | bool handleURLDrops; |
68 | OCompletionBox *completionBox; | 68 | OCompletionBox *completionBox; |
69 | }; | 69 | }; |
70 | 70 | ||
71 | 71 | ||
72 | /*====================================================================================== | 72 | /*====================================================================================== |
73 | * OLineEdit | 73 | * OLineEdit |
74 | *======================================================================================*/ | 74 | *======================================================================================*/ |
75 | 75 | ||
76 | OLineEdit::OLineEdit( const QString &string, QWidget *parent, const char *name ) | 76 | OLineEdit::OLineEdit( const QString &string, QWidget *parent, const char *name ) |
77 | : QLineEdit( string, parent, name ) | 77 | : QLineEdit( string, parent, name ) |
78 | { | 78 | { |
79 | init(); | 79 | init(); |
80 | } | 80 | } |
81 | 81 | ||
82 | OLineEdit::OLineEdit( QWidget *parent, const char *name ) | 82 | OLineEdit::OLineEdit( QWidget *parent, const char *name ) |
83 | : QLineEdit( parent, name ) | 83 | : QLineEdit( parent, name ) |
84 | { | 84 | { |
85 | init(); | 85 | init(); |
86 | } | 86 | } |
87 | 87 | ||
88 | OLineEdit::~OLineEdit () | 88 | OLineEdit::~OLineEdit () |
89 | { | 89 | { |
90 | delete d; | 90 | delete d; |
91 | } | 91 | } |
92 | 92 | ||
93 | void OLineEdit::init() | 93 | void OLineEdit::init() |
94 | { | 94 | { |
95 | d = new OLineEditPrivate; | 95 | d = new OLineEditPrivate; |
96 | possibleTripleClick = false; | 96 | possibleTripleClick = false; |
97 | // Enable the context menu by default. | 97 | // Enable the context menu by default. |
98 | setContextMenuEnabled( true ); | 98 | setContextMenuEnabled( true ); |
99 | //OCursor::setAutoHideCursor( this, true, true ); | 99 | //OCursor::setAutoHideCursor( this, true, true ); |
100 | installEventFilter( this ); | 100 | installEventFilter( this ); |
101 | } | 101 | } |
102 | 102 | ||
103 | void OLineEdit::setCompletionMode( OGlobalSettings::Completion mode ) | 103 | void OLineEdit::setCompletionMode( OGlobalSettings::Completion mode ) |
104 | { | 104 | { |
105 | OGlobalSettings::Completion oldMode = completionMode(); | 105 | OGlobalSettings::Completion oldMode = completionMode(); |
106 | if ( oldMode != mode && oldMode == OGlobalSettings::CompletionPopup && | 106 | if ( oldMode != mode && oldMode == OGlobalSettings::CompletionPopup && |
107 | d->completionBox && d->completionBox->isVisible() ) | 107 | d->completionBox && d->completionBox->isVisible() ) |
108 | d->completionBox->hide(); | 108 | d->completionBox->hide(); |
109 | 109 | ||
110 | // If the widgets echo mode is not Normal, no completion | 110 | // If the widgets echo mode is not Normal, no completion |
111 | // feature will be enabled even if one is requested. | 111 | // feature will be enabled even if one is requested. |
112 | if ( echoMode() != QLineEdit::Normal ) | 112 | if ( echoMode() != QLineEdit::Normal ) |
113 | mode = OGlobalSettings::CompletionNone; // Override the request. | 113 | mode = OGlobalSettings::CompletionNone; // Override the request. |
114 | 114 | ||
115 | OCompletionBase::setCompletionMode( mode ); | 115 | OCompletionBase::setCompletionMode( mode ); |
116 | } | 116 | } |
117 | 117 | ||
118 | void OLineEdit::setCompletedText( const QString& t, bool marked ) | 118 | void OLineEdit::setCompletedText( const QString& t, bool marked ) |
119 | { | 119 | { |
120 | QString txt = text(); | 120 | QString txt = text(); |
121 | if ( t != txt ) | 121 | if ( t != txt ) |
122 | { | 122 | { |
123 | int curpos = marked ? txt.length() : t.length(); | 123 | int curpos = marked ? txt.length() : t.length(); |
124 | validateAndSet( t, curpos, curpos, t.length() ); | 124 | validateAndSet( t, curpos, curpos, t.length() ); |
125 | } | 125 | } |
126 | } | 126 | } |
127 | 127 | ||
128 | void OLineEdit::setCompletedText( const QString& text ) | 128 | void OLineEdit::setCompletedText( const QString& text ) |
129 | { | 129 | { |
130 | OGlobalSettings::Completion mode = completionMode(); | 130 | OGlobalSettings::Completion mode = completionMode(); |
131 | bool marked = ( mode == OGlobalSettings::CompletionAuto || | 131 | bool marked = ( mode == OGlobalSettings::CompletionAuto || |
132 | mode == OGlobalSettings::CompletionMan || | 132 | mode == OGlobalSettings::CompletionMan || |
133 | mode == OGlobalSettings::CompletionPopup ); | 133 | mode == OGlobalSettings::CompletionPopup ); |
134 | setCompletedText( text, marked ); | 134 | setCompletedText( text, marked ); |
135 | } | 135 | } |
136 | 136 | ||
137 | void OLineEdit::rotateText( OCompletionBase::KeyBindingType type ) | 137 | void OLineEdit::rotateText( OCompletionBase::KeyBindingType type ) |
138 | { | 138 | { |
139 | OCompletion* comp = compObj(); | 139 | OCompletion* comp = compObj(); |
140 | if ( comp && | 140 | if ( comp && |
141 | (type == OCompletionBase::PrevCompletionMatch || | 141 | (type == OCompletionBase::PrevCompletionMatch || |
142 | type == OCompletionBase::NextCompletionMatch ) ) | 142 | type == OCompletionBase::NextCompletionMatch ) ) |
143 | { | 143 | { |
144 | QString input = (type == OCompletionBase::PrevCompletionMatch) ? comp->previousMatch() : comp->nextMatch(); | 144 | QString input = (type == OCompletionBase::PrevCompletionMatch) ? comp->previousMatch() : comp->nextMatch(); |
145 | // Skip rotation if previous/next match is null or the same text | 145 | // Skip rotation if previous/next match is null or the same text |
146 | if ( input.isNull() || input == displayText() ) | 146 | if ( input.isNull() || input == displayText() ) |
147 | return; | 147 | return; |
148 | #if QT_VERSION > 290 | 148 | #if QT_VERSION > 290 |
149 | setCompletedText( input, hasSelectedText() ); | 149 | setCompletedText( input, hasSelectedText() ); |
150 | #else | 150 | #else |
151 | setCompletedText( input, hasMarkedText() ); | 151 | setCompletedText( input, hasMarkedText() ); |
152 | #endif | 152 | #endif |
153 | } | 153 | } |
154 | } | 154 | } |
155 | 155 | ||
156 | void OLineEdit::makeCompletion( const QString& text ) | 156 | void OLineEdit::makeCompletion( const QString& text ) |
157 | { | 157 | { |
158 | OCompletion *comp = compObj(); | 158 | OCompletion *comp = compObj(); |
159 | if ( !comp ) | 159 | if ( !comp ) |
160 | return; // No completion object... | 160 | return; // No completion object... |
161 | 161 | ||
162 | QString match = comp->makeCompletion( text ); | 162 | QString match = comp->makeCompletion( text ); |
163 | OGlobalSettings::Completion mode = completionMode(); | 163 | OGlobalSettings::Completion mode = completionMode(); |
164 | if ( mode == OGlobalSettings::CompletionPopup ) | 164 | if ( mode == OGlobalSettings::CompletionPopup ) |
165 | { | 165 | { |
166 | if ( match.isNull() ) | 166 | if ( match.isNull() ) |
167 | { | 167 | { |
168 | if ( d->completionBox ) { | 168 | if ( d->completionBox ) { |
169 | d->completionBox->hide(); | 169 | d->completionBox->hide(); |
170 | d->completionBox->clear(); | 170 | d->completionBox->clear(); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | else | 173 | else |
174 | setCompletedItems( comp->allMatches() ); | 174 | setCompletedItems( comp->allMatches() ); |
175 | } | 175 | } |
176 | else | 176 | else |
177 | { | 177 | { |
178 | // all other completion modes | 178 | // all other completion modes |
179 | // If no match or the same match, simply return without completing. | 179 | // If no match or the same match, simply return without completing. |
180 | if ( match.isNull() || match == text ) | 180 | if ( match.isNull() || match == text ) |
181 | return; | 181 | return; |
182 | 182 | ||
183 | setCompletedText( match ); | 183 | setCompletedText( match ); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | void OLineEdit::setReadOnly(bool readOnly) | 187 | void OLineEdit::setReadOnly(bool readOnly) |
188 | { | 188 | { |
189 | QPalette p = palette(); | 189 | QPalette p = palette(); |
190 | if (readOnly) | 190 | if (readOnly) |
191 | { | 191 | { |
192 | QColor color = p.color(QPalette::Disabled, QColorGroup::Background); | 192 | QColor color = p.color(QPalette::Disabled, QColorGroup::Background); |
193 | p.setColor(QColorGroup::Base, color); | 193 | p.setColor(QColorGroup::Base, color); |
194 | p.setColor(QColorGroup::Background, color); | 194 | p.setColor(QColorGroup::Background, color); |
195 | } | 195 | } |
196 | else | 196 | else |
197 | { | 197 | { |
198 | QColor color = p.color(QPalette::Normal, QColorGroup::Base); | 198 | QColor color = p.color(QPalette::Normal, QColorGroup::Base); |
199 | p.setColor(QColorGroup::Base, color); | 199 | p.setColor(QColorGroup::Base, color); |
200 | p.setColor(QColorGroup::Background, color); | 200 | p.setColor(QColorGroup::Background, color); |
201 | } | 201 | } |
202 | setPalette(p); | 202 | setPalette(p); |
203 | 203 | ||
204 | QLineEdit::setReadOnly (readOnly); | 204 | QLineEdit::setReadOnly (readOnly); |
205 | } | 205 | } |
206 | 206 | ||
207 | void OLineEdit::keyPressEvent( QKeyEvent *e ) | 207 | void OLineEdit::keyPressEvent( QKeyEvent *e ) |
208 | { | 208 | { |
209 | qDebug( "OLineEdit::keyPressEvent()" ); | 209 | qDebug( "OLineEdit::keyPressEvent()" ); |
210 | 210 | ||
211 | /* | 211 | /* |
212 | 212 | ||
213 | KKey key( e ); | 213 | KKey key( e ); |
214 | 214 | ||
215 | if ( KStdAccel::copy().contains( key ) ) { | 215 | if ( KStdAccel::copy().contains( key ) ) { |
216 | copy(); | 216 | copy(); |
217 | return; | 217 | return; |
218 | } | 218 | } |
219 | else if ( KStdAccel::paste().contains( key ) ) { | 219 | else if ( KStdAccel::paste().contains( key ) ) { |
220 | paste(); | 220 | paste(); |
221 | return; | 221 | return; |
222 | } | 222 | } |
223 | else if ( KStdAccel::cut().contains( key ) ) { | 223 | else if ( KStdAccel::cut().contains( key ) ) { |
224 | cut(); | 224 | cut(); |
225 | return; | 225 | return; |
226 | } | 226 | } |
227 | else if ( KStdAccel::undo().contains( key ) ) { | 227 | else if ( KStdAccel::undo().contains( key ) ) { |
228 | undo(); | 228 | undo(); |
229 | return; | 229 | return; |
230 | } | 230 | } |
231 | else if ( KStdAccel::redo().contains( key ) ) { | 231 | else if ( KStdAccel::redo().contains( key ) ) { |
232 | redo(); | 232 | redo(); |
233 | return; | 233 | return; |
234 | } | 234 | } |
235 | else if ( KStdAccel::deleteWordBack().contains( key ) ) | 235 | else if ( KStdAccel::deleteWordBack().contains( key ) ) |
236 | { | 236 | { |
237 | cursorWordBackward(TRUE); | 237 | cursorWordBackward(TRUE); |
238 | if ( hasSelectedText() ) | 238 | if ( hasSelectedText() ) |
239 | del(); | 239 | del(); |
240 | 240 | ||
241 | e->accept(); | 241 | e->accept(); |
242 | return; | 242 | return; |
243 | } | 243 | } |
244 | else if ( KStdAccel::deleteWordForward().contains( key ) ) | 244 | else if ( KStdAccel::deleteWordForward().contains( key ) ) |
245 | { | 245 | { |
246 | // Workaround for QT bug where | 246 | // Workaround for QT bug where |
247 | cursorWordForward(TRUE); | 247 | cursorWordForward(TRUE); |
248 | if ( hasSelectedText() ) | 248 | if ( hasSelectedText() ) |
249 | del(); | 249 | del(); |
250 | 250 | ||
251 | e->accept(); | 251 | e->accept(); |
252 | return; | 252 | return; |
253 | } | 253 | } |
254 | */ | 254 | */ |
255 | 255 | ||
256 | // Filter key-events if EchoMode is normal & | 256 | // Filter key-events if EchoMode is normal & |
257 | // completion mode is not set to CompletionNone | 257 | // completion mode is not set to CompletionNone |
258 | if ( echoMode() == QLineEdit::Normal && | 258 | if ( echoMode() == QLineEdit::Normal && |
259 | completionMode() != OGlobalSettings::CompletionNone ) | 259 | completionMode() != OGlobalSettings::CompletionNone ) |
260 | { | 260 | { |
261 | KeyBindingMap keys = getKeyBindings(); | 261 | KeyBindingMap keys = getKeyBindings(); |
262 | OGlobalSettings::Completion mode = completionMode(); | 262 | OGlobalSettings::Completion mode = completionMode(); |
263 | bool noModifier = (e->state() == NoButton || e->state()== ShiftButton); | 263 | bool noModifier = (e->state() == NoButton || e->state()== ShiftButton); |
264 | 264 | ||
265 | if ( (mode == OGlobalSettings::CompletionAuto || | 265 | if ( (mode == OGlobalSettings::CompletionAuto || |
266 | mode == OGlobalSettings::CompletionMan) && noModifier ) | 266 | mode == OGlobalSettings::CompletionMan) && noModifier ) |
267 | { | 267 | { |
268 | QString keycode = e->text(); | 268 | QString keycode = e->text(); |
269 | if ( !keycode.isNull() && keycode.unicode()->isPrint() ) | 269 | if ( !keycode.isNull() && keycode.unicode()->isPrint() ) |
270 | { | 270 | { |
271 | QLineEdit::keyPressEvent ( e ); | 271 | QLineEdit::keyPressEvent ( e ); |
272 | QString txt = text(); | 272 | QString txt = text(); |
273 | int len = txt.length(); | 273 | int len = txt.length(); |
274 | #if QT_VERSION > 290 | 274 | #if QT_VERSION > 290 |
275 | if ( !hasSelectedText() && len && cursorPosition() == len ) | 275 | if ( !hasSelectedText() && len && cursorPosition() == len ) |
276 | #else | 276 | #else |
277 | if ( !hasMarkedText() && len && cursorPosition() == len ) | 277 | if ( !hasMarkedText() && len && cursorPosition() == len ) |
278 | #endif | 278 | #endif |
279 | { | 279 | { |
280 | if ( emitSignals() ) | 280 | if ( emitSignals() ) |
281 | emit completion( txt ); | 281 | emit completion( txt ); |
282 | if ( handleSignals() ) | 282 | if ( handleSignals() ) |
283 | makeCompletion( txt ); | 283 | makeCompletion( txt ); |
284 | e->accept(); | 284 | e->accept(); |
285 | } | 285 | } |
286 | return; | 286 | return; |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | else if ( mode == OGlobalSettings::CompletionPopup && noModifier ) | 290 | else if ( mode == OGlobalSettings::CompletionPopup && noModifier ) |
291 | { | 291 | { |
292 | qDebug( "OLineEdit::keyPressEvent() - global settings = CompletionPopup & noModifier" ); | 292 | qDebug( "OLineEdit::keyPressEvent() - global settings = CompletionPopup & noModifier" ); |
293 | 293 | ||
294 | QString old_txt = text(); | 294 | QString old_txt = text(); |
295 | QLineEdit::keyPressEvent ( e ); | 295 | QLineEdit::keyPressEvent ( e ); |
296 | QString txt = text(); | 296 | QString txt = text(); |
297 | int len = txt.length(); | 297 | int len = txt.length(); |
298 | QString keycode = e->text(); | 298 | QString keycode = e->text(); |
299 | 299 | ||
300 | 300 | ||
301 | if ( txt != old_txt && len && cursorPosition() == len && | 301 | if ( txt != old_txt && len && cursorPosition() == len && |
302 | ( (!keycode.isNull() && keycode.unicode()->isPrint()) || | 302 | ( (!keycode.isNull() && keycode.unicode()->isPrint()) || |
303 | e->key() == Key_Backspace ) ) | 303 | e->key() == Key_Backspace ) ) |
304 | { | 304 | { |
305 | if ( emitSignals() ) | 305 | if ( emitSignals() ) |
306 | emit completion( txt ); // emit when requested... | 306 | emit completion( txt ); // emit when requested... |
307 | if ( handleSignals() ) | 307 | if ( handleSignals() ) |
308 | makeCompletion( txt ); // handle when requested... | 308 | makeCompletion( txt ); // handle when requested... |
309 | e->accept(); | 309 | e->accept(); |
310 | } | 310 | } |
311 | else if (!len && d->completionBox && d->completionBox->isVisible()) | 311 | else if (!len && d->completionBox && d->completionBox->isVisible()) |
312 | d->completionBox->hide(); | 312 | d->completionBox->hide(); |
313 | 313 | ||
314 | return; | 314 | return; |
315 | } | 315 | } |
316 | 316 | ||
317 | /*else if ( mode == OGlobalSettings::CompletionShell ) | 317 | /*else if ( mode == OGlobalSettings::CompletionShell ) |
318 | { | 318 | { |
319 | // Handles completion. | 319 | // Handles completion. |
320 | KShortcut cut; | 320 | KShortcut cut; |
321 | if ( keys[TextCompletion].isNull() ) | 321 | if ( keys[TextCompletion].isNull() ) |
322 | cut = KStdAccel::shortcut(KStdAccel::TextCompletion); | 322 | cut = KStdAccel::shortcut(KStdAccel::TextCompletion); |
323 | else | 323 | else |
324 | cut = keys[TextCompletion]; | 324 | cut = keys[TextCompletion]; |
325 | 325 | ||
326 | if ( cut.contains( key ) ) | 326 | if ( cut.contains( key ) ) |
327 | { | 327 | { |
328 | // Emit completion if the completion mode is CompletionShell | 328 | // Emit completion if the completion mode is CompletionShell |
329 | // and the cursor is at the end of the string. | 329 | // and the cursor is at the end of the string. |
330 | QString txt = text(); | 330 | QString txt = text(); |
331 | int len = txt.length(); | 331 | int len = txt.length(); |
332 | if ( cursorPosition() == len && len != 0 ) | 332 | if ( cursorPosition() == len && len != 0 ) |
333 | { | 333 | { |
334 | if ( emitSignals() ) | 334 | if ( emitSignals() ) |
335 | emit completion( txt ); | 335 | emit completion( txt ); |
336 | if ( handleSignals() ) | 336 | if ( handleSignals() ) |
337 | makeCompletion( txt ); | 337 | makeCompletion( txt ); |
338 | return; | 338 | return; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | else if ( d->completionBox ) | 341 | else if ( d->completionBox ) |
342 | d->completionBox->hide(); | 342 | d->completionBox->hide(); |
343 | } | 343 | } |
344 | 344 | ||
345 | // handle rotation | 345 | // handle rotation |
346 | if ( mode != OGlobalSettings::CompletionNone ) | 346 | if ( mode != OGlobalSettings::CompletionNone ) |
347 | { | 347 | { |
348 | // Handles previous match | 348 | // Handles previous match |
349 | KShortcut cut; | 349 | KShortcut cut; |
350 | if ( keys[PrevCompletionMatch].isNull() ) | 350 | if ( keys[PrevCompletionMatch].isNull() ) |
351 | cut = KStdAccel::shortcut(KStdAccel::PrevCompletion); | 351 | cut = KStdAccel::shortcut(KStdAccel::PrevCompletion); |
352 | else | 352 | else |
353 | cut = keys[PrevCompletionMatch]; | 353 | cut = keys[PrevCompletionMatch]; |
354 | 354 | ||
355 | if ( cut.contains( key ) ) | 355 | if ( cut.contains( key ) ) |
356 | { | 356 | { |
357 | if ( emitSignals() ) | 357 | if ( emitSignals() ) |
358 | emit textRotation( OCompletionBase::PrevCompletionMatch ); | 358 | emit textRotation( OCompletionBase::PrevCompletionMatch ); |
359 | if ( handleSignals() ) | 359 | if ( handleSignals() ) |
360 | rotateText( OCompletionBase::PrevCompletionMatch ); | 360 | rotateText( OCompletionBase::PrevCompletionMatch ); |
361 | return; | 361 | return; |
362 | } | 362 | } |
363 | 363 | ||
364 | // Handles next match | 364 | // Handles next match |
365 | if ( keys[NextCompletionMatch].isNull() ) | 365 | if ( keys[NextCompletionMatch].isNull() ) |
366 | cut = KStdAccel::key(KStdAccel::NextCompletion); | 366 | cut = KStdAccel::key(KStdAccel::NextCompletion); |
367 | else | 367 | else |
368 | cut = keys[NextCompletionMatch]; | 368 | cut = keys[NextCompletionMatch]; |
369 | 369 | ||
370 | if ( cut.contains( key ) ) | 370 | if ( cut.contains( key ) ) |
371 | { | 371 | { |
372 | if ( emitSignals() ) | 372 | if ( emitSignals() ) |
373 | emit textRotation( OCompletionBase::NextCompletionMatch ); | 373 | emit textRotation( OCompletionBase::NextCompletionMatch ); |
374 | if ( handleSignals() ) | 374 | if ( handleSignals() ) |
375 | rotateText( OCompletionBase::NextCompletionMatch ); | 375 | rotateText( OCompletionBase::NextCompletionMatch ); |
376 | return; | 376 | return; |
377 | } | 377 | } |
378 | } | 378 | } |
379 | 379 | ||
380 | // substring completion | 380 | // substring completion |
381 | if ( compObj() ) | 381 | if ( compObj() ) |
382 | { | 382 | { |
383 | KShortcut cut; | 383 | KShortcut cut; |
384 | if ( keys[SubstringCompletion].isNull() ) | 384 | if ( keys[SubstringCompletion].isNull() ) |
385 | cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion); | 385 | cut = KStdAccel::shortcut(KStdAccel::SubstringCompletion); |
386 | else | 386 | else |
387 | cut = keys[SubstringCompletion]; | 387 | cut = keys[SubstringCompletion]; |
388 | 388 | ||
389 | if ( cut.contains( key ) ) | 389 | if ( cut.contains( key ) ) |
390 | { | 390 | { |
391 | if ( emitSignals() ) | 391 | if ( emitSignals() ) |
392 | emit substringCompletion( text() ); | 392 | emit substringCompletion( text() ); |
393 | if ( handleSignals() ) | 393 | if ( handleSignals() ) |
394 | { | 394 | { |
395 | setCompletedItems( compObj()->substringCompletion(text())); | 395 | setCompletedItems( compObj()->substringCompletion(text())); |
396 | e->accept(); | 396 | e->accept(); |
397 | } | 397 | } |
398 | return; | 398 | return; |
399 | } | 399 | } |
400 | } */ | 400 | } */ |
401 | } | 401 | } |
402 | 402 | ||
403 | // Let QLineEdit handle any other keys events. | 403 | // Let QLineEdit handle any other keys events. |
404 | QLineEdit::keyPressEvent ( e ); | 404 | QLineEdit::keyPressEvent ( e ); |
405 | } | 405 | } |
406 | 406 | ||
407 | void OLineEdit::mouseDoubleClickEvent( QMouseEvent* e ) | 407 | void OLineEdit::mouseDoubleClickEvent( QMouseEvent* e ) |
408 | { | 408 | { |
409 | if ( e->button() == Qt::LeftButton ) | 409 | if ( e->button() == Qt::LeftButton ) |
410 | { | 410 | { |
411 | possibleTripleClick=true; | 411 | possibleTripleClick=true; |
412 | QTimer::singleShot( QApplication::doubleClickInterval(),this, | 412 | QTimer::singleShot( QApplication::doubleClickInterval(),this, |
413 | SLOT(tripleClickTimeout()) ); | 413 | SLOT(tripleClickTimeout()) ); |
414 | } | 414 | } |
415 | QLineEdit::mouseDoubleClickEvent( e ); | 415 | QLineEdit::mouseDoubleClickEvent( e ); |
416 | } | 416 | } |
417 | 417 | ||
418 | void OLineEdit::mousePressEvent( QMouseEvent* e ) | 418 | void OLineEdit::mousePressEvent( QMouseEvent* e ) |
419 | { | 419 | { |
420 | if ( possibleTripleClick && e->button() == Qt::LeftButton ) | 420 | if ( possibleTripleClick && e->button() == Qt::LeftButton ) |
421 | { | 421 | { |
422 | selectAll(); | 422 | selectAll(); |
423 | return; | 423 | return; |
424 | } | 424 | } |
425 | QLineEdit::mousePressEvent( e ); | 425 | QLineEdit::mousePressEvent( e ); |
426 | } | 426 | } |
427 | 427 | ||
428 | void OLineEdit::tripleClickTimeout() | 428 | void OLineEdit::tripleClickTimeout() |
429 | { | 429 | { |
430 | possibleTripleClick=false; | 430 | possibleTripleClick=false; |
431 | } | 431 | } |
432 | 432 | ||
433 | QPopupMenu *OLineEdit::createPopupMenu() | 433 | QPopupMenu *OLineEdit::createPopupMenu() |
434 | { | 434 | { |
435 | // Return if popup menu is not enabled !! | 435 | // Return if popup menu is not enabled !! |
436 | if ( !m_bEnableMenu ) | 436 | if ( !m_bEnableMenu ) |
437 | return 0; | 437 | return 0; |
438 | 438 | ||
439 | #if QT_VERSION > 290 | 439 | #if QT_VERSION > 290 |
440 | QPopupMenu *popup = QLineEdit::createPopupMenu(); | 440 | QPopupMenu *popup = QLineEdit::createPopupMenu(); |
441 | #else | 441 | #else |
442 | QPopupMenu *popup = new QPopupMenu(); | 442 | QPopupMenu *popup = new QPopupMenu(); |
443 | #warning OLineEdit is not fully functional on Qt2 | 443 | #warning OLineEdit is not fully functional on Qt2 |
444 | #endif | 444 | #endif |
445 | 445 | ||
446 | // completion object is present. | 446 | // completion object is present. |
447 | if ( compObj() ) | 447 | if ( compObj() ) |
448 | { | 448 | { |
449 | QPopupMenu *subMenu = new QPopupMenu( popup ); | 449 | QPopupMenu *subMenu = new QPopupMenu( popup ); |
450 | connect( subMenu, SIGNAL( activated( int ) ), | 450 | connect( subMenu, SIGNAL( activated(int) ), |
451 | this, SLOT( completionMenuActivated( int ) ) ); | 451 | this, SLOT( completionMenuActivated(int) ) ); |
452 | 452 | ||
453 | popup->insertSeparator(); | 453 | popup->insertSeparator(); |
454 | //popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"), | 454 | //popup->insertItem( SmallIconSet("completion"), i18n("Text Completion"), |
455 | // subMenu ); | 455 | // subMenu ); |
456 | 456 | ||
457 | popup->insertItem( tr("Text Completion"), subMenu ); | 457 | popup->insertItem( tr("Text Completion"), subMenu ); |
458 | 458 | ||
459 | subMenu->insertItem( tr("None"), NoCompletion ); | 459 | subMenu->insertItem( tr("None"), NoCompletion ); |
460 | subMenu->insertItem( tr("Manual"), ShellCompletion ); | 460 | subMenu->insertItem( tr("Manual"), ShellCompletion ); |
461 | subMenu->insertItem( tr("Automatic"), AutoCompletion ); | 461 | subMenu->insertItem( tr("Automatic"), AutoCompletion ); |
462 | subMenu->insertItem( tr("Dropdown List"), PopupCompletion ); | 462 | subMenu->insertItem( tr("Dropdown List"), PopupCompletion ); |
463 | subMenu->insertItem( tr("Short Automatic"), SemiAutoCompletion ); | 463 | subMenu->insertItem( tr("Short Automatic"), SemiAutoCompletion ); |
464 | 464 | ||
465 | //subMenu->setAccel( KStdAccel::completion(), ShellCompletion ); | 465 | //subMenu->setAccel( KStdAccel::completion(), ShellCompletion ); |
466 | subMenu->setAccel( Key_Tab, ShellCompletion ); | 466 | subMenu->setAccel( Key_Tab, ShellCompletion ); |
467 | 467 | ||
468 | OGlobalSettings::Completion mode = completionMode(); | 468 | OGlobalSettings::Completion mode = completionMode(); |
469 | subMenu->setItemChecked( NoCompletion, | 469 | subMenu->setItemChecked( NoCompletion, |
470 | mode == OGlobalSettings::CompletionNone ); | 470 | mode == OGlobalSettings::CompletionNone ); |
471 | subMenu->setItemChecked( ShellCompletion, | 471 | subMenu->setItemChecked( ShellCompletion, |
472 | mode == OGlobalSettings::CompletionShell ); | 472 | mode == OGlobalSettings::CompletionShell ); |
473 | subMenu->setItemChecked( PopupCompletion, | 473 | subMenu->setItemChecked( PopupCompletion, |
474 | mode == OGlobalSettings::CompletionPopup ); | 474 | mode == OGlobalSettings::CompletionPopup ); |
475 | subMenu->setItemChecked( AutoCompletion, | 475 | subMenu->setItemChecked( AutoCompletion, |
476 | mode == OGlobalSettings::CompletionAuto ); | 476 | mode == OGlobalSettings::CompletionAuto ); |
477 | subMenu->setItemChecked( SemiAutoCompletion, | 477 | subMenu->setItemChecked( SemiAutoCompletion, |
478 | mode == OGlobalSettings::CompletionMan ); | 478 | mode == OGlobalSettings::CompletionMan ); |
479 | if ( mode != OGlobalSettings::completionMode() ) | 479 | if ( mode != OGlobalSettings::completionMode() ) |
480 | { | 480 | { |
481 | subMenu->insertSeparator(); | 481 | subMenu->insertSeparator(); |
482 | subMenu->insertItem( tr("Default"), Default ); | 482 | subMenu->insertItem( tr("Default"), Default ); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | // ### do we really need this? Yes, Please do not remove! This | 485 | // ### do we really need this? Yes, Please do not remove! This |
486 | // allows applications to extend the popup menu without having to | 486 | // allows applications to extend the popup menu without having to |
487 | // inherit from this class! (DA) | 487 | // inherit from this class! (DA) |
488 | emit aboutToShowContextMenu( popup ); | 488 | emit aboutToShowContextMenu( popup ); |
489 | 489 | ||
490 | return popup; | 490 | return popup; |
491 | } | 491 | } |
492 | 492 | ||
493 | void OLineEdit::completionMenuActivated( int id ) | 493 | void OLineEdit::completionMenuActivated( int id ) |
494 | { | 494 | { |
495 | OGlobalSettings::Completion oldMode = completionMode(); | 495 | OGlobalSettings::Completion oldMode = completionMode(); |
496 | 496 | ||
497 | switch ( id ) | 497 | switch ( id ) |
498 | { | 498 | { |
499 | case Default: | 499 | case Default: |
500 | setCompletionMode( OGlobalSettings::completionMode() ); break; | 500 | setCompletionMode( OGlobalSettings::completionMode() ); break; |
501 | case NoCompletion: | 501 | case NoCompletion: |
502 | setCompletionMode( OGlobalSettings::CompletionNone ); break; | 502 | setCompletionMode( OGlobalSettings::CompletionNone ); break; |
503 | case AutoCompletion: | 503 | case AutoCompletion: |
504 | setCompletionMode( OGlobalSettings::CompletionAuto ); break; | 504 | setCompletionMode( OGlobalSettings::CompletionAuto ); break; |
505 | case SemiAutoCompletion: | 505 | case SemiAutoCompletion: |
506 | setCompletionMode( OGlobalSettings::CompletionMan ); break; | 506 | setCompletionMode( OGlobalSettings::CompletionMan ); break; |
507 | case ShellCompletion: | 507 | case ShellCompletion: |
508 | setCompletionMode( OGlobalSettings::CompletionShell ); break; | 508 | setCompletionMode( OGlobalSettings::CompletionShell ); break; |
509 | case PopupCompletion: | 509 | case PopupCompletion: |
510 | setCompletionMode( OGlobalSettings::CompletionPopup ); break; | 510 | setCompletionMode( OGlobalSettings::CompletionPopup ); break; |
511 | default: return; | 511 | default: return; |
512 | } | 512 | } |
513 | 513 | ||
514 | if ( oldMode != completionMode() ) | 514 | if ( oldMode != completionMode() ) |
515 | { | 515 | { |
516 | if ( oldMode == OGlobalSettings::CompletionPopup && | 516 | if ( oldMode == OGlobalSettings::CompletionPopup && |
517 | d->completionBox && d->completionBox->isVisible() ) | 517 | d->completionBox && d->completionBox->isVisible() ) |
518 | d->completionBox->hide(); | 518 | d->completionBox->hide(); |
519 | emit completionModeChanged( completionMode() ); | 519 | emit completionModeChanged( completionMode() ); |
520 | } | 520 | } |
521 | } | 521 | } |
522 | 522 | ||
523 | /*void OLineEdit::dropEvent(QDropEvent *e) | 523 | /*void OLineEdit::dropEvent(QDropEvent *e) |
524 | { | 524 | { |
525 | KURL::List urlList; | 525 | KURL::List urlList; |
526 | if( d->handleURLDrops && KURLDrag::decode( e, urlList ) ) | 526 | if( d->handleURLDrops && KURLDrag::decode( e, urlList ) ) |
527 | { | 527 | { |
528 | QString dropText = text(); | 528 | QString dropText = text(); |
529 | KURL::List::ConstIterator it; | 529 | KURL::List::ConstIterator it; |
530 | for( it = urlList.begin() ; it != urlList.end() ; ++it ) | 530 | for( it = urlList.begin() ; it != urlList.end() ; ++it ) |
531 | { | 531 | { |
532 | if(!dropText.isEmpty()) | 532 | if(!dropText.isEmpty()) |
533 | dropText+=' '; | 533 | dropText+=' '; |
534 | 534 | ||
535 | dropText += (*it).prettyURL(); | 535 | dropText += (*it).prettyURL(); |
536 | } | 536 | } |
537 | 537 | ||
538 | validateAndSet( dropText, dropText.length(), 0, 0); | 538 | validateAndSet( dropText, dropText.length(), 0, 0); |
539 | 539 | ||
540 | e->accept(); | 540 | e->accept(); |
541 | } | 541 | } |
542 | else | 542 | else |
543 | QLineEdit::dropEvent(e); | 543 | QLineEdit::dropEvent(e); |
544 | }*/ | 544 | }*/ |
545 | 545 | ||
546 | bool OLineEdit::eventFilter( QObject* o, QEvent* ev ) | 546 | bool OLineEdit::eventFilter( QObject* o, QEvent* ev ) |
547 | { | 547 | { |
548 | if( o == this ) | 548 | if( o == this ) |
549 | { | 549 | { |
550 | //OCursor::autoHideEventFilter( this, ev ); | 550 | //OCursor::autoHideEventFilter( this, ev ); |
551 | if ( ev->type() == QEvent::AccelOverride ) | 551 | if ( ev->type() == QEvent::AccelOverride ) |
552 | { | 552 | { |
553 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 553 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
554 | // if (overrideAccel (e)) | 554 | // if (overrideAccel (e)) |
555 | // { | 555 | // { |
556 | // e->accept(); | 556 | // e->accept(); |
557 | // return true; | 557 | // return true; |
558 | // } | 558 | // } |
559 | } | 559 | } |
560 | else if( ev->type() == QEvent::KeyPress ) | 560 | else if( ev->type() == QEvent::KeyPress ) |
561 | { | 561 | { |
562 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); | 562 | QKeyEvent *e = static_cast<QKeyEvent *>( ev ); |
563 | 563 | ||
564 | if( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) | 564 | if( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter ) |
565 | { | 565 | { |
566 | bool trap = d->completionBox && d->completionBox->isVisible(); | 566 | bool trap = d->completionBox && d->completionBox->isVisible(); |
567 | 567 | ||
568 | // Qt will emit returnPressed() itself if we return false | 568 | // Qt will emit returnPressed() itself if we return false |
569 | if ( d->grabReturnKeyEvents || trap ) | 569 | if ( d->grabReturnKeyEvents || trap ) |
570 | emit QLineEdit::returnPressed(); | 570 | emit QLineEdit::returnPressed(); |
571 | 571 | ||
572 | emit returnPressed( displayText() ); | 572 | emit returnPressed( displayText() ); |
573 | 573 | ||
574 | if ( trap ) | 574 | if ( trap ) |
575 | d->completionBox->hide(); | 575 | d->completionBox->hide(); |
576 | 576 | ||
577 | // Eat the event if the user asked for it, or if a completionbox was visible | 577 | // Eat the event if the user asked for it, or if a completionbox was visible |
578 | return d->grabReturnKeyEvents || trap; | 578 | return d->grabReturnKeyEvents || trap; |
579 | } | 579 | } |
580 | } | 580 | } |
581 | } | 581 | } |
582 | return QLineEdit::eventFilter( o, ev ); | 582 | return QLineEdit::eventFilter( o, ev ); |
583 | } | 583 | } |
584 | 584 | ||
585 | 585 | ||
586 | void OLineEdit::setURLDropsEnabled(bool enable) | 586 | void OLineEdit::setURLDropsEnabled(bool enable) |
587 | { | 587 | { |
588 | d->handleURLDrops=enable; | 588 | d->handleURLDrops=enable; |
589 | } | 589 | } |
590 | 590 | ||
591 | bool OLineEdit::isURLDropsEnabled() const | 591 | bool OLineEdit::isURLDropsEnabled() const |
592 | { | 592 | { |
593 | return d->handleURLDrops; | 593 | return d->handleURLDrops; |
594 | } | 594 | } |
595 | 595 | ||
596 | void OLineEdit::setTrapReturnKey( bool grab ) | 596 | void OLineEdit::setTrapReturnKey( bool grab ) |
597 | { | 597 | { |
598 | d->grabReturnKeyEvents = grab; | 598 | d->grabReturnKeyEvents = grab; |
599 | } | 599 | } |
600 | 600 | ||
601 | bool OLineEdit::trapReturnKey() const | 601 | bool OLineEdit::trapReturnKey() const |
602 | { | 602 | { |
603 | return d->grabReturnKeyEvents; | 603 | return d->grabReturnKeyEvents; |
604 | } | 604 | } |
605 | 605 | ||
606 | /*void OLineEdit::setURL( const KURL& url ) | 606 | /*void OLineEdit::setURL( const KURL& url ) |
607 | { | 607 | { |
608 | QLineEdit::setText( url.prettyURL() ); | 608 | QLineEdit::setText( url.prettyURL() ); |
609 | }*/ | 609 | }*/ |
610 | 610 | ||
611 | void OLineEdit::makeCompletionBox() | 611 | void OLineEdit::makeCompletionBox() |
612 | { | 612 | { |
613 | if ( d->completionBox ) | 613 | if ( d->completionBox ) |
614 | return; | 614 | return; |
615 | 615 | ||
616 | d->completionBox = new OCompletionBox( this, "completion box" ); | 616 | d->completionBox = new OCompletionBox( this, "completion box" ); |
617 | if ( handleSignals() ) | 617 | if ( handleSignals() ) |
618 | { | 618 | { |
619 | connect( d->completionBox, SIGNAL(highlighted( const QString& )), | 619 | connect( d->completionBox, SIGNAL(highlighted(const QString&)), |
620 | SLOT(setText( const QString& )) ); | 620 | SLOT(setText(const QString&)) ); |
621 | connect( d->completionBox, SIGNAL(userCancelled( const QString& )), | 621 | connect( d->completionBox, SIGNAL(userCancelled(const QString&)), |
622 | SLOT(setText( const QString& )) ); | 622 | SLOT(setText(const QString&)) ); |
623 | 623 | ||
624 | // Nice lil' hacklet ;) KComboBox doesn't know when the completionbox | 624 | // Nice lil' hacklet ;) KComboBox doesn't know when the completionbox |
625 | // is created (childEvent() is even more hacky, IMHO), so we simply | 625 | // is created (childEvent() is even more hacky, IMHO), so we simply |
626 | // forward the completionbox' activated signal from here. | 626 | // forward the completionbox' activated signal from here. |
627 | if ( parentWidget() && parentWidget()->inherits("KComboBox") ) | 627 | if ( parentWidget() && parentWidget()->inherits("KComboBox") ) |
628 | connect( d->completionBox, SIGNAL( activated( const QString& )), | 628 | connect( d->completionBox, SIGNAL( activated(const QString&)), |
629 | parentWidget(), SIGNAL( activated( const QString & ))); | 629 | parentWidget(), SIGNAL( activated(const QString&))); |
630 | } | 630 | } |
631 | } | 631 | } |
632 | 632 | ||
633 | /*bool OLineEdit::overrideAccel (const QKeyEvent* e) | 633 | /*bool OLineEdit::overrideAccel (const QKeyEvent* e) |
634 | { | 634 | { |
635 | KShortcut scKey; | 635 | KShortcut scKey; |
636 | 636 | ||
637 | KKey key( e ); | 637 | KKey key( e ); |
638 | KeyBindingMap keys = getKeyBindings(); | 638 | KeyBindingMap keys = getKeyBindings(); |
639 | 639 | ||
640 | if (keys[TextCompletion].isNull()) | 640 | if (keys[TextCompletion].isNull()) |
641 | scKey = KStdAccel::shortcut(KStdAccel::TextCompletion); | 641 | scKey = KStdAccel::shortcut(KStdAccel::TextCompletion); |
642 | else | 642 | else |
643 | scKey = keys[TextCompletion]; | 643 | scKey = keys[TextCompletion]; |
644 | 644 | ||
645 | if (scKey.contains( key )) | 645 | if (scKey.contains( key )) |
646 | return true; | 646 | return true; |
647 | 647 | ||
648 | if (keys[NextCompletionMatch].isNull()) | 648 | if (keys[NextCompletionMatch].isNull()) |
649 | scKey = KStdAccel::shortcut(KStdAccel::NextCompletion); | 649 | scKey = KStdAccel::shortcut(KStdAccel::NextCompletion); |
650 | else | 650 | else |
651 | scKey = keys[NextCompletionMatch]; | 651 | scKey = keys[NextCompletionMatch]; |
652 | 652 | ||
653 | if (scKey.contains( key )) | 653 | if (scKey.contains( key )) |
654 | return true; | 654 | return true; |
655 | 655 | ||
656 | if (keys[PrevCompletionMatch].isNull()) | 656 | if (keys[PrevCompletionMatch].isNull()) |
657 | scKey = KStdAccel::shortcut(KStdAccel::PrevCompletion); | 657 | scKey = KStdAccel::shortcut(KStdAccel::PrevCompletion); |
658 | else | 658 | else |
659 | scKey = keys[PrevCompletionMatch]; | 659 | scKey = keys[PrevCompletionMatch]; |
660 | 660 | ||
661 | if (scKey.contains( key )) | 661 | if (scKey.contains( key )) |
662 | return true; | 662 | return true; |
663 | 663 | ||
664 | if (KStdAccel::deleteWordBack().contains( key )) | 664 | if (KStdAccel::deleteWordBack().contains( key )) |
665 | return true; | 665 | return true; |
666 | if (KStdAccel::deleteWordForward().contains( key )) | 666 | if (KStdAccel::deleteWordForward().contains( key )) |
667 | return true; | 667 | return true; |
668 | 668 | ||
669 | if (d->completionBox && d->completionBox->isVisible ()) | 669 | if (d->completionBox && d->completionBox->isVisible ()) |
670 | if (e->key () == Key_Backtab) | 670 | if (e->key () == Key_Backtab) |
671 | return true; | 671 | return true; |
672 | 672 | ||
673 | return false; | 673 | return false; |
674 | }*/ | 674 | }*/ |
675 | 675 | ||
676 | void OLineEdit::setCompletedItems( const QStringList& items ) | 676 | void OLineEdit::setCompletedItems( const QStringList& items ) |
677 | { | 677 | { |
678 | QString txt = text(); | 678 | QString txt = text(); |
679 | if ( !items.isEmpty() && | 679 | if ( !items.isEmpty() && |
680 | !(items.count() == 1 && txt == items.first()) ) | 680 | !(items.count() == 1 && txt == items.first()) ) |
681 | { | 681 | { |
682 | if ( !d->completionBox ) | 682 | if ( !d->completionBox ) |
683 | makeCompletionBox(); | 683 | makeCompletionBox(); |
684 | 684 | ||
685 | if ( !txt.isEmpty() ) | 685 | if ( !txt.isEmpty() ) |
686 | d->completionBox->setCancelledText( txt ); | 686 | d->completionBox->setCancelledText( txt ); |
687 | d->completionBox->setItems( items ); | 687 | d->completionBox->setItems( items ); |
688 | d->completionBox->popup(); | 688 | d->completionBox->popup(); |
689 | } | 689 | } |
690 | else | 690 | else |
691 | { | 691 | { |
692 | if ( d->completionBox && d->completionBox->isVisible() ) | 692 | if ( d->completionBox && d->completionBox->isVisible() ) |
693 | d->completionBox->hide(); | 693 | d->completionBox->hide(); |
694 | } | 694 | } |
695 | } | 695 | } |
696 | 696 | ||
697 | OCompletionBox * OLineEdit::completionBox( bool create ) | 697 | OCompletionBox * OLineEdit::completionBox( bool create ) |
698 | { | 698 | { |
699 | if ( create ) | 699 | if ( create ) |
700 | makeCompletionBox(); | 700 | makeCompletionBox(); |
701 | 701 | ||
702 | return d->completionBox; | 702 | return d->completionBox; |
703 | } | 703 | } |
704 | 704 | ||
705 | void OLineEdit::setCompletionObject( OCompletion* comp, bool hsig ) | 705 | void OLineEdit::setCompletionObject( OCompletion* comp, bool hsig ) |
706 | { | 706 | { |
707 | OCompletion *oldComp = compObj(); | 707 | OCompletion *oldComp = compObj(); |
708 | if ( oldComp && handleSignals() ) | 708 | if ( oldComp && handleSignals() ) |
709 | disconnect( oldComp, SIGNAL( matches( const QStringList& )), | 709 | disconnect( oldComp, SIGNAL( matches(const QStringList&)), |
710 | this, SLOT( setCompletedItems( const QStringList& ))); | 710 | this, SLOT( setCompletedItems(const QStringList&))); |
711 | 711 | ||
712 | if ( comp && hsig ) | 712 | if ( comp && hsig ) |
713 | connect( comp, SIGNAL( matches( const QStringList& )), | 713 | connect( comp, SIGNAL( matches(const QStringList&)), |
714 | this, SLOT( setCompletedItems( const QStringList& ))); | 714 | this, SLOT( setCompletedItems(const QStringList&))); |
715 | 715 | ||
716 | OCompletionBase::setCompletionObject( comp, hsig ); | 716 | OCompletionBase::setCompletionObject( comp, hsig ); |
717 | } | 717 | } |
718 | 718 | ||
719 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding | 719 | // QWidget::create() turns off mouse-Tracking which would break auto-hiding |
720 | void OLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow ) | 720 | void OLineEdit::create( WId id, bool initializeWindow, bool destroyOldWindow ) |
721 | { | 721 | { |
722 | QLineEdit::create( id, initializeWindow, destroyOldWindow ); | 722 | QLineEdit::create( id, initializeWindow, destroyOldWindow ); |
723 | //OCursor::setAutoHideCursor( this, true, true ); | 723 | //OCursor::setAutoHideCursor( this, true, true ); |
724 | } | 724 | } |
725 | 725 | ||
726 | void OLineEdit::clear() | 726 | void OLineEdit::clear() |
727 | { | 727 | { |
728 | setText( QString::null ); | 728 | setText( QString::null ); |
729 | } | 729 | } |