本文整理汇总了C++中KCompletion类的典型用法代码示例。如果您正苦于以下问题:C++ KCompletion类的具体用法?C++ KCompletion怎么用?C++ KCompletion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KCompletion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: maxCount
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();
}
示例2: KTextEdit
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() ) );
}
示例3: KDialog
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();
}
示例4: compObj
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);
}
}
示例5: QVERIFY
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);
}
示例6: sender
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&)) );
}
示例7:
void
Test_KCompletion::isEmpty()
{
KCompletion completion;
QVERIFY(completion.isEmpty());
QVERIFY(completion.items().isEmpty());
}
示例8: AbstractDockWidget
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 );
}
示例9: if
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 );
}
}
示例10: KDialog
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);
}
示例11: compObj
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() );
}
}
示例12: compObj
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( ¶, &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
}
}
示例13: compObj
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);
}
}
示例14: AbstractAccountParametersWidget
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());
}
示例15: KDialog
/*! \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);
}