20 #include "ktextedit.h"
22 #include <tqapplication.h>
23 #include <tqclipboard.h>
24 #include <tqpopupmenu.h>
26 #include <ksyntaxhighlighter.h>
29 #include <tdeglobalsettings.h>
30 #include <tdestdaccel.h>
31 #include <kiconloader.h>
34 class KTextEdit::KTextEditPrivate
38 : customPalette( false ),
55 TQWidget *parent,
const char *name )
56 : TQTextEdit ( text, context, parent, name )
58 d =
new KTextEditPrivate();
63 : TQTextEdit ( parent, name )
65 d =
new KTextEditPrivate();
117 CursorAction action = MoveWordBackward;
119 getCursorPosition( ¶, & index );
120 if (text(para).isRightToLeft())
121 action = MoveWordForward;
122 moveCursor(action,
false );
128 CursorAction action = MoveWordForward;
130 getCursorPosition( ¶, & index );
131 if (text(para).isRightToLeft())
132 action = MoveWordBackward;
133 moveCursor( action,
false );
139 moveCursor( MovePgDown,
false );
145 moveCursor( MovePgUp,
false );
151 moveCursor( MoveHome,
false );
157 moveCursor( MoveEnd,
false );
163 moveCursor( MoveLineStart,
false );
169 moveCursor(MoveLineEnd,
false);
175 TQString text = TQApplication::clipboard()->text( TQClipboard::Selection);
176 if ( !text.isEmpty() )
183 else if ( e->state() == ControlButton &&
184 (e->key() == Key_Return || e->key() == Key_Enter) &&
185 topLevelWidget()->inherits(
"KDialog" ) )
191 TQTextEdit::keyPressEvent( e );
197 moveCursor( MoveWordBackward,
true );
198 removeSelectedText();
204 moveCursor( MoveWordForward,
true );
205 removeSelectedText();
208 void KTextEdit::slotAllowTab()
210 setTabChangesFocus(!tabChangesFocus());
215 enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll };
217 TQPopupMenu *menu = TQTextEdit::createPopupMenu( pos );
220 menu->changeItem( menu->idAt(0), SmallIconSet(
"edit-copy"), menu->text( menu->idAt(0) ) );
222 int id = menu->idAt(0);
223 menu->changeItem(
id - IdUndo, SmallIconSet(
"edit-undo"), menu->text(
id - IdUndo) );
224 menu->changeItem(
id - IdRedo, SmallIconSet(
"edit-redo"), menu->text(
id - IdRedo) );
225 menu->changeItem(
id - IdCut, SmallIconSet(
"edit-cut"), menu->text(
id - IdCut) );
226 menu->changeItem(
id - IdCopy, SmallIconSet(
"edit-copy"), menu->text(
id - IdCopy) );
227 menu->changeItem(
id - IdPaste, SmallIconSet(
"edit-paste"), menu->text(
id - IdPaste) );
228 menu->changeItem(
id - IdClear, SmallIconSet(
"edit-clear"), menu->text(
id - IdClear) );
230 menu->insertSeparator();
231 id = menu->insertItem( SmallIconSet(
"tools-check-spelling" ), i18n(
"Check Spelling..." ),
234 if( text().isEmpty() )
235 menu->setItemEnabled(
id,
false );
237 id = menu->insertItem( i18n(
"Auto Spell Check" ),
238 this, TQ_SLOT( toggleAutoSpellCheck() ) );
239 menu->setItemChecked(
id, d->checkSpellingEnabled);
240 menu->insertSeparator();
241 id=menu->insertItem(i18n(
"Allow Tabulations"),
this,TQ_SLOT(slotAllowTab()));
242 menu->setItemChecked(
id, !tabChangesFocus());
250 return TQTextEdit::createPopupMenu();
256 TQTextEdit::contentsWheelEvent( e );
258 TQScrollView::contentsWheelEvent( e );
263 TQTextEdit::setPalette( palette );
266 d->customPalette = ownPalette();
269 void KTextEdit::toggleAutoSpellCheck()
276 if ( check == d->checkSpellingEnabled )
283 d->checkSpellingEnabled = check;
291 delete d->highlighter;
298 if ( d->checkSpellingEnabled && !isReadOnly() && !d->highlighter )
301 TQTextEdit::focusInEvent( e );
306 return d->checkSpellingEnabled;
311 if ( !readOnly && hasFocus() && d->checkSpellingEnabled && !d->highlighter )
314 if ( readOnly == isReadOnly() )
319 delete d->highlighter;
322 bool custom = ownPalette();
323 TQPalette p = palette();
324 TQColor color = p.color(TQPalette::Disabled, TQColorGroup::Background);
325 p.setColor(TQColorGroup::Base, color);
326 p.setColor(TQColorGroup::Background, color);
328 d->customPalette = custom;
332 if ( d->customPalette )
334 TQPalette p = palette();
335 TQColor color = p.color(TQPalette::Active, TQColorGroup::Base);
336 p.setColor(TQColorGroup::Base, color);
337 p.setColor(TQColorGroup::Background, color);
344 TQTextEdit::setReadOnly (readOnly);
347 void KTextEdit::virtual_hook(
int,
void* )
353 d->spell =
new KSpell(
this, i18n(
"Spell Checking" ),
354 this, TQ_SLOT( slotSpellCheckReady(
KSpell *) ), 0,
true,
true);
356 connect( d->spell, TQ_SIGNAL( death() ),
357 this, TQ_SLOT( spellCheckerFinished() ) );
359 connect( d->spell, TQ_SIGNAL( misspelling(
const TQString &,
const TQStringList &,
unsigned int ) ),
360 this, TQ_SLOT( spellCheckerMisspelling(
const TQString &,
const TQStringList &,
unsigned int ) ) );
362 connect( d->spell, TQ_SIGNAL( corrected(
const TQString &,
const TQString &,
unsigned int ) ),
363 this, TQ_SLOT( spellCheckerCorrected(
const TQString &,
const TQString &,
unsigned int ) ) );
366 void KTextEdit::spellCheckerMisspelling(
const TQString &text,
const TQStringList &,
unsigned int pos )
368 highLightWord( text.length(), pos );
371 void KTextEdit::spellCheckerCorrected(
const TQString &oldWord,
const TQString &newWord,
unsigned int pos )
374 unsigned int cnt = 0;
375 if ( oldWord != newWord ) {
376 posToRowCol( pos, l, cnt );
377 setSelection( l, cnt, l, cnt + oldWord.length() );
378 removeSelectedText();
383 void KTextEdit::posToRowCol(
unsigned int pos,
unsigned int &line,
unsigned int &col)
385 for ( line = 0; line < static_cast<uint>( lines() ) && col <= pos; line++ )
386 col += paragraphLength( line ) + 1;
389 col = pos - col + paragraphLength( line ) + 1;
392 void KTextEdit::spellCheckerFinished()
398 void KTextEdit::slotSpellCheckReady(
KSpell *s )
401 connect( s, TQ_SIGNAL( done(
const TQString & ) ),
this, TQ_SLOT( slotSpellCheckDone(
const TQString & ) ) );
404 void KTextEdit::slotSpellCheckDone(
const TQString &s )
411 void KTextEdit::highLightWord(
unsigned int length,
unsigned int pos )
414 unsigned int cnt = 0;
415 posToRowCol( pos, l, cnt );
416 setSelection( l, cnt, l, cnt + length );
419 #include "ktextedit.moc"
static void setAutoHideCursor(TQWidget *w, bool enable)
Sets auto-hiding the cursor for widget w.
Dictionary sensitive text highlighter.
virtual bool check(const TQString &_buffer, bool usedialog=true)
Spellchecks a buffer of many words in plain text format.
virtual void setPalette(const TQPalette &palette)
Reimplemented for tracking custom palettes.
bool checkSpellingEnabled() const
Returns true if spell checking is enabled for this text edit.
void checkSpelling()
Create a modal dialog to check the spelling.
void setCheckSpellingEnabled(bool check)
Turns spell checking for this text edit on or off.
virtual void keyPressEvent(TQKeyEvent *)
Reimplemented to catch "delete word" key events.
KTextEdit(const TQString &text, const TQString &context=TQString::null, TQWidget *parent=0, const char *name=0)
Constructs a KTextEdit object.
virtual void setReadOnly(bool readOnly)
Reimplemented to set a proper "deactivated" background color.
virtual void deleteWordBack()
Deletes a word backwards from the current cursor position, if available.
virtual void contentsWheelEvent(TQWheelEvent *)
Reimplemented to allow fast-wheelscrolling with Ctrl-Wheel or zoom.
virtual TQPopupMenu * createPopupMenu()
This is just a reimplementation of a deprecated method from TQTextEdit and is just here to keep sourc...
~KTextEdit()
Destroys the KTextEdit object.
virtual void focusInEvent(TQFocusEvent *)
Reimplemented to instantiate a KDictSpellingHighlighter, if spellchecking is enabled.
virtual void deleteWordForward()
Deletes a word forwards from the current cursor position, if available.
static bool wheelMouseZooms()
const TDEShortcut & copy()
const TDEShortcut & endOfLine()
const TDEShortcut & next()
const TDEShortcut & paste()
const TDEShortcut & prior()
const TDEShortcut & insert()
const TDEShortcut & cut()
const TDEShortcut & end()
const TDEShortcut & redo()
const TDEShortcut & forwardWord()
const TDEShortcut & beginningOfLine()
const TDEShortcut & deleteWordBack()
const TDEShortcut & undo()
const TDEShortcut & home()
const TDEShortcut & backwardWord()
const TDEShortcut & pasteSelection()
const TDEShortcut & deleteWordForward()