45 #ifndef QT_NO_TEXTBROWSER 53 #include "private/qtextdocumentlayout_p.h" 70 #ifdef QT_KEYPAD_NAVIGATION
71 , lastKeypadScrollValue(-1)
91 if (-i <
stack.count())
130 textOrSourceChanged =
true;
131 forceLoadOnSourceChange = !currentURL.
path().
isEmpty();
144 #ifdef QT_KEYPAD_NAVIGATION 145 void keypadMove(
bool next);
147 int lastKeypadScrollValue;
211 emit q->anchorClicked(url);
217 #ifndef QT_NO_DESKTOPSERVICES 230 emit q->anchorClicked(url);
255 emit q->highlighted(url);
272 bool doSetText =
false;
285 #ifndef QT_NO_TEXTCODEC 296 if (q->isVisible()) {
302 #ifndef QT_NO_WHATSTHIS 317 #ifndef QT_NO_TEXTHTMLPARSER 318 q->QTextEdit::setHtml(txt);
321 q->QTextEdit::setPlainText(txt);
324 #ifdef QT_KEYPAD_NAVIGATION 337 #ifdef QT_KEYPAD_NAVIGATION 347 emit q->sourceChanged(url);
350 #ifdef QT_KEYPAD_NAVIGATION 351 void QTextBrowserPrivate::keypadMove(
bool next)
356 const int overlap =
qBound(20, height / 5, 40);
357 const int visibleLinkAmount = overlap;
359 int scrollYOffset =
qBound(0, next ? yOffset + height - overlap : yOffset - height + overlap,
vbar->
maximum());
361 bool foundNextAnchor =
false;
362 bool focusIt =
false;
373 if (prevFocus.isNull()) {
381 if (lastKeypadScrollValue != yOffset) {
385 bool findOnScreen =
true;
388 if (prevFocus.hasSelection()) {
391 findOnScreen =
false;
404 }
else if (prevFocus.hasSelection()) {
408 if ((next && prevRect.
bottom() > (yOffset + height)) ||
409 (!next && prevRect.
top() < yOffset)) {
410 anchorToFocus = prevFocus;
411 focusedPos = scrollYOffset;
421 if (!focusIt && !foundNextAnchor) {
425 yOffset = scrollYOffset = 0;
430 bothViewRects = viewRect.
united(newViewRect);
440 bothViewRects = viewRect.
united(newViewRect);
449 if (foundNextAnchor) {
462 if(bothViewRects.contains(desiredRect)
463 || bothViewRects.adjusted(0, visibleLinkAmount, 0, -visibleLinkAmount).intersects(desiredRect)) {
469 if (desiredRect.
height() > height) {
471 focusedPos = (int) desiredRect.
top();
473 focusedPos = (int) desiredRect.
bottom() - height;
475 focusedPos = (int) ((desiredRect.
top() + desiredRect.
bottom()) / 2 - (height / 2));
479 focusedPos =
qBound(yOffset, focusedPos, scrollYOffset);
481 focusedPos =
qBound(scrollYOffset, focusedPos, yOffset);
488 if (!focusIt && prevFocus.hasSelection()) {
491 if(newViewRect.intersects(desiredRect)) {
492 focusedPos = scrollYOffset;
494 anchorToFocus = prevFocus;
509 lastKeypadScrollValue = focusedPos;
515 emit q->highlighted(url);
520 lastKeypadScrollValue = scrollYOffset;
540 entry.
url = q_func()->source();
541 entry.
title = q_func()->documentTitle();
567 #ifdef QT_KEYPAD_NAVIGATION 572 const QString href = prevFocus.charFormat().anchorHref();
574 emit q->highlighted(url);
666 q->setUndoRedoEnabled(
false);
733 if (
d->stack.isEmpty())
736 return d->stack.top().url;
755 return d->searchPaths;
761 d->searchPaths = paths;
770 QUrl s =
d->currentURL;
771 d->currentURL =
QUrl();
787 if (!
d->stack.isEmpty() &&
d->stack.top().url == url)
790 if (!
d->stack.isEmpty())
791 d->stack.top() = historyEntry;
798 d->stack.push(entry);
802 if (!
d->forwardStack.isEmpty() &&
d->forwardStack.top().url == url) {
803 d->forwardStack.pop();
806 d->forwardStack.clear();
908 if (
d->stack.count() <= 1)
912 d->forwardStack.push(
d->createHistoryEntry());
914 d->restoreHistoryEntry(
d->stack.top());
930 if (
d->forwardStack.isEmpty())
932 if (!
d->stack.isEmpty()) {
934 d->stack.top() =
d->createHistoryEntry();
936 d->stack.push(
d->forwardStack.pop());
937 d->restoreHistoryEntry(
d->stack.top());
950 if (
d->home.isValid())
965 #ifdef QT_KEYPAD_NAVIGATION 969 if (QApplication::keypadNavigationEnabled()) {
970 if (!hasEditFocus()) {
984 if (QApplication::keypadNavigationEnabled()) {
985 if (hasEditFocus()) {
994 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {
1002 switch (ev->
key()) {
1017 #ifdef QT_KEYPAD_NAVIGATION 1020 d->keypadMove(
false);
1023 d->keypadMove(
true);
1060 #ifndef QT_NO_CURSOR 1073 if (
d->control->setFocusToNextOrPreviousAnchor(next)) {
1074 #ifdef QT_KEYPAD_NAVIGATION 1076 if (
d->prevFocus !=
d->control->textCursor() &&
d->control->textCursor().hasSelection()) {
1077 const QString href =
d->control->anchorAtCursor();
1078 QUrl url =
d->resolveUrl(href);
1082 d->prevFocus =
d->control->textCursor();
1086 #ifdef QT_KEYPAD_NAVIGATION 1160 return d->stack.count() > 1;
1177 return !
d->forwardStack.isEmpty();
1194 d->forwardStack.clear();
1195 if (!
d->stack.isEmpty()) {
1198 d->stack.push(historyEntry);
1199 d->home = historyEntry.
url;
1221 return d->history(i).url;
1241 return d->history(i).title;
1253 return d->forwardStack.count();
1264 return d->stack.count()-1;
1284 return d->openExternalLinks;
1290 d->openExternalLinks =
open;
1311 return d->openLinks;
1317 d->openLinks =
open;
1328 #include "moc_qtextbrowser.cpp" 1330 #endif // QT_NO_TEXTBROWSER The QVariant class acts like a union for the most common Qt data types.
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QPainter class performs low-level painting on widgets and other paint devices.
virtual bool event(QEvent *e)
int anchor() const
Returns the anchor position; this is the same as position() unless there is a selection in which case...
HistoryEntry history(int i) const
The QKeyEvent class describes a key event.
bool findNextPrevAnchor(const QTextCursor &from, bool next, QTextCursor &newAnchor)
virtual void paintEvent(QPaintEvent *e)
Reimplemented Function
bool isValid() const
Returns true if the URL is valid; otherwise returns false.
The QTextCharFormat class provides formatting information for characters in a QTextDocument.
The QCursor class provides a mouse cursor with an arbitrary shape.
QTextCharFormat charFormat() const
Returns the format of the character immediately before the cursor position().
#define QT_END_NAMESPACE
This macro expands to.
virtual void forward()
Changes the document displayed to the next document in the list of documents built by navigating link...
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
virtual void focusOutEvent(QFocusEvent *ev)
Reimplemented Function
QString anchorAtCursor() const
void setTextCursor(const QTextCursor &cursor)
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
bool open(OpenMode flags)
Opens the file using OpenMode mode, returning true if successful; otherwise false.
void setTextInteractionFlags(Qt::TextInteractionFlags flags)
void setOpenExternalLinks(bool open)
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
qreal width() const
Returns the width.
The QByteArray class provides an array of bytes.
virtual void keyPressEvent(QKeyEvent *ev)
The event ev is used to provide the following keyboard shortcuts:
void setOpenLinks(bool open)
The QPointF class defines a point in the plane using floating point precision.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
virtual bool focusNextPrevChild(bool next)
Reimplemented Function
QStringList searchPaths() const
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QStack class is a template class that provides a stack.
QString anchorHref() const
Returns the text format's hypertext link, or an empty string if none has been set.
virtual void mousePressEvent(QMouseEvent *e)
Reimplemented Function
bool intersects(const QRectF &r) const
Returns true if this rectangle intersects with the given rectangle (i.
The QUrl class provides a convenient interface for working with URLs.
The QString class provides a Unicode character string.
int forwardHistoryCount() const
Returns the number of locations forward in the history.
QUrl resolveUrl(const QString &url) const
virtual void mousePressEvent(QMouseEvent *ev)
Reimplemented Function
virtual QVariant loadResource(int type, const QUrl &name)
This function is called when the document is loaded and for each image in the document.
void setSource(const QUrl &url)
QString fragment() const
Returns the fragment of the URL.
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
bool isRelative() const
Returns true if the URL is relative; otherwise returns false.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
QString documentTitle() const
QTextCursor textCursor() const
void setSearchPaths(const QStringList &paths)
QString path() const
Returns the path of the URL.
void setObjectName(const QString &name)
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.
virtual void home()
Changes the document displayed to be the first document from the history.
virtual void setSource(const QUrl &name)
#define QT_BEGIN_NAMESPACE
This macro expands to.
void _q_highlightLink(const QString &href)
The QRectF class defines a rectangle in the plane using floating point precision. ...
virtual void mouseMoveEvent(QMouseEvent *e)
Reimplemented Function
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
bool hasSelection() const
Returns true if the cursor contains a selection; otherwise returns false.
virtual void reload()
Reloads the current set source.
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
virtual void mouseReleaseEvent(QMouseEvent *e)
Reimplemented Function
void historyChanged()
This signal is emitted when the history changes.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
The QTextCursor class offers an API to access and modify QTextDocuments.
qreal height() const
Returns the height of the rectangle.
The QStringList class provides a list of strings.
virtual bool focusNextPrevChild(bool next)
Reimplemented Function
bool isBackwardAvailable() const
Returns true if the text browser can go backward in the document history using backward().
Q_CORE_EXPORT void qWarning(const char *,...)
QStack< HistoryEntry > stack
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
static QTextCodec * codec(MYSQL *mysql)
QTextEdit(QWidget *parent=0)
Constructs an empty QTextEdit with parent parent.
QStack< HistoryEntry > forwardStack
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
int position() const
Returns the absolute position of the cursor within the document.
void restoreHistoryEntry(const HistoryEntry entry)
virtual QUrl resolveUrl(const QUrl &url) const
virtual void focusOutEvent(QFocusEvent *e)
Reimplemented Function
QString toLocalFile() const
Returns the path of this URL formatted as a local file path.
void setFragment(const QString &fragment)
Sets the fragment of the URL to fragment.
void clearSelection()
Clears the current selection by setting the anchor to the cursor position.
HistoryEntry createHistoryEntry() const
QTextDocument * document() const
QRectF selectionRect(const QTextCursor &cursor) const
virtual void backward()
Changes the document displayed to the previous document in the list of documents built by navigating ...
The QMouseEvent class contains parameters that describe a mouse event.
void highlighted(const QUrl &)
This signal is emitted when the user has selected but not activated an anchor in the document...
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
virtual void mouseMoveEvent(QMouseEvent *ev)
Reimplemented Function
void setCursorIsFocusIndicator(bool b)
QString scheme() const
Returns the scheme of the URL.
#define Q_DECLARE_PUBLIC(Class)
QString & append(QChar c)
The QFile class provides an interface for reading from and writing to files.
bool openExternalLinks() const
QString findFile(const QUrl &name) const
Type type() const
Returns the storage type of the value stored in the variant.
QObject * parent() const
Returns a pointer to the parent object.
QRectF united(const QRectF &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
The QTextBrowser class provides a rich text browser with hypertext navigation.
void _q_activateAnchor(const QString &href)
bool event(QEvent *e)
Reimplemented Function
bool hasFragment() const
Returns true if this URL contains a fragment (i.
QByteArray readAll()
Reads all available data from the device, and returns it as a QByteArray.
int backwardHistoryCount() const
Returns the number of locations backward in the history.
bool setFocusToAnchor(const QTextCursor &newCursor)
void _q_documentModified()
QTextCursor cursorForPosition(const QPointF &pos) const
void setPosition(int pos, MoveMode mode=MoveAnchor)
Moves the cursor to the absolute position in the document specified by pos using a MoveMode specified...
static void setOverrideCursor(const QCursor &)
Use changeOverrideCursor(cursor) (if replace is true) or setOverrideCursor(cursor) (if replace is fal...
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
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).
bool isForwardAvailable() const
Returns true if the text browser can go forward in the document history using forward().
QString historyTitle(int) const
Returns the documentTitle() of the HistoryItem.
QUrl historyUrl(int) const
Returns the url of the HistoryItem.
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
static void restoreOverrideCursor()
Undoes the last setOverrideCursor().
static QUrl fromEncoded(const QByteArray &url)
Parses input and returns the corresponding QUrl.
The QTextCodec class provides conversions between text encodings.
static void showText(const QPoint &pos, const QString &text, QWidget *w=0)
Shows text as a "What's This?" window, at global position pos.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
The QFileInfo class provides system-independent file information.
bool cursorIsFocusIndicator() const
bool forceLoadOnSourceChange
The QPaintEvent class contains event parameters for paint events.
void backwardAvailable(bool)
This signal is emitted when the availability of backward() changes.
virtual void mouseReleaseEvent(QMouseEvent *ev)
Reimplemented Function
virtual void close()
Calls QFile::flush() and closes the file.
void clearHistory()
Clears the history of visited documents and disables the forward and backward navigation.
void forwardAvailable(bool)
This signal is emitted when the availability of forward() changes.
The QEvent class is the base class of all event classes.
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
virtual void keyPressEvent(QKeyEvent *e)
Reimplemented Function
The QFocusEvent class contains event parameters for widget focus events.
The QTextEdit class provides a widget that is used to edit and display both plain and rich text...
QTextBrowser(QWidget *parent=0)
Constructs an empty QTextBrowser with parent parent.
int open(const char *, int,...)
static QPoint pos()
Returns the position of the cursor (hot spot) in global screen coordinates.
int focusIndicatorPosition
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false.
Qt::CursorShape shape() const
Returns the cursor shape identifier.
Q_GUI_EXPORT QTextCodec * codecForHtml(const QByteArray &ba)
This function is defined in the <QTextDocument> header file.