• Skip to content
  • Skip to link menu
Brand

API Documentation

  1. KDE API Reference
  2. The KDE Frameworks
  3. KDELibs4Support
  • KDE Home
  • Contact Us

Quick Links

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

Class Picker

About

Porting aid from KDELibs4

Maintainer
The KDE Community
Supported platforms
FreeBSD, Linux, MacOSX, Windows
Community
IRC: #kde-devel on Freenode
Mailing list: kde-frameworks-devel
Clone
git clone git://anongit.kde.org/kdelibs4support.git
Browse source
KDELibs4Support on cgit.kde.org

KDELibs4Support

  • frameworks
  • frameworks
  • kdelibs4support
  • src
  • kdeui
ktextbrowser.cpp
1 /* This file is part of the KDE Libraries
2  * Copyright (C) 1999-2000 Espen Sand ([email protected])
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 <QAction>
24 #include <QMenu>
25 #include <QKeyEvent>
26 #include <QTextBrowser>
27 #include <QWhatsThis>
28 
29 #include <kicontheme.h>
30 #include <kglobalsettings.h>
31 #include <qdesktopservices.h>
32 
33 class Q_DECL_HIDDEN KTextBrowser::Private
34 {
35 public:
36  Private()
37  : notifyClick(false)
38  {
39  }
40 
41  ~Private()
42  {
43  }
44 
45  bool notifyClick;
46 };
47 
48 KTextBrowser::KTextBrowser(QWidget *parent, bool notifyClick)
49  : QTextBrowser(parent), d(new Private)
50 {
51  d->notifyClick = notifyClick;
52 }
53 
54 KTextBrowser::~KTextBrowser()
55 {
56  delete d;
57 }
58 
59 void KTextBrowser::setNotifyClick(bool notifyClick)
60 {
61  d->notifyClick = notifyClick;
62 }
63 
64 bool KTextBrowser::isNotifyClick() const
65 {
66  return d->notifyClick;
67 }
68 
69 void KTextBrowser::setSource(const QUrl &name)
70 {
71  QString strName = name.toString();
72  if (strName.isNull()) {
73  return;
74  }
75 
76  QRegExp whatsthis("whatsthis:/*([^/].*)");
77  if (!d->notifyClick && whatsthis.exactMatch(strName)) {
78  QWhatsThis::showText(QCursor::pos(), whatsthis.cap(1));
79  } else if (strName.indexOf('@') > -1) {
80  if (!d->notifyClick) {
81  QDesktopServices::openUrl(name);
82  } else {
83  emit mailClick(QString(), strName);
84  }
85  } else {
86  if (!d->notifyClick) {
87  QDesktopServices::openUrl(name);
88  } else {
89  emit urlClick(strName);
90  }
91  }
92 }
93 
94 void KTextBrowser::keyPressEvent(QKeyEvent *event)
95 {
96  if (event->key() == Qt::Key_Escape) {
97  event->ignore();
98  } else if (event->key() == Qt::Key_F1) {
99  event->ignore();
100  } else {
101  QTextBrowser::keyPressEvent(event);
102  }
103 }
104 
105 void KTextBrowser::wheelEvent(QWheelEvent *event)
106 {
107  if (KGlobalSettings::wheelMouseZooms()) {
108  QTextBrowser::wheelEvent(event);
109  } else { // thanks, we don't want to zoom, so skip QTextEdit's impl.
110  QAbstractScrollArea::wheelEvent(event);
111  }
112 }
113 
114 void KTextBrowser::contextMenuEvent(QContextMenuEvent *event)
115 {
116  QMenu *popup = createStandardContextMenu(event->pos());
117  if (popup) {
118  KIconTheme::assignIconsToContextMenu(isReadOnly() ? KIconTheme::ReadOnlyText
119  : KIconTheme::TextEditor,
120  popup->actions());
121 
122  popup->exec(event->globalPos());
123  delete popup;
124  }
125 }
126 
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::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:54
QTextEdit::createStandardContextMenu
QMenu * createStandardContextMenu()
QTextBrowser::keyPressEvent
virtual void keyPressEvent(QKeyEvent *ev)
KTextBrowser::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event) override
Re-implemented for internal reasons.
Definition: ktextbrowser.cpp:114
QWheelEvent
QAbstractScrollArea::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
QContextMenuEvent::globalPos
const QPoint & globalPos() const
QUrl::toString
QString toString(QFlags< QUrl::UrlFormattingOption > options) const
QString::isNull
bool isNull() const
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:64
QContextMenuEvent
KTextBrowser::KTextBrowser
KDELIBS4SUPPORT_DEPRECATED KTextBrowser(QWidget *parent=nullptr, bool notifyClick=false)
Creates a new text browser.
Definition: ktextbrowser.cpp:48
KGlobalSettings::wheelMouseZooms
static bool wheelMouseZooms()
Typically, QScrollView derived classes can be scrolled fast by holding down the Ctrl-button during wh...
Definition: kglobalsettings.cpp:524
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...
QString
QMenu::exec
QAction * exec()
QTextEdit::wheelEvent
virtual void wheelEvent(QWheelEvent *e)
QKeyEvent::key
int key() const
QMenu
QUrl
KTextBrowser
Extended QTextBrowser.
Definition: ktextbrowser.h:56
KTextBrowser::setSource
void setSource(const QUrl &name) override
Reimplemented to NOT set the source but to do the special handling of links being clicked...
Definition: ktextbrowser.cpp:69
KTextBrowser::keyPressEvent
void keyPressEvent(QKeyEvent *event) override
Makes sure Key_Escape is ignored.
Definition: ktextbrowser.cpp:94
QKeyEvent
QContextMenuEvent::pos
const QPoint & pos() const
QCursor::pos
QPoint pos()
QTextBrowser::event
virtual bool event(QEvent *e)
QTextBrowser
QTextEdit::isReadOnly
bool isReadOnly() const
QDesktopServices::openUrl
bool openUrl(const QUrl &url)
KIconTheme::assignIconsToContextMenu
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
QWidget::actions
QList< QAction * > actions() const
QRegExp::exactMatch
bool exactMatch(const QString &str) const
KTextBrowser::wheelEvent
void wheelEvent(QWheelEvent *event) override
Reimplemented to support Qt2 behavior (Ctrl-Wheel = fast scroll)
Definition: ktextbrowser.cpp:105
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:59
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Thu Dec 5 2019 03:47:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

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