23 #include <tqclipboard.h>
24 #include <tqlistbox.h>
25 #include <tqpopupmenu.h>
26 #include <tqapplication.h>
28 #include <tdecompletionbox.h>
30 #include <kiconloader.h>
31 #include <kicontheme.h>
32 #include <tdelistviewsearchline.h>
33 #include <klineedit.h>
35 #include <knotifyclient.h>
36 #include <kpixmapprovider.h>
37 #include <tdestdaccel.h>
43 #include "kcombobox.h"
47 class KComboBox::KComboBoxPrivate
50 KComboBoxPrivate() : klineEdit(0L)
61 : TQComboBox( parent, name ), d(new KComboBoxPrivate)
67 : TQComboBox( rw, parent, name ), d(new KComboBoxPrivate)
83 void KComboBox::init()
86 TQComboBox::setAutoCompletion(
false );
96 if ( _text.isEmpty() )
99 const int itemCount = count();
100 for (
int i = 0; i < itemCount; ++i )
102 if ( text(i) == _text )
128 d->klineEdit->setContextMenuEnabled( showMenu );
135 d->klineEdit->setURLDropsEnabled( enable );
140 return d->klineEdit && d->klineEdit->isURLDropsEnabled();
147 d->klineEdit->setCompletedText( text, marked );
153 d->klineEdit->setCompletedText( text );
159 d->klineEdit->makeCompletion( text );
163 if( text.isNull() || !listBox() )
166 const int index = listBox()->index( listBox()->findItem( text ) );
175 d->klineEdit->rotateText( type );
181 return TQComboBox::eventFilter( o, ev );
187 d->klineEdit->setTrapReturnKey( grab );
189 tqWarning(
"KComboBox::setTrapReturnKey not supported with a non-KLineEdit.");
194 return d->klineEdit && d->klineEdit->trapReturnKey();
200 TQComboBox::setEditText( url.
prettyURL() );
205 TQComboBox::insertItem( url.
prettyURL(), index );
210 TQComboBox::insertItem( pixmap, url.
prettyURL(), index );
215 TQComboBox::changeItem( url.
prettyURL(), index );
220 TQComboBox::changeItem( pixmap, url.
prettyURL(), index );
226 d->klineEdit->setCompletedItems( items );
232 return d->klineEdit->completionBox(
create );
239 TQComboBox::create(
id, initializeWindow, destroyOldWindow );
243 void KComboBox::wheelEvent( TQWheelEvent *ev )
246 TQComboBox::wheelEvent( ev );
251 if ( !editable() && edit &&
252 !qstrcmp( edit->className(),
"TQLineEdit" ) )
260 edit =
new KLineEdit(
this,
"combo edit" );
263 TQComboBox::setLineEdit( edit );
264 d->klineEdit =
dynamic_cast<KLineEdit*
>( edit );
277 connect( edit, TQ_SIGNAL( destroyed() ), TQ_SLOT( lineEditDeleted() ));
279 connect( d->klineEdit, TQ_SIGNAL(
returnPressed(
const TQString& )),
282 connect( d->klineEdit, TQ_SIGNAL(
completion(
const TQString& )),
288 connect( d->klineEdit,
292 connect( d->klineEdit,
296 connect( d->klineEdit,
300 connect( d->klineEdit,
301 TQ_SIGNAL( completionBoxActivated(
const TQString& )),
302 TQ_SIGNAL( activated(
const TQString& )) );
310 const int itemCount = count();
311 for (
int i = 0; i < itemCount; ++i)
320 if (sel == -1 && insert)
322 insertItem(item, index);
331 void KComboBox::lineEditDeleted()
347 class KHistoryCombo::KHistoryComboPrivate
350 KHistoryComboPrivate() : bHistoryEditorEnabled(false)
353 ~KHistoryComboPrivate()
357 bool bHistoryEditorEnabled;
362 :
KComboBox( true, parent, name ), d(new KHistoryComboPrivate)
369 TQWidget *parent,
const char *name )
370 :
KComboBox( true, parent, name ), d(new KHistoryComboPrivate)
375 void KHistoryCombo::init(
bool useCompletion )
383 setInsertionPolicy( NoInsertion );
389 TQCString histControl = getenv(
"HISTCONTROL");
390 if ( histControl ==
"ignoredups" || histControl ==
"ignoreboth" )
391 setDuplicatesEnabled(
false );
394 TQ_SLOT(addContextMenuItems(TQPopupMenu*)) );
395 connect(
this, TQ_SIGNAL( activated(
int) ), TQ_SLOT( slotReset() ));
396 connect(
this, TQ_SIGNAL(
returnPressed(
const TQString&) ), TQ_SLOT(slotReset()));
401 delete myPixProvider;
405 bool setCompletionList )
410 const int itemCount = items.count();
411 const int toRemove = itemCount - maxCount();
413 if (toRemove >= itemCount) {
416 for (
int i = 0; i < toRemove; ++i)
436 const int itemCount = count();
437 for (
int i = 0; i < itemCount; ++i )
438 list.append( text( i ) );
445 const TQString temp = currentText();
452 void KHistoryCombo::addContextMenuItems( TQPopupMenu* menu )
456 menu->insertSeparator();
457 if (d->bHistoryEditorEnabled) {
458 int idedit = menu->insertItem( SmallIconSet(
"edit"), i18n(
"&Edit History..."),
this, TQ_SLOT( slotEdit()) );
459 menu->setItemEnabled(idedit, count());
461 int id = menu->insertItem( SmallIconSet(
"history_clear"), i18n(
"Clear &History"),
this, TQ_SLOT( slotClear()));
463 menu->setItemEnabled(
id,
false);
469 if ( item.isEmpty() || (count() > 0 && item == text(0) )) {
473 bool wasCurrent =
false;
475 if ( !duplicatesEnabled() ) {
477 int itemCount = count();
478 while ( i < itemCount ) {
479 if ( text( i ) == item ) {
481 wasCurrent = ( i == currentItem() );
494 insertItem( item, 0 );
501 const int last = count() - 1;
502 const int mc = maxCount();
503 const int stopAt = TQMAX(mc, 0);
505 for (
int rmIndex = last; rmIndex >= stopAt; --rmIndex) {
509 const TQString rmItem = text( rmIndex );
510 removeItem( rmIndex );
511 if ( useComp && !
contains( rmItem ) )
521 if ( item.isEmpty() )
524 bool removed =
false;
525 const TQString temp = currentText();
527 int itemCount = count();
528 while ( i < itemCount ) {
529 if ( item == text( i ) ) {
545 void KHistoryCombo::rotateUp()
548 if ( myIterateIndex == -1 )
549 myText = currentText();
554 const int last = count() - 1;
555 const TQString currText = currentText();
557 while ( myIterateIndex < last &&
558 (currText == text( myIterateIndex ) ||
559 text( myIterateIndex ).isEmpty()) )
562 if ( myIterateIndex >= count() ) {
567 if ( count() > 0 && myText == text(0) )
570 setEditText( myText );
573 setEditText( text( myIterateIndex ));
576 void KHistoryCombo::rotateDown()
579 if ( myIterateIndex == -1 )
580 myText = currentText();
584 const TQString currText = currentText();
586 while ( myIterateIndex >= 0 &&
587 (currText == text( myIterateIndex ) ||
588 text( myIterateIndex ).isEmpty()) )
592 if ( myIterateIndex < 0 ) {
593 if ( myRotated && myIterateIndex == -2 ) {
595 myIterateIndex = count() - 1;
596 setEditText( text(myIterateIndex) );
599 if ( myIterateIndex == -2 ) {
601 i18n(
"No further item in the history."));
605 if ( currentText() != myText )
606 setEditText( myText );
610 setEditText( text( myIterateIndex ));
627 KComboBox::keyPressEvent( e );
633 TQListBox*
const lb = listBox();
634 if ( lb && lb->isVisible() )
636 TQApplication::sendEvent( lb, ev );
640 if ( ev->delta() > 0 ) {
648 void KHistoryCombo::slotReset()
657 if ( myPixProvider == prov )
660 delete myPixProvider;
661 myPixProvider = prov;
675 TQStringList::ConstIterator it = items.constBegin();
676 const TQStringList::ConstIterator itEnd = items.constEnd();
678 while ( it != itEnd ) {
679 const TQString item = *it;
680 if ( !item.isEmpty() ) {
691 void KHistoryCombo::slotClear()
697 void KHistoryCombo::slotEdit()
700 connect( &dlg, TQ_SIGNAL(
removeFromHistory(
const TQString&) ), TQ_SLOT( slotRemoveFromHistory(
const TQString&)) );
704 void KHistoryCombo::slotRemoveFromHistory(
const TQString &entry)
712 d->bHistoryEditorEnabled = enable;
715 bool KHistoryCombo::isHistoryEditorEnabled()
const
717 return d->bHistoryEditorEnabled;
720 void KComboBox::virtual_hook(
int id,
void* data )
721 { TDECompletionBase::virtual_hook(
id, data ); }
723 void KHistoryCombo::virtual_hook(
int id,
void* data )
724 { KComboBox::virtual_hook(
id, data ); }
726 void KHistoryComboEditor::virtual_hook(
int id,
void* data )
727 { KDialogBase::virtual_hook(
id, data ); }
729 KHistoryComboEditor::KHistoryComboEditor(
const TQStringList& entries, TQWidget *parent )
730 :
KDialogBase( parent,
"khistorycomboeditor", true, i18n(
"History Editor" ),
732 KGuiItem( i18n(
"&Delete Entry" ),
"edit-delete") ), d(0)
734 TQVBox* box =
new TQVBox(
this );
736 setMainWidget( box );
738 new TQLabel( i18n(
"This dialog allows you to delete unwanted history items." ), box );
741 TQHBox* searchbox =
new TQHBox( box );
744 TQToolButton *clearSearch =
new TQToolButton(searchbox);
745 clearSearch->setTextLabel(i18n(
"Clear Search"),
true);
746 clearSearch->setIconSet(SmallIconSet(TQApplication::reverseLayout() ?
"clear_left" :
"locationbar_erase"));
747 TQLabel* slbl =
new TQLabel(i18n(
"&Search:"), searchbox);
749 slbl->setBuddy(listViewSearch);
750 connect(clearSearch, TQ_SIGNAL(pressed()), listViewSearch, TQ_SLOT(
clear()));
755 m_pListView->setAllColumnsShowFocus(
true);
756 m_pListView->header()->hide();
757 m_pListView->addColumn(
"");
758 m_pListView->setRenameable( 0 );
760 box->setStretchFactor( m_pListView, 1 );
762 TQStringList newlist = entries;
763 for ( TQStringList::Iterator it = newlist.begin(); it != newlist.end(); ++it ) {
764 new TQListViewItem( m_pListView, *it );
767 m_pListView->setMinimumSize( m_pListView->sizeHint() );
769 connect( m_pListView, TQ_SIGNAL( selectionChanged( TQListViewItem * ) ),
770 this, TQ_SLOT( slotSelectionChanged( TQListViewItem * ) ) );
774 resize( sizeHint() );
777 KHistoryComboEditor::~KHistoryComboEditor()
781 void KHistoryComboEditor::slotUser1()
783 TQListViewItem *item = m_pListView->selectedItem();
786 emit removeFromHistory( item->text(0) );
787 m_pListView->takeItem( item );
792 void KHistoryComboEditor::slotSelectionChanged( TQListViewItem * item )
797 #include "kcombobox.moc"
void setEditURL(const KURL &url)
Sets url into the edit field of the combobox.
void completionModeChanged(TDEGlobalSettings::Completion)
Emitted whenever the completion mode is changed by the user through the context menu.
void aboutToShowContextMenu(TQPopupMenu *p)
Emitted before the context menu is displayed.
void setCurrentItem(const TQString &item, bool insert=false, int index=-1)
Selects the first item that matches item.
bool isURLDropsEnabled() const
Returns true when decoded URL drops are enabled.
void insertURL(const KURL &url, int index=-1)
Inserts url at position index into the combobox.
void textRotation(TDECompletionBase::KeyBindingType)
Emitted when the text rotation key-bindings are pressed.
virtual ~KComboBox()
Destructor.
virtual void setContextMenuEnabled(bool showMenu)
Enables or disable the popup (context) menu.
bool trapReturnKey() const
void setTrapReturnKey(bool trap)
By default, KComboBox recognizes Key_Return and Key_Enter and emits the returnPressed() signals,...
void changeURL(const KURL &url, int index)
Replaces the item at position index with url.
virtual bool eventFilter(TQObject *, TQEvent *)
Re-implemented for internal reasons.
TDECompletionBox * completionBox(bool create=true)
void setCompletedItems(const TQStringList &items)
Sets items into the completion-box if completionMode() is CompletionPopup.
virtual void create(WId=0, bool initializeWindow=true, bool destroyOldWindow=true)
Reimplemented for internal reasons, the API is not affected.
virtual void setLineEdit(TQLineEdit *)
Re-implemented for internal reasons.
void setURLDropsEnabled(bool enable)
Enables/Disables handling of URL drops.
void substringCompletion(const TQString &)
Emitted when the shortcut for substring completion is pressed.
virtual void makeCompletion(const TQString &)
Completes text according to the completion mode.
void returnPressed()
Emitted when the user presses the Enter key.
virtual void setCompletedText(const TQString &)
Sets the completed text in the line-edit appropriately.
void completion(const TQString &)
Emitted when the completion key is pressed.
void rotateText(TDECompletionBase::KeyBindingType type)
Iterates through all possible matches of the completed text or the history list.
bool contains(const TQString &text) const
Convenience method which iterates over all items and checks if any of them is equal to text.
virtual void setAutoCompletion(bool autocomplete)
Re-implemented from TQComboBox.
KComboBox(TQWidget *parent=0, const char *name=0)
Constructs a read-only or rather select-only combo box with a parent object and a name.
static void setAutoHideCursor(TQWidget *w, bool enable)
Sets auto-hiding the cursor for widget w.
A dialog base class with standard buttons and predefined layouts.
@ User1
Show User defined button 1.
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
An abstract class for GUI data such as ToolTip and Icon.
TQStringList historyItems() const
Returns the list of history items.
void setHistoryEditorEnabled(bool enable)
When enabling it you have to connect to "removed" signal and save changes.
bool useCompletion() const
void insertItems(const TQStringList &items)
Inserts items into the combo, honoring pixmapProvider() Does not update the completionObject.
void cleared()
Emitted when the history was cleared by the entry in the popup menu.
~KHistoryCombo()
Destructs the combo, the completion-object and the pixmap-provider.
void clearHistory()
Clears the history and the completion list.
void setHistoryItems(TQStringList items)
Inserts items into the combobox.
virtual void wheelEvent(TQWheelEvent *ev)
Handling wheel-events, to rotate the items.
virtual void keyPressEvent(TQKeyEvent *)
Handling key-events, the shortcuts to rotate the items.
KHistoryCombo(TQWidget *parent=0L, const char *name=0L)
Constructs a "read-write" combobox.
void addToHistory(const TQString &item)
Adds an item to the end of the history list and to the completion list.
bool removeFromHistory(const TQString &item)
Removes all items named item.
void setPixmapProvider(KPixmapProvider *prov)
Sets a pixmap provider, so that items in the combobox can have a pixmap.
An enhanced TQLineEdit widget for inputting text.
virtual TQPixmap pixmapFor(const TQString &text, int size=0)=0
TQString prettyURL(int _trailing=0) const
TDECompletionBase * delegate() const
virtual void setCompletionMode(TDEGlobalSettings::Completion mode)
void setDelegate(TDECompletionBase *delegate)
TDECompletion * completionObject(bool hsig=true)
A helper widget for "completion-widgets" (KLineEdit, KComboBox))
virtual void setOrder(CompOrder order)
void removeItem(const TQString &item)
virtual void setItems(const TQStringList &list)
void addItem(const TQString &item)
static Completion completionMode()
This class makes it easy to add a search line for filtering the items in a listview based on a simple...
void setListView(TDEListView *lv)
Sets the TDEListView that is filtered by this search line.
This Widget extends the functionality of TQListView to honor the system wide settings for Single Clic...
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
const TDEShortcut & rotateUp()
const TDEShortcut & rotateDown()