ktextedit.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "ktextedit.h"
00021
00022 #include <qapplication.h>
00023 #include <qclipboard.h>
00024
00025 #include <kcursor.h>
00026 #include <kglobalsettings.h>
00027 #include <kstdaccel.h>
00028
00029 class KTextEdit::KTextEditPrivate
00030 {
00031 public:
00032 KTextEditPrivate()
00033 : customPalette( false )
00034 {}
00035
00036 bool customPalette;
00037 };
00038
00039 KTextEdit::KTextEdit( const QString& text, const QString& context,
00040 QWidget *parent, const char *name )
00041 : QTextEdit ( text, context, parent, name )
00042 {
00043 d = new KTextEditPrivate();
00044 KCursor::setAutoHideCursor( this, true, false );
00045 }
00046
00047 KTextEdit::KTextEdit( QWidget *parent, const char *name )
00048 : QTextEdit ( parent, name )
00049 {
00050 d = new KTextEditPrivate();
00051 KCursor::setAutoHideCursor( this, true, false );
00052 }
00053
00054 KTextEdit::~KTextEdit()
00055 {
00056 delete d;
00057 }
00058
00059 void KTextEdit::keyPressEvent( QKeyEvent *e )
00060 {
00061 KKey key( e );
00062
00063 if ( KStdAccel::copy().contains( key ) ) {
00064 copy();
00065 e->accept();
00066 return;
00067 }
00068 else if ( KStdAccel::paste().contains( key ) ) {
00069 paste();
00070 e->accept();
00071 return;
00072 }
00073 else if ( KStdAccel::cut().contains( key ) ) {
00074 cut();
00075 e->accept();
00076 return;
00077 }
00078 else if ( KStdAccel::undo().contains( key ) ) {
00079 undo();
00080 e->accept();
00081 return;
00082 }
00083 else if ( KStdAccel::redo().contains( key ) ) {
00084 redo();
00085 e->accept();
00086 return;
00087 }
00088 else if ( KStdAccel::deleteWordBack().contains( key ) )
00089 {
00090 deleteWordBack();
00091 e->accept();
00092 return;
00093 }
00094 else if ( KStdAccel::deleteWordForward().contains( key ) )
00095 {
00096 deleteWordForward();
00097 e->accept();
00098 return;
00099 }
00100
00101 else if ( e->key() == Key_Insert &&
00102 (e->state() == (ShiftButton | ControlButton)) )
00103 {
00104 QString text = QApplication::clipboard()->text( QClipboard::Selection);
00105 if ( !text.isEmpty() )
00106 insert( text );
00107 e->accept();
00108 return;
00109 }
00110
00111
00112 else if ( e->state() == ControlButton &&
00113 (e->key() == Key_Return || e->key() == Key_Enter) &&
00114 topLevelWidget()->inherits( "KDialog" ) )
00115 {
00116 e->ignore();
00117 return;
00118 }
00119
00120 QTextEdit::keyPressEvent( e );
00121 }
00122
00123 void KTextEdit::deleteWordBack()
00124 {
00125 removeSelection();
00126 moveCursor( MoveWordBackward, true );
00127 removeSelectedText();
00128 }
00129
00130 void KTextEdit::deleteWordForward()
00131 {
00132 removeSelection();
00133 moveCursor( MoveWordForward, true );
00134 removeSelectedText();
00135 }
00136
00137 void KTextEdit::contentsWheelEvent( QWheelEvent *e )
00138 {
00139 if ( KGlobalSettings::wheelMouseZooms() )
00140 QTextEdit::contentsWheelEvent( e );
00141 else
00142 QScrollView::contentsWheelEvent( e );
00143 }
00144
00145 void KTextEdit::setPalette( const QPalette& palette )
00146 {
00147 QTextEdit::setPalette( palette );
00148
00149
00150 d->customPalette = ownPalette();
00151 }
00152
00153 void KTextEdit::setReadOnly(bool readOnly)
00154 {
00155 if ( readOnly == isReadOnly() )
00156 return;
00157
00158 if (readOnly)
00159 {
00160 bool custom = ownPalette();
00161 QPalette p = palette();
00162 QColor color = p.color(QPalette::Disabled, QColorGroup::Background);
00163 p.setColor(QColorGroup::Base, color);
00164 p.setColor(QColorGroup::Background, color);
00165 setPalette(p);
00166 d->customPalette = custom;
00167 }
00168 else
00169 {
00170 if ( d->customPalette )
00171 {
00172 QPalette p = palette();
00173 QColor color = p.color(QPalette::Normal, QColorGroup::Base);
00174 p.setColor(QColorGroup::Base, color);
00175 p.setColor(QColorGroup::Background, color);
00176 setPalette(p);
00177 }
00178 else
00179 unsetPalette();
00180 }
00181
00182 QTextEdit::setReadOnly (readOnly);
00183 }
00184
00185 void KTextEdit::virtual_hook( int, void* )
00186 { }
00187
00188 #include "ktextedit.moc"
This file is part of the documentation for kdelibs Version 3.1.5.