Ejemplo n.º 1
0
void KHistoryComboBox::setHistoryItems( const QStringList &items,
                                     bool setCompletionList )
{
    QStringList insertingItems = items;
    KComboBox::clear();

    // limit to maxCount()
    const int itemCount = insertingItems.count();
    const int toRemove = itemCount - maxCount();

    if (toRemove >= itemCount) {
        insertingItems.clear();
    } else {
        for (int i = 0; i < toRemove; ++i)
            insertingItems.pop_front();
    }

    insertItems( insertingItems );

    if ( setCompletionList && useCompletion() ) {
        // we don't have any weighting information here ;(
        KCompletion *comp = completionObject();
        comp->setOrder( KCompletion::Insertion );
        comp->setItems( insertingItems );
        comp->setOrder( KCompletion::Weighted );
    }

    clearEditText();
}
Ejemplo n.º 2
0
KreTextEdit::KreTextEdit( QWidget *parent ):
	KTextEdit( parent )//, KCompletionBase()
{
	KCompletion * comp = completionObject(); //creates the completion object
	comp->setIgnoreCase( true );

	completing = false;

	QString spellCheckingConfigFileName = KStandardDirs::locateLocal( "config",
		KCmdLineArgs::aboutData()->appName() + "rc" );

	KConfig localConfig( spellCheckingConfigFileName, KConfig::SimpleConfig );
	KConfigGroup localGroup( &localConfig, "Spelling" );

	//If we don't have our local configuration for spell checking, fall back to
	//user's global configuration.
	if ( !localConfig.hasGroup( "Spelling" ) ) {
		KConfig globalSonnetConfig( KStandardDirs::locateLocal( "config", "sonnetrc" ) );
		KConfigGroup globalGroup( &globalSonnetConfig, "Spelling" );
		globalGroup.copyTo( &localGroup );
		localConfig.sync();
		KConfigGroup group( KGlobal::config(), "Spelling" );
		globalGroup.copyTo( &group );
	}

	setSpellCheckingConfigFileName( spellCheckingConfigFileName );

	if ( localGroup.readEntry( "checkerEnabledByDefault", false ) )
		setCheckSpellingEnabled( true );
	else
		setCheckSpellingEnabled( false );

	//connect( this, SIGNAL( clicked( int, int ) ), SLOT( haltCompletion() ) );
}
CMakeBuildDirChooser::CMakeBuildDirChooser(QWidget* parent)
    : KDialog(parent)
{
    setDefaultButton(KDialog::Ok);
    setCaption(i18n("Configure a build directory"));

//     QWidget* w= new QWidget(this);
    m_chooserUi = new Ui::CMakeBuildDirChooser;
    m_chooserUi->setupUi(mainWidget());
    m_chooserUi->buildFolder->setMode(KFile::Directory|KFile::ExistingOnly);
    m_chooserUi->installPrefix->setMode(KFile::Directory|KFile::ExistingOnly);
//     setMainWidget(w);

    setCMakeBinary(Path(QStandardPaths::findExecutable( "cmake" )));

    KConfigGroup config = KSharedConfig::openConfig()->group("CMakeBuildDirChooser");
    QStringList lastExtraArguments = config.readEntry("LastExtraArguments", QStringList());;
    m_chooserUi->extraArguments->addItem("");
    m_chooserUi->extraArguments->addItems(lastExtraArguments);
    m_chooserUi->extraArguments->setInsertPolicy(QComboBox::InsertAtTop);
    KCompletion *comp = m_chooserUi->extraArguments->completionObject();
    connect(m_chooserUi->extraArguments, static_cast<void(KComboBox::*)(const QString&)>(&KComboBox::returnPressed), comp, static_cast<void(KCompletion::*)(const QString&)>(&KCompletion::addItem));
    comp->insertItems(lastExtraArguments);

    connect(m_chooserUi->cmakeBin, &KUrlRequester::textChanged, this, &CMakeBuildDirChooser::updated);
    connect(m_chooserUi->buildFolder, &KUrlRequester::textChanged, this, &CMakeBuildDirChooser::updated);
    connect(m_chooserUi->buildType, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentIndexChanged), this, &CMakeBuildDirChooser::updated);
    connect(m_chooserUi->extraArguments, &KComboBox::editTextChanged, this, &CMakeBuildDirChooser::updated);
    updated();
}
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);
	}
}
Ejemplo n.º 5
0
void
Test_KCompletion::substringCompletion_Insertion()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    completion.setCompletionMode(KCompletion::CompletionAuto);

    completion.setOrder(KCompletion::Insertion);
    completion.setItems(strings);
    QVERIFY(completion.items().count() == 4);

    QStringList matches = completion.substringCompletion(QStringLiteral("c"));
    QVERIFY(matches.count() == 4);
    QCOMPARE(matches[0], clampet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carpet);
    QCOMPARE(matches[3], carp);

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], coolcat);
    QCOMPARE(matches[1], carpet);
    QCOMPARE(matches[2], carp);

    matches = completion.substringCompletion(QStringLiteral("car"));
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], carp);

    matches = completion.substringCompletion(QStringLiteral("pet"));
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], clampet);
    QCOMPARE(matches[1], carpet);
}
Ejemplo n.º 6
0
void
MetaQueryWidget::populateComboBox( QStringList results )
{
    QObject* query = sender();
    if( !query )
        return;

    QWeakPointer<KComboBox> combo = m_runningQueries.value(query);
    if( combo.isNull() )
        return;

    // note: adding items seems to reset the edit text, so we have
    //   to take care of that.
    disconnect( combo.data(), 0, this, 0 );

    // want the results unique and sorted
    const QSet<QString> dataSet = results.toSet();
    QStringList dataList = dataSet.toList();
    dataList.sort();
    combo.data()->addItems( dataList );

    KCompletion* comp = combo.data()->completionObject();
    comp->setItems( dataList );

    // reset the text and re-enable the signal
    combo.data()->setEditText( m_filter.value );
    connect( combo.data(), SIGNAL(editTextChanged( const QString& ) ),
            SLOT(valueChanged(const QString&)) );
}
Ejemplo n.º 7
0
void
Test_KCompletion::isEmpty()
{
	KCompletion completion;
	QVERIFY(completion.isEmpty());
	QVERIFY(completion.items().isEmpty());
}
Ejemplo n.º 8
0
void
Test_KCompletion::substringCompletion_Weighted()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	completion.setCompletionMode(KGlobalSettings::CompletionAuto);

	completion.setOrder(KCompletion::Weighted);
	completion.setItems(wstrings);
	QVERIFY(completion.items().count() == 4);

	QStringList matches = completion.substringCompletion("c");
	QVERIFY(matches.count() == 4);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], clampet);
	QCOMPARE(matches[2], coolcat);
	QCOMPARE(matches[3], carp);

	matches = completion.substringCompletion("ca");
	QVERIFY(matches.count() == 3);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], coolcat);
	QCOMPARE(matches[2], carp);

	matches = completion.substringCompletion("car");
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], carp);

	matches = completion.substringCompletion("pet");
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], clampet);
}
Ejemplo n.º 9
0
void // virtual
KClassicGreeter::loadUsers( const QStringList &users )
{
	KCompletion *userNamesCompletion = new KCompletion;
	userNamesCompletion->setItems( users );
	loginEdit->setCompletionObject( userNamesCompletion );
	loginEdit->setAutoDeleteCompletionObject( true );
	loginEdit->setCompletionMode( KGlobalSettings::CompletionAuto );
}
Ejemplo n.º 10
0
void
Test_KCompletion::allMatches_Insertion()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	completion.setCompletionMode(KGlobalSettings::CompletionAuto);

	completion.setOrder(KCompletion::Insertion);
	completion.setItems(strings);
	QVERIFY(completion.items().count() == 4);

	QStringList matches = completion.allMatches("c");
	QVERIFY(matches.count() == 4);
	QCOMPARE(matches[0], clampet);
	QCOMPARE(matches[1], coolcat);
	QCOMPARE(matches[2], carpet);
	QCOMPARE(matches[3], carp);

	matches = completion.allMatches("ca");
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carpet);
	QCOMPARE(matches[1], carp);

	matches = completion.allMatches("pet");
	QVERIFY(matches.count() == 0);
}
Ejemplo n.º 11
0
ConsoleDockWidget::ConsoleDockWidget( ProjectModel *projectModel, KActionMenu *showDocksAction,
                                      QWidget *parent )
    : AbstractDockWidget( i18nc("@title:window Dock title", "Console"), showDocksAction, parent ),
      m_consoleWidget(0), m_commandLineEdit(0), m_cancelButton(0), m_consoleHistoryIndex(-1),
      m_projectModel(projectModel), m_state(WaitingForInput)
{
    setObjectName( "console" );

    setWhatsThis( i18nc("@info:whatsthis", "<title>A debugger console</title>"
                        "<para>Provides some commands (type <icode>.help</icode>) and can "
                        "execute script code in the current script context. If values are altered "
                        "by a console command they are also altered in a running script.</para>") );

    QWidget *container = new QWidget( this );
    container->setMinimumSize( 150, 100 );
    m_consoleWidget = new QPlainTextEdit( container );
    m_consoleWidget->setReadOnly( true );
    m_consoleWidget->setFont( KGlobalSettings::fixedFont() );
    m_consoleWidget->setContextMenuPolicy( Qt::CustomContextMenu );
    m_commandLineEdit = new KLineEdit( container );
    m_commandLineEdit->setFont( KGlobalSettings::fixedFont() );
    m_commandLineEdit->setClickMessage( i18nc("@info/plain", "Enter a command, eg. '.help'") );
    m_cancelButton = new QToolButton( container );
    m_cancelButton->setToolButtonStyle( Qt::ToolButtonIconOnly );
    m_cancelButton->setToolTip( i18nc("@info:tooltip", "Cancel evaluation and abort debugger") );
    m_cancelButton->setIcon( KIcon("process-stop") );
    m_cancelButton->hide();

    QHBoxLayout *inputBarLayout = new QHBoxLayout();
    inputBarLayout->setContentsMargins( 0, 0, 0, 0 );
    inputBarLayout->addWidget( m_commandLineEdit );
    inputBarLayout->addWidget( m_cancelButton );

    QVBoxLayout *consoleLayout = new QVBoxLayout( container );
    consoleLayout->setSpacing( 0 );
    consoleLayout->setContentsMargins( 0, 0, 0, 0 );
    consoleLayout->addWidget( m_consoleWidget );
    consoleLayout->addLayout( inputBarLayout );
    setWidget( container );
    connect( m_consoleWidget, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(contextMenu(QPoint)) );
    connect( m_commandLineEdit, SIGNAL(returnPressed(QString)),
             this, SLOT(executeCommand(QString)) );
    connect( m_cancelButton, SIGNAL(clicked(bool)), this, SLOT(cancelEvaluation()) );

    m_consoleHistoryIndex = -1;
    m_commandLineEdit->installEventFilter( this );
    KCompletion *completion = m_commandLineEdit->completionObject();
    completion->setItems( Debugger::ConsoleCommand::defaultCompletions() );

    connect( projectModel, SIGNAL(activeProjectAboutToChange(Project*,Project*)),
             this, SLOT(activeProjectAboutToChange(Project*,Project*)) );

    setState( WaitingForInput );
}
Ejemplo n.º 12
0
void
Test_KCompletion::allMatches_Weighted()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    completion.setCompletionMode(KCompletion::CompletionAuto);

    completion.setOrder(KCompletion::Weighted);
    completion.setItems(wstrings);
    QVERIFY(completion.items().count() == 4);

    QStringList matches = completion.allMatches(QStringLiteral("c"));
    QVERIFY(matches.count() == 4);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], clampet);
    QCOMPARE(matches[2], coolcat);
    QCOMPARE(matches[3], carp);

    matches = completion.allMatches(QStringLiteral("ca"));
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], carp);

    matches = completion.allMatches(QStringLiteral("pet"));
    QVERIFY(matches.count() == 0);
}
Ejemplo n.º 13
0
void JourneySearchParser::doCorrections( KLineEdit *lineEdit, QString *searchLine, int cursorPos,
                                         const QStringList &words, int removedWordsFromLeft )
{
    int selStart = -1;
    int selLength = 0;

    int pos = searchLine->lastIndexOf( ' ', cursorPos - 1 );
    int posEnd = searchLine->indexOf( ' ', cursorPos );
    if ( posEnd == -1 ) {
        posEnd = searchLine->length();
    }
    QString lastWordBeforeCursor;
    if ( posEnd == cursorPos && pos != -1 && !( lastWordBeforeCursor = searchLine->mid(
                    pos, posEnd - pos ).trimmed() ).isEmpty() ) {
        if ( timeKeywordsAt().contains( lastWordBeforeCursor, Qt::CaseInsensitive ) ) {
            // Automatically add the current time after 'at'
            QString formattedTime = KGlobal::locale()->formatTime( QTime::currentTime() );
            searchLine->insert( posEnd, ' ' + formattedTime );
            selStart = posEnd + 1; // +1 for the added space
            selLength = formattedTime.length();
        } else if ( timeKeywordsIn().contains( lastWordBeforeCursor, Qt::CaseInsensitive ) ) {
            // Automatically add '5 minutes' after 'in'
            searchLine->insert( posEnd, ' ' + relativeTimeString(5) );
            selStart = posEnd + 1; // +1 for the added space
            selLength = 1; // only select the number (5)
        } else {
            QStringList completionItems;
            completionItems << timeKeywordsAt() << timeKeywordsIn() << timeKeywordsTomorrow()
                    << departureKeywords() << arrivalKeywords();

            KCompletion *comp = lineEdit->completionObject( false );
            comp->setItems( completionItems );
            comp->setIgnoreCase( true );
            QString completion = comp->makeCompletion( lastWordBeforeCursor );
            setJourneySearchWordCompletion( lineEdit, completion );
        }
    }

    // Select an appropriate substring after inserting something
    if ( selStart != -1 ) {
        QStringList removedWords = ( QStringList )words.mid( 0, removedWordsFromLeft );
        QString removedPart = removedWords.join( " " ).trimmed();
        QString correctedSearch;
        if ( removedPart.isEmpty() ) {
            correctedSearch = *searchLine;
        } else {
            correctedSearch = removedPart + ' ' + *searchLine;
            selStart += removedPart.length() + 1;
        }
        lineEdit->setText( correctedSearch );
        lineEdit->setSelection( selStart, selLength );
    }
}
Ejemplo n.º 14
0
FITSHeaderEditAddUnitDialog::FITSHeaderEditAddUnitDialog(const QString& unit, QWidget *parent) :
    KDialog(parent) {
    QWidget* mainWidget = new QWidget(this);
    ui.setupUi(mainWidget);
    setMainWidget( mainWidget );

    setWindowTitle(i18n("Specify the new unit"));
    setButtons( KDialog::Ok | KDialog::Cancel );
    setButtonText(KDialog::Ok, i18n("&Add unit"));
    KCompletion* keyCompletion = new KCompletion;
    keyCompletion->setItems(FITSFilter::units());
    if (!unit.isEmpty()) {
        ui.kleUnit->setText(unit);
    }
    ui.kleUnit->setCompletionObject(keyCompletion);
    ui.kleUnit->setAutoDeleteCompletionObject(true);
    connect(this, SIGNAL(okClicked()), this, SLOT(addUnit()));
    setAttribute(Qt::WA_DeleteOnClose);
}
Ejemplo n.º 15
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() );
    }
}
Ejemplo n.º 16
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
	}
}
Ejemplo n.º 17
0
void LogMessageEdit::rotateMatches(KeyBindingType type)
{
    KCompletion* completionObj = compObj();
    if( completionObj && m_completing &&
        (type == PrevCompletionMatch || type == NextCompletionMatch) )
    {
        QString match = (type == PrevCompletionMatch) ? completionObj->previousMatch()
                                                      : completionObj->nextMatch();

        int pos = textCursor().position();
        QString text = toPlainText();

        QString word = text.mid(m_completionStartPos, pos - m_completionStartPos);

        if( match.isEmpty() || match == word )
            return;

        setCompletedText(match);
    }
}
SkypeMainOptionsWidget::SkypeMainOptionsWidget(ParameterEditModel *model, QWidget *parent)
 : AbstractAccountParametersWidget(model, parent)
{
    // Set up the UI.
    m_ui = new Ui::SkypeMainOptionsWidget;
    m_ui->setupUi(this);

    handleParameter(QLatin1String("account"), QVariant::String, m_ui->accountLineEdit, m_ui->accountLabel);

#ifdef Q_WS_X11
    // get autocomplete choices for the accountname
    // Skype stores data for each account that has been used in $HOME/.Skype/<accountname>/
    QDir skypeConfigDir(QDir::home().filePath(QLatin1String(".Skype")));

    skypeConfigDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
    QFileInfoList folderList = skypeConfigDir.entryInfoList();

    KCompletion *completion = new KCompletion;
    Q_FOREACH (const QFileInfo &info, folderList) {
        completion->addItem(info.fileName());
    }
Ejemplo n.º 19
0
/*! \class FITSHeaderEditNewKeywordDialog
 * \brief Dialog class for adding new keywords to the FITSHeaderEditDialog's table.
 * \since 2.2.0
 * \ingroup widgets
 */
FITSHeaderEditNewKeywordDialog::FITSHeaderEditNewKeywordDialog(QWidget *parent) : KDialog(parent) {
    QWidget* mainWidget = new QWidget(this);
    ui.setupUi(mainWidget);
    setMainWidget( mainWidget );
    setWindowTitle(i18n("Specify the new keyword"));
    setButtons( KDialog::Ok | KDialog::Cancel );
    setButtonText(KDialog::Ok, i18n("&Add keyword"));
    setAttribute(Qt::WA_DeleteOnClose);

    KCompletion* keyCompletion = new KCompletion;
    keyCompletion->setItems(FITSFilter::standardKeywords());
    ui.kleKey->setCompletionObject(keyCompletion);
    ui.kleKey->setAutoDeleteCompletionObject(true);

    ui.kleValue->setPlaceholderText(i18n("Specify the value"));
    ui.kleComment->setPlaceholderText(i18n("Specify the comment"));

    ui.kleKey->setMaxLength(FLEN_KEYWORD);
    ui.kleValue->setMaxLength(FLEN_VALUE);
    ui.kleComment->setMaxLength(FLEN_COMMENT);
}
Ejemplo n.º 20
0
AddEditLink::AddEditLink( QWidget *parent )
        : KDialog( parent )
{
    setAttribute(Qt::WA_DeleteOnClose);
    QWidget *dialog = new QWidget( this );
    ui.setupUi( dialog );
    ui.btnClear->setIcon(KIcon("edit-clear"));
    this->setMainWidget( dialog );

    this->resize( dialog->width(), dialog->height() );

    confGroup = new KConfigGroup( KGlobal::config(), QString::fromLatin1("AddEditLinkDialog") );
    QStringList linksList = confGroup->readEntry("LinksCache", QStringList());
    ui.txtAddress->addItems(linksList);
    KCompletion *comp = ui.txtAddress->completionObject( true );
    comp->setItems(linksList);
    ui.txtAddress->setCompletionMode(KGlobalSettings::CompletionPopupAuto);

    ui.txtAddress->setFocus();
    resize( confGroup->readEntry("Size", this->size()) );
    connect(ui.btnClear, SIGNAL(clicked(bool)), SLOT(slotClearLinkCache()) );
}
Ejemplo n.º 21
0
void
Test_KCompletion::cycleMatches_Sorted()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    completion.setOrder(KCompletion::Sorted);
    completion.setItems(strings);
    completion.setCompletionMode(KCompletion::CompletionAuto);

    completion.makeCompletion(QStringLiteral("ca"));
    QCOMPARE(completion.nextMatch(), carp);
    QCOMPARE(completion.nextMatch(), carpet);
    QCOMPARE(completion.previousMatch(), carp);
    QCOMPARE(completion.previousMatch(), carpet);
}
Ejemplo n.º 22
0
void
Test_KCompletion::cycleMatches_Weighted()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	completion.setOrder(KCompletion::Weighted);
	completion.setItems(wstrings);
	completion.setCompletionMode(KGlobalSettings::CompletionAuto);

	completion.makeCompletion("ca");
	QCOMPARE(completion.nextMatch(), carpet);
	QCOMPARE(completion.nextMatch(), carp);
	QCOMPARE(completion.previousMatch(), carpet);
	QCOMPARE(completion.previousMatch(), carp);
}
Ejemplo n.º 23
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 );
    }
}
Ejemplo n.º 24
0
void
Test_KCompletion::weightedOrder()
{
    KCompletion completion;
    completion.setSoundsEnabled(false);
    QSignalSpy spy1(&completion, SIGNAL(match(QString)));
    QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

    completion.setOrder(KCompletion::Weighted);
    QVERIFY(completion.order() == KCompletion::Weighted);

    completion.setItems(wstrings);
    QVERIFY(completion.items().count() == 4);

    completion.setCompletionMode(KCompletion::CompletionShell);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), QStringLiteral("carp"));
    spy1.takeFirst(); // empty the list
    QVERIFY(spy3.count() == 1); spy3.takeFirst();

    QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
    completion.makeCompletion(QStringLiteral("ca"));
    QCOMPARE(spy2.count(), 1);
    QVERIFY(spy3.count() == 0); // shouldn't be signaled on 2nd call

    QStringList matches = spy2.takeFirst().at(0).toStringList();
    QVERIFY(matches.count() == 2);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], carp);

    completion.setCompletionMode(KCompletion::CompletionAuto);
    QCOMPARE(completion.makeCompletion(QStringLiteral("ca")), carpet);

    matches = completion.substringCompletion(QStringLiteral("ca"));
    QVERIFY(matches.count() == 3);
    QCOMPARE(matches[0], carpet);
    QCOMPARE(matches[1], coolcat);
    QCOMPARE(matches[2], carp);
}
Ejemplo n.º 25
0
void FindBarBase::addToCompletion(const QString &text)
{
    KCompletion *comp = mSearch->completionObject();
    comp->addItem(text);
}
Ejemplo n.º 26
0
void TitleWidget::addJourneySearchWidgets()
{
    // Add recent journeys button
    Plasma::ToolButton *recentJourneysButton = new Plasma::ToolButton;
    recentJourneysButton->setIcon( KIcon("document-open-recent") );
    recentJourneysButton->setToolTip( i18nc("@info:tooltip", "Use a favorite/recent journey search") );
    recentJourneysButton->nativeWidget()->setPopupMode( QToolButton::InstantPopup );
    // This is needed, to have the popup menu drawn above other widgets
    recentJourneysButton->setZValue( 9999 );
    connect( recentJourneysButton, SIGNAL(clicked()), this, SLOT(slotJourneysIconClicked()) );

    // Add button to start the journey search
    Plasma::ToolButton *journeySearchButton = new Plasma::ToolButton;
    journeySearchButton->setIcon( KIcon("edit-find") );
    journeySearchButton->setToolTip( i18nc("@info:tooltip", "Find journeys") );
    journeySearchButton->setEnabled( false );
    connect( journeySearchButton, SIGNAL(clicked()), this, SLOT(slotJourneySearchInputFinished()) );

    // Add journey search query input field
    Plasma::LineEdit *journeySearchLineEdit = new Plasma::LineEdit;
    journeySearchLineEdit->setNativeWidget( new JourneySearchLineEdit );
    journeySearchLineEdit->setToolTip(
            i18nc("@info:tooltip This should match the localized keywords.",
            "<para>Type a <emphasis strong='1'>target stop</emphasis> or "
            "<emphasis strong='1'>journey request</emphasis>.</para>"
            "<para><emphasis strong='1'>Samples:</emphasis><list>"
            "<item><emphasis>To target in 15 mins</emphasis></item>"
            "<item><emphasis>From origin arriving tomorrow at 18:00</emphasis></item>"
            "<item><emphasis>Target at 6:00 2010-03-07</emphasis></item>"
            "</list></para>") );
    journeySearchLineEdit->installEventFilter( this ); // Handle up/down keys (selecting stop suggestions)
    journeySearchLineEdit->setClearButtonShown( true );
    journeySearchLineEdit->nativeWidget()->setCompletionMode( KGlobalSettings::CompletionAuto );
    journeySearchLineEdit->nativeWidget()->setCompletionModeDisabled(
            KGlobalSettings::CompletionMan );
    journeySearchLineEdit->nativeWidget()->setCompletionModeDisabled(
            KGlobalSettings::CompletionPopup );
    journeySearchLineEdit->nativeWidget()->setCompletionModeDisabled(
            KGlobalSettings::CompletionPopupAuto );
    journeySearchLineEdit->nativeWidget()->setCompletionModeDisabled(
            KGlobalSettings::CompletionShell );
    journeySearchLineEdit->setEnabled( true );

    KLineEdit *journeySearch = journeySearchLineEdit->nativeWidget();
    journeySearch->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
    journeySearch->setClickMessage( i18nc("@info/plain", "Target stop name or journey request") );
    KCompletion *completion = journeySearch->completionObject( false );
    completion->setIgnoreCase( true );
    journeySearchLineEdit->setFont( m_settings->sizedFont() );
    connect( journeySearchLineEdit, SIGNAL(returnPressed()),
             this, SLOT(slotJourneySearchInputFinished()) );
    connect( journeySearchLineEdit, SIGNAL(textEdited(QString)),
             this, SIGNAL(journeySearchInputEdited(QString)) );
    connect( journeySearchLineEdit, SIGNAL(textChanged(QString)),
             this, SLOT(slotJourneySearchInputChanged(QString)) );

    // Add widgets
    addWidget( journeySearchLineEdit, WidgetJourneySearchLine );
    addWidget( recentJourneysButton, WidgetFillJourneySearchLineButton );
    addWidget( journeySearchButton, WidgetStartJourneySearchButton );
}
Ejemplo n.º 27
0
void
Test_KCompletion::sortedOrder()
{
	KCompletion completion;
	completion.setSoundsEnabled(false);
	QSignalSpy spy1(&completion, SIGNAL(match(QString)));
	QSignalSpy spy3(&completion, SIGNAL(multipleMatches()));

	completion.setOrder(KCompletion::Sorted);
	QVERIFY(completion.order() == KCompletion::Sorted);

	completion.setItems(strings);
	QVERIFY(completion.items().count() == 4);

	completion.setCompletionMode(KGlobalSettings::CompletionShell);
	QCOMPARE(completion.makeCompletion("ca"), QString("carp"));
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), QString("carp"));
	QVERIFY(spy3.count() == 1); spy3.takeFirst();

	QSignalSpy spy2(&completion, SIGNAL(matches(QStringList)));
	completion.makeCompletion("ca");
	QCOMPARE(spy2.count(), 1);
	QVERIFY(spy3.count() == 0); // shouldn't be signaled on 2nd call

	QStringList matches = spy2.takeFirst().at(0).toStringList();
	QVERIFY(matches.count() == 2);
	QCOMPARE(matches[0], carp);
	QCOMPARE(matches[1], carpet);

	completion.setCompletionMode(KGlobalSettings::CompletionAuto);
	QCOMPARE(completion.makeCompletion("ca"), carp);
	QVERIFY(spy1.count() == 1);
	QCOMPARE(spy1.takeFirst().at(0).toString(), carp);
}
Ejemplo n.º 28
0
void ConsoleDockWidget::executeCommand( const QString &_commandString )
{
    if ( _commandString.isEmpty() ) {
        kDebug() << "No command given";
        return;
    }

    Project *project = m_projectModel->activeProject();
    if ( !project ) {
        kDebug() << "No active project";
        return;
    }

    setState( EvaluatingResult );

    // Check if the command string ends with a '\'. If it does, add the command to the current
    // multiline command and wait for more input. If not, check if there are entered multiline
    // command lines.
    QString commandString = _commandString;
    if ( commandString.endsWith('\\') ) {
        const QString correctedCommandString = commandString.left( commandString.length() - 1 );
        if ( m_enteredMultilineCommandLines.isEmpty() ) {
            // Write first line of a multiline command to console
            appendToConsole( QString("<b> &gt; %1</b>").arg(encodeInput(correctedCommandString)) );
        } else {
            // Write following line of a multiline command to console
            appendToConsole( QString("<b>   %1</b>").arg(encodeInput(correctedCommandString)) );
        }
        m_enteredMultilineCommandLines << correctedCommandString;
        setState( WaitingForInput );
        return;
    } else if ( !m_enteredMultilineCommandLines.isEmpty() ) {
        // Write last line of a multiline command to console
        appendToConsole( QString("<b>   %1</b>").arg(encodeInput(commandString)) );

        // Prepend already entered lines
        commandString.prepend( m_enteredMultilineCommandLines.join("\n") + '\n' );
        m_enteredMultilineCommandLines.clear();
    } else {
        // Write executed command to console
        appendToConsole( QString("<b> &gt; %1</b>").arg(encodeInput(commandString)) );
    }

    // Store executed command in history (use up/down keys)
    if ( m_consoleHistory.isEmpty() || m_consoleHistory.first() != commandString ) {
        m_consoleHistory.prepend( commandString );
    }
    m_consoleHistoryIndex = -1;

    // Add executed command to completion object
    KCompletion *completion = m_commandLineEdit->completionObject();
    if ( !completion->items().contains(commandString) ) {
        completion->addItem( commandString );
    }

    // Check if commandString contains a command of the form ".<command> ..."
    Debugger::ConsoleCommand command = Debugger::ConsoleCommand::fromString( commandString );
    if ( command.isValid() )  {
        if ( command.command() == ConsoleCommand::ClearCommand ) {
            // The clear command cannot be executed in the debugger,
            // simply clear the console history here
            m_consoleWidget->clear();
            setState( WaitingForInput );
        } else {
            // Execute the command
            project->debugger()->executeCommand( command );
        }
    } else {
        // No command given, execute string as script code
        project->debugger()->evaluateInContext( commandString,
                                                i18nc("@info/plain", "Console Command (%1)", commandString) );
    }
}
Ejemplo n.º 29
0
//BEGIN class PropertyEditorList
PropertyEditorList::PropertyEditorList( QWidget * parent, Property * property, const char * name )
	: PropertySubEditor( parent, property, name )
{
    QWidget *box = new QWidget(this);
    QHBoxLayout *boxLayout = new QHBoxLayout;

	m_combo = new PropComboBox( box );
	m_combo->setGeometry(frameGeometry());

    boxLayout->addWidget(m_combo);
    box->setLayout(boxLayout);

	bool isEditable = false;
	switch ( property->type() )
	{
		case Property::Type::Port:
		case Property::Type::Pin:
		case Property::Type::PenStyle:
		case Property::Type::PenCapStyle:
		case Property::Type::SevenSegment:
		case Property::Type::KeyPad:
		case Property::Type::Select:
			isEditable = false;
			break;
			
		case Property::Type::String:
		case Property::Type::Multiline:
		case Property::Type::RichText:
		case Property::Type::Combo:
		case Property::Type::FileName:
		case Property::Type::VarName:
			isEditable = true;
			break;
				
		case Property::Type::None:
		case Property::Type::Int:
		case Property::Type::Raw:
		case Property::Type::Double:
		case Property::Type::Color:
		case Property::Type::Bool:
			// not handled by this
			break;
	}
	
	m_combo->setEditable( isEditable );
	
	m_combo->setInsertPolicy(QComboBox::InsertAtBottom);
	m_combo->setAutoCompletion(true);
	m_combo->setMinimumSize(10, 0); // to allow the combo to be resized to a small size

	m_combo->insertItems(m_combo->count(), m_property->allowed() );
	//m_combo->setCurrentText( m_property->displayString() ); // 2018.12.07
    {
        QString text = m_property->displayString();
        int i = m_combo->findText(text);
        if (i != -1)
            m_combo->setCurrentIndex(i);
        else if (m_combo->isEditable())
            m_combo->setEditText(text);
        else
            m_combo->setItemText(m_combo->currentIndex(), text);
    }

	KCompletion *comp = m_combo->completionObject();
	comp->insertItems( m_property->allowed() );

	setWidget(box, m_combo->lineEdit());
	
	connect( m_combo, SIGNAL(activated( const QString & )), this, SLOT(valueChanged( const QString & )) );
	connect( m_property, SIGNAL(valueChanged( const QString& )), m_combo, SLOT(setCurrentItem( const QString & )) );
}
Ejemplo n.º 30
0
CDDAHeaderDataDialog::CDDAHeaderDataDialog(CDDAModel *cddaModel, QWidget *parent) : QDialog(parent) {

  Q_UNUSED(parent);

  cdda_model = cddaModel;
  if (!cdda_model) {
    qDebug() << "CDDAModel is NULL!";
    return;
  }



  setWindowTitle(i18n("Edit Data"));

  QVBoxLayout *mainLayout = new QVBoxLayout;
  setLayout(mainLayout);

  QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Apply|QDialogButtonBox::Cancel);
  okButton = buttonBox->button(QDialogButtonBox::Ok);
  applyButton = buttonBox->button(QDialogButtonBox::Apply);
  okButton->setDefault(true);
  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
  connect(buttonBox, &QDialogButtonBox::accepted, this, &CDDAHeaderDataDialog::slotAccepted);
  connect(buttonBox, &QDialogButtonBox::rejected, this, &CDDAHeaderDataDialog::reject);
  connect(applyButton, &QPushButton::clicked, this, &CDDAHeaderDataDialog::slotApplied);

  QWidget *widget = new QWidget(this);
  mainLayout->addWidget(widget);
  mainLayout->addWidget(buttonBox);
  ui.setupUi(widget);

  QStringList genres; for (int i = 0; i < GENRE_MAX; ++i) genres.append(QString().fromAscii(ID3_GENRES[i]));
  genres.sort();
  KCompletion *comp = ui.kcombobox_genre->completionObject();
  comp->insertItems(genres);
  ui.kcombobox_genre->addItems(genres);
  connect(ui.kcombobox_genre, SIGNAL(returnPressed(const QString&)), comp, SLOT(addItem(const QString&)));

  ui.checkBox_various->setChecked(cdda_model->isVarious());
  connect(ui.checkBox_various, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
  ui.checkBox_multicd->setChecked(cdda_model->isMultiCD());
  connect(ui.checkBox_multicd, SIGNAL(toggled(bool)), this, SLOT(enable_checkbox_multicd(bool)));
  connect(ui.checkBox_multicd, SIGNAL(toggled(bool)), this, SLOT(trigger_changed()));
  ui.qlineedit_artist->setText(cdda_model->artist());
  connect(ui.qlineedit_artist, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed()));
  ui.qlineedit_title->setText(cdda_model->title());
  connect(ui.qlineedit_title, SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed()));
  ui.kintspinbox_cdnum->setValue(cdda_model->cdNum());
  connect(ui.kintspinbox_cdnum, SIGNAL(valueChanged(int)), this, SLOT(trigger_changed()));
  ui.kintspinbox_trackoffset->setValue(cdda_model->trackOffset());
  connect(ui.kintspinbox_trackoffset, SIGNAL(valueChanged(int)), this, SLOT(trigger_changed()));
  ui.kcombobox_genre->lineEdit()->setText(cdda_model->genre());
  connect(ui.kcombobox_genre->lineEdit(), SIGNAL(textEdited(const QString&)), this, SLOT(trigger_changed()));
  {
    bool ok; int year = cdda_model->year().toInt(&ok);
    if (ok) ui.kintspinbox_year->setValue(year); else ui.kintspinbox_year->setValue(QDate::currentDate().year());
  }
  connect(ui.kintspinbox_year, SIGNAL(valueChanged(int)), this, SLOT(trigger_changed()));
  ui.ktextedit_extdata->setText(cdda_model->extendedData().join("\n"));
  connect(ui.ktextedit_extdata, SIGNAL(textChanged()), this, SLOT(trigger_changed()));
  ui.qlineedit_freedbdiscid->setText(QString("0x%1").arg(DiscIDCalculator::FreeDBId(cdda_model->discSignature()), 0, 16));

  enable_checkbox_multicd(cdda_model->isMultiCD());

  applyButton->setEnabled(false);

}