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

📄 qtextedit.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (d->lineWrap != FixedPixelWidth        && e->oldSize().width() != e->size().width())        d->relayoutDocument();    else        d->_q_adjustScrollbars();}void QTextEditPrivate::relayoutDocument(){    QTextDocument *doc = control->document();    QAbstractTextDocumentLayout *layout = doc->documentLayout();    if (QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout)) {        if (lineWrap == QTextEdit::FixedColumnWidth)            tlayout->setFixedColumnWidth(lineWrapColumnOrWidth);        else            tlayout->setFixedColumnWidth(-1);    }    QTextDocumentLayout *tlayout = qobject_cast<QTextDocumentLayout *>(layout);    QSize lastUsedSize;    if (tlayout)        lastUsedSize = tlayout->dynamicDocumentSize().toSize();    else        lastUsedSize = layout->documentSize().toSize();    // ignore calls to _q_adjustScrollbars caused by an emission of the    // usedSizeChanged() signal in the layout, as we're calling it    // later on our own anyway (or deliberately not) .    const bool oldIgnoreScrollbarAdjustment = ignoreAutomaticScrollbarAdjustment;    ignoreAutomaticScrollbarAdjustment = true;    int width = viewport->width();    if (lineWrap == QTextEdit::FixedPixelWidth)        width = lineWrapColumnOrWidth;    else if (lineWrap == QTextEdit::NoWrap) {        QVariant alignmentProperty = doc->documentLayout()->property("contentHasAlignment");        if (alignmentProperty.type() == QVariant::Bool && !alignmentProperty.toBool()) {            width = 0;        }    }    doc->setPageSize(QSize(width, -1));    if (tlayout)        tlayout->ensureLayouted(verticalOffset() + viewport->height());    ignoreAutomaticScrollbarAdjustment = oldIgnoreScrollbarAdjustment;    QSize usedSize;    if (tlayout)        usedSize = tlayout->dynamicDocumentSize().toSize();    else        usedSize = layout->documentSize().toSize();    // this is an obscure situation in the layout that can happen:    // if a character at the end of a line is the tallest one and therefore    // influencing the total height of the line and the line right below it    // is always taller though, then it can happen that if due to line breaking    // that tall character wraps into the lower line the document not only shrinks    // horizontally (causing the character to wrap in the first place) but also    // vertically, because the original line is now smaller and the one below kept    // its size. So a layout with less width _can_ take up less vertical space, too.    // If the wider case causes a vertical scroll bar to appear and the narrower one    // (narrower because the vertical scroll bar takes up horizontal space)) to disappear    // again then we have an endless loop, as _q_adjustScrollBars sets new ranges on the    // scroll bars, the QAbstractScrollArea will find out about it and try to show/hide    // the scroll bars again. That's why we try to detect this case here and break out.    //    // (if you change this please also check the layoutingLoop() testcase in    // QTextEdit's autotests)    if (lastUsedSize.isValid()        && !vbar->isHidden()        && viewport->width() < lastUsedSize.width()        && usedSize.height() < lastUsedSize.height()        && usedSize.height() <= viewport->height())        return;    _q_adjustScrollbars();}void QTextEditPrivate::paint(QPainter *p, QPaintEvent *e){    const int xOffset = horizontalOffset();    const int yOffset = verticalOffset();    QRect r = e->rect();    p->translate(-xOffset, -yOffset);    r.translate(xOffset, yOffset);    control->drawContents(p, r, q_func());}/*! \reimp*/void QTextEdit::paintEvent(QPaintEvent *e){    Q_D(QTextEdit);    QPainter p(d->viewport);    d->paint(&p, e);}void QTextEditPrivate::_q_currentCharFormatChanged(const QTextCharFormat &fmt){    Q_Q(QTextEdit);    emit q->currentCharFormatChanged(fmt);#ifdef QT3_SUPPORT    // compat signals    emit q->currentFontChanged(fmt.font());    emit q->currentColorChanged(fmt.foreground().color());#endif}void QTextEditPrivate::updateDefaultTextOption(){    QTextDocument *doc = control->document();    QTextOption opt = doc->defaultTextOption();    QTextOption::WrapMode oldWrapMode = opt.wrapMode();    if (lineWrap == QTextEdit::NoWrap)        opt.setWrapMode(QTextOption::NoWrap);    else        opt.setWrapMode(wordWrap);    if (opt.wrapMode() != oldWrapMode)        doc->setDefaultTextOption(opt);}/*! \reimp*/void QTextEdit::mousePressEvent(QMouseEvent *e){    Q_D(QTextEdit);#ifdef QT_KEYPAD_NAVIGATION    if (QApplication::keypadNavigationEnabled() && !hasEditFocus())        setEditFocus(true);#endif    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::mouseMoveEvent(QMouseEvent *e){    Q_D(QTextEdit);    const QPoint pos = e->pos();    d->sendControlEvent(e);    if (!(e->buttons() & Qt::LeftButton))        return;    if (d->autoScrollTimer.isActive()) {        if (d->viewport->rect().contains(pos))            d->autoScrollTimer.stop();    } else {        if (!d->viewport->rect().contains(pos))            d->autoScrollTimer.start(100, this);    }}/*! \reimp*/void QTextEdit::mouseReleaseEvent(QMouseEvent *e){    Q_D(QTextEdit);    d->autoScrollTimer.stop();    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::mouseDoubleClickEvent(QMouseEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}/*! \reimp*/bool QTextEdit::focusNextPrevChild(bool next){    Q_D(const QTextEdit);    if (!d->tabChangesFocus && d->control->textInteractionFlags() & Qt::TextEditable)        return false;    return QAbstractScrollArea::focusNextPrevChild(next);}/*!  \fn void QTextEdit::contextMenuEvent(QContextMenuEvent *event)  Shows the standard context menu created with createStandardContextMenu().  If you do not want the text edit to have a context menu, you can set  its \l contextMenuPolicy to Qt::NoContextMenu. If you want to  customize the context menu, reimplement this function. If you want  to extend the standard context menu, reimplement this function, call  createStandardContextMenu() and extend the menu returned.  Information about the event is passed in the \a event object.  \code  void MyTextEdit::contextMenuEvent(QContextMenuEvent *event)  {      QMenu *menu = createStandardContextMenu();      menu->addAction(tr("My Menu Item"));      //...      menu->exec(event->globalPos());      delete menu;  }  \endcode*/void QTextEdit::contextMenuEvent(QContextMenuEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}#ifndef QT_NO_DRAGANDDROP/*! \reimp*/void QTextEdit::dragEnterEvent(QDragEnterEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::dragLeaveEvent(QDragLeaveEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::dragMoveEvent(QDragMoveEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::dropEvent(QDropEvent *e){    Q_D(QTextEdit);    d->sendControlEvent(e);}#endif // QT_NO_DRAGANDDROP/*! \reimp */void QTextEdit::inputMethodEvent(QInputMethodEvent *e){    Q_D(QTextEdit);#ifdef QT_KEYPAD_NAVIGATION    if (d->control->textInteractionFlags() & Qt::TextEditable        && QApplication::keypadNavigationEnabled()        && !hasEditFocus()) {        setEditFocus(true);        selectAll();    // so text is replaced rather than appended to    }#endif    d->sendControlEvent(e);}/*!\reimp*/void QTextEdit::scrollContentsBy(int dx, int dy){    Q_D(QTextEdit);    if (isRightToLeft())        dx = -dx;    d->viewport->scroll(dx, dy);}/*!\reimp*/QVariant QTextEdit::inputMethodQuery(Qt::InputMethodQuery property) const{    Q_D(const QTextEdit);    QVariant v = d->control->inputMethodQuery(property);    const QPoint offset(-d->horizontalOffset(), -d->verticalOffset());    if (v.type() == QVariant::RectF)        v = v.toRectF().toRect().translated(offset);    else if (v.type() == QVariant::PointF)        v = v.toPointF().toPoint() + offset;    else if (v.type() == QVariant::Rect)        v = v.toRect().translated(offset);    else if (v.type() == QVariant::Point)        v = v.toPoint() + offset;    return v;}/*! \reimp*/void QTextEdit::focusInEvent(QFocusEvent *e){    Q_D(QTextEdit);    QAbstractScrollArea::focusInEvent(e);    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::focusOutEvent(QFocusEvent *e){    Q_D(QTextEdit);    QAbstractScrollArea::focusOutEvent(e);    d->sendControlEvent(e);}/*! \reimp*/void QTextEdit::showEvent(QShowEvent *){    Q_D(QTextEdit);    if (!d->anchorToScrollToWhenVisible.isEmpty()) {        scrollToAnchor(d->anchorToScrollToWhenVisible);        d->anchorToScrollToWhenVisible.clear();        d->showCursorOnInitialShow = false;    } else if (d->showCursorOnInitialShow) {        d->showCursorOnInitialShow = false;        ensureCursorVisible();    }}/*! \reimp*/void QTextEdit::changeEvent(QEvent *e){    Q_D(QTextEdit);    QAbstractScrollArea::changeEvent(e);    if (e->type() == QEvent::ApplicationFontChange        || e->type() == QEvent::FontChange) {        d->control->document()->setDefaultFont(font());    }  else if(e->type() == QEvent::ActivationChange) {        if (!isActiveWindow())            d->autoScrollTimer.stop();    } else if (e->type() == QEvent::EnabledChange) {        e->setAccepted(isEnabled());        d->sendControlEvent(e);    } else if (e->type() == QEvent::PaletteChange) {        d->control->setPalette(palette());    }}/*! \reimp*/#ifndef QT_NO_WHEELEVENTvoid QTextEdit::wheelEvent(QWheelEvent *e){    Q_D(QTextEdit);    if (!(d->control->textInteractionFlags() & Qt::TextEditable)) {        if (e->modifiers() & Qt::ControlModifier) {            const int delta = e->delta();            if (delta > 0)                zoomOut();            else if (delta < 0)                zoomIn();            return;        }    }    QAbstractScrollArea::wheelEvent(e);    updateMicroFocus();}#endif#ifndef QT_NO_CONTEXTMENU/*!  This function creates the standard context menu which is shown  when the user clicks on the line edit with the right mouse  button. It is called from the default contextMenuEvent() handler.  The popup menu's ownership is transferred to the caller.*/QMenu *QTextEdit::createStandardContextMenu(){    Q_D(QTextEdit);    return d->control->createStandardContextMenu(QPointF(), this);}#endif // QT_NO_CONTEXTMENU/*!  returns a QTextCursor at position \a pos (in viewport coordinates).*/QTextCursor QTextEdit::cursorForPosition(const QPoint &pos) const{    Q_D(const QTextEdit);    return d->control->cursorForPosition(d->mapToContents(pos));}/*!  returns a rectangle (in viewport coordinates) that includes the  \a cursor. */QRect QTextEdit::cursorRect(const QTextCursor &cursor) const{    Q_D(const QTextEdit);    if (cursor.isNull())        return QRect();    QRect r = d->control->cursorRect(cursor).toRect();    r.translate(-d->horizontalOffset(),-d->verticalOffset());    return r;}/*!  returns a rectangle (in viewport coordinates) that includes the  cursor of the text edit. */QRect QTextEdit::cursorRect() const{    Q_D(const QTextEdit);    QRect r = d->control->cursorRect().toRect();    r.translate(-d->horizontalOffset(),-d->verticalOffset());    return r;}/*!    Returns the reference of the anchor at position \a pos, or an    empty string if no anchor exists at that point.*/QString QTextEdit::anchorAt(const QPoint& pos) const{    Q_D(const QTextEdit);    return d->control->anchorAt(d->mapToContents(pos));}/*!   \property QTextEdit::overwriteMode   \since 4.1*/bool QTextEdit::overwriteMode() const{    Q_D(const QTextEdit);    return d->control->overwriteMode();}void QTextEdit::setOverwriteMode(bool overwrite){

⌨️ 快捷键说明

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