mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
generic: drop support for spelling correction via dialog
the context menu of Kate (which could be implemented for KTextEdit aswell) offers the same functionality Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
15319dc6bc
commit
66eb4985f2
12 changed files with 7 additions and 622 deletions
|
@ -120,8 +120,6 @@ set(katepart_PART_SRCS
|
|||
spellcheck/ontheflycheck.cpp
|
||||
spellcheck/spellcheck.h
|
||||
spellcheck/spellcheck.cpp
|
||||
spellcheck/spellcheckdialog.h
|
||||
spellcheck/spellcheckdialog.cpp
|
||||
spellcheck/spellingmenu.h
|
||||
spellcheck/spellingmenu.cpp
|
||||
|
||||
|
|
|
@ -1,311 +0,0 @@
|
|||
/* This file is part of the KDE libraries and the Kate part.
|
||||
*
|
||||
* Copyright (C) 2009-2010 by Michel Ludwig <michel.ludwig@kdemail.net>
|
||||
* Copyright (C) 2008 Mirko Stocker <me@misto.ch>
|
||||
* Copyright (C) 2004-2005 Anders Lund <anders@alweb.dk>
|
||||
* Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
|
||||
* Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
|
||||
* Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
|
||||
* Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "spellcheckdialog.h"
|
||||
#include "moc_spellcheckdialog.cpp"
|
||||
|
||||
#include "katedocument.h"
|
||||
#include "kateglobal.h"
|
||||
#include "kateview.h"
|
||||
#include "spellcheck/spellcheck.h"
|
||||
|
||||
#include <kaction.h>
|
||||
#include <kactioncollection.h>
|
||||
#include <kicon.h>
|
||||
#include <kstandardaction.h>
|
||||
#include <kspelldialog.h>
|
||||
|
||||
KateSpellCheckDialog::KateSpellCheckDialog( KateView* view )
|
||||
: QObject( view )
|
||||
, m_view (view)
|
||||
, m_spellDialog(NULL)
|
||||
, m_globalSpellCheckRange(NULL)
|
||||
, m_spellCheckCancelledByUser(false)
|
||||
{
|
||||
}
|
||||
|
||||
KateSpellCheckDialog::~KateSpellCheckDialog()
|
||||
{
|
||||
delete m_globalSpellCheckRange;
|
||||
delete m_spellDialog;
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::createActions( KActionCollection* ac )
|
||||
{
|
||||
ac->addAction( KStandardAction::Spelling, this, SLOT(spellcheck()) );
|
||||
|
||||
KAction *a = new KAction( i18n("Spelling (from cursor)..."), this);
|
||||
ac->addAction("tools_spelling_from_cursor", a );
|
||||
a->setIcon( KIcon( "tools-check-spelling" ) );
|
||||
a->setWhatsThis(i18n("Check the document's spelling from the cursor and forward"));
|
||||
connect( a, SIGNAL(triggered()), this, SLOT(spellcheckFromCursor()) );
|
||||
|
||||
m_spellcheckSelection = new KAction( i18n("Spellcheck Selection..."), this );
|
||||
ac->addAction("tools_spelling_selection", m_spellcheckSelection);
|
||||
m_spellcheckSelection->setIcon( KIcon( "tools-check-spelling" ) );
|
||||
m_spellcheckSelection->setWhatsThis(i18n("Check spelling of the selected text"));
|
||||
connect( m_spellcheckSelection, SIGNAL(triggered()), this, SLOT(spellcheckSelection()) );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::updateActions ()
|
||||
{
|
||||
m_spellcheckSelection->setEnabled (m_view->selection ());
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::spellcheckFromCursor()
|
||||
{
|
||||
spellcheck( m_view->cursorPosition() );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::spellcheckSelection()
|
||||
{
|
||||
spellcheck( m_view->selectionRange().start(), m_view->selectionRange().end() );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::spellcheck()
|
||||
{
|
||||
spellcheck( KTextEditor::Cursor( 0, 0 ) );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::spellcheck( const KTextEditor::Cursor &from, const KTextEditor::Cursor &to )
|
||||
{
|
||||
KTextEditor::Cursor start = from;
|
||||
KTextEditor::Cursor end = to;
|
||||
|
||||
if ( end.line() == 0 && end.column() == 0 )
|
||||
{
|
||||
end = m_view->doc()->documentEnd();
|
||||
}
|
||||
|
||||
if ( !m_spellDialog )
|
||||
{
|
||||
m_spellDialog = new KSpellDialog(KGlobal::config().data(), m_view);
|
||||
m_spellDialog->showSpellCheckCompletionMessage();
|
||||
m_spellDialog->setSpellCheckContinuedAfterReplacement(false);
|
||||
|
||||
connect(m_spellDialog,SIGNAL(accepted()),this,SLOT(installNextSpellCheckRange()));
|
||||
|
||||
connect(m_spellDialog,SIGNAL(replace(QString,int,QString)),
|
||||
this,SLOT(corrected(QString,int,QString)));
|
||||
|
||||
connect(m_spellDialog,SIGNAL(misspelling(QString,int)),
|
||||
this,SLOT(misspelling(QString,int)));
|
||||
|
||||
connect(m_spellDialog,SIGNAL(rejected()),
|
||||
this,SLOT(cancelClicked()));
|
||||
|
||||
connect(m_spellDialog,SIGNAL(destroyed(QObject*)),
|
||||
this,SLOT(objectDestroyed(QObject*)));
|
||||
|
||||
connect(m_spellDialog,SIGNAL(languageChanged(QString)),
|
||||
this,SLOT(languageChanged(QString)));
|
||||
}
|
||||
|
||||
m_userSpellCheckLanguage.clear();
|
||||
m_previousGivenSpellCheckLanguage.clear();
|
||||
delete m_globalSpellCheckRange;
|
||||
// we expand to handle the situation when the last word in the range is replace by a new one
|
||||
m_globalSpellCheckRange = m_view->doc()->newMovingRange (KTextEditor::Range( start, end ),
|
||||
KTextEditor::MovingRange::ExpandLeft | KTextEditor::MovingRange::ExpandRight);
|
||||
m_spellCheckCancelledByUser = false;
|
||||
performSpellCheck( m_globalSpellCheckRange->toRange() );
|
||||
}
|
||||
|
||||
KTextEditor::Cursor KateSpellCheckDialog::locatePosition( int pos )
|
||||
{
|
||||
uint remains;
|
||||
|
||||
while ( m_spellLastPos < (uint)pos )
|
||||
{
|
||||
remains = pos - m_spellLastPos;
|
||||
uint l = m_view->doc()->lineLength( m_spellPosCursor.line() ) - m_spellPosCursor.column();
|
||||
if ( l > remains )
|
||||
{
|
||||
m_spellPosCursor.setColumn( m_spellPosCursor.column() + remains );
|
||||
m_spellLastPos = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_spellPosCursor.setLine( m_spellPosCursor.line() + 1 );
|
||||
m_spellPosCursor.setColumn(0);
|
||||
m_spellLastPos += l + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return m_spellPosCursor;
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::misspelling( const QString& word, int pos )
|
||||
{
|
||||
KTextEditor::Cursor cursor;
|
||||
int length;
|
||||
int origPos = m_view->doc()->computePositionWrtOffsets( m_currentDecToEncOffsetList, pos );
|
||||
cursor = locatePosition( origPos );
|
||||
length = m_view->doc()->computePositionWrtOffsets( m_currentDecToEncOffsetList, pos + word.length() )
|
||||
- origPos;
|
||||
|
||||
m_view->setCursorPositionInternal (cursor, 1);
|
||||
m_view->setSelection( KTextEditor::Range(cursor, length) );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::corrected( const QString& word, int pos, const QString& newWord )
|
||||
{
|
||||
int origPos = m_view->doc()->computePositionWrtOffsets( m_currentDecToEncOffsetList, pos );
|
||||
|
||||
int length = m_view->doc()->computePositionWrtOffsets( m_currentDecToEncOffsetList, pos + word.length() )
|
||||
- origPos;
|
||||
|
||||
KTextEditor::Cursor replacementStartCursor = locatePosition( origPos );
|
||||
KTextEditor::Range replacementRange = KTextEditor::Range( replacementStartCursor, length );
|
||||
KateDocument *doc = m_view->doc();
|
||||
KateGlobal::self()->spellCheckManager()->replaceCharactersEncodedIfNecessary( newWord, doc, replacementRange );
|
||||
|
||||
m_currentSpellCheckRange.setRange( KTextEditor::Range( replacementStartCursor, m_currentSpellCheckRange.end() ) );
|
||||
// we have to be careful here: due to static word wrapping the text might change in addition to simply
|
||||
// the misspelled word being replaced, i.e. new line breaks might be inserted as well. As such, the text
|
||||
// in the 'KSpellDialog' might be eventually out of sync with the visible text. Therefore, we 'restart'
|
||||
// spell checking from the current position.
|
||||
performSpellCheck( KTextEditor::Range( replacementStartCursor, m_globalSpellCheckRange->end().toCursor() ) );
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::performSpellCheck(const KTextEditor::Range& range)
|
||||
{
|
||||
if(range.isEmpty()) {
|
||||
spellCheckDone();
|
||||
}
|
||||
m_languagesInSpellCheckRange = KateGlobal::self()->spellCheckManager()->spellCheckLanguageRanges(m_view->doc(), range);
|
||||
m_currentLanguageRangeIterator = m_languagesInSpellCheckRange.begin();
|
||||
m_currentSpellCheckRange = KTextEditor::Range::invalid();
|
||||
installNextSpellCheckRange();
|
||||
// first check if there is really something to spell check
|
||||
if(m_currentSpellCheckRange.isValid()) {
|
||||
m_spellDialog->show();
|
||||
}
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::installNextSpellCheckRange()
|
||||
{
|
||||
if ( m_spellCheckCancelledByUser
|
||||
|| m_currentLanguageRangeIterator == m_languagesInSpellCheckRange.end() )
|
||||
{
|
||||
spellCheckDone();
|
||||
return;
|
||||
}
|
||||
KateSpellCheckManager *spellCheckManager = KateGlobal::self()->spellCheckManager();
|
||||
KTextEditor::Cursor nextRangeBegin = (m_currentSpellCheckRange.isValid() ? m_currentSpellCheckRange.end()
|
||||
: KTextEditor::Cursor::invalid());
|
||||
m_currentSpellCheckRange = KTextEditor::Range::invalid();
|
||||
m_currentDecToEncOffsetList.clear();
|
||||
QList<QPair<KTextEditor::Range, QString> > rangeDictionaryPairList;
|
||||
while ( m_currentLanguageRangeIterator != m_languagesInSpellCheckRange.end() )
|
||||
{
|
||||
const KTextEditor::Range& currentLanguageRange = (*m_currentLanguageRangeIterator).first;
|
||||
const QString& dictionary = (*m_currentLanguageRangeIterator).second;
|
||||
KTextEditor::Range languageSubRange = (nextRangeBegin.isValid() ? KTextEditor::Range(nextRangeBegin, currentLanguageRange.end())
|
||||
: currentLanguageRange);
|
||||
rangeDictionaryPairList = spellCheckManager->spellCheckWrtHighlightingRanges(m_view->doc(),
|
||||
languageSubRange,
|
||||
dictionary,
|
||||
false, true);
|
||||
Q_ASSERT(rangeDictionaryPairList.size() <= 1);
|
||||
if(rangeDictionaryPairList.size() == 0) {
|
||||
++m_currentLanguageRangeIterator;
|
||||
if ( m_currentLanguageRangeIterator != m_languagesInSpellCheckRange.end() )
|
||||
{
|
||||
nextRangeBegin = (*m_currentLanguageRangeIterator).first.start();
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_currentSpellCheckRange = rangeDictionaryPairList.first().first;
|
||||
QString dictionary = rangeDictionaryPairList.first().second;
|
||||
const bool languageChanged = (dictionary != m_previousGivenSpellCheckLanguage);
|
||||
m_previousGivenSpellCheckLanguage = dictionary;
|
||||
|
||||
// if there was no change of dictionary stemming from the document language ranges and
|
||||
// the user has set a dictionary in the dialog, we use that one
|
||||
if(!languageChanged && !m_userSpellCheckLanguage.isEmpty()) {
|
||||
dictionary = m_userSpellCheckLanguage;
|
||||
}
|
||||
// we only allow the user to override the preset dictionary within a language range
|
||||
// given by the document
|
||||
else if(languageChanged) {
|
||||
m_userSpellCheckLanguage.clear();
|
||||
}
|
||||
|
||||
m_spellPosCursor = m_currentSpellCheckRange.start();
|
||||
m_spellLastPos = 0;
|
||||
|
||||
m_currentDecToEncOffsetList.clear();
|
||||
KateDocument::OffsetList encToDecOffsetList;
|
||||
QString text = m_view->doc()->decodeCharacters(m_currentSpellCheckRange,
|
||||
m_currentDecToEncOffsetList,
|
||||
encToDecOffsetList);
|
||||
// ensure that no empty string is passed on to speller as this can lead to a crash
|
||||
// (bug 228789)
|
||||
if(text.isEmpty()) {
|
||||
nextRangeBegin = m_currentSpellCheckRange.end();
|
||||
continue;
|
||||
}
|
||||
|
||||
m_spellDialog->changeLanguage(dictionary);
|
||||
m_spellDialog->setBuffer(text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( m_currentLanguageRangeIterator == m_languagesInSpellCheckRange.end() )
|
||||
{
|
||||
spellCheckDone();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::cancelClicked()
|
||||
{
|
||||
m_spellCheckCancelledByUser = true;
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::spellCheckDone()
|
||||
{
|
||||
m_currentSpellCheckRange = KTextEditor::Range::invalid();
|
||||
m_currentDecToEncOffsetList.clear();
|
||||
m_view->clearSelection();
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::objectDestroyed(QObject *object)
|
||||
{
|
||||
Q_UNUSED(object);
|
||||
m_spellDialog = NULL;
|
||||
}
|
||||
|
||||
void KateSpellCheckDialog::languageChanged(const QString &language)
|
||||
{
|
||||
m_userSpellCheckLanguage = language;
|
||||
}
|
||||
|
||||
//END
|
||||
|
||||
|
||||
// kate: space-indent on; indent-width 2; replace-tabs on;
|
|
@ -1,116 +0,0 @@
|
|||
/* This file is part of the KDE libraries and the Kate part.
|
||||
*
|
||||
* Copyright (C) 2009-2010 by Michel Ludwig <michel.ludwig@kdemail.net>
|
||||
* Copyright (C) 2008 Mirko Stocker <me@misto.ch>
|
||||
* Copyright (C) 2004-2005 Anders Lund <anders@alweb.dk>
|
||||
* Copyright (C) 2002 John Firebaugh <jfirebaugh@kde.org>
|
||||
* Copyright (C) 2001-2004 Christoph Cullmann <cullmann@kde.org>
|
||||
* Copyright (C) 2001 Joseph Wenninger <jowenn@kde.org>
|
||||
* Copyright (C) 1999 Jochen Wilhelmy <digisnap@cs.tu-berlin.de>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public License
|
||||
* along with this library; see the file COPYING.LIB. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __KATE_SPELLCHECKDIALOG_H__
|
||||
#define __KATE_SPELLCHECKDIALOG_H__
|
||||
|
||||
#include <QtCore/QObject>
|
||||
|
||||
class KateView;
|
||||
|
||||
class KAction;
|
||||
class KActionCollection;
|
||||
class KProgressDialog;
|
||||
class KSpellDialog;
|
||||
|
||||
#include "ktexteditor/range.h"
|
||||
|
||||
namespace KTextEditor {
|
||||
class MovingRange;
|
||||
}
|
||||
|
||||
class KateSpellCheckDialog : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KateSpellCheckDialog( KateView* );
|
||||
~KateSpellCheckDialog();
|
||||
|
||||
void createActions( KActionCollection* );
|
||||
|
||||
void updateActions ();
|
||||
|
||||
// spellcheck from cursor, selection
|
||||
private Q_SLOTS:
|
||||
void spellcheckFromCursor();
|
||||
|
||||
// defined here in anticipation of per view selections ;)
|
||||
void spellcheckSelection();
|
||||
|
||||
void spellcheck();
|
||||
|
||||
/**
|
||||
* Spellcheck a defined portion of the text.
|
||||
*
|
||||
* @param from Where to start the check
|
||||
* @param to Where to end. If this is (0,0), it will be set to the end of the document.
|
||||
*/
|
||||
void spellcheck( const KTextEditor::Cursor &from, const KTextEditor::Cursor &to=KTextEditor::Cursor() );
|
||||
|
||||
void misspelling( const QString&, int );
|
||||
void corrected ( const QString&, int, const QString&);
|
||||
|
||||
void performSpellCheck(const KTextEditor::Range& range);
|
||||
void installNextSpellCheckRange();
|
||||
|
||||
void cancelClicked();
|
||||
|
||||
void objectDestroyed(QObject *object);
|
||||
|
||||
void languageChanged(const QString &language);
|
||||
|
||||
private:
|
||||
KTextEditor::Cursor locatePosition( int pos );
|
||||
|
||||
KateView *m_view;
|
||||
KAction *m_spellcheckSelection;
|
||||
|
||||
KSpellDialog *m_spellDialog;
|
||||
|
||||
// define the part of the text that is to be checked
|
||||
KTextEditor::Range m_currentSpellCheckRange;
|
||||
KTextEditor::MovingRange *m_globalSpellCheckRange;
|
||||
|
||||
QList<QPair<int, int> > m_currentDecToEncOffsetList;
|
||||
|
||||
QList<QPair<KTextEditor::Range, QString> > m_languagesInSpellCheckRange;
|
||||
QList<QPair<KTextEditor::Range, QString> >::iterator m_currentLanguageRangeIterator;
|
||||
|
||||
// keep track of where we are.
|
||||
KTextEditor::Cursor m_spellPosCursor;
|
||||
uint m_spellLastPos;
|
||||
|
||||
bool m_spellCheckCancelledByUser;
|
||||
|
||||
QString m_userSpellCheckLanguage, m_previousGivenSpellCheckLanguage;
|
||||
|
||||
void spellCheckDone();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// kate: space-indent on; indent-width 2; replace-tabs on;
|
|
@ -49,7 +49,6 @@
|
|||
#include "katekeywordcompletion.h"
|
||||
#include "katelayoutcache.h"
|
||||
#include "spellcheck/spellcheck.h"
|
||||
#include "spellcheck/spellcheckdialog.h"
|
||||
#include "spellcheck/spellingmenu.h"
|
||||
#include "katebuffer.h"
|
||||
#include "katemessagewidget.h"
|
||||
|
@ -121,7 +120,6 @@ KateView::KateView( KateDocument *doc, QWidget *parent )
|
|||
, m_config( new KateViewConfig( this ) )
|
||||
, m_renderer( new KateRenderer( doc, m_textFolding, this ) )
|
||||
, m_viewInternal( new KateViewInternal( this ) )
|
||||
, m_spell( new KateSpellCheckDialog( this ) )
|
||||
, m_bookmarks( new KateBookmarks( this ) )
|
||||
, m_startingUp (true)
|
||||
, m_updatingDocumentConfig (false)
|
||||
|
@ -647,7 +645,6 @@ void KateView::setupActions()
|
|||
a = ac->addAction( KStandardAction::Replace, this, SLOT(replace()) );
|
||||
a->setWhatsThis(i18n("Look up a piece of text or regular expression and replace the result with some given text."));
|
||||
|
||||
m_spell->createActions( ac );
|
||||
m_toggleOnTheFlySpellCheck = new KToggleAction(i18n("Automatic Spell Checking"), this);
|
||||
m_toggleOnTheFlySpellCheck->setWhatsThis(i18n("Enable/disable automatic spell checking"));
|
||||
m_toggleOnTheFlySpellCheck->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_O));
|
||||
|
@ -1497,8 +1494,6 @@ void KateView::slotSelectionChanged ()
|
|||
return;
|
||||
|
||||
m_cut->setEnabled (selection() || m_config->smartCopyCut() );
|
||||
|
||||
m_spell->updateActions ();
|
||||
}
|
||||
|
||||
void KateView::switchToCmdLine ()
|
||||
|
|
|
@ -52,7 +52,6 @@ class KateBookmarks;
|
|||
class KateCommandLineBar;
|
||||
class KateViewConfig;
|
||||
class KateRenderer;
|
||||
class KateSpellCheckDialog;
|
||||
class KateCompletionWidget;
|
||||
class KateViewInternal;
|
||||
class KateSearchBar;
|
||||
|
@ -627,7 +626,6 @@ class KATEPARTINTERFACES_EXPORT KateView : public KTextEditor::View,
|
|||
KateViewConfig *const m_config;
|
||||
KateRenderer *const m_renderer;
|
||||
KateViewInternal *const m_viewInternal;
|
||||
KateSpellCheckDialog *m_spell;
|
||||
KateBookmarks *const m_bookmarks;
|
||||
|
||||
QVBoxLayout *m_vBox;
|
||||
|
|
|
@ -2,7 +2,6 @@ add_subdirectory(pixmaps)
|
|||
|
||||
set(kmenueditcommon_STAT_SRCS
|
||||
preferencesdlg.cpp
|
||||
klinespellchecking.cpp
|
||||
basictab.cpp
|
||||
treeview.cpp
|
||||
kmenuedit.cpp
|
||||
|
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
#include "khotkeys.h"
|
||||
|
||||
#include "klinespellchecking.h"
|
||||
#include "menuinfo.h"
|
||||
|
||||
#include "moc_basictab.cpp"
|
||||
|
@ -60,9 +59,9 @@ BasicTab::BasicTab( QWidget *parent )
|
|||
// setup line inputs
|
||||
_nameEdit = new KLineEdit(general_group);
|
||||
_nameEdit->setAcceptDrops(false);
|
||||
_descriptionEdit = new KLineSpellChecking(general_group);
|
||||
_descriptionEdit = new KLineEdit(general_group);
|
||||
_descriptionEdit->setAcceptDrops(false);
|
||||
_commentEdit = new KLineSpellChecking(general_group);
|
||||
_commentEdit = new KLineEdit(general_group);
|
||||
_commentEdit->setAcceptDrops(false);
|
||||
_execEdit = new KUrlRequester(general_group);
|
||||
_execEdit->lineEdit()->setAcceptDrops(false);
|
||||
|
|
|
@ -23,16 +23,15 @@
|
|||
#include <KTabWidget>
|
||||
#include <KShortcut>
|
||||
#include <KService>
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
|
||||
class KKeySequenceWidget;
|
||||
class KLineEdit;
|
||||
class KIconButton;
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
class KUrlRequester;
|
||||
class KService;
|
||||
class KLineSpellChecking;
|
||||
|
||||
class MenuFolderInfo;
|
||||
class MenuEntryInfo;
|
||||
|
@ -73,8 +72,8 @@ protected:
|
|||
|
||||
protected:
|
||||
KLineEdit *_nameEdit;
|
||||
KLineSpellChecking*_commentEdit;
|
||||
KLineSpellChecking *_descriptionEdit;
|
||||
KLineEdit *_commentEdit;
|
||||
KLineEdit *_descriptionEdit;
|
||||
KKeySequenceWidget *_keyEdit;
|
||||
KUrlRequester *_execEdit, *_pathEdit;
|
||||
KLineEdit *_termOptEdit, *_uidEdit;
|
||||
|
|
|
@ -1,94 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Montel Laurent <montel@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#include "klinespellchecking.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
#include <KStandardAction>
|
||||
#include <KActionCollection>
|
||||
#include <KAction>
|
||||
#include <KSpellDialog>
|
||||
|
||||
KLineSpellChecking::KLineSpellChecking(QWidget* parent)
|
||||
: KLineEdit(parent)
|
||||
{
|
||||
KActionCollection *ac = new KActionCollection(this);
|
||||
m_spellAction = KStandardAction::spelling( this, SLOT(slotCheckSpelling()), ac );
|
||||
}
|
||||
|
||||
KLineSpellChecking::~KLineSpellChecking()
|
||||
{
|
||||
}
|
||||
|
||||
void KLineSpellChecking::slotCheckSpelling()
|
||||
{
|
||||
if ( text().isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
KSpellDialog *spellDialog = new KSpellDialog(KGlobal::config().data(), 0);
|
||||
connect(spellDialog, SIGNAL(replace(QString,int,QString)), this, SLOT(spellCheckerCorrected(QString,int,QString)));
|
||||
connect(spellDialog, SIGNAL(misspelling(QString,int)), this, SLOT(spellCheckerMisspelling(QString,int)));
|
||||
spellDialog->setBuffer(text());
|
||||
spellDialog->show();
|
||||
}
|
||||
|
||||
void KLineSpellChecking::spellCheckerMisspelling( const QString &_text, int pos)
|
||||
{
|
||||
highLightWord( _text.length(),pos );
|
||||
}
|
||||
|
||||
void KLineSpellChecking::highLightWord( unsigned int length, unsigned int pos )
|
||||
{
|
||||
setSelection ( pos, length );
|
||||
}
|
||||
|
||||
void KLineSpellChecking::spellCheckerCorrected( const QString &old, int pos, const QString &corr )
|
||||
{
|
||||
if( old!= corr )
|
||||
{
|
||||
setSelection ( pos, old.length() );
|
||||
insert( corr );
|
||||
setSelection ( pos, corr.length() );
|
||||
}
|
||||
}
|
||||
|
||||
void KLineSpellChecking::contextMenuEvent(QContextMenuEvent *e)
|
||||
{
|
||||
QMenu* popup = createStandardContextMenu();
|
||||
|
||||
if ( !popup )
|
||||
return;
|
||||
|
||||
if (echoMode() == QLineEdit::Normal &&
|
||||
!isReadOnly()) {
|
||||
popup->addSeparator();
|
||||
|
||||
popup->addAction( m_spellAction );
|
||||
m_spellAction->setEnabled( !text().isEmpty() );
|
||||
}
|
||||
popup->exec(e->globalPos());
|
||||
delete popup;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#include "moc_klinespellchecking.cpp"
|
||||
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2008 Montel Laurent <montel@kde.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
*/
|
||||
#ifndef KLINESPELLCHECKING_H
|
||||
#define KLINESPELLCHECKING_H
|
||||
|
||||
#include <KLineEdit>
|
||||
|
||||
class KAction;
|
||||
|
||||
class KLineSpellChecking : public KLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KLineSpellChecking( QWidget *parent = 0 );
|
||||
~KLineSpellChecking();
|
||||
|
||||
void highLightWord( unsigned int length, unsigned int pos );
|
||||
|
||||
protected:
|
||||
virtual void contextMenuEvent(QContextMenuEvent *e);
|
||||
|
||||
private slots:
|
||||
void slotCheckSpelling();
|
||||
void spellCheckerMisspelling( const QString &text, int pos);
|
||||
void spellCheckerCorrected( const QString &, int, const QString &);
|
||||
|
||||
private:
|
||||
KAction *m_spellAction;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -37,35 +37,14 @@ PreferencesDialog::PreferencesDialog( QWidget *parent )
|
|||
page->setIcon( KIcon( "kmenuedit" ) );
|
||||
addPage(page);
|
||||
|
||||
m_pageSpellChecking = new SpellCheckingPage( this );
|
||||
page = new KPageWidgetItem( m_pageSpellChecking , i18n( "Spell Checking" ) );
|
||||
page->setHeader( i18n( "Spell checking Options" ) );
|
||||
page->setIcon( KIcon( "tools-check-spelling" ) );
|
||||
addPage(page);
|
||||
|
||||
connect( this, SIGNAL(okClicked()), this, SLOT(slotSave()) );
|
||||
}
|
||||
|
||||
void PreferencesDialog::slotSave()
|
||||
{
|
||||
m_pageSpellChecking->saveOptions();
|
||||
m_pageMisc->saveOptions();
|
||||
}
|
||||
|
||||
SpellCheckingPage::SpellCheckingPage( QWidget *parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
QHBoxLayout *lay = new QHBoxLayout( this );
|
||||
m_confPage = new KSpellConfigWidget(KGlobal::config().data(), this );
|
||||
lay->addWidget( m_confPage );
|
||||
setLayout( lay );
|
||||
}
|
||||
|
||||
void SpellCheckingPage::saveOptions()
|
||||
{
|
||||
m_confPage->save();
|
||||
}
|
||||
|
||||
MiscPage::MiscPage( QWidget *parent )
|
||||
: QWidget( parent )
|
||||
{
|
||||
|
|
|
@ -22,9 +22,7 @@
|
|||
|
||||
#include <QCheckBox>
|
||||
#include <KPageDialog>
|
||||
#include <KSpellConfigWidget>
|
||||
|
||||
class SpellCheckingPage;
|
||||
class MiscPage;
|
||||
|
||||
class PreferencesDialog : public KPageDialog
|
||||
|
@ -37,20 +35,9 @@ protected slots:
|
|||
void slotSave();
|
||||
|
||||
private:
|
||||
SpellCheckingPage *m_pageSpellChecking;
|
||||
MiscPage *m_pageMisc;
|
||||
};
|
||||
|
||||
class SpellCheckingPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpellCheckingPage( QWidget * );
|
||||
void saveOptions();
|
||||
private:
|
||||
KSpellConfigWidget *m_confPage;
|
||||
};
|
||||
|
||||
class MiscPage : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
Loading…
Add table
Reference in a new issue