2
* Copyright (C) 2008 Montel Laurent <montel@kde.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "klinespellchecking.h"
22
#include <QContextMenuEvent>
24
#include <KStandardAction>
25
#include <KActionCollection>
27
#include <sonnet/dialog.h>
28
#include <sonnet/backgroundchecker.h>
30
KLineSpellChecking::KLineSpellChecking(QWidget* parent)
33
KActionCollection *ac = new KActionCollection(this);
34
m_spellAction = KStandardAction::spelling( this, SLOT(slotCheckSpelling()), ac );
37
KLineSpellChecking::~KLineSpellChecking()
41
void KLineSpellChecking::slotCheckSpelling()
43
if ( text().isEmpty() ) {
46
Sonnet::Dialog *spellDialog = new Sonnet::Dialog(new Sonnet::BackgroundChecker(this), 0);
47
connect(spellDialog, SIGNAL(replace(QString,int,QString)), this, SLOT(spellCheckerCorrected(QString,int,QString)));
48
connect(spellDialog, SIGNAL(misspelling(QString,int)), this, SLOT(spellCheckerMisspelling(QString,int)));
49
connect(spellDialog, SIGNAL(done(QString)), this, SLOT(slotSpellCheckDone(QString)));
50
connect(spellDialog, SIGNAL(cancel()), this, SLOT(spellCheckerFinished()));
51
connect(spellDialog, SIGNAL(stop()), this, SLOT(spellCheckerFinished()));
52
spellDialog->setBuffer(text());
56
void KLineSpellChecking::spellCheckerMisspelling( const QString &_text, int pos)
58
highLightWord( _text.length(),pos );
61
void KLineSpellChecking::highLightWord( unsigned int length, unsigned int pos )
63
setSelection ( pos, length );
66
void KLineSpellChecking::spellCheckerCorrected( const QString &old, int pos, const QString &corr )
70
setSelection ( pos, old.length() );
72
setSelection ( pos, corr.length() );
76
void KLineSpellChecking::spellCheckerFinished()
80
void KLineSpellChecking::slotSpellCheckDone( const QString &s )
86
void KLineSpellChecking::contextMenuEvent(QContextMenuEvent *e)
88
QMenu* popup = createStandardContextMenu();
93
if (echoMode() == QLineEdit::Normal &&
95
popup->addSeparator();
97
popup->addAction( m_spellAction );
98
m_spellAction->setEnabled( !text().isEmpty() );
100
popup->exec(e->globalPos());
106
#include "klinespellchecking.moc"