kdeui Library API Documentation

ktextedit.cpp

00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 #include "ktextedit.h"
00021 
00022 #include <kcursor.h>
00023 #include <kglobalsettings.h>
00024 #include <kstdaccel.h>
00025 
00026 KTextEdit::KTextEdit( const QString& text, const QString& context,
00027                       QWidget *parent, const char *name )
00028     : QTextEdit ( text, context, parent, name )
00029 {
00030     KCursor::setAutoHideCursor( this, true, false );
00031 }
00032 
00033 KTextEdit::KTextEdit( QWidget *parent, const char *name )
00034     : QTextEdit ( parent, name )
00035 {
00036     KCursor::setAutoHideCursor( this, true, false );
00037 }
00038 
00039 KTextEdit::~KTextEdit()
00040 {
00041 }
00042 
00043 void KTextEdit::keyPressEvent( QKeyEvent *e )
00044 {
00045     KKey key( e );
00046 
00047     if ( KStdAccel::copy().contains( key ) ) {
00048         copy();
00049         e->accept();
00050     return;
00051     }
00052     else if ( KStdAccel::paste().contains( key ) ) {
00053         paste();
00054         e->accept();
00055     return;
00056     }
00057     else if ( KStdAccel::cut().contains( key ) ) {
00058         cut();
00059         e->accept();
00060     return;
00061     }
00062     else if ( KStdAccel::undo().contains( key ) ) {
00063         undo();
00064         e->accept();
00065     return;
00066     }
00067     else if ( KStdAccel::redo().contains( key ) ) {
00068         redo();
00069         e->accept();
00070     return;
00071     }
00072     else if ( KStdAccel::deleteWordBack().contains( key ) )
00073     {
00074         deleteWordBack();
00075         e->accept();
00076         return;
00077     }
00078     else if ( KStdAccel::deleteWordForward().contains( key ) )
00079     {
00080         deleteWordForward();
00081         e->accept();
00082         return;
00083     }
00084 
00085     // ignore Ctrl-Return so that KDialogs can close the dialog
00086     else if ( e->state() == ControlButton &&
00087               (e->key() == Key_Return || e->key() == Key_Enter) &&
00088               topLevelWidget()->inherits( "KDialog" ) )
00089     {
00090         e->ignore();
00091         return;
00092     }
00093 
00094     QTextEdit::keyPressEvent( e );
00095 }
00096 
00097 void KTextEdit::deleteWordBack()
00098 {
00099     removeSelection();
00100     moveCursor( MoveWordBackward, true );
00101     removeSelectedText();
00102 }
00103 
00104 void KTextEdit::deleteWordForward()
00105 {
00106     removeSelection();
00107     moveCursor( MoveWordForward, true );
00108     removeSelectedText();
00109 }
00110 
00111 void KTextEdit::contentsWheelEvent( QWheelEvent *e )
00112 {
00113     if ( KGlobalSettings::wheelMouseZooms() )
00114         QTextEdit::contentsWheelEvent( e );
00115     else // thanks, we don't want to zoom, so skip QTextEdit's impl.
00116         QScrollView::contentsWheelEvent( e );
00117 }
00118 
00119 void KTextEdit::setReadOnly(bool readOnly)
00120 {
00121     QPalette p = palette();
00122     if (readOnly)
00123     {
00124         QColor color = p.color(QPalette::Disabled, QColorGroup::Background);
00125         p.setColor(QColorGroup::Base, color);
00126         p.setColor(QColorGroup::Background, color);
00127     }
00128     else
00129     {
00130         QColor color = p.color(QPalette::Normal, QColorGroup::Base);
00131         p.setColor(QColorGroup::Base, color);
00132         p.setColor(QColorGroup::Background, color);
00133     }
00134     setPalette(p);
00135 
00136     QTextEdit::setReadOnly (readOnly);
00137 }
00138 
00139 void KTextEdit::virtual_hook( int, void* )
00140 { /*BASE::virtual_hook( id, data );*/ }
00141 
00142 #include "ktextedit.moc"
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:01 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001