summaryrefslogtreecommitdiff
path: root/libopie2/qt3
Unidiff
Diffstat (limited to 'libopie2/qt3') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opieui/ocombobox.cpp5
-rw-r--r--libopie2/qt3/opieui/oeditlistbox.cpp5
2 files changed, 7 insertions, 3 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp
index a1dd5f5..8dbda8f 100644
--- a/libopie2/qt3/opieui/ocombobox.cpp
+++ b/libopie2/qt3/opieui/ocombobox.cpp
@@ -1,666 +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
50class OComboBox::OComboBoxPrivate 50class OComboBox::OComboBoxPrivate
51{ 51{
52public: 52public:
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
68OComboBox::OComboBox( QWidget *parent, const char *name ) 68OComboBox::OComboBox( QWidget *parent, const char *name )
69 : QComboBox( parent, name ) 69 : QComboBox( parent, name )
70{ 70{
71 init(); 71 init();
72} 72}
73 73
74OComboBox::OComboBox( bool rw, QWidget *parent, const char *name ) 74OComboBox::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
86OComboBox::~OComboBox() 86OComboBox::~OComboBox()
87{ 87{
88 delete d; 88 delete d;
89} 89}
90 90
91void OComboBox::init() 91void 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
116bool OComboBox::contains( const QString& _text ) const 116bool 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
128void OComboBox::setAutoCompletion( bool autocomplete ) 128void 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
145void OComboBox::setContextMenuEnabled( bool showMenu ) 145void 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/*
155void OComboBox::setURLDropsEnabled( bool enable ) 155void 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
161bool OComboBox::isURLDropsEnabled() const 161bool 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
167void OComboBox::setCompletedText( const QString& text, bool marked ) 167void 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
173void OComboBox::setCompletedText( const QString& text ) 173void 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
179void OComboBox::makeCompletion( const QString& text ) 179void 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
196void OComboBox::rotateText( OCompletionBase::KeyBindingType type ) 196void 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
202bool OComboBox::eventFilter( QObject* o, QEvent* ev ) 202bool 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
260void OComboBox::setTrapReturnKey( bool grab ) 260void OComboBox::setTrapReturnKey( bool grab )
261{ 261{
262 m_trapReturnKey = grab; 262 m_trapReturnKey = grab;
263} 263}
264 264
265bool OComboBox::trapReturnKey() const 265bool OComboBox::trapReturnKey() const
266{ 266{
267 return m_trapReturnKey; 267 return m_trapReturnKey;
268} 268}
269 269
270/* 270/*
271void OComboBox::setEditURL( const OURL& url ) 271void OComboBox::setEditURL( const OURL& url )
272{ 272{
273 QComboBox::setEditText( url.prettyURL() ); 273 QComboBox::setEditText( url.prettyURL() );
274} 274}
275 275
276void OComboBox::insertURL( const OURL& url, int index ) 276void 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
281void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index ) 281void 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
286void OComboBox::changeURL( const OURL& url, int index ) 286void 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
291void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index ) 291void 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
298void OComboBox::setCompletedItems( const QStringList& items ) 298void 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
305OCompletionBox * OComboBox::completionBox( bool create ) 305OCompletionBox * 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
313void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow ) 313void 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
319void OComboBox::setLineEdit( OLineEdit *edit ) 319void 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 d->olineEdit = dynamic_cast<OLineEdit*>( edit ); 323 if ( !edit->inherits( "OLineEdit" ) )
324 d->olineEdit = 0;
325 else
326 d->olineEdit = static_cast<OLineEdit*>( edit );
324 setDelegate( d->olineEdit ); 327 setDelegate( d->olineEdit );
325 328
326 // forward some signals. We only emit returnPressed() ourselves. 329 // forward some signals. We only emit returnPressed() ourselves.
327 if ( d->olineEdit ) { 330 if ( d->olineEdit ) {
328 connect( d->olineEdit, SIGNAL( completion( const QString& )), 331 connect( d->olineEdit, SIGNAL( completion( const QString& )),
329 SIGNAL( completion( const QString& )) ); 332 SIGNAL( completion( const QString& )) );
330 connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )), 333 connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )),
331 SIGNAL( substringCompletion( const QString& )) ); 334 SIGNAL( substringCompletion( const QString& )) );
332 connect( d->olineEdit, 335 connect( d->olineEdit,
333 SIGNAL( textRotation( OCompletionBase::KeyBindingType )), 336 SIGNAL( textRotation( OCompletionBase::KeyBindingType )),
334 SIGNAL( textRotation( OCompletionBase::KeyBindingType )) ); 337 SIGNAL( textRotation( OCompletionBase::KeyBindingType )) );
335 connect( d->olineEdit, 338 connect( d->olineEdit,
336 SIGNAL( completionModeChanged( OGlobalSettings::Completion )), 339 SIGNAL( completionModeChanged( OGlobalSettings::Completion )),
337 SIGNAL( completionModeChanged( OGlobalSettings::Completion))); 340 SIGNAL( completionModeChanged( OGlobalSettings::Completion)));
338 341
339 connect( d->olineEdit, 342 connect( d->olineEdit,
340 SIGNAL( aboutToShowContextMenu( QPopupMenu * )), 343 SIGNAL( aboutToShowContextMenu( QPopupMenu * )),
341 SIGNAL( aboutToShowContextMenu( QPopupMenu * )) ); 344 SIGNAL( aboutToShowContextMenu( QPopupMenu * )) );
342 } 345 }
343 #else 346 #else
344 #warning OComboBox is not fully functional with Qt2 347 #warning OComboBox is not fully functional with Qt2
345 #endif 348 #endif
346} 349}
347 350
348// Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001 351// Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001
349void OComboBox::deleteWordForward() 352void OComboBox::deleteWordForward()
350{ 353{
351 lineEdit()->cursorWordForward(TRUE); 354 lineEdit()->cursorWordForward(TRUE);
352 #if QT_VERSION > 290 355 #if QT_VERSION > 290
353 if ( lineEdit()->hasSelectedText() ) 356 if ( lineEdit()->hasSelectedText() )
354 #else 357 #else
355 if ( lineEdit()->hasMarkedText() ) 358 if ( lineEdit()->hasMarkedText() )
356 #endif 359 #endif
357 { 360 {
358 lineEdit()->del(); 361 lineEdit()->del();
359 } 362 }
360} 363}
361 364
362void OComboBox::deleteWordBack() 365void OComboBox::deleteWordBack()
363{ 366{
364 lineEdit()->cursorWordBackward(TRUE); 367 lineEdit()->cursorWordBackward(TRUE);
365 #if QT_VERSION > 290 368 #if QT_VERSION > 290
366 if ( lineEdit()->hasSelectedText() ) 369 if ( lineEdit()->hasSelectedText() )
367 #else 370 #else
368 if ( lineEdit()->hasMarkedText() ) 371 if ( lineEdit()->hasMarkedText() )
369 #endif 372 #endif
370 { 373 {
371 lineEdit()->del(); 374 lineEdit()->del();
372 } 375 }
373} 376}
374 377
375void OComboBox::setCurrentItem( const QString& item, bool insert, int index ) 378void OComboBox::setCurrentItem( const QString& item, bool insert, int index )
376{ 379{
377 int sel = -1; 380 int sel = -1;
378 for (int i = 0; i < count(); ++i) 381 for (int i = 0; i < count(); ++i)
379 if (text(i) == item) 382 if (text(i) == item)
380 { 383 {
381 sel = i; 384 sel = i;
382 break; 385 break;
383 } 386 }
384 if (sel == -1 && insert) 387 if (sel == -1 && insert)
385 { 388 {
386 insertItem(item, index); 389 insertItem(item, index);
387 if (index >= 0) 390 if (index >= 0)
388 sel = index; 391 sel = index;
389 else 392 else
390 sel = count() - 1; 393 sel = count() - 1;
391 } 394 }
392 setCurrentItem(sel); 395 setCurrentItem(sel);
393} 396}
394 397
395void OComboBox::setCurrentItem(int index) 398void OComboBox::setCurrentItem(int index)
396{ 399{
397 QComboBox::setCurrentItem(index); 400 QComboBox::setCurrentItem(index);
398} 401}
399 402
400 403
401/*====================================================================================== 404/*======================================================================================
402 * OHistoryCombo 405 * OHistoryCombo
403 *======================================================================================*/ 406 *======================================================================================*/
404 407
405// we are always read-write 408// we are always read-write
406OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name ) 409OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name )
407 : OComboBox( true, parent, name ) 410 : OComboBox( true, parent, name )
408{ 411{
409 init( true ); // using completion 412 init( true ); // using completion
410} 413}
411 414
412// we are always read-write 415// we are always read-write
413OHistoryCombo::OHistoryCombo( bool useCompletion, 416OHistoryCombo::OHistoryCombo( bool useCompletion,
414 QWidget *parent, const char *name ) 417 QWidget *parent, const char *name )
415 : OComboBox( true, parent, name ) 418 : OComboBox( true, parent, name )
416{ 419{
417 init( useCompletion ); 420 init( useCompletion );
418} 421}
419 422
420void OHistoryCombo::init( bool useCompletion ) 423void OHistoryCombo::init( bool useCompletion )
421{ 424{
422 if ( useCompletion ) 425 if ( useCompletion )
423 completionObject()->setOrder( OCompletion::Weighted ); 426 completionObject()->setOrder( OCompletion::Weighted );
424 427
425 setInsertionPolicy( NoInsertion ); 428 setInsertionPolicy( NoInsertion );
426 myIterateIndex = -1; 429 myIterateIndex = -1;
427 myRotated = false; 430 myRotated = false;
428 myPixProvider = 0L; 431 myPixProvider = 0L;
429 432
430 connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)), 433 connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)),
431 SLOT(addContextMenuItems(QPopupMenu*)) ); 434 SLOT(addContextMenuItems(QPopupMenu*)) );
432 connect( this, SIGNAL( activated(int) ), SLOT( slotReset() )); 435 connect( this, SIGNAL( activated(int) ), SLOT( slotReset() ));
433 connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset())); 436 connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset()));
434} 437}
435 438
436OHistoryCombo::~OHistoryCombo() 439OHistoryCombo::~OHistoryCombo()
437{ 440{
438 delete myPixProvider; 441 delete myPixProvider;
439} 442}
440 443
441void OHistoryCombo::setHistoryItems( QStringList items, 444void OHistoryCombo::setHistoryItems( QStringList items,
442 bool setCompletionList ) 445 bool setCompletionList )
443{ 446{
444 OComboBox::clear(); 447 OComboBox::clear();
445 448
446 // limit to maxCount() 449 // limit to maxCount()
447 while ( (int) items.count() > maxCount() && !items.isEmpty() ) 450 while ( (int) items.count() > maxCount() && !items.isEmpty() )
448 items.remove( items.begin() ); 451 items.remove( items.begin() );
449 452
450 insertItems( items ); 453 insertItems( items );
451 454
452 if ( setCompletionList && useCompletion() ) { 455 if ( setCompletionList && useCompletion() ) {
453 // we don't have any weighting information here ;( 456 // we don't have any weighting information here ;(
454 OCompletion *comp = completionObject(); 457 OCompletion *comp = completionObject();
455 comp->setOrder( OCompletion::Insertion ); 458 comp->setOrder( OCompletion::Insertion );
456 comp->setItems( items ); 459 comp->setItems( items );
457 comp->setOrder( OCompletion::Weighted ); 460 comp->setOrder( OCompletion::Weighted );
458 } 461 }
459 462
460 clearEdit(); 463 clearEdit();
461} 464}
462 465
463QStringList OHistoryCombo::historyItems() const 466QStringList OHistoryCombo::historyItems() const
464{ 467{
465 QStringList list; 468 QStringList list;
466 for ( int i = 0; i < count(); i++ ) 469 for ( int i = 0; i < count(); i++ )
467 list.append( text( i ) ); 470 list.append( text( i ) );
468 471
469 return list; 472 return list;
470} 473}
471 474
472void OHistoryCombo::clearHistory() 475void OHistoryCombo::clearHistory()
473{ 476{
474 OComboBox::clear(); 477 OComboBox::clear();
475 if ( useCompletion() ) 478 if ( useCompletion() )
476 completionObject()->clear(); 479 completionObject()->clear();
477} 480}
478 481
479void OHistoryCombo::addContextMenuItems( QPopupMenu* menu ) 482void OHistoryCombo::addContextMenuItems( QPopupMenu* menu )
480{ 483{
481 if ( menu &&!lineEdit()->text().isEmpty()) 484 if ( menu &&!lineEdit()->text().isEmpty())
482 { 485 {
483 menu->insertSeparator(); 486 menu->insertSeparator();
484 menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear())); 487 menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear()));
485 } 488 }
486} 489}
487 490
488void OHistoryCombo::addToHistory( const QString& item ) 491void OHistoryCombo::addToHistory( const QString& item )
489{ 492{
490 if ( item.isEmpty() || (count() > 0 && item == text(0) )) 493 if ( item.isEmpty() || (count() > 0 && item == text(0) ))
491 return; 494 return;
492 495
493 // remove all existing items before adding 496 // remove all existing items before adding
494 if ( !duplicatesEnabled() ) { 497 if ( !duplicatesEnabled() ) {
495 for ( int i = 0; i < count(); i++ ) { 498 for ( int i = 0; i < count(); i++ ) {
496 if ( text( i ) == item ) 499 if ( text( i ) == item )
497 removeItem( i ); 500 removeItem( i );
498 } 501 }
499 } 502 }
500 503
501 // now add the item 504 // now add the item
502 if ( myPixProvider ) 505 if ( myPixProvider )
503 //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0); 506 //insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0);
504 insertItem( myPixProvider->pixmapFor(item, 16), item, 0); 507 insertItem( myPixProvider->pixmapFor(item, 16), item, 0);
505 else 508 else
506 insertItem( item, 0 ); 509 insertItem( item, 0 );
507 510
508 int last; 511 int last;
509 QString rmItem; 512 QString rmItem;
510 513
511 bool useComp = useCompletion(); 514 bool useComp = useCompletion();
512 while ( count() > maxCount() && count() > 0 ) { 515 while ( count() > maxCount() && count() > 0 ) {
513 // 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()
514 // remove the removed item from the completionObject if it isn't 517 // remove the removed item from the completionObject if it isn't
515 // anymore available at all in the combobox. 518 // anymore available at all in the combobox.
516 last = count() - 1; 519 last = count() - 1;
517 rmItem = text( last ); 520 rmItem = text( last );
518 removeItem( last ); 521 removeItem( last );
519 if ( useComp && !contains( rmItem ) ) 522 if ( useComp && !contains( rmItem ) )
520 completionObject()->removeItem( rmItem ); 523 completionObject()->removeItem( rmItem );
521 } 524 }
522 525
523 if ( useComp ) 526 if ( useComp )
524 completionObject()->addItem( item ); 527 completionObject()->addItem( item );
525} 528}
526 529
527bool OHistoryCombo::removeFromHistory( const QString& item ) 530bool OHistoryCombo::removeFromHistory( const QString& item )
528{ 531{
529 if ( item.isEmpty() ) 532 if ( item.isEmpty() )
530 return false; 533 return false;
531 534
532 bool removed = false; 535 bool removed = false;
533 QString temp = currentText(); 536 QString temp = currentText();
534 for ( int i = 0; i < count(); i++ ) { 537 for ( int i = 0; i < count(); i++ ) {
535 while ( item == text( i ) ) { 538 while ( item == text( i ) ) {
536 removed = true; 539 removed = true;
537 removeItem( i ); 540 removeItem( i );
538 } 541 }
539 } 542 }
540 543
541 if ( removed && useCompletion() ) 544 if ( removed && useCompletion() )
542 completionObject()->removeItem( item ); 545 completionObject()->removeItem( item );
543 546
544 setEditText( temp ); 547 setEditText( temp );
545 return removed; 548 return removed;
546} 549}
547 550
548void OHistoryCombo::keyPressEvent( QKeyEvent *e ) 551void OHistoryCombo::keyPressEvent( QKeyEvent *e )
549{ 552{
550 // save the current text in the lineedit 553 // save the current text in the lineedit
551 if ( myIterateIndex == -1 ) 554 if ( myIterateIndex == -1 )
552 myText = currentText(); 555 myText = currentText();
553 556
554 // going up in the history, rotating when reaching QListBox::count() 557 // going up in the history, rotating when reaching QListBox::count()
555 //if ( OStdAccel::isEqual( e, OStdAccel::rotateUp() ) ) { 558 //if ( OStdAccel::isEqual( e, OStdAccel::rotateUp() ) ) {
556 if ( e->key() == Qt::Key_Up ) { 559 if ( e->key() == Qt::Key_Up ) {
557 myIterateIndex++; 560 myIterateIndex++;
558 561
559 // skip duplicates/empty items 562 // skip duplicates/empty items
560 while ( myIterateIndex < count()-1 && 563 while ( myIterateIndex < count()-1 &&
561 (currentText() == text( myIterateIndex ) || 564 (currentText() == text( myIterateIndex ) ||
562 text( myIterateIndex ).isEmpty()) ) 565 text( myIterateIndex ).isEmpty()) )
563 myIterateIndex++; 566 myIterateIndex++;
564 567
565 if ( myIterateIndex >= count() ) { 568 if ( myIterateIndex >= count() ) {
566 myRotated = true; 569 myRotated = true;
567 myIterateIndex = -1; 570 myIterateIndex = -1;
568 571
569 // 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
570 if ( myText == text(0) ) 573 if ( myText == text(0) )
571 myIterateIndex = 0; 574 myIterateIndex = 0;
572 575
573 setEditText( myText ); 576 setEditText( myText );
574 } 577 }
575 else 578 else
576 setEditText( text( myIterateIndex )); 579 setEditText( text( myIterateIndex ));
577 } 580 }
578 581
579 582
580 // 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
581 // the text that was in the lineedit before Up was called. 584 // the text that was in the lineedit before Up was called.
582 //else if ( OStdAccel::isEqual( e, OStdAccel::rotateDown() ) ) { 585 //else if ( OStdAccel::isEqual( e, OStdAccel::rotateDown() ) ) {
583 else if ( e->key() == Qt::Key_Down ) { 586 else if ( e->key() == Qt::Key_Down ) {
584 myIterateIndex--; 587 myIterateIndex--;
585 588
586 // skip duplicates/empty items 589 // skip duplicates/empty items
587 while ( myIterateIndex >= 0 && 590 while ( myIterateIndex >= 0 &&
588 (currentText() == text( myIterateIndex ) || 591 (currentText() == text( myIterateIndex ) ||
589 text( myIterateIndex ).isEmpty()) ) 592 text( myIterateIndex ).isEmpty()) )
590 myIterateIndex--; 593 myIterateIndex--;
591 594
592 595
593 if ( myIterateIndex < 0 ) { 596 if ( myIterateIndex < 0 ) {
594 if ( myRotated && myIterateIndex == -2 ) { 597 if ( myRotated && myIterateIndex == -2 ) {
595 myRotated = false; 598 myRotated = false;
596 myIterateIndex = count() - 1; 599 myIterateIndex = count() - 1;
597 setEditText( text(myIterateIndex) ); 600 setEditText( text(myIterateIndex) );
598 } 601 }
599 else { // bottom of history 602 else { // bottom of history
600 if ( myIterateIndex == -2 ) { 603 if ( myIterateIndex == -2 ) {
601 qDebug( "ONotifyClient is not implemented yet." ); 604 qDebug( "ONotifyClient is not implemented yet." );
602 //ONotifyClient::event( ONotifyClient::notification, 605 //ONotifyClient::event( ONotifyClient::notification,
603 // i18n("No further item in the history.")); 606 // i18n("No further item in the history."));
604 } 607 }
605 608
606 myIterateIndex = -1; 609 myIterateIndex = -1;
607 if ( currentText() != myText ) 610 if ( currentText() != myText )
608 setEditText( myText ); 611 setEditText( myText );
609 } 612 }
610 } 613 }
611 else 614 else
612 setEditText( text( myIterateIndex )); 615 setEditText( text( myIterateIndex ));
613 } 616 }
614 617
615 else 618 else
616 OComboBox::keyPressEvent( e ); 619 OComboBox::keyPressEvent( e );
617} 620}
618 621
619void OHistoryCombo::slotReset() 622void OHistoryCombo::slotReset()
620{ 623{
621 myIterateIndex = -1; 624 myIterateIndex = -1;
622 myRotated = false; 625 myRotated = false;
623} 626}
624 627
625 628
626void OHistoryCombo::setPixmapProvider( OPixmapProvider *prov ) 629void OHistoryCombo::setPixmapProvider( OPixmapProvider *prov )
627{ 630{
628 if ( myPixProvider == prov ) 631 if ( myPixProvider == prov )
629 return; 632 return;
630 633
631 delete myPixProvider; 634 delete myPixProvider;
632 myPixProvider = prov; 635 myPixProvider = prov;
633 636
634 // re-insert all the items with/without pixmap 637 // re-insert all the items with/without pixmap
635 // 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
636 // when using an editable combobox (what we do) 639 // when using an editable combobox (what we do)
637 if ( count() > 0 ) { 640 if ( count() > 0 ) {
638 QStringList items( historyItems() ); 641 QStringList items( historyItems() );
639 clear(); 642 clear();
640 insertItems( items ); 643 insertItems( items );
641 } 644 }
642} 645}
643 646
644void OHistoryCombo::insertItems( const QStringList& items ) 647void OHistoryCombo::insertItems( const QStringList& items )
645{ 648{
646 QStringList::ConstIterator it = items.begin(); 649 QStringList::ConstIterator it = items.begin();
647 QString item; 650 QString item;
648 while ( it != items.end() ) { 651 while ( it != items.end() ) {
649 item = *it; 652 item = *it;
650 if ( !item.isEmpty() ) { // only insert non-empty items 653 if ( !item.isEmpty() ) { // only insert non-empty items
651 if ( myPixProvider ) 654 if ( myPixProvider )
652 // insertItem( myPixProvider->pixmapFor(item, OIcon::SizeSmall), item ); 655 // insertItem( myPixProvider->pixmapFor(item, OIcon::SizeSmall), item );
653 insertItem( myPixProvider->pixmapFor(item, 16), item ); 656 insertItem( myPixProvider->pixmapFor(item, 16), item );
654 else 657 else
655 insertItem( item ); 658 insertItem( item );
656 } 659 }
657 ++it; 660 ++it;
658 } 661 }
659} 662}
660 663
661void OHistoryCombo::slotClear() 664void OHistoryCombo::slotClear()
662{ 665{
663 clearHistory(); 666 clearHistory();
664 emit cleared(); 667 emit cleared();
665} 668}
666 669
diff --git a/libopie2/qt3/opieui/oeditlistbox.cpp b/libopie2/qt3/opieui/oeditlistbox.cpp
index 3c53552..0e95274 100644
--- a/libopie2/qt3/opieui/oeditlistbox.cpp
+++ b/libopie2/qt3/opieui/oeditlistbox.cpp
@@ -30,387 +30,388 @@
30 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/ocombobox.h> 33#include <opie2/ocombobox.h>
34#include <opie2/odialog.h> 34#include <opie2/odialog.h>
35#include <opie2/olineedit.h> 35#include <opie2/olineedit.h>
36#include <opie2/oeditlistbox.h> 36#include <opie2/oeditlistbox.h>
37 37
38/* UNIX */ 38/* UNIX */
39 39
40#include <assert.h> 40#include <assert.h>
41 41
42/*====================================================================================== 42/*======================================================================================
43 * OEditListBoxPrivate 43 * OEditListBoxPrivate
44 *======================================================================================*/ 44 *======================================================================================*/
45 45
46class OEditListBoxPrivate 46class OEditListBoxPrivate
47{ 47{
48public: 48public:
49 bool m_checkAtEntering; 49 bool m_checkAtEntering;
50 int buttons; 50 int buttons;
51}; 51};
52 52
53/*====================================================================================== 53/*======================================================================================
54 * OEditListBox 54 * OEditListBox
55 *======================================================================================*/ 55 *======================================================================================*/
56 56
57OEditListBox::OEditListBox(QWidget *parent, const char *name, 57OEditListBox::OEditListBox(QWidget *parent, const char *name,
58 bool checkAtEntering, int buttons ) 58 bool checkAtEntering, int buttons )
59 :QGroupBox(parent, name ) 59 :QGroupBox(parent, name )
60{ 60{
61 init( checkAtEntering, buttons ); 61 init( checkAtEntering, buttons );
62} 62}
63 63
64OEditListBox::OEditListBox(const QString& title, QWidget *parent, 64OEditListBox::OEditListBox(const QString& title, QWidget *parent,
65 const char *name, bool checkAtEntering, int buttons) 65 const char *name, bool checkAtEntering, int buttons)
66 :QGroupBox(title, parent, name ) 66 :QGroupBox(title, parent, name )
67{ 67{
68 init( checkAtEntering, buttons ); 68 init( checkAtEntering, buttons );
69} 69}
70 70
71OEditListBox::OEditListBox(const QString& title, const CustomEditor& custom, 71OEditListBox::OEditListBox(const QString& title, const CustomEditor& custom,
72 QWidget *parent, const char *name, 72 QWidget *parent, const char *name,
73 bool checkAtEntering, int buttons) 73 bool checkAtEntering, int buttons)
74 :QGroupBox(title, parent, name ) 74 :QGroupBox(title, parent, name )
75{ 75{
76 m_lineEdit = custom.lineEdit(); 76 m_lineEdit = custom.lineEdit();
77 init( checkAtEntering, buttons, custom.representationWidget() ); 77 init( checkAtEntering, buttons, custom.representationWidget() );
78} 78}
79 79
80OEditListBox::~OEditListBox() 80OEditListBox::~OEditListBox()
81{ 81{
82 delete d; 82 delete d;
83 d=0; 83 d=0;
84} 84}
85 85
86void OEditListBox::init( bool checkAtEntering, int buttons, 86void OEditListBox::init( bool checkAtEntering, int buttons,
87 QWidget *representationWidget ) 87 QWidget *representationWidget )
88{ 88{
89 d=new OEditListBoxPrivate; 89 d=new OEditListBoxPrivate;
90 d->m_checkAtEntering=checkAtEntering; 90 d->m_checkAtEntering=checkAtEntering;
91 d->buttons = buttons; 91 d->buttons = buttons;
92 92
93 int lostButtons = 0; 93 int lostButtons = 0;
94 if ( (buttons & Add) == 0 ) 94 if ( (buttons & Add) == 0 )
95 lostButtons++; 95 lostButtons++;
96 if ( (buttons & Remove) == 0 ) 96 if ( (buttons & Remove) == 0 )
97 lostButtons++; 97 lostButtons++;
98 if ( (buttons & UpDown) == 0 ) 98 if ( (buttons & UpDown) == 0 )
99 lostButtons += 2; 99 lostButtons += 2;
100 100
101 101
102 servNewButton = servRemoveButton = servUpButton = servDownButton = 0L; 102 servNewButton = servRemoveButton = servUpButton = servDownButton = 0L;
103 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, 103 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,
104 QSizePolicy::MinimumExpanding)); 104 QSizePolicy::MinimumExpanding));
105 105
106 QWidget * gb = this; 106 QWidget * gb = this;
107 QGridLayout * grid = new QGridLayout(gb, 7 - lostButtons, 2, 107 QGridLayout * grid = new QGridLayout(gb, 7 - lostButtons, 2,
108 ODialog::marginHint(), 108 ODialog::marginHint(),
109 ODialog::spacingHint()); 109 ODialog::spacingHint());
110 grid->addRowSpacing(0, fontMetrics().lineSpacing()); 110 grid->addRowSpacing(0, fontMetrics().lineSpacing());
111 for ( int i = 1; i < 7 - lostButtons; i++ ) 111 for ( int i = 1; i < 7 - lostButtons; i++ )
112 grid->setRowStretch(i, 1); 112 grid->setRowStretch(i, 1);
113 113
114 grid->setMargin(15); 114 grid->setMargin(15);
115 115
116 if ( representationWidget ) 116 if ( representationWidget )
117 representationWidget->reparent( gb, QPoint(0,0) ); 117 representationWidget->reparent( gb, QPoint(0,0) );
118 else 118 else
119 m_lineEdit=new OLineEdit(gb); 119 m_lineEdit=new OLineEdit(gb);
120 120
121 m_listBox = new QListBox(gb); 121 m_listBox = new QListBox(gb);
122 122
123 QWidget *editingWidget = representationWidget ? 123 QWidget *editingWidget = representationWidget ?
124 representationWidget : m_lineEdit; 124 representationWidget : m_lineEdit;
125 grid->addMultiCellWidget(editingWidget,1,1,0,1); 125 grid->addMultiCellWidget(editingWidget,1,1,0,1);
126 grid->addMultiCellWidget(m_listBox, 2, 6 - lostButtons, 0, 0); 126 grid->addMultiCellWidget(m_listBox, 2, 6 - lostButtons, 0, 0);
127 int row = 2; 127 int row = 2;
128 if ( buttons & Add ) { 128 if ( buttons & Add ) {
129 servNewButton = new QPushButton(tr("&Add"), gb); 129 servNewButton = new QPushButton(tr("&Add"), gb);
130 servNewButton->setEnabled(false); 130 servNewButton->setEnabled(false);
131 connect(servNewButton, SIGNAL(clicked()), SLOT(addItem())); 131 connect(servNewButton, SIGNAL(clicked()), SLOT(addItem()));
132 132
133 grid->addWidget(servNewButton, row++, 1); 133 grid->addWidget(servNewButton, row++, 1);
134 } 134 }
135 135
136 if ( buttons & Remove ) { 136 if ( buttons & Remove ) {
137 servRemoveButton = new QPushButton(tr("&Remove"), gb); 137 servRemoveButton = new QPushButton(tr("&Remove"), gb);
138 servRemoveButton->setEnabled(false); 138 servRemoveButton->setEnabled(false);
139 connect(servRemoveButton, SIGNAL(clicked()), SLOT(removeItem())); 139 connect(servRemoveButton, SIGNAL(clicked()), SLOT(removeItem()));
140 140
141 grid->addWidget(servRemoveButton, row++, 1); 141 grid->addWidget(servRemoveButton, row++, 1);
142 } 142 }
143 143
144 if ( buttons & UpDown ) { 144 if ( buttons & UpDown ) {
145 servUpButton = new QPushButton(tr("Move &Up"), gb); 145 servUpButton = new QPushButton(tr("Move &Up"), gb);
146 servUpButton->setEnabled(false); 146 servUpButton->setEnabled(false);
147 connect(servUpButton, SIGNAL(clicked()), SLOT(moveItemUp())); 147 connect(servUpButton, SIGNAL(clicked()), SLOT(moveItemUp()));
148 148
149 servDownButton = new QPushButton(tr("Move &Down"), gb); 149 servDownButton = new QPushButton(tr("Move &Down"), gb);
150 servDownButton->setEnabled(false); 150 servDownButton->setEnabled(false);
151 connect(servDownButton, SIGNAL(clicked()), SLOT(moveItemDown())); 151 connect(servDownButton, SIGNAL(clicked()), SLOT(moveItemDown()));
152 152
153 grid->addWidget(servUpButton, row++, 1); 153 grid->addWidget(servUpButton, row++, 1);
154 grid->addWidget(servDownButton, row++, 1); 154 grid->addWidget(servDownButton, row++, 1);
155 } 155 }
156 156
157 connect(m_lineEdit,SIGNAL(textChanged(const QString&)),this,SLOT(typedSomething(const QString&))); 157 connect(m_lineEdit,SIGNAL(textChanged(const QString&)),this,SLOT(typedSomething(const QString&)));
158 m_lineEdit->setTrapReturnKey(true); 158 m_lineEdit->setTrapReturnKey(true);
159 connect(m_lineEdit,SIGNAL(returnPressed()),this,SLOT(addItem())); 159 connect(m_lineEdit,SIGNAL(returnPressed()),this,SLOT(addItem()));
160 connect(m_listBox, SIGNAL(highlighted(int)), SLOT(enableMoveButtons(int))); 160 connect(m_listBox, SIGNAL(highlighted(int)), SLOT(enableMoveButtons(int)));
161 161
162 // maybe supplied lineedit has some text already 162 // maybe supplied lineedit has some text already
163 typedSomething( m_lineEdit->text() ); 163 typedSomething( m_lineEdit->text() );
164} 164}
165 165
166void OEditListBox::typedSomething(const QString& text) 166void OEditListBox::typedSomething(const QString& text)
167{ 167{
168 if(currentItem() >= 0) { 168 if(currentItem() >= 0) {
169 if(currentText() != m_lineEdit->text()) 169 if(currentText() != m_lineEdit->text())
170 { 170 {
171 // IMHO changeItem() shouldn't do anything with the value 171 // IMHO changeItem() shouldn't do anything with the value
172 // of currentItem() ... like changing it or emitting signals ... 172 // of currentItem() ... like changing it or emitting signals ...
173 // but TT disagree with me on this one (it's been that way since ages ... grrr) 173 // but TT disagree with me on this one (it's been that way since ages ... grrr)
174 bool block = m_listBox->signalsBlocked(); 174 bool block = m_listBox->signalsBlocked();
175 m_listBox->blockSignals( true ); 175 m_listBox->blockSignals( true );
176 m_listBox->changeItem(text, currentItem()); 176 m_listBox->changeItem(text, currentItem());
177 m_listBox->blockSignals( block ); 177 m_listBox->blockSignals( block );
178 emit changed(); 178 emit changed();
179 } 179 }
180 } 180 }
181 181
182 if ( !servNewButton ) 182 if ( !servNewButton )
183 return; 183 return;
184 184
185 if (!d->m_checkAtEntering) 185 if (!d->m_checkAtEntering)
186 servNewButton->setEnabled(!text.isEmpty()); 186 servNewButton->setEnabled(!text.isEmpty());
187 else 187 else
188 { 188 {
189 if (text.isEmpty()) 189 if (text.isEmpty())
190 { 190 {
191 servNewButton->setEnabled(false); 191 servNewButton->setEnabled(false);
192 } 192 }
193 else 193 else
194 { 194 {
195 #if QT_VERSION > 290 195 #if QT_VERSION > 290
196 StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive ); 196 StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive );
197 bool enable = (m_listBox->findItem( text, mode ) == 0L); 197 bool enable = (m_listBox->findItem( text, mode ) == 0L);
198 #else 198 #else
199 bool enable = (m_listBox->findItem( text ) == 0L); 199 bool enable = (m_listBox->findItem( text ) == 0L);
200 #endif 200 #endif
201 servNewButton->setEnabled( enable ); 201 servNewButton->setEnabled( enable );
202 } 202 }
203 } 203 }
204} 204}
205 205
206void OEditListBox::moveItemUp() 206void OEditListBox::moveItemUp()
207{ 207{
208 if (!m_listBox->isEnabled()) 208 if (!m_listBox->isEnabled())
209 { 209 {
210 //ONotifyClient::beep(); 210 //ONotifyClient::beep();
211 return; 211 return;
212 } 212 }
213 213
214 unsigned int selIndex = m_listBox->currentItem(); 214 unsigned int selIndex = m_listBox->currentItem();
215 if (selIndex == 0) 215 if (selIndex == 0)
216 { 216 {
217 //ONotifyClient::beep(); 217 //ONotifyClient::beep();
218 return; 218 return;
219 } 219 }
220 220
221 QListBoxItem *selItem = m_listBox->item(selIndex); 221 QListBoxItem *selItem = m_listBox->item(selIndex);
222 m_listBox->takeItem(selItem); 222 m_listBox->takeItem(selItem);
223 m_listBox->insertItem(selItem, selIndex-1); 223 m_listBox->insertItem(selItem, selIndex-1);
224 m_listBox->setCurrentItem(selIndex - 1); 224 m_listBox->setCurrentItem(selIndex - 1);
225 225
226 emit changed(); 226 emit changed();
227} 227}
228 228
229void OEditListBox::moveItemDown() 229void OEditListBox::moveItemDown()
230{ 230{
231 if (!m_listBox->isEnabled()) 231 if (!m_listBox->isEnabled())
232 { 232 {
233 //ONotifyClient::beep(); 233 //ONotifyClient::beep();
234 return; 234 return;
235 } 235 }
236 236
237 unsigned int selIndex = m_listBox->currentItem(); 237 unsigned int selIndex = m_listBox->currentItem();
238 if (selIndex == m_listBox->count() - 1) 238 if (selIndex == m_listBox->count() - 1)
239 { 239 {
240 //ONotifyClient::beep(); 240 //ONotifyClient::beep();
241 return; 241 return;
242 } 242 }
243 243
244 QListBoxItem *selItem = m_listBox->item(selIndex); 244 QListBoxItem *selItem = m_listBox->item(selIndex);
245 m_listBox->takeItem(selItem); 245 m_listBox->takeItem(selItem);
246 m_listBox->insertItem(selItem, selIndex+1); 246 m_listBox->insertItem(selItem, selIndex+1);
247 m_listBox->setCurrentItem(selIndex + 1); 247 m_listBox->setCurrentItem(selIndex + 1);
248 248
249 emit changed(); 249 emit changed();
250} 250}
251 251
252void OEditListBox::addItem() 252void OEditListBox::addItem()
253{ 253{
254 // when m_checkAtEntering is true, the add-button is disabled, but this 254 // when m_checkAtEntering is true, the add-button is disabled, but this
255 // slot can still be called through Key_Return/Key_Enter. So we guard 255 // slot can still be called through Key_Return/Key_Enter. So we guard
256 // against this. 256 // against this.
257 if ( !servNewButton || !servNewButton->isEnabled() ) 257 if ( !servNewButton || !servNewButton->isEnabled() )
258 return; 258 return;
259 259
260 const QString& currentTextLE=m_lineEdit->text(); 260 const QString& currentTextLE=m_lineEdit->text();
261 bool alreadyInList(false); 261 bool alreadyInList(false);
262 //if we didn't check for dupes at the inserting we have to do it now 262 //if we didn't check for dupes at the inserting we have to do it now
263 if (!d->m_checkAtEntering) 263 if (!d->m_checkAtEntering)
264 { 264 {
265 // first check current item instead of dumb iterating the entire list 265 // first check current item instead of dumb iterating the entire list
266 if ( m_listBox->currentText() == currentTextLE ) 266 if ( m_listBox->currentText() == currentTextLE )
267 alreadyInList = true; 267 alreadyInList = true;
268 else 268 else
269 { 269 {
270 #if QT_VERSION > 290 270 #if QT_VERSION > 290
271 StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive ); 271 StringComparisonMode mode = (StringComparisonMode) (ExactMatch | CaseSensitive );
272 alreadyInList =(m_listBox->findItem(currentTextLE, mode) != 0); 272 alreadyInList =(m_listBox->findItem(currentTextLE, mode) != 0);
273 #else 273 #else
274 alreadyInList =(m_listBox->findItem(currentTextLE) != 0); 274 alreadyInList =(m_listBox->findItem(currentTextLE) != 0);
275 #endif 275 #endif
276 } 276 }
277 } 277 }
278 278
279 if ( servNewButton ) 279 if ( servNewButton )
280 servNewButton->setEnabled(false); 280 servNewButton->setEnabled(false);
281 281
282 bool block = m_lineEdit->signalsBlocked(); 282 bool block = m_lineEdit->signalsBlocked();
283 m_lineEdit->blockSignals(true); 283 m_lineEdit->blockSignals(true);
284 m_lineEdit->clear(); 284 m_lineEdit->clear();
285 m_lineEdit->blockSignals(block); 285 m_lineEdit->blockSignals(block);
286 286
287 m_listBox->setSelected(currentItem(), false); 287 m_listBox->setSelected(currentItem(), false);
288 288
289 if (!alreadyInList) 289 if (!alreadyInList)
290 { 290 {
291 block = m_listBox->signalsBlocked(); 291 block = m_listBox->signalsBlocked();
292 m_listBox->blockSignals( true ); 292 m_listBox->blockSignals( true );
293 m_listBox->insertItem(currentTextLE); 293 m_listBox->insertItem(currentTextLE);
294 m_listBox->blockSignals( block ); 294 m_listBox->blockSignals( block );
295 emit changed(); 295 emit changed();
296 emit added( currentTextLE ); 296 emit added( currentTextLE );
297 } 297 }
298} 298}
299 299
300int OEditListBox::currentItem() const 300int OEditListBox::currentItem() const
301{ 301{
302 int nr = m_listBox->currentItem(); 302 int nr = m_listBox->currentItem();
303 #if QT_VERSION > 290 303 #if QT_VERSION > 290
304 if(nr >= 0 && !m_listBox->item(nr)->isSelected()) return -1; 304 if(nr >= 0 && !m_listBox->item(nr)->isSelected()) return -1;
305 #else 305 #else
306 if(nr >= 0 && !m_listBox->isSelected(m_listBox->item(nr))) return -1; 306 if(nr >= 0 && !m_listBox->isSelected(m_listBox->item(nr))) return -1;
307 #endif 307 #endif
308 return nr; 308 return nr;
309} 309}
310 310
311void OEditListBox::removeItem() 311void OEditListBox::removeItem()
312{ 312{
313 int selected = m_listBox->currentItem(); 313 int selected = m_listBox->currentItem();
314 314
315 if ( selected >= 0 ) 315 if ( selected >= 0 )
316 { 316 {
317 QString removedText = m_listBox->currentText(); 317 QString removedText = m_listBox->currentText();
318 318
319 m_listBox->removeItem( selected ); 319 m_listBox->removeItem( selected );
320 if ( count() > 0 ) 320 if ( count() > 0 )
321 m_listBox->setSelected( QMIN( selected, count() - 1 ), true ); 321 m_listBox->setSelected( QMIN( selected, count() - 1 ), true );
322 322
323 emit changed(); 323 emit changed();
324 emit removed( removedText ); 324 emit removed( removedText );
325 } 325 }
326 326
327 if ( servRemoveButton && m_listBox->currentItem() == -1 ) 327 if ( servRemoveButton && m_listBox->currentItem() == -1 )
328 servRemoveButton->setEnabled(false); 328 servRemoveButton->setEnabled(false);
329} 329}
330 330
331void OEditListBox::enableMoveButtons(int index) 331void OEditListBox::enableMoveButtons(int index)
332{ 332{
333 // Update the lineEdit when we select a different line. 333 // Update the lineEdit when we select a different line.
334 if(currentText() != m_lineEdit->text()) 334 if(currentText() != m_lineEdit->text())
335 m_lineEdit->setText(currentText()); 335 m_lineEdit->setText(currentText());
336 336
337 bool moveEnabled = servUpButton && servDownButton; 337 bool moveEnabled = servUpButton && servDownButton;
338 338
339 if (moveEnabled ) 339 if (moveEnabled )
340 { 340 {
341 if (m_listBox->count() <= 1) 341 if (m_listBox->count() <= 1)
342 { 342 {
343 servUpButton->setEnabled(false); 343 servUpButton->setEnabled(false);
344 servDownButton->setEnabled(false); 344 servDownButton->setEnabled(false);
345 } 345 }
346 else if ((uint) index == (m_listBox->count() - 1)) 346 else if ((uint) index == (m_listBox->count() - 1))
347 { 347 {
348 servUpButton->setEnabled(true); 348 servUpButton->setEnabled(true);
349 servDownButton->setEnabled(false); 349 servDownButton->setEnabled(false);
350 } 350 }
351 else if (index == 0) 351 else if (index == 0)
352 { 352 {
353 servUpButton->setEnabled(false); 353 servUpButton->setEnabled(false);
354 servDownButton->setEnabled(true); 354 servDownButton->setEnabled(true);
355 } 355 }
356 else 356 else
357 { 357 {
358 servUpButton->setEnabled(true); 358 servUpButton->setEnabled(true);
359 servDownButton->setEnabled(true); 359 servDownButton->setEnabled(true);
360 } 360 }
361 } 361 }
362 362
363 if ( servRemoveButton ) 363 if ( servRemoveButton )
364 servRemoveButton->setEnabled(true); 364 servRemoveButton->setEnabled(true);
365} 365}
366 366
367void OEditListBox::clear() 367void OEditListBox::clear()
368{ 368{
369 m_lineEdit->clear(); 369 m_lineEdit->clear();
370 m_listBox->clear(); 370 m_listBox->clear();
371 emit changed(); 371 emit changed();
372} 372}
373 373
374void OEditListBox::insertStringList(const QStringList& list, int index) 374void OEditListBox::insertStringList(const QStringList& list, int index)
375{ 375{
376 m_listBox->insertStringList(list,index); 376 m_listBox->insertStringList(list,index);
377} 377}
378 378
379void OEditListBox::insertStrList(const QStrList* list, int index) 379void OEditListBox::insertStrList(const QStrList* list, int index)
380{ 380{
381 m_listBox->insertStrList(list,index); 381 m_listBox->insertStrList(list,index);
382} 382}
383 383
384void OEditListBox::insertStrList(const QStrList& list, int index) 384void OEditListBox::insertStrList(const QStrList& list, int index)
385{ 385{
386 m_listBox->insertStrList(list,index); 386 m_listBox->insertStrList(list,index);
387} 387}
388 388
389void OEditListBox::insertStrList(const char ** list, int numStrings, int index) 389void OEditListBox::insertStrList(const char ** list, int numStrings, int index)
390{ 390{
391 m_listBox->insertStrList(list,numStrings,index); 391 m_listBox->insertStrList(list,numStrings,index);
392} 392}
393 393
394QStringList OEditListBox::items() const 394QStringList OEditListBox::items() const
395{ 395{
396 QStringList list; 396 QStringList list;
397 for ( uint i = 0; i < m_listBox->count(); i++ ) 397 for ( uint i = 0; i < m_listBox->count(); i++ )
398 list.append( m_listBox->text( i )); 398 list.append( m_listBox->text( i ));
399 399
400 return list; 400 return list;
401} 401}
402 402
403void OEditListBox::virtual_hook( int, void* ) 403void OEditListBox::virtual_hook( int, void* )
404{ /*BASE::virtual_hook( id, data );*/ } 404{ /*BASE::virtual_hook( id, data );*/ }
405 405
406 406
407/*====================================================================================== 407/*======================================================================================
408 * CustomEditor 408 * CustomEditor
409 *======================================================================================*/ 409 *======================================================================================*/
410 410
411OEditListBox::CustomEditor::CustomEditor( OComboBox *combo ) 411OEditListBox::CustomEditor::CustomEditor( OComboBox *combo )
412{ 412{
413 m_representationWidget = combo; 413 m_representationWidget = combo;
414 m_lineEdit = dynamic_cast<OLineEdit*>( combo->lineEdit() ); 414 assert( combo->lineEdit()->inherits( "OLineEdit" ) );
415 assert( m_lineEdit ); 415 m_lineEdit = static_cast<OLineEdit*>( combo->lineEdit() );
416
416} 417}