KDELibs4Support

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 
55 {
56  delete d;
57 }
58 
59 void KTextBrowser::setNotifyClick(bool notifyClick)
60 {
61  d->notifyClick = notifyClick;
62 }
63 
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) {
82  } else {
83  emit mailClick(QString(), strName);
84  }
85  } else {
86  if (!d->notifyClick) {
88  } else {
89  emit urlClick(strName);
90  }
91  }
92 }
93 
95 {
96  if (event->key() == Qt::Key_Escape) {
97  event->ignore();
98  } else if (event->key() == Qt::Key_F1) {
99  event->ignore();
100  } else {
102  }
103 }
104 
106 {
109  } else { // thanks, we don't want to zoom, so skip QTextEdit's impl.
111  }
112 }
113 
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 
void showText(const QPoint &pos, const QString &text, QWidget *w)
int indexOf(QChar ch, int from, Qt::CaseSensitivity cs) const const
QString cap(int nth) const const
void urlClick(const QString &url)
Emitted if mailClick() is not emitted and the widget has been configured to emit the signal...
~KTextBrowser()
Destroys the text browser.
QMenu * createStandardContextMenu()
virtual void keyPressEvent(QKeyEvent *ev) override
void contextMenuEvent(QContextMenuEvent *event) override
Re-implemented for internal reasons.
virtual void wheelEvent(QWheelEvent *e) override
const QPoint & globalPos() const const
QString toString(QUrl::FormattingOptions options) const const
bool isNull() const const
bool isNotifyClick() const
Returns whether a click on a link should be handled internally or if a signal should be emitted...
KTextBrowser(QWidget *parent=nullptr, bool notifyClick=false)
Creates a new text browser.
static bool wheelMouseZooms()
Typically, QScrollView derived classes can be scrolled fast by holding down the Ctrl-button during wh...
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...
QAction * exec()
virtual void wheelEvent(QWheelEvent *e) override
int key() const const
Extended QTextBrowser.
Definition: ktextbrowser.h:56
void setSource(const QUrl &name) override
Reimplemented to NOT set the source but to do the special handling of links being clicked...
void keyPressEvent(QKeyEvent *event) override
Makes sure Key_Escape is ignored.
const QPoint & pos() const const
QPoint pos()
virtual bool event(QEvent *e) override
bool isReadOnly() const const
bool openUrl(const QUrl &url)
static void assignIconsToContextMenu(ContextMenus type, QList< QAction * > actions)
QList< QAction * > actions() const const
bool exactMatch(const QString &str) const const
void wheelEvent(QWheelEvent *event) override
Reimplemented to support Qt2 behavior (Ctrl-Wheel = fast scroll)
Key_Escape
void setNotifyClick(bool notifyClick)
Decide whether a click on a link should be handled internally or if a signal should be emitted...
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 22:58:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.