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

📄 q3textedit.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    is next emitted.    \sa undo() undoDepth()*//*!    \fn void Q3TextEdit::modificationChanged(bool m)    This signal is emitted when the modification status of the    document has changed. If \a m is true, the document was modified,    otherwise the modification state has been reset to unmodified.    \sa modified*//*!    \fn void Q3TextEdit::redoAvailable(bool yes)    This signal is emitted when the availability of redo changes. If    \a yes is true, then redo() will work until redoAvailable(false)    is next emitted.    \sa redo() undoDepth()*//*!    \fn void Q3TextEdit::currentFontChanged(const QFont &f)    This signal is emitted if the font of the current format has    changed.    The new font is \a f.    \sa setCurrentFont()*//*!    \fn void Q3TextEdit::currentColorChanged(const QColor &c)    This signal is emitted if the color of the current format has    changed.    The new color is \a c.    \sa setColor()*//*!    \fn void Q3TextEdit::currentVerticalAlignmentChanged(Q3TextEdit::VerticalAlignment a)    This signal is emitted if the vertical alignment of the current    format has changed.    The new vertical alignment is \a a.*//*!    \fn void Q3TextEdit::currentAlignmentChanged(int a)    This signal is emitted if the alignment of the current paragraph    has changed.    The new alignment is \a a.    \sa setAlignment()*//*!    \fn void Q3TextEdit::cursorPositionChanged(Q3TextCursor *c)    \internal*//*!    \fn void Q3TextEdit::cursorPositionChanged(int para, int pos)    \overload    This signal is emitted if the position of the cursor has changed.    \a para contains the paragraph index and \a pos contains the    character position within the paragraph.    \sa setCursorPosition()*//*!    \fn void Q3TextEdit::clicked(int para, int pos)    This signal is emitted when the mouse is clicked on the paragraph    \a para at character position \a pos.    \sa doubleClicked()*//*! \fn void Q3TextEdit::doubleClicked(int para, int pos)  This signal is emitted when the mouse is double-clicked on the  paragraph \a para at character position \a pos.  \sa clicked()*//*!    \fn void Q3TextEdit::returnPressed()    This signal is emitted if the user pressed the Return or the Enter    key.*//*!    \fn Q3TextCursor *Q3TextEdit::textCursor() const    Returns the text edit's text cursor.    \warning Q3TextCursor is not in the public API, but in special    circumstances you might wish to use it.*//*!    Constructs an empty Q3TextEdit called \a name, with parent \a    parent.*/Q3TextEdit::Q3TextEdit(QWidget *parent, const char *name)    : Q3ScrollView(parent, name, Qt::WStaticContents | Qt::WNoAutoErase),      doc(new Q3TextDocument(0)), undoRedoInfo(doc){    init();}/*!    Constructs a Q3TextEdit called \a name, with parent \a parent. The    text edit will display the text \a text using context \a context.    The \a context is a path which the text edit's Q3MimeSourceFactory    uses to resolve the locations of files and images. It is passed to    the mimeSourceFactory() when quering data.    For example if the text contains an image tag,    \c{<img src="image.png">}, and the context is "path/to/look/in", the    Q3MimeSourceFactory will try to load the image from    "path/to/look/in/image.png". If the tag was    \c{<img src="/image.png">}, the context will not be used (because    Q3MimeSourceFactory recognizes that we have used an absolute path)    and will try to load "/image.png". The context is applied in exactly    the same way to \e hrefs, for example,    \c{<a href="target.html">Target</a>}, would resolve to    "path/to/look/in/target.html".*/Q3TextEdit::Q3TextEdit(const QString& text, const QString& context,                      QWidget *parent, const char *name)    : Q3ScrollView(parent, name, Qt::WStaticContents | Qt::WNoAutoErase),      doc(new Q3TextDocument(0)), undoRedoInfo(doc){    init();    setText(text, context);}/*!    Destructor.*/Q3TextEdit::~Q3TextEdit(){    delete undoRedoInfo.d;    undoRedoInfo.d = 0;    delete cursor;    delete doc;#ifdef QT_TEXTEDIT_OPTIMIZATION    delete d->od;#endif    delete d;}void Q3TextEdit::init(){    d = new Q3TextEditPrivate;    doc->formatCollection()->setPaintDevice(this);    undoEnabled = true;    readonly = true;    setReadOnly(false);    setFrameStyle(LineEditPanel | Sunken);    connect(doc, SIGNAL(minimumWidthChanged(int)),             this, SLOT(documentWidthChanged(int)));    mousePressed = false;    inDoubleClick = false;    modified = false;    mightStartDrag = false;    onLink.clear();    d->onName.clear();    overWrite = false;    wrapMode = WidgetWidth;    wrapWidth = -1;    wPolicy = AtWhiteSpace;    inDnD = false;    doc->setFormatter(new Q3TextFormatterBreakWords);    QFont f = Q3ScrollView::font();    if (f.kerning())        f.setKerning(false);    doc->formatCollection()->defaultFormat()->setFont(f);    doc->formatCollection()->defaultFormat()->setColor(palette().color(QPalette::Text));    currentFormat = doc->formatCollection()->defaultFormat();    currentAlignment = Qt::AlignAuto;    setBackgroundRole(QPalette::Base);    viewport()->setBackgroundRole(QPalette::Base);    viewport()->setAcceptDrops(true);    resizeContents(0, doc->lastParagraph() ?                    (doc->lastParagraph()->paragId() + 1) * doc->formatCollection()->defaultFormat()->height() : 0);    setAttribute(Qt::WA_KeyCompression, true);    viewport()->setMouseTracking(true);#ifndef QT_NO_CURSOR    viewport()->setCursor(isReadOnly() ? Qt::ArrowCursor : Qt::IBeamCursor);#endif    cursor = new Q3TextCursor(doc);    formatTimer = new QTimer(this);    connect(formatTimer, SIGNAL(timeout()),             this, SLOT(formatMore()));    lastFormatted = doc->firstParagraph();    scrollTimer = new QTimer(this);    connect(scrollTimer, SIGNAL(timeout()),             this, SLOT(autoScrollTimerDone()));    interval = 0;    changeIntervalTimer = new QTimer(this);    connect(changeIntervalTimer, SIGNAL(timeout()),             this, SLOT(doChangeInterval()));    cursorVisible = true;    blinkTimer = new QTimer(this);    connect(blinkTimer, SIGNAL(timeout()),             this, SLOT(blinkCursor()));#ifndef QT_NO_DRAGANDDROP    dragStartTimer = new QTimer(this);    connect(dragStartTimer, SIGNAL(timeout()),             this, SLOT(startDrag()));#endif    d->trippleClickTimer = new QTimer(this);    formatMore();    blinkCursorVisible = false;    viewport()->setFocusProxy(this);    viewport()->setFocusPolicy(Qt::WheelFocus);    setFocusPolicy(Qt::WheelFocus);    setInputMethodEnabled(true);    viewport()->installEventFilter(this);    connect(this, SIGNAL(horizontalSliderReleased()), this, SLOT(sliderReleased()));    connect(this, SIGNAL(verticalSliderReleased()), this, SLOT(sliderReleased()));    installEventFilter(this);}void Q3TextEdit::paintDocument(bool drawAll, QPainter *p, int cx, int cy, int cw, int ch){#ifdef QT_TEXTEDIT_OPTIMIZATION    Q_ASSERT(!d->optimMode);    if (d->optimMode)        return;#endif    bool drawCur = blinkCursorVisible && (hasFocus() || viewport()->hasFocus());    if ((hasSelectedText() && !style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected, 0, this)) ||        isReadOnly() || !cursorVisible)        drawCur = false;    QPalette pal = palette();    if (doc->paper())        pal.setBrush(QPalette::Base, *doc->paper());    if (contentsY() < doc->y()) {        p->fillRect(contentsX(), contentsY(), visibleWidth(), doc->y(),                     pal.base());    }    if (drawAll && doc->width() - contentsX() < cx + cw) {        p->fillRect(doc->width() - contentsX(), cy, cx + cw - doc->width() + contentsX(), ch,                     pal.base());    }    p->setBrushOrigin(-contentsX(), -contentsY());    lastFormatted = doc->draw(p, cx, cy, cw, ch, pal, !drawAll, drawCur, cursor);    if (lastFormatted == doc->lastParagraph())        resizeContents(contentsWidth(), doc->height());    if (contentsHeight() < visibleHeight() && (!doc->lastParagraph() || doc->lastParagraph()->isValid()) && drawAll)        p->fillRect(0, contentsHeight(), visibleWidth(),                     visibleHeight() - contentsHeight(), pal.base());}/*!    \reimp*/void Q3TextEdit::drawContents(QPainter *p, int cx, int cy, int cw, int ch){#ifdef QT_TEXTEDIT_OPTIMIZATION    if (d->optimMode) {        optimDrawContents(p, cx, cy, cw, ch);        return;    }#endif    paintDocument(true, p, cx, cy, cw, ch);    int v;    p->setPen(palette().color(foregroundRole()));    if (document()->isPageBreakEnabled() &&  (v = document()->flow()->pageSize()) > 0) {        int l = int(cy / v) * v;        while (l < cy + ch) {            p->drawLine(cx, l, cx + cw - 1, l);            l += v;        }    }}/*!    \internal*/void Q3TextEdit::drawContents(QPainter *p){    if (horizontalScrollBar()->isVisible() &&         verticalScrollBar()->isVisible()) {        const QRect verticalRect = verticalScrollBar()->geometry();        const QRect horizontalRect = horizontalScrollBar()->geometry();        QRect cornerRect;        cornerRect.setTop(verticalRect.bottom());        cornerRect.setBottom(horizontalRect.bottom());        cornerRect.setLeft(verticalRect.left());        cornerRect.setRight(verticalRect.right());        p->fillRect(cornerRect, palette().background());    }}/*!    \reimp*/bool Q3TextEdit::event(QEvent *e){    if (e->type() == QEvent::AccelOverride && !isReadOnly()) {        QKeyEvent* ke = (QKeyEvent*) e;        switch(ke->state()) {        case Qt::NoButton:        case Qt::Keypad:        case Qt::ShiftButton:            if (ke->key() < Qt::Key_Escape) {                ke->accept();            } else {                switch (ke->key()) {                case Qt::Key_Return:                case Qt::Key_Enter:                case Qt::Key_Delete:                case Qt::Key_Home:                case Qt::Key_End:                case Qt::Key_Backspace:                case Qt::Key_Left:                case Qt::Key_Right:                    ke->accept();                default:                    break;                }            }

⌨️ 快捷键说明

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