void KonqComboLineEdit::setCompletedItems( const QStringList& items, bool ) { QString txt; KonqComboCompletionBox *completionbox = static_cast<KonqComboCompletionBox*>( completionBox() ); if ( completionbox && completionbox->isVisible() ) // The popup is visible already - do the matching on the initial string, // not on the currently selected one. txt = completionbox->cancelledText(); else txt = text(); if ( !items.isEmpty() && !(items.count() == 1 && txt == items.first()) ) { if ( !completionBox( false ) ) { setCompletionBox( new KonqComboCompletionBox( this ) ); completionbox = static_cast<KonqComboCompletionBox*>( completionBox() ); } if ( completionbox->isVisible() ) { // This code is copied from KLineEdit::setCompletedItems QListWidgetItem* currentItem = completionbox->currentItem(); QString currentSelection; if ( currentItem != 0 ) { currentSelection = currentItem->text(); } completionbox->setItems( items ); const QList<QListWidgetItem*> matchedItems = completionbox->findItems(currentSelection, Qt::MatchExactly); QListWidgetItem* matchedItem = matchedItems.isEmpty() ? 0 : matchedItems.first(); if (matchedItem) { const bool blocked = completionbox->blockSignals(true); completionbox->setCurrentItem(matchedItem); completionbox->blockSignals(blocked); } else { completionbox->setCurrentRow(-1); } } else { // completion box not visible yet -> show it if ( !txt.isEmpty() ) completionbox->setCancelledText( txt ); completionbox->setItems( items ); completionbox->popup(); } if ( autoSuggest() ) { int index = items.first().indexOf( txt ); QString newText = items.first().mid( index ); setUserSelection( false ); setCompletedText( newText, true ); } } else if ( completionbox && completionbox->isVisible() ) completionbox->hide(); }
void CKeyReferenceLineEdit::makeCompletion(const QString &text) { KCompletion *comp = compObj(); KGlobalSettings::Completion mode = completionMode(); if ( !comp || mode == KGlobalSettings::CompletionNone ) return; // No completion object... QString match = comp->makeCompletion( text ); if ( mode == KGlobalSettings::CompletionPopup || mode == KGlobalSettings::CompletionPopupAuto ) { if ( match.isNull() ) { KCompletionBox *compbox = completionBox(); compbox->hide(); compbox->clear(); } else { QStringList t; t.append(match); setCompletedItems(t); } } else { KLineEdit::makeCompletion(text); } }
KonqCombo::KonqCombo( QWidget *parent ) : KHistoryComboBox( parent ), m_returnPressed( false ), m_permanent( false ), m_pageSecurity( KonqMainWindow::NotCrypted ) { setLayoutDirection(Qt::LeftToRight); setInsertPolicy( NoInsert ); setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed )); setSizeAdjustPolicy( QComboBox::AdjustToMinimumContentsLength ); Q_ASSERT( s_config ); KConfigGroup locationBarGroup( s_config, "Location Bar" ); setMaxCount( locationBarGroup.readEntry("Maximum of URLs in combo", 20 )); // We should also connect the completionBox' highlighted signal to // our setEditText() slot, because we're handling the signals ourselves. // But we're lazy and let KCompletionBox do this and simply switch off // handling of signals later. setHandleSignals( true ); KonqComboLineEdit *edit = new KonqComboLineEdit( this ); edit->setHandleSignals( true ); edit->setCompletionBox( new KonqComboCompletionBox( edit ) ); setLineEdit( edit ); setItemDelegate( new KonqComboItemDelegate( this ) ); connect( edit, SIGNAL(textEdited(QString)), this, SLOT(slotTextEdited(QString)) ); completionBox()->setTabHandling(true); // #167135 completionBox()->setItemDelegate( new KonqComboItemDelegate( this ) ); // Make the lineedit consume the Qt::Key_Enter event... setTrapReturnKey( true ); connect( KonqHistoryManager::kself(), SIGNAL(cleared()), SLOT(slotCleared()) ); connect( this, SIGNAL(cleared()), SLOT(slotCleared()) ); connect( this, SIGNAL(highlighted(int)), SLOT(slotSetIcon(int)) ); connect( this, SIGNAL(activated(QString)), SLOT(slotActivated(QString)) ); }