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"
21
#include <KStandardAction>
22
#include <KActionCollection>
24
#include <QContextMenuEvent>
25
#include <sonnet/dialog.h>
26
#include <sonnet/backgroundchecker.h>
28
KLineSpellChecking::KLineSpellChecking(QWidget* parent)
31
KActionCollection *ac = new KActionCollection(this);
32
m_spellAction = KStandardAction::spelling( this, SLOT( slotCheckSpelling() ), ac );
35
KLineSpellChecking::~KLineSpellChecking()
39
void KLineSpellChecking::slotCheckSpelling()
41
if ( text().isEmpty() ) {
44
Sonnet::Dialog *spellDialog = new Sonnet::Dialog(new Sonnet::BackgroundChecker(this), 0);
45
connect(spellDialog, SIGNAL(replace( const QString&, int,const QString&)), this, SLOT(spellCheckerCorrected( const QString&, int,const QString&)));
46
connect(spellDialog, SIGNAL(misspelling( const QString&, int)), this, SLOT(spellCheckerMisspelling(const QString &,int)));
47
connect(spellDialog, SIGNAL(done(const QString&)), this, SLOT(slotSpellCheckDone(const QString&)));
48
connect(spellDialog, SIGNAL(cancel()), this, SLOT(spellCheckerFinished()));
49
connect(spellDialog, SIGNAL(stop()), this, SLOT(spellCheckerFinished()));
50
spellDialog->setBuffer(text());
54
void KLineSpellChecking::spellCheckerMisspelling( const QString &_text, int pos)
56
highLightWord( _text.length(),pos );
59
void KLineSpellChecking::highLightWord( unsigned int length, unsigned int pos )
61
setSelection ( pos, length );
64
void KLineSpellChecking::spellCheckerCorrected( const QString &old, int pos, const QString &corr )
68
setSelection ( pos, old.length() );
70
setSelection ( pos, corr.length() );
74
void KLineSpellChecking::spellCheckerFinished()
78
void KLineSpellChecking::slotSpellCheckDone( const QString &s )
84
void KLineSpellChecking::contextMenuEvent(QContextMenuEvent *e)
86
QMenu* popup = createStandardContextMenu();
91
if (echoMode() == QLineEdit::Normal &&
93
popup->addSeparator();
95
popup->addAction( m_spellAction );
96
m_spellAction->setEnabled( !text().isEmpty() );
98
popup->exec(e->globalPos());
104
#include "klinespellchecking.moc"