31 #include <sonnet/speller.h>
34 #include <QContextMenuEvent>
36 #include <QApplication>
38 #include <QStyleOptionFrameV2>
45 class SpellCheckLineEdit::Private
60 Sonnet::Speller* speller;
67 d->configFile = configFile;
69 enableFindReplace(
false);
70 #ifdef HAVE_SHOWTABACTION
73 setAcceptRichText(
false);
74 setTabChangesFocus(
true );
76 setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Fixed));
77 setLineWrapMode(NoWrap);
78 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
79 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
80 setCheckSpellingEnabledInternal(
true );
81 document()->adjustSize();
83 document()->setDocumentMargin(2);
95 return d->activateLanguageMenu;
100 d->activateLanguageMenu = activate;
106 Sonnet::Highlighter *highlighter =
new Sonnet::Highlighter(
this, d->configFile);
107 highlighter->setAutomatic(
false );
109 KTextEdit::setHighlighter(highlighter);
111 if (!spellCheckingLanguage().isEmpty()) {
112 setSpellCheckingLanguage( spellCheckingLanguage() );
118 if (e->key() == Qt::Key_Enter ||
119 e->key() == Qt::Key_Return ||
120 e->key() == Qt::Key_Down) {
123 }
else if (e->key() == Qt::Key_Up) {
127 KTextEdit::keyPressEvent(e);
132 QFontMetrics fm(font());
134 const int h = document()->size().toSize().height() - fm.descent() + 2 * frameWidth();
136 QStyleOptionFrameV2 opt;
138 opt.rect = QRect(0, 0, 100, h);
139 opt.lineWidth = lineWidth();
140 opt.midLineWidth = 0;
141 opt.state |= QStyle::State_Sunken;
143 QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()),
this);
161 QString pasteText = source->text();
164 if (!pasteText.isEmpty()) {
166 pasteText.replace(QLatin1Char(
'\r' ),QLatin1Char(
'\n' ));
168 while(pasteText.contains(QLatin1String(
"\n\n" )))
169 pasteText.replace(QLatin1String(
"\n\n" ),QLatin1String(
"\n" ));
171 QRegExp reTopSpace(QLatin1String(
"^ *\n" ));
172 while(pasteText.contains(reTopSpace))
173 pasteText.remove(reTopSpace);
175 QRegExp reBottomSpace(QLatin1String(
"\n *$" ));
176 while(pasteText.contains(reBottomSpace))
177 pasteText.remove(reBottomSpace);
180 if(pasteText.contains(QLatin1Char(
'\n' )))
181 pasteText.remove(QLatin1Char(
'\n' ));
183 insertPlainText(pasteText);
184 ensureCursorVisible();
187 KTextEdit::insertFromMimeData(source);
191 static inline QString
i18n_kdelibs4(
const char *str) {
return ki18n(str).toString(QLatin1String(
"kdelibs4")); }
195 if (!checkSpellingEnabled())
198 if (!d->activateLanguageMenu)
201 QAction* spellCheckAction = 0;
203 foreach (QAction* action, contextMenu->actions())
207 spellCheckAction = action;
212 if (spellCheckAction)
214 QMenu* languagesMenu =
new QMenu(i18n(
"Spell Checking Language"), contextMenu);
215 QActionGroup* languagesGroup =
new QActionGroup(languagesMenu);
216 languagesGroup->setExclusive(
true);
219 d->speller =
new Sonnet::Speller();
221 QMapIterator<QString, QString> i(d->speller->availableDictionaries());
222 QAction* languageAction = 0;
228 languageAction = languagesMenu->addAction(i.key());
229 languageAction->setCheckable(
true);
230 languageAction->setChecked(spellCheckingLanguage() == i.value() || (spellCheckingLanguage().isEmpty()
231 && d->speller->defaultLanguage() == i.value()));
232 languageAction->setData(i.value());
233 languageAction->setActionGroup(languagesGroup);
234 connect(languageAction, SIGNAL(triggered(
bool)),
this, SLOT(
languageSelected()));
237 contextMenu->insertMenu(spellCheckAction, languagesMenu);
243 QAction* languageAction =
static_cast<QAction*
>(QObject::sender());
244 setSpellCheckingLanguage(languageAction->data().toString());
248 #include "spellchecklineedit.moc"
QSize minimumSizeHint() const
void setActivateLanguageMenu(bool activate)
void insertLanguageMenu(QMenu *contextMenu)
static QString i18n_kdelibs4(const char *str)
~SpellCheckLineEdit()
Destructor.
bool activateLanguageMenu() const
SpellCheckLineEdit(QWidget *parent, const QString &configFile)
Constructs a SpellCheckLineEdit object.
void keyPressEvent(QKeyEvent *)
void focusUp()
Emitted when the user uses the up arrow in the first line.
void insertFromMimeData(const QMimeData *source)