⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtextbrowser.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    This signal is emitted when the source has changed, \a src    being the new source.    Source changes happen both programmatically when calling    setSource(), forward(), backword() or home() or when the user    clicks on links or presses the equivalent key sequences.*//*!  \fn void QTextBrowser::highlighted(const QUrl &link)    This signal is emitted when the user has selected but not    activated an anchor in the document. The URL referred to by the    anchor is passed in \a link.*//*!  \fn void QTextBrowser::highlighted(const QString &link)     \overload     Convenience signal that allows connecting to a slot     that takes just a QString, like for example QStatusBar's     message().*//*!    \fn void QTextBrowser::anchorClicked(const QUrl &link)    This signal is emitted when the user clicks an anchor. The    URL referred to by the anchor is passed in \a link.    Note that the browser will automatically handle navigation to the    location specified by \a link unless the openLinks property    is set to false or you call setSource() in a slot connected.    This mechanism is used to override the default navigation features of the browser.*//*!    Changes the document displayed to the previous document in the    list of documents built by navigating links. Does nothing if there    is no previous document.    \sa forward(), backwardAvailable()*/void QTextBrowser::backward(){    Q_D(QTextBrowser);    if (d->stack.count() <= 1)        return;    // Update the history entry    d->forwardStack.push(d->createHistoryEntry());    d->stack.pop(); // throw away the old version of the current entry    d->restoreHistoryEntry(d->stack.top()); // previous entry    emit backwardAvailable(d->stack.count() > 1);    emit forwardAvailable(true);}/*!    Changes the document displayed to the next document in the list of    documents built by navigating links. Does nothing if there is no    next document.    \sa backward(), forwardAvailable()*/void QTextBrowser::forward(){    Q_D(QTextBrowser);    if (d->forwardStack.isEmpty())        return;    if (!d->stack.isEmpty()) {        // Update the history entry        d->stack.top() = d->createHistoryEntry();    }    d->stack.push(d->forwardStack.pop());    d->restoreHistoryEntry(d->stack.top());    emit backwardAvailable(true);    emit forwardAvailable(!d->forwardStack.isEmpty());}/*!    Changes the document displayed to be the first document the    browser displayed.*/void QTextBrowser::home(){    Q_D(QTextBrowser);    if (d->home.isValid())        setSource(d->home);}/*!    The event \a ev is used to provide the following keyboard shortcuts:    \table    \header \i Keypress            \i Action    \row \i Alt+Left Arrow  \i \l backward()    \row \i Alt+Right Arrow \i \l forward()    \row \i Alt+Up Arrow    \i \l home()    \endtable*/void QTextBrowser::keyPressEvent(QKeyEvent *ev){#ifdef QT_KEYPAD_NAVIGATION    Q_D(QTextBrowser);    switch (ev->key()) {    case Qt::Key_Select:        if (QApplication::keypadNavigationEnabled()) {            if (!hasEditFocus()) {                setEditFocus(true);                return;            } else {                QTextCursor cursor = d->control->textCursor();                QTextCharFormat charFmt = cursor.charFormat();                if (!cursor.hasSelection() || charFmt.anchorHref().isEmpty()) {                    ev->accept();                    return;                }            }        }        break;    case Qt::Key_Back:        if (QApplication::keypadNavigationEnabled()) {            if (hasEditFocus()) {                setEditFocus(false);                ev->accept();                return;            }        }        QTextEdit::keyPressEvent(ev);        return;    default:        if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {            ev->ignore();            return;        }    }#endif    if (ev->modifiers() & Qt::AltModifier) {        switch (ev->key()) {        case Qt::Key_Right:            forward();            ev->accept();            return;        case Qt::Key_Left:            backward();            ev->accept();            return;        case Qt::Key_Up:            home();            ev->accept();            return;        }    }#ifdef QT_KEYPAD_NAVIGATION    else {        if (ev->key() == Qt::Key_Up) {            d->keypadMove(false);            return;        } else if (ev->key() == Qt::Key_Down) {            d->keypadMove(true);            return;        }    }#endif    QTextEdit::keyPressEvent(ev);}/*!    \reimp*/void QTextBrowser::mouseMoveEvent(QMouseEvent *e){    QTextEdit::mouseMoveEvent(e);}/*!    \reimp*/void QTextBrowser::mousePressEvent(QMouseEvent *e){    QTextEdit::mousePressEvent(e);}/*!    \reimp*/void QTextBrowser::mouseReleaseEvent(QMouseEvent *e){    QTextEdit::mouseReleaseEvent(e);}/*!    \reimp*/void QTextBrowser::focusOutEvent(QFocusEvent *ev){#ifndef QT_NO_CURSOR    Q_D(QTextBrowser);    d->viewport->setCursor((!(d->control->textInteractionFlags() & Qt::TextEditable)) ? d->oldCursor : Qt::IBeamCursor);#endif    QTextEdit::focusOutEvent(ev);}/*!    \reimp*/bool QTextBrowser::focusNextPrevChild(bool next){    Q_D(QTextBrowser);    if (d->control->setFocusToNextOrPreviousAnchor(next)) {#ifdef QT_KEYPAD_NAVIGATION        // Might need to synthesize a highlight event.        if (d->prevFocus != d->control->textCursor() && d->control->textCursor().hasSelection()) {            const QString href = d->control->anchorAtCursor();            QUrl url = d->resolveUrl(href);            emit highlighted(url);            emit highlighted(url.toString());        }        d->prevFocus = d->control->textCursor();#endif        return true;    } else {#ifdef QT_KEYPAD_NAVIGATION        // We assume we have no highlight now.        emit highlighted(QUrl());        emit highlighted(QString());#endif    }    return QTextEdit::focusNextPrevChild(next);}/*!  \reimp*/void QTextBrowser::paintEvent(QPaintEvent *e){    Q_D(QTextBrowser);    QPainter p(d->viewport);    d->paint(&p, e);}/*!    This function is called when the document is loaded. The \a type    indicates the type of resource to be loaded. For each image in    the document, this function is called once.    The default implementation ignores \a type and tries to locate    the resources by interpreting \a name as a file name. If it is    not an absolute path it tries to find the file in the paths of    the \l searchPaths property and in the same directory as the    current source. On success, the result is a QVariant that stores    a QByteArray with the contents of the file.    If you reimplement this function, you can return other QVariant    types. The table below shows which variant types are supported    depending on the resource type:    \table    \header \i ResourceType  \i QVariant::Type    \row    \i QTextDocument::HtmlResource  \i QString or QByteArray    \row    \i QTextDocument::ImageResource \i QImage, QPixmap or QByteArray    \row    \i QTextDocument::StyleSheetResource \i QString or QByteArray    \endtable*/QVariant QTextBrowser::loadResource(int /*type*/, const QUrl &name){    Q_D(QTextBrowser);    QByteArray data;    QString fileName = d->findFile(d->resolveUrl(name));    QFile f(fileName);    if (f.open(QFile::ReadOnly)) {        data = f.readAll();        f.close();    } else {        qWarning("QTextBrowser: Cannot open '%s' for reading", name.toString().toLocal8Bit().data());        return QVariant();    }    return data;}/*!    \since 4.2    Returns true if the text browser can go backward in the document history    using backward().    \sa backwardAvailable(), backward()*/bool QTextBrowser::isBackwardAvailable() const{    Q_D(const QTextBrowser);    return d->stack.count() > 1;}/*!    \since 4.2    Returns true if the text browser can go forward in the document history    using forward().    \sa forwardAvailable(), forward()*/bool QTextBrowser::isForwardAvailable() const{    Q_D(const QTextBrowser);    return !d->forwardStack.isEmpty();}/*!    \since 4.2    Clears the history of visited documents and disables the forward and    backward navigation.    \sa backward(), forward()*/void QTextBrowser::clearHistory(){    Q_D(QTextBrowser);    d->forwardStack.clear();    if (!d->stack.isEmpty())        d->stack.resize(1);    emit forwardAvailable(false);    emit backwardAvailable(false);}/*!    \property QTextBrowser::openExternalLinks    \since 4.2    Specifies whether QTextBrowser should automatically open links to external    sources using QDesktopServices::openUrl() instead of emitting the    anchorClicked signal. Links are considered external if their scheme is    neither file or qrc.    The default value is false.*/bool QTextBrowser::openExternalLinks() const{    Q_D(const QTextBrowser);    return d->openExternalLinks;}void QTextBrowser::setOpenExternalLinks(bool open){    Q_D(QTextBrowser);    d->openExternalLinks = open;}/*!   \property QTextBrowser::openLinks   \since 4.3   This property specifies whether QTextBrowser should automatically open links the user tries to   activate by mouse or keyboard.   Regardless of the value of this property the anchorClicked signal is always emitted.   The default value is true.*/bool QTextBrowser::openLinks() const{    Q_D(const QTextBrowser);    return d->openLinks;}void QTextBrowser::setOpenLinks(bool open){    Q_D(QTextBrowser);    d->openLinks = open;}/*! \reimp */bool QTextBrowser::event(QEvent *e){    return QTextEdit::event(e);}#include "moc_qtextbrowser.cpp"#endif // QT_NO_TEXTBROWSER

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -