Example #1
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() ) );
}
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 );
    }
}
Example #3
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 );
}