• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • kdeui
  • widgets
ktextbrowser.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE Libraries
2  * Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
3  * Copyright (C) 2006 Urs Wolfer <uwolfer at fwo.ch>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "ktextbrowser.h"
22 
23 #include <QtGui/QAction>
24 #include <QtGui/QMenu>
25 #include <QtGui/QKeyEvent>
26 #include <QtGui/QTextBrowser>
27 #include <QtGui/QWhatsThis>
28 
29 #include <kcursor.h>
30 #include <kglobalsettings.h>
31 #include <kicon.h>
32 #include <kicontheme.h>
33 #include <kurl.h>
34 #include <ktoolinvocation.h>
35 
36 class KTextBrowser::Private
37 {
38  public:
39  Private()
40  : notifyClick( false )
41  {
42  }
43 
44  ~Private()
45  {
46  }
47 
48  bool notifyClick;
49 };
50 
51 KTextBrowser::KTextBrowser( QWidget *parent, bool notifyClick )
52  : QTextBrowser( parent ), d( new Private )
53 {
54  d->notifyClick = notifyClick;
55 }
56 
57 KTextBrowser::~KTextBrowser()
58 {
59  delete d;
60 }
61 
62 
63 void KTextBrowser::setNotifyClick( bool notifyClick )
64 {
65  d->notifyClick = notifyClick;
66 }
67 
68 
69 bool KTextBrowser::isNotifyClick() const
70 {
71  return d->notifyClick;
72 }
73 
74 
75 void KTextBrowser::setSource( const QUrl& name )
76 {
77  QString strName = name.toString();
78  if ( strName.isNull() )
79  return;
80 
81  QRegExp whatsthis( "whatsthis:/*([^/].*)" );
82  if ( !d->notifyClick && whatsthis.exactMatch( strName ) ) {
83  QWhatsThis::showText( QCursor::pos(), whatsthis.cap( 1 ) );
84  } else if ( strName.indexOf( '@' ) > -1 ) {
85  if ( !d->notifyClick ) {
86  KToolInvocation::invokeMailer( KUrl( strName ) );
87  } else {
88  emit mailClick( QString(), strName );
89  }
90  } else {
91  if ( !d->notifyClick ) {
92  KToolInvocation::invokeBrowser( strName );
93  } else {
94  emit urlClick( strName );
95  }
96  }
97 }
98 
99 
100 void KTextBrowser::keyPressEvent( QKeyEvent *event )
101 {
102  if ( event->key() == Qt::Key_Escape )
103  event->ignore();
104  else if ( event->key() == Qt::Key_F1 )
105  event->ignore();
106  else
107  QTextBrowser::keyPressEvent( event );
108 }
109 
110 void KTextBrowser::wheelEvent( QWheelEvent *event )
111 {
112  if ( KGlobalSettings::wheelMouseZooms() )
113  QTextBrowser::wheelEvent( event );
114  else // thanks, we don't want to zoom, so skip QTextEdit's impl.
115  QAbstractScrollArea::wheelEvent( event );
116 }
117 
118 void KTextBrowser::contextMenuEvent( QContextMenuEvent *event )
119 {
120  QMenu *popup = createStandardContextMenu(event->pos());
121  if (popup) {
122  KIconTheme::assignIconsToContextMenu( isReadOnly() ? KIconTheme::ReadOnlyText
123  : KIconTheme::TextEditor,
124  popup->actions() );
125 
126  popup->exec( event->globalPos() );
127  delete popup;
128  }
129 }
130 
131 #include "ktextbrowser.moc"
ktextbrowser.h
QWhatsThis::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
QString::indexOf
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
QWidget
QRegExp::cap
QString cap(int nth) const
KTextBrowser::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event)
Makes sure Key_Escape is ignored.
Definition: ktextbrowser.cpp:100
KTextBrowser::urlClick
void urlClick(const QString &url)
Emitted if mailClick() is not emitted and the widget has been configured to emit the signal...
KTextBrowser::~KTextBrowser
~KTextBrowser()
Destroys the text browser.
Definition: ktextbrowser.cpp:57
QTextEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
kurl.h
kglobalsettings.h
QTextBrowser::keyPressEvent
virtual void keyPressEvent(QKeyEvent *ev)
QWheelEvent
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
QAbstractScrollArea::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
KToolInvocation::invokeMailer
static void invokeMailer(const QString &address, const QString &subject, const QByteArray &startup_id=QByteArray())
ktoolinvocation.h
QContextMenuEvent::globalPos
const QPoint & globalPos() const
QUrl::toString
QString toString(QFlags< QUrl::FormattingOption > options) const
KUrl
QString::isNull
bool isNull() const
kcursor.h
QRegExp
KTextBrowser::isNotifyClick
bool isNotifyClick() const
Returns whether a click on a link should be handled internally or if a signal should be emitted...
Definition: ktextbrowser.cpp:69
QEvent::ignore
void ignore()
KTextBrowser::KTextBrowser
KTextBrowser(QWidget *parent=0, bool notifyClick=false)
Creates a new text browser.
Definition: ktextbrowser.cpp:51
QContextMenuEvent
KTextBrowser::wheelEvent
virtual void wheelEvent(QWheelEvent *event)
Reimplemented to support Qt2 behavior (Ctrl-Wheel = fast scroll)
Definition: ktextbrowser.cpp:110
KGlobalSettings::wheelMouseZooms
static bool wheelMouseZooms()
Typically, QScrollView derived classes can be scrolled fast by holding down the Ctrl-button during wh...
Definition: kglobalsettings.cpp:707
KTextBrowser::mailClick
void mailClick(const QString &name, const QString &address)
Emitted when a mail link has been activated and the widget has been configured to emit the signal...
KTextBrowser::notifyClick
bool notifyClick
Definition: ktextbrowser.h:54
QString
KTextBrowser::contextMenuEvent
virtual void contextMenuEvent(QContextMenuEvent *event)
Re-implemented for internal reasons.
Definition: ktextbrowser.cpp:118
QMenu::exec
QAction * exec()
QTextEdit::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
QKeyEvent::key
int key() const
QMenu
QUrl
kicontheme.h
QKeyEvent
QContextMenuEvent::pos
const QPoint & pos() const
QCursor::pos
QPoint pos()
KIconTheme::ReadOnlyText
Definition: kicontheme.h:203
QTextBrowser
KTextBrowser::setSource
void setSource(const QUrl &name)
Reimplemented to NOT set the source but to do the special handling of links being clicked...
Definition: ktextbrowser.cpp:75
QTextEdit::isReadOnly
bool isReadOnly() const
KToolInvocation::invokeBrowser
static void invokeBrowser(const QString &url, const QByteArray &startup_id=QByteArray())
kicon.h
KIconTheme::assignIconsToContextMenu
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
Assigns standard icons to the various standard text edit context menus.
Definition: kicontheme.cpp:599
QWidget::actions
QList< QAction * > actions() const
QRegExp::exactMatch
bool exactMatch(const QString &str) const
KIconTheme::TextEditor
Definition: kicontheme.h:202
KTextBrowser::setNotifyClick
void setNotifyClick(bool notifyClick)
Decide whether a click on a link should be handled internally or if a signal should be emitted...
Definition: ktextbrowser.cpp:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal