22#include <QtGui/QApplication>
23#include <QtGui/QClipboard>
24#include <Qt3Support/Q3PopupMenu>
35class K3TextEdit::K3TextEditPrivate
39 : customPalette( false ),
40 checkSpellingEnabled( false ),
44 ~K3TextEditPrivate() {
50 bool checkSpellingEnabled;
56 QWidget *parent,
const char *name )
59 d =
new K3TextEditPrivate();
66 d =
new K3TextEditPrivate();
118 CursorAction action = MoveWordBackward;
120 getCursorPosition( ¶, & index );
121 if (text(para).isRightToLeft())
122 action = MoveWordForward;
123 moveCursor(action,
false );
129 CursorAction action = MoveWordForward;
131 getCursorPosition( ¶, & index );
132 if (text(para).isRightToLeft())
133 action = MoveWordBackward;
134 moveCursor( action,
false );
140 moveCursor( MovePgDown,
false );
146 moveCursor( MovePgUp,
false );
152 moveCursor( MoveHome,
false );
158 moveCursor( MoveEnd,
false );
164 moveCursor( MoveLineStart,
false );
170 moveCursor(MoveLineEnd,
false);
176 QString text = QApplication::clipboard()->text( QClipboard::Selection);
177 if ( !text.isEmpty() )
184 else if ( e->state() == Qt::ControlModifier &&
185 (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) &&
186 topLevelWidget()->inherits(
"KDialog" ) )
192 Q3TextEdit::keyPressEvent( e );
198 moveCursor( MoveWordBackward,
true );
199 removeSelectedText();
205 moveCursor( MoveWordForward,
true );
206 removeSelectedText();
209void K3TextEdit::slotAllowTab()
211setTabChangesFocus(!tabChangesFocus());
216 enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
218 Q3PopupMenu *menu = Q3TextEdit::createPopupMenu( pos );
221 menu->changeItem( menu->idAt(0),
KIcon(
"edit-copy"), menu->text( menu->idAt(0) ) );
223 int id = menu->idAt(0);
224 menu->changeItem(
id - IdUndo,
KIcon(
"edit-undo"), menu->text(
id - IdUndo) );
225 menu->changeItem(
id - IdRedo,
KIcon(
"edit-redo"), menu->text(
id - IdRedo) );
226 menu->changeItem(
id - IdCut,
KIcon(
"edit-cut"), menu->text(
id - IdCut) );
227 menu->changeItem(
id - IdCopy,
KIcon(
"edit-copy"), menu->text(
id - IdCopy) );
228 menu->changeItem(
id - IdPaste,
KIcon(
"edit-paste"), menu->text(
id - IdPaste) );
229 menu->changeItem(
id - IdClear,
KIcon(
"edit-clear"), menu->text(
id - IdClear) );
231 menu->insertSeparator();
232 id = menu->insertItem(
KIcon(
"tools-check-spelling" ),
i18n(
"Check Spelling..." ),
235 if( text().isEmpty() )
236 menu->setItemEnabled(
id,
false );
238 id = menu->insertItem(
i18n(
"Auto Spell Check" ),
239 this, SLOT(toggleAutoSpellCheck()) );
240 menu->setItemChecked(
id, d->checkSpellingEnabled);
241 menu->insertSeparator();
242 id=menu->insertItem(
i18n(
"Allow Tabulations"),
this,SLOT(slotAllowTab()));
243 menu->setItemChecked(
id, !tabChangesFocus());
251 return Q3TextEdit::createPopupMenu();
257 Q3TextEdit::contentsWheelEvent( e );
259 Q3ScrollView::contentsWheelEvent( e );
264 Q3TextEdit::setPalette( palette );
267 d->customPalette = ownPalette();
270void K3TextEdit::toggleAutoSpellCheck()
272 setCheckSpellingEnabled( !d->checkSpellingEnabled );
277 if ( check == d->checkSpellingEnabled )
284 d->checkSpellingEnabled = check;
292 delete d->highlighter;
299 if ( d->checkSpellingEnabled && !d->highlighter )
302 Q3TextEdit::focusInEvent( e );
307 return d->checkSpellingEnabled;
312 if ( readOnly == isReadOnly() )
317 bool custom = ownPalette();
318 QPalette p = palette();
319 QColor color = p.color(QPalette::Disabled, QPalette::Background);
320 p.setColor(QPalette::Base, color);
321 p.setColor(QPalette::Background, color);
323 d->customPalette = custom;
327 if ( d->customPalette )
329 QPalette p = palette();
330 QColor color = p.color(QPalette::Normal, QPalette::Base);
331 p.setColor(QPalette::Base, color);
332 p.setColor(QPalette::Background, color);
339 Q3TextEdit::setReadOnly (readOnly);
348 d->spell =
new K3Spell(
this,
i18n(
"Spell Checking" ),
349 this, SLOT(slotSpellCheckReady(
K3Spell*)), 0,
true,
true);
351 connect( d->spell, SIGNAL(death()),
352 this, SLOT(spellCheckerFinished()) );
354 connect( d->spell, SIGNAL(misspelling(QString,QStringList,uint)),
355 this, SLOT(spellCheckerMisspelling(QString,QStringList,uint)) );
357 connect( d->spell, SIGNAL(corrected(QString,QString,uint)),
358 this, SLOT(spellCheckerCorrected(QString,QString,uint)) );
361void K3TextEdit::spellCheckerMisspelling(
const QString &text,
const QStringList &,
unsigned int pos )
363 highLightWord( text.length(), pos );
366void K3TextEdit::spellCheckerCorrected(
const QString &oldWord,
const QString &newWord,
unsigned int pos )
369 unsigned int cnt = 0;
370 if ( oldWord != newWord ) {
371 posToRowCol( pos, l, cnt );
372 setSelection( l, cnt, l, cnt + oldWord.length() );
373 removeSelectedText();
378void K3TextEdit::posToRowCol(
unsigned int pos,
unsigned int &line,
unsigned int &col)
380 for ( line = 0; line < static_cast<uint>( lines() ) && col <= pos; line++ )
381 col += paragraphLength( line ) + 1;
384 col = pos - col + paragraphLength( line ) + 1;
387void K3TextEdit::spellCheckerFinished()
393void K3TextEdit::slotSpellCheckReady(
K3Spell *s )
396 connect( s, SIGNAL(done(QString)),
this, SLOT(slotSpellCheckDone(QString)) );
399void K3TextEdit::slotSpellCheckDone(
const QString &s )
409 unsigned int cnt = 0;
410 posToRowCol( pos, l, cnt );
411 setSelection( l, cnt, l, cnt + length );
414#include "k3textedit.moc"
Dictionary sensitive text highlighter.
virtual bool check(const QString &_buffer, bool usedialog=true)
Spellchecks a buffer of many words in plain text format.
virtual void virtual_hook(int id, void *data)
virtual void keyPressEvent(QKeyEvent *)
Reimplemented to catch "delete word" key events.
virtual void setPalette(const QPalette &palette)
Reimplemented for tracking custom palettes.
virtual Q3PopupMenu * createPopupMenu()
This is just a reimplementation of a deprecated method from Q3TextEdit and is just here to keep sourc...
K3TextEdit(const QString &text, const QString &context=QString(), QWidget *parent=0, const char *name=0)
Constructs a K3TextEdit object.
virtual void contentsWheelEvent(QWheelEvent *)
Reimplemented to allow fast-wheelscrolling with Ctrl-Wheel or zoom.
void highLightWord(unsigned int length, unsigned int pos)
virtual void deleteWordForward()
Deletes a word forwards from the current cursor position, if available.
virtual void focusInEvent(QFocusEvent *)
Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
virtual void setReadOnly(bool readOnly)
Reimplemented to set a proper "deactivated" background color.
bool checkSpellingEnabled() const
Returns true if spell checking is enabled for this text edit.
void setCheckSpellingEnabled(bool check)
Turns spell checking for this text edit on or off.
~K3TextEdit()
Destroys the K3TextEdit object.
virtual void deleteWordBack()
Deletes a word backwards from the current cursor position, if available.
void checkSpelling()
Create a modal dialog to check the spelling.
static void setAutoHideCursor(QWidget *w, bool enable, bool customEventFilter=false)
static bool wheelMouseZooms()
QString i18n(const char *text)
const KShortcut & prior()
const KShortcut & forwardWord()
const KShortcut & deleteWordBack()
const KShortcut & endOfLine()
const KShortcut & beginningOfLine()
const KShortcut & backwardWord()
const KShortcut & begin()
const KShortcut & paste()
const KShortcut & deleteWordForward()
const KShortcut & pasteSelection()