9#include <private/qapplication_p.h>
13#include "private/qtextdocumentlayout_p.h"
16#if QT_CONFIG(whatsthis)
29#if defined (Q_OS_ANDROID)
43 : textOrSourceChanged(
false), forceLoadOnSourceChange(
false), openExternalLinks(
false),
45#ifdef QT_KEYPAD_NAVIGATION
46 , lastKeypadScrollValue(-1)
54 : hpos(0), vpos(0), focusIndicatorPosition(-1),
55 focusIndicatorAnchor(-1) {}
67 if (-
i < stack.size())
68 return stack[stack.size()+
i-1];
72 if (
i <= forwardStack.size())
73 return forwardStack[forwardStack.size()-
i];
79 HistoryEntry createHistoryEntry()
const;
80 void restoreHistoryEntry(
const HistoryEntry &
entry);
108 textOrSourceChanged =
true;
109 forceLoadOnSourceChange = !currentURL.
path().
isEmpty();
112 void _q_activateAnchor(
const QString &href);
113 void _q_highlightLink(
const QString &href);
118 virtual QUrl resolveUrl(
const QUrl &
url)
const override;
120 {
return resolveUrl(
QUrl(
url)); }
122#ifdef QT_KEYPAD_NAVIGATION
123 void keypadMove(
bool next);
125 int lastKeypadScrollValue;
138 if (
name.scheme() ==
"qrc"_L1) {
140 }
else if (
name.scheme().isEmpty()) {
143#if defined(Q_OS_ANDROID)
144 if (
name.scheme() ==
"assets"_L1)
158 if (!
path.endsWith(u
'/'))
212#ifndef QT_NO_DESKTOPSERVICES
215#if defined(Q_OS_ANDROID)
264 bool doSetText =
false;
272#if QT_CONFIG(textmarkdownreader)
286 if (
data.userType() == QMetaType::QString) {
288 }
else if (
data.userType() == QMetaType::QByteArray) {
292 if (!decoder.isValid())
303 if (
q->isVisible()) {
309#if QT_CONFIG(whatsthis)
331 qCDebug(lcBrowser) <<
"loading" <<
currentURL <<
"base" <<
q->document()->baseUrl() <<
"type" <<
type <<
txt.size() <<
"chars";
332#if QT_CONFIG(textmarkdownreader)
334 q->QTextEdit::setMarkdown(
txt);
337#ifndef QT_NO_TEXTHTMLPARSER
338 q->QTextEdit::setHtml(
txt);
340 q->QTextEdit::setPlainText(
txt);
343#ifdef QT_KEYPAD_NAVIGATION
356#ifdef QT_KEYPAD_NAVIGATION
357 lastKeypadScrollValue = vbar->value();
368#ifdef QT_KEYPAD_NAVIGATION
369void QTextBrowserPrivate::keypadMove(
bool next)
375 const int visibleLinkAmount = overlap;
376 int yOffset = vbar->value();
377 int scrollYOffset =
qBound(0,
next ? yOffset +
height - overlap : yOffset -
height + overlap, vbar->maximum());
379 bool foundNextAnchor =
false;
380 bool focusIt =
false;
391 if (prevFocus.isNull()) {
399 if (lastKeypadScrollValue != yOffset) {
403 bool findOnScreen =
true;
406 if (prevFocus.hasSelection()) {
409 findOnScreen =
false;
422 }
else if (prevFocus.hasSelection()) {
427 (!
next && prevRect.
top() < yOffset)) {
428 anchorToFocus = prevFocus;
429 focusedPos = scrollYOffset;
439 if (!focusIt && !foundNextAnchor) {
441 if (yOffset == vbar->maximum()) {
443 yOffset = scrollYOffset = 0;
448 bothViewRects = viewRect.
united(newViewRect);
453 yOffset = scrollYOffset = vbar->maximum();
458 bothViewRects = viewRect.
united(newViewRect);
467 if (foundNextAnchor) {
480 if (bothViewRects.
contains(desiredRect)
481 || bothViewRects.
adjusted(0, visibleLinkAmount, 0, -visibleLinkAmount).
intersects(desiredRect)) {
489 focusedPos = (int) desiredRect.
top();
493 focusedPos = (int) ((desiredRect.
top() + desiredRect.
bottom()) / 2 - (
height / 2));
497 focusedPos =
qBound(yOffset, focusedPos, scrollYOffset);
499 focusedPos =
qBound(scrollYOffset, focusedPos, yOffset);
506 if (!focusIt && prevFocus.hasSelection()) {
510 focusedPos = scrollYOffset;
512 anchorToFocus = prevFocus;
518 const int savedXOffset = hbar->value();
526 vbar->setValue(focusedPos);
527 lastKeypadScrollValue = focusedPos;
528 hbar->setValue(savedXOffset);
536 vbar->setValue(scrollYOffset);
537 lastKeypadScrollValue = scrollYOffset;
545 hbar->setValue(savedXOffset);
546 vbar->setValue(scrollYOffset);
556 entry.url = q_func()->source();
557 entry.type = q_func()->sourceType();
558 entry.title = q_func()->documentTitle();
559 entry.hpos = hbar->value();
560 entry.vpos = vbar->value();
564 &&
cursor.hasSelection()) {
575 hbar->setValue(
entry.hpos);
576 vbar->setValue(
entry.vpos);
577 if (
entry.focusIndicatorAnchor != -1 &&
entry.focusIndicatorPosition != -1) {
584#ifdef QT_KEYPAD_NAVIGATION
585 lastKeypadScrollValue = vbar->value();
589 const QString href = prevFocus.charFormat().anchorHref();
671 q->setUndoRedoEnabled(
false);
728 if (
d->stack.isEmpty())
731 return d->stack.top().url;
745 if (
d->stack.isEmpty())
748 return d->stack.top().type;
764 return d->searchPaths;
780 d->currentURL =
QUrl();
817 if (!
d->stack.isEmpty() &&
d->stack.top().url ==
url)
820 if (!
d->stack.isEmpty())
821 d->stack.top() = historyEntry;
825 entry.type =
d->currentType;
833 if (!
d->forwardStack.isEmpty() &&
d->forwardStack.top().url ==
url) {
834 d->forwardStack.pop();
837 d->forwardStack.clear();
909 if (
d->stack.size() <= 1)
913 d->forwardStack.push(
d->createHistoryEntry());
915 d->restoreHistoryEntry(
d->stack.top());
931 if (
d->forwardStack.isEmpty())
933 if (!
d->stack.isEmpty()) {
935 d->stack.top() =
d->createHistoryEntry();
937 d->stack.push(
d->forwardStack.pop());
938 d->restoreHistoryEntry(
d->stack.top());
951 if (
d->home.isValid())
966#ifdef QT_KEYPAD_NAVIGATION
970 if (QApplicationPrivate::keypadNavigationEnabled()) {
971 if (!hasEditFocus()) {
985 if (QApplicationPrivate::keypadNavigationEnabled()) {
986 if (hasEditFocus()) {
995 if (QApplicationPrivate::keypadNavigationEnabled() && !hasEditFocus()) {
1003 switch (ev->
key()) {
1018#ifdef QT_KEYPAD_NAVIGATION
1021 d->keypadMove(
false);
1024 d->keypadMove(
true);
1074 if (
d->control->setFocusToNextOrPreviousAnchor(
next)) {
1075#ifdef QT_KEYPAD_NAVIGATION
1077 if (
d->prevFocus !=
d->control->textCursor() &&
d->control->textCursor().hasSelection()) {
1078 const QString href =
d->control->anchorAtCursor();
1080 emitHighlighted(
url);
1082 d->prevFocus =
d->control->textCursor();
1086#ifdef QT_KEYPAD_NAVIGATION
1088 emitHighlighted(
QUrl());
1159 return d->stack.size() > 1;
1173 return !
d->forwardStack.isEmpty();
1187 d->forwardStack.clear();
1188 if (!
d->stack.isEmpty()) {
1191 d->stack.push(historyEntry);
1192 d->home = historyEntry.
url;
1214 return d->history(
i).url;
1234 return d->history(
i).title;
1246 return d->forwardStack.size();
1257 return d->stack.size()-1;
1274 return d->openExternalLinks;
1280 d->openExternalLinks =
open;
1298 return d->openLinks;
1304 d->openLinks =
open;
1315#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.
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
void accept()
Sets the accept flag of the event object, the equivalent of calling setAccepted(true).
\inmodule QtCore \reentrant
QString absolutePath() const
Returns a file's path absolute path.
bool isAbsolute() const
Returns true if the file path is absolute, otherwise returns false (i.e.
bool exists() const
Returns true if the file exists; otherwise returns false.
bool isReadable() const
Returns true if the user can read the file; otherwise returns false.
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.
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
int key() const
Returns the code of the key that was pressed or released.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\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 bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
constexpr qreal height() const noexcept
Returns the height of the rectangle.
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
bool intersects(const QRectF &r) const noexcept
Returns true if this rectangle intersects with the given rectangle (i.e.
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...
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
bool startsWith(QStringView s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
void _q_activateAnchor(const QString &href)
bool forceLoadOnSourceChange
QUrl resolveUrl(const QString &url) const
QTextDocument::ResourceType currentType
void restoreHistoryEntry(const HistoryEntry &entry)
void _q_highlightLink(const QString &href)
void emitHighlighted(const QUrl &url)
HistoryEntry history(int i) const
QStack< HistoryEntry > stack
void _q_documentModified()
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.
QString anchorHref() const
Returns the text format's hypertext link, or an empty string if none has been set.
\reentrant \inmodule QtGui
ResourceType
This enum describes the types of resources that can be loaded by QTextDocument's loadResource() funct...
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
Qt::TextInteractionFlags textInteractionFlags
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.
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)
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
QTextDocument * document() const
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
Combined button and popup list for selecting options.
#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
GLsizei const GLuint * paths
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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)
QFileInfo fi("c:/temp/foo")
[newstuff]
QUrl url("example.com")
[constructor-url-reference]
view viewport() -> scroll(dx, dy, deviceRect)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent