| # kdeui Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# 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 <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     // ignore Ctrl-Return so that KDialogs can close the dialog
    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 // thanks, we don't want to zoom, so skip QTextEdit's impl.
    00142         QScrollView::contentsWheelEvent( e );
    00143 }
    00144
    00145 void KTextEdit::setPalette( const QPalette& palette )
    00146 {
    00147     QTextEdit::setPalette( palette );
    00148     // unsetPalette() is not virtual and calls setPalette() as well
    00149     // so we can use ownPalette() to find out about unsetting
    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 { /*BASE::virtual_hook( id, data );*/ }
    00187
    00188 #include "ktextedit.moc"

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 12:57:47 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001