Beispiel #1
0
void KMyMoneySecurity::setCurrentTextById(const QString& id)
{
  if (!id.isEmpty()) {
    QString security = MyMoneyFile::instance()->account(id).name();
    setCompletedText(security);
    setEditText(security);
  } else {
    setCompletedText(QString());
    clearEditText();
  }
}
Beispiel #2
0
void KMyMoneyCategory::setCurrentTextById(const QString& id)
{
  if (!id.isEmpty()) {
    QString category = MyMoneyFile::instance()->accountToCategory(id);
    setCompletedText(category);
    setEditText(category);
  } else {
    setCompletedText(QString());
    clearEditText();
  }
  setSuppressObjectCreation(false);
}
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();
}
Beispiel #4
0
void KLineEdit::setCompletedText( const QString& text )
{
    KGlobalSettings::Completion mode = completionMode();
    bool marked = ( mode == KGlobalSettings::CompletionAuto ||
                    mode == KGlobalSettings::CompletionMan ||
                    mode == KGlobalSettings::CompletionPopup ||
                    mode == KGlobalSettings::CompletionPopupAuto );
    setCompletedText( text, marked );
}
Beispiel #5
0
void KLineEdit::rotateText( KCompletionBase::KeyBindingType type )
{
    KCompletion* comp = compObj();
    if ( comp &&
       (type == KCompletionBase::PrevCompletionMatch ||
        type == KCompletionBase::NextCompletionMatch ) )
    {
       QString input;

       if (type == KCompletionBase::PrevCompletionMatch)
          comp->previousMatch();
       else
          comp->nextMatch();

       // Skip rotation if previous/next match is null or the same text
       if ( input.isNull() || input == displayText() )
            return;
       setCompletedText( input, hasSelectedText() );
    }
}
Beispiel #6
0
void KreTextEdit::rotateText( KCompletionBase::KeyBindingType type )
{
	KCompletion * comp = compObj();
	if ( comp && completing &&
	( type == KCompletionBase::PrevCompletionMatch ||
	type == KCompletionBase::NextCompletionMatch ) ) {
#if 0
		QString input = ( type == KCompletionBase::PrevCompletionMatch ) ? comp->previousMatch() : comp->nextMatch();

		// Skip rotation if previous/next match is null or the same text
		int para, index;
		getCursorPosition( &para, &index );
		QString para_text = text( para );
		QString complete_word = para_text.mid( completion_begin, index - completion_begin );
		if ( input.isNull() || input == complete_word )
			return ;
		setCompletedText( input );
#endif
	}
}
Beispiel #7
0
void KreTextEdit::tryCompletion()
{
#if 0
	int para, index;
	getCursorPosition( &para, &index );

	QString para_text = text( para );
	if ( para_text.at( index ).isSpace() || completing ) {
		if ( !completing )
			completion_begin = para_text.lastIndexOf( ' ', index - 1 ) + 1;

		QString completing_word = para_text.mid( completion_begin, index - completion_begin );

		QString match = compObj() ->makeCompletion( completing_word );

		if ( !match.isNull() && match != completing_word )
			setCompletedText( match );
		else
			completing = false;
	}
#endif
}
Beispiel #8
0
void KLineEdit::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() )
        {
            if ( d->completionBox )
            {
                d->completionBox->hide();
                d->completionBox->clear();
            }
        }
        else
            setCompletedItems( comp->allMatches() );
    }
    else // Auto,  ShortAuto (Man) and Shell
    {
        // all other completion modes
        // If no match or the same match, simply return without completing.
        if ( match.isNull() || match == text )
            return;

        if ( mode != KGlobalSettings::CompletionShell )
            setUserSelection(false);

        if ( d->autoSuggest )
            setCompletedText( match );
    }
}