9#include <private/qapplication_p.h>
13#include "private/qtextdocumentlayout_p.h"
16#if QT_CONFIG(whatsthis)
29#if defined (Q_OS_ANDROID)
32 return !texbrowser->isReadOnly();
43 : textOrSourceChanged(
false), forceLoadOnSourceChange(
false), openExternalLinks(
false),
45#ifdef QT_KEYPAD_NAVIGATION
46 , lastKeypadScrollValue(-1)
59 : hpos(0), vpos(0), focusIndicatorPosition(-1),
60 focusIndicatorAnchor(-1) {}
72 if (-
i < stack.size())
73 return stack[stack.size()+
i-1];
77 if (
i <= forwardStack.size())
78 return forwardStack[forwardStack.size()-
i];
84 HistoryEntry createHistoryEntry()
const;
85 void restoreHistoryEntry(
const HistoryEntry &
entry);
113 textOrSourceChanged =
true;
114 forceLoadOnSourceChange = !currentURL.
path().
isEmpty();
117 void activateAnchor(
const QString &href);
118 void highlightLink(
const QString &href);
123 virtual QUrl resolveUrl(
const QUrl &
url)
const override;
125 {
return resolveUrl(
QUrl(
url)); }
127#ifdef QT_KEYPAD_NAVIGATION
128 void keypadMove(
bool next);
130 int lastKeypadScrollValue;
144 if (
name.scheme() ==
"qrc"_L1) {
146 }
else if (
name.scheme().isEmpty()) {
149#if defined(Q_OS_ANDROID)
150 if (
name.scheme() ==
"assets"_L1)
164 if (!
path.endsWith(u
'/'))
218#ifndef QT_NO_DESKTOPSERVICES
221#if defined(Q_OS_ANDROID)
270 bool doSetText =
false;
278#if QT_CONFIG(textmarkdownreader)
292 if (
data.userType() == QMetaType::QString) {
294 }
else if (
data.userType() == QMetaType::QByteArray) {
298 if (!decoder.isValid())
309 if (
q->isVisible()) {
311 if (firstTag.startsWith(
"<qt"_L1) && firstTag.contains(
"type"_L1) && firstTag.contains(
"detail"_L1)) {
315#if QT_CONFIG(whatsthis)
337 qCDebug(lcBrowser) <<
"loading" <<
currentURL <<
"base" <<
q->document()->baseUrl() <<
"type" <<
type <<
txt.size() <<
"chars";
338#if QT_CONFIG(textmarkdownreader)
340 q->QTextEdit::setMarkdown(
txt);
343#ifndef QT_NO_TEXTHTMLPARSER
344 q->QTextEdit::setHtml(
txt);
346 q->QTextEdit::setPlainText(
txt);
349#ifdef QT_KEYPAD_NAVIGATION
362#ifdef QT_KEYPAD_NAVIGATION
363 lastKeypadScrollValue = vbar->value();
374#ifdef QT_KEYPAD_NAVIGATION
375void QTextBrowserPrivate::keypadMove(
bool next)
381 const int visibleLinkAmount = overlap;
382 int yOffset = vbar->value();
383 int scrollYOffset =
qBound(0,
next ? yOffset +
height - overlap : yOffset -
height + overlap, vbar->maximum());
385 bool foundNextAnchor =
false;
386 bool focusIt =
false;
397 if (prevFocus.isNull()) {
405 if (lastKeypadScrollValue != yOffset) {
409 bool findOnScreen =
true;
412 if (prevFocus.hasSelection()) {
414 if (viewRect.intersects(prevRect))
415 findOnScreen =
false;
428 }
else if (prevFocus.hasSelection()) {
432 if ((
next && prevRect.bottom() > (yOffset +
height)) ||
433 (!
next && prevRect.top() < yOffset)) {
434 anchorToFocus = prevFocus;
435 focusedPos = scrollYOffset;
445 if (!focusIt && !foundNextAnchor) {
447 if (yOffset == vbar->maximum()) {
449 yOffset = scrollYOffset = 0;
454 bothViewRects = viewRect.united(newViewRect);
459 yOffset = scrollYOffset = vbar->maximum();
464 bothViewRects = viewRect.united(newViewRect);
473 if (foundNextAnchor) {
486 if (bothViewRects.contains(desiredRect)
487 || bothViewRects.adjusted(0, visibleLinkAmount, 0, -visibleLinkAmount).intersects(desiredRect)) {
493 if (desiredRect.height() >
height) {
495 focusedPos = (int) desiredRect.
top();
497 focusedPos = (int) desiredRect.bottom() -
height;
499 focusedPos = (int) ((desiredRect.top() + desiredRect.bottom()) / 2 - (
height / 2));
503 focusedPos =
qBound(yOffset, focusedPos, scrollYOffset);
505 focusedPos =
qBound(scrollYOffset, focusedPos, yOffset);
512 if (!focusIt && prevFocus.hasSelection()) {
515 if (newViewRect.intersects(desiredRect)) {
516 focusedPos = scrollYOffset;
518 anchorToFocus = prevFocus;
524 const int savedXOffset = hbar->value();
532 vbar->setValue(focusedPos);
533 lastKeypadScrollValue = focusedPos;
534 hbar->setValue(savedXOffset);
542 vbar->setValue(scrollYOffset);
543 lastKeypadScrollValue = scrollYOffset;
551 hbar->setValue(savedXOffset);
552 vbar->setValue(scrollYOffset);
563 entry.type = q_func()->sourceType();
564 entry.title = q_func()->documentTitle();
565 entry.hpos = hbar->value();
566 entry.vpos = vbar->value();
570 &&
cursor.hasSelection()) {
581 hbar->setValue(
entry.hpos);
582 vbar->setValue(
entry.vpos);
583 if (
entry.focusIndicatorAnchor != -1 &&
entry.focusIndicatorPosition != -1) {
590#ifdef QT_KEYPAD_NAVIGATION
591 lastKeypadScrollValue = vbar->value();
595 const QString href = prevFocus.charFormat().anchorHref();
677 q->setUndoRedoEnabled(
false);
737 if (
d->stack.isEmpty())
740 return d->stack.top().url;
754 if (
d->stack.isEmpty())
757 return d->stack.top().type;
773 return d->searchPaths;
789 d->currentURL =
QUrl();
826 if (!
d->stack.isEmpty() &&
d->stack.top().url ==
url)
829 if (!
d->stack.isEmpty())
830 d->stack.top() = historyEntry;
834 entry.type =
d->currentType;
842 if (!
d->forwardStack.isEmpty() &&
d->forwardStack.top().url ==
url) {
843 d->forwardStack.pop();
846 d->forwardStack.clear();
918 if (
d->stack.size() <= 1)
922 d->forwardStack.push(
d->createHistoryEntry());
924 d->restoreHistoryEntry(
d->stack.top());
940 if (
d->forwardStack.isEmpty())
942 if (!
d->stack.isEmpty()) {
944 d->stack.top() =
d->createHistoryEntry();
946 d->stack.push(
d->forwardStack.pop());
947 d->restoreHistoryEntry(
d->stack.top());
960 if (
d->home.isValid())
975#ifdef QT_KEYPAD_NAVIGATION
979 if (QApplicationPrivate::keypadNavigationEnabled()) {
980 if (!hasEditFocus()) {
986 if (!
cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {
994 if (QApplicationPrivate::keypadNavigationEnabled()) {
995 if (hasEditFocus()) {
1004 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1012 switch (ev->key()) {
1027#ifdef QT_KEYPAD_NAVIGATION
1030 d->keypadMove(
false);
1033 d->keypadMove(
true);
1083 if (
d->control->setFocusToNextOrPreviousAnchor(
next)) {
1084#ifdef QT_KEYPAD_NAVIGATION
1086 if (
d->prevFocus !=
d->control->textCursor() &&
d->control->textCursor().hasSelection()) {
1087 const QString href =
d->control->anchorAtCursor();
1089 emitHighlighted(
url);
1091 d->prevFocus =
d->control->textCursor();
1095#ifdef QT_KEYPAD_NAVIGATION
1097 emitHighlighted(
QUrl());
1168 return d->stack.size() > 1;
1182 return !
d->forwardStack.isEmpty();
1196 d->forwardStack.clear();
1197 if (!
d->stack.isEmpty()) {
1200 d->stack.push(historyEntry);
1201 d->home = historyEntry.
url;
1223 return d->history(
i).url;
1243 return d->history(
i).title;
1255 return d->forwardStack.size();
1266 return d->stack.size()-1;
1283 return d->openExternalLinks;
1289 d->openExternalLinks =
open;
1307 return d->openLinks;
1313 d->openLinks =
open;
1324#include "moc_qtextbrowser.cpp"
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
The QCursor class provides a mouse cursor with an arbitrary shape.
static QPoint pos()
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates.
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user's desktop environment,...
static QChar separator()
Returns the native directory separator: "/" under Unix and "\\" under Windows.
bool isAbsolute() const
Returns true if the file system entry's path is absolute, otherwise returns false (that is,...
bool isReadable() const
Returns true if the user can read the file system entry this QFileInfo refers to; otherwise returns f...
The QFocusEvent class contains event parameters for widget focus events.
static void setOverrideCursor(const QCursor &)
Sets the application override cursor to cursor.
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
The QKeyEvent class describes a key event.
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
The QPaintEvent class contains event parameters for paint events.
The QPainter class performs low-level painting on widgets and other paint devices.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr qreal top() const noexcept
Returns the y-coordinate of the rectangle's top edge.
QRectF united(const QRectF &other) const noexcept
constexpr qreal width() const noexcept
Returns the width.
static Q_CORE_EXPORT QStringDecoder decoderForHtml(QByteArrayView data)
Tries to determine the encoding of the HTML in data by looking at leading byte order marks or a chars...
constexpr QStringView left(qsizetype n) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString & append(QChar c)
bool forceLoadOnSourceChange
QUrl resolveUrl(const QString &url) const
QTextDocument::ResourceType currentType
void restoreHistoryEntry(const HistoryEntry &entry)
std::array< QMetaObject::Connection, 3 > connections
void activateAnchor(const QString &href)
void emitHighlighted(const QUrl &url)
void highlightLink(const QString &href)
HistoryEntry history(int i) const
QStack< HistoryEntry > stack
QStack< HistoryEntry > forwardStack
HistoryEntry createHistoryEntry() const
QString findFile(const QUrl &name) const
virtual QUrl resolveUrl(const QUrl &url) const override
void setSource(const QUrl &url, QTextDocument::ResourceType type)
The QTextBrowser class provides a rich text browser with hypertext navigation.
virtual void focusOutEvent(QFocusEvent *ev) override
\reimp
virtual void mouseMoveEvent(QMouseEvent *ev) override
\reimp
void setSearchPaths(const QStringList &paths)
bool event(QEvent *e) override
\reimp
virtual void backward()
Changes the document displayed to the previous document in the list of documents built by navigating ...
void backwardAvailable(bool)
This signal is emitted when the availability of backward() changes.
int backwardHistoryCount() const
Returns the number of locations backward in the history.
QUrl historyUrl(int) const
Returns the url of the HistoryItem.
virtual bool focusNextPrevChild(bool next) override
\reimp
virtual void mousePressEvent(QMouseEvent *ev) override
\reimp
virtual QVariant loadResource(int type, const QUrl &name) override
This function is called when the document is loaded and for each image in the document.
QStringList searchPaths
the search paths used by the text browser to find supporting content
QTextDocument::ResourceType sourceType
the type of the displayed document
virtual void paintEvent(QPaintEvent *e) override
\reimp
bool isForwardAvailable() const
int forwardHistoryCount() const
Returns the number of locations forward in the history.
virtual void doSetSource(const QUrl &name, QTextDocument::ResourceType type=QTextDocument::UnknownResource)
Attempts to load the document at the given url with the specified type.
virtual void reload()
Reloads the current set source.
virtual void home()
Changes the document displayed to be the first document from the history.
virtual void keyPressEvent(QKeyEvent *ev) override
The event ev is used to provide the following keyboard shortcuts: \table \header.
void setOpenLinks(bool open)
bool isBackwardAvailable() const
QTextBrowser(QWidget *parent=nullptr)
Constructs an empty QTextBrowser with parent parent.
void setOpenExternalLinks(bool open)
void setSource(const QUrl &name, QTextDocument::ResourceType type=QTextDocument::UnknownResource)
Attempts to load the document at the given url with the specified type.
virtual void forward()
Changes the document displayed to the next document in the list of documents built by navigating link...
void forwardAvailable(bool)
This signal is emitted when the availability of forward() changes.
QUrl source
the name of the displayed document.
virtual void mouseReleaseEvent(QMouseEvent *ev) override
\reimp
QString historyTitle(int) const
Returns the documentTitle() of the HistoryItem.
\reentrant \inmodule QtGui
ResourceType
This enum describes the types of resources that can be loaded by QTextDocument's loadResource() funct...
void contentsChanged()
This signal is emitted whenever the document's content changes; for example, when text is inserted or...
QWidgetTextControl * control
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
virtual void mousePressEvent(QMouseEvent *e) override
\reimp
virtual bool focusNextPrevChild(bool next) override
\reimp
virtual void mouseReleaseEvent(QMouseEvent *e) override
\reimp
QString documentTitle
the title of the document parsed from the text.
virtual void keyPressEvent(QKeyEvent *e) override
\reimp
virtual void mouseMoveEvent(QMouseEvent *e) override
\reimp
virtual bool event(QEvent *e) override
virtual void focusOutEvent(QFocusEvent *e) override
\reimp
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
QString fragment(ComponentFormattingOptions options=PrettyDecoded) const
Returns the fragment of the URL.
QString fileName(ComponentFormattingOptions options=FullyDecoded) const
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
void setFragment(const QString &fragment, ParsingMode mode=TolerantMode)
Sets the fragment of the URL to fragment.
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
bool isValid() const
Returns true if the URL is non-empty and valid; otherwise returns false.
QUrl adjusted(FormattingOptions options) const
QString scheme() const
Returns the scheme of the URL.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
QString path(ComponentFormattingOptions options=FullyDecoded) const
Returns the path of the URL.
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
static void showText(const QPoint &pos, const QString &text, QWidget *w=nullptr)
Shows text as a "What's This?" window, at global position pos.
QTextCursor textCursor() const
void setCursorIsFocusIndicator(bool b)
void setTextCursor(const QTextCursor &cursor, bool selectionClipboard=false)
void linkActivated(const QString &link)
QTextCursor cursorForPosition(const QPointF &pos) const
bool setFocusToAnchor(const QTextCursor &newCursor)
bool findNextPrevAnchor(const QTextCursor &from, bool next, QTextCursor &newAnchor)
QString anchorAtCursor() const
QRectF selectionRect(const QTextCursor &cursor) const
bool cursorIsFocusIndicator() const
void linkHovered(const QString &)
QTextDocument * document() const
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Combined button and popup list for selecting options.
DBusConnection * connection
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLsizei const GLuint * paths
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
static QString findFile(const QDir &dir, const QString &baseName, const QStringList &extensions)
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
static bool shouldEnableInputMethod(QTextBrowser *texbrowser)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
file open(QIODevice::ReadOnly)
QUrl url("example.com")
[constructor-url-reference]
view viewport() -> scroll(dx, dy, deviceRect)