ktextbrowser.cpp
00001 /* This file is part of the KDE Libraries 00002 * Copyright (C) 1999-2000 Espen Sand (espen@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., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 */ 00019 00020 00021 #include <tqpopupmenu.h> 00022 #include <kapplication.h> 00023 #include <kglobalsettings.h> 00024 #include <ktextbrowser.h> 00025 #include <kcursor.h> 00026 #include <kurl.h> 00027 #include <kiconloader.h> 00028 00029 KTextBrowser::KTextBrowser( TQWidget *parent, const char *name, 00030 bool notifyClick ) 00031 : TQTextBrowser( parent, name ), mNotifyClick(notifyClick) 00032 { 00033 // 00034 //1999-10-04 Espen Sand: Not required anymore ? 00035 //connect( this, TQT_SIGNAL(highlighted(const TQString &)), 00036 // this, TQT_SLOT(refChanged(const TQString &))); 00037 } 00038 00039 KTextBrowser::~KTextBrowser( void ) 00040 { 00041 } 00042 00043 00044 void KTextBrowser::setNotifyClick( bool notifyClick ) 00045 { 00046 mNotifyClick = notifyClick; 00047 } 00048 00049 00050 bool KTextBrowser::isNotifyClick() const 00051 { 00052 return mNotifyClick; 00053 } 00054 00055 00056 void KTextBrowser::setSource( const TQString& name ) 00057 { 00058 if( name.isNull() ) 00059 { 00060 return; 00061 } 00062 00063 if( name.find('@') > -1 ) 00064 { 00065 if( !mNotifyClick ) 00066 { 00067 kapp->invokeMailer( KURL( name ) ); 00068 } 00069 else 00070 { 00071 emit mailClick( TQString::null, name ); 00072 } 00073 } 00074 else 00075 { 00076 if( !mNotifyClick ) 00077 { 00078 kapp->invokeBrowser( name ); 00079 } 00080 else 00081 { 00082 emit urlClick( name ); 00083 } 00084 } 00085 } 00086 00087 00088 void KTextBrowser::keyPressEvent(TQKeyEvent *e) 00089 { 00090 if( e->key() == Key_Escape ) 00091 { 00092 e->ignore(); 00093 } 00094 else if( e->key() == Key_F1 ) 00095 { 00096 e->ignore(); 00097 } 00098 else 00099 { 00100 TQTextBrowser::keyPressEvent(e); 00101 } 00102 } 00103 00104 void KTextBrowser::viewportMouseMoveEvent( TQMouseEvent* e) 00105 { 00106 // do this first so we get the right type of cursor 00107 TQTextBrowser::viewportMouseMoveEvent(e); 00108 00109 if ( viewport()->cursor().shape() == PointingHandCursor ) 00110 viewport()->setCursor( KCursor::handCursor() ); 00111 } 00112 00113 void KTextBrowser::contentsWheelEvent( TQWheelEvent *e ) 00114 { 00115 if ( KGlobalSettings::wheelMouseZooms() ) 00116 TQTextBrowser::contentsWheelEvent( e ); 00117 else // thanks, we don't want to zoom, so skip QTextEdit's impl. 00118 TQScrollView::contentsWheelEvent( e ); 00119 } 00120 00121 TQPopupMenu *KTextBrowser::createPopupMenu( const TQPoint & pos ) 00122 { 00123 enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; 00124 00125 TQPopupMenu *popup = TQTextBrowser::createPopupMenu( pos ); 00126 00127 if ( isReadOnly() ) 00128 popup->changeItem( popup->idAt(0), SmallIconSet("editcopy"), popup->text( popup->idAt(0) ) ); 00129 else { 00130 int id = popup->idAt(0); 00131 popup->changeItem( id - IdUndo, SmallIconSet("undo"), popup->text( id - IdUndo) ); 00132 popup->changeItem( id - IdRedo, SmallIconSet("redo"), popup->text( id - IdRedo) ); 00133 popup->changeItem( id - IdCut, SmallIconSet("editcut"), popup->text( id - IdCut) ); 00134 popup->changeItem( id - IdCopy, SmallIconSet("editcopy"), popup->text( id - IdCopy) ); 00135 popup->changeItem( id - IdPaste, SmallIconSet("editpaste"), popup->text( id - IdPaste) ); 00136 popup->changeItem( id - IdClear, SmallIconSet("editclear"), popup->text( id - IdClear) ); 00137 } 00138 00139 return popup; 00140 } 00141 00142 void KTextBrowser::virtual_hook( int, void* ) 00143 { /*BASE::virtual_hook( id, data );*/ } 00144 00145 #include "ktextbrowser.moc"