KDEUI
ktextbrowser.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE Libraries 00002 * Copyright (C) 1999-2000 Espen Sand (espen@kde.org) 00003 * Copyright (C) 2006 Urs Wolfer <uwolfer at fwo.ch> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Library General Public License 00016 * along with this library; see the file COPYING.LIB. If not, write to 00017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 * Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "ktextbrowser.h" 00022 00023 #include <QtGui/QAction> 00024 #include <QtGui/QMenu> 00025 #include <QtGui/QKeyEvent> 00026 #include <QtGui/QTextBrowser> 00027 #include <QtGui/QWhatsThis> 00028 00029 #include <kcursor.h> 00030 #include <kglobalsettings.h> 00031 #include <kicon.h> 00032 #include <kicontheme.h> 00033 #include <kurl.h> 00034 #include <ktoolinvocation.h> 00035 00036 class KTextBrowser::Private 00037 { 00038 public: 00039 Private() 00040 : notifyClick( false ) 00041 { 00042 } 00043 00044 ~Private() 00045 { 00046 } 00047 00048 bool notifyClick; 00049 }; 00050 00051 KTextBrowser::KTextBrowser( QWidget *parent, bool notifyClick ) 00052 : QTextBrowser( parent ), d( new Private ) 00053 { 00054 d->notifyClick = notifyClick; 00055 } 00056 00057 KTextBrowser::~KTextBrowser() 00058 { 00059 delete d; 00060 } 00061 00062 00063 void KTextBrowser::setNotifyClick( bool notifyClick ) 00064 { 00065 d->notifyClick = notifyClick; 00066 } 00067 00068 00069 bool KTextBrowser::isNotifyClick() const 00070 { 00071 return d->notifyClick; 00072 } 00073 00074 00075 void KTextBrowser::setSource( const QUrl& name ) 00076 { 00077 QString strName = name.toString(); 00078 if ( strName.isNull() ) 00079 return; 00080 00081 QRegExp whatsthis( "whatsthis:/*([^/].*)" ); 00082 if ( !d->notifyClick && whatsthis.exactMatch( strName ) ) { 00083 QWhatsThis::showText( QCursor::pos(), whatsthis.cap( 1 ) ); 00084 } else if ( strName.indexOf( '@' ) > -1 ) { 00085 if ( !d->notifyClick ) { 00086 KToolInvocation::invokeMailer( KUrl( strName ) ); 00087 } else { 00088 emit mailClick( QString(), strName ); 00089 } 00090 } else { 00091 if ( !d->notifyClick ) { 00092 KToolInvocation::invokeBrowser( strName ); 00093 } else { 00094 emit urlClick( strName ); 00095 } 00096 } 00097 } 00098 00099 00100 void KTextBrowser::keyPressEvent( QKeyEvent *event ) 00101 { 00102 if ( event->key() == Qt::Key_Escape ) 00103 event->ignore(); 00104 else if ( event->key() == Qt::Key_F1 ) 00105 event->ignore(); 00106 else 00107 QTextBrowser::keyPressEvent( event ); 00108 } 00109 00110 void KTextBrowser::wheelEvent( QWheelEvent *event ) 00111 { 00112 if ( KGlobalSettings::wheelMouseZooms() ) 00113 QTextBrowser::wheelEvent( event ); 00114 else // thanks, we don't want to zoom, so skip QTextEdit's impl. 00115 QAbstractScrollArea::wheelEvent( event ); 00116 } 00117 00118 void KTextBrowser::contextMenuEvent( QContextMenuEvent *event ) 00119 { 00120 QMenu *popup = createStandardContextMenu(event->pos()); 00121 KIconTheme::assignIconsToContextMenu( isReadOnly() ? KIconTheme::ReadOnlyText 00122 : KIconTheme::TextEditor, 00123 popup->actions() ); 00124 00125 popup->exec( event->globalPos() ); 00126 delete popup; 00127 } 00128 00129 #include "ktextbrowser.moc"