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

📄 q3richtext.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            para = s;            idx = 0;        }    }    invalidateNested();}bool Q3TextCursor::remove(){    tmpX = -1;    if (!atParagEnd()) {        int next = para->string()->nextCursorPosition(idx);        para->remove(idx, next-idx);        int h = para->rect().height();        para->format(-1, true);        if (h != para->rect().height())            invalidateNested();        else if (para->document() && para->document()->parent())            para->document()->nextDoubleBuffered = true;        return false;    } else if (para->next()) {        para->join(para->next());        invalidateNested();        return true;    }    return false;}/* needed to implement backspace the correct way */bool Q3TextCursor::removePreviousChar(){    tmpX = -1;    if (!atParagStart()) {        para->remove(idx-1, 1);        int h = para->rect().height();        idx--;        // shouldn't be needed, just to make sure.        fixCursorPosition();        para->format(-1, true);        if (h != para->rect().height())            invalidateNested();        else if (para->document() && para->document()->parent())            para->document()->nextDoubleBuffered = true;        return false;    } else if (para->prev()) {        para = para->prev();        para->join(para->next());        invalidateNested();        return true;    }    return false;}void Q3TextCursor::indent(){    int oi = 0, ni = 0;    para->indent(&oi, &ni);    if (oi == ni)        return;    if (idx >= oi)        idx += ni - oi;    else        idx = ni;}void Q3TextCursor::fixCursorPosition(){    // searches for the closest valid cursor position    if (para->string()->validCursorPosition(idx))        return;    int lineIdx;    Q3TextStringChar *start = para->lineStartOfChar(idx, &lineIdx, 0);    int x = para->string()->at(idx).x;    int diff = QABS(start->x - x);    int best = lineIdx;    Q3TextStringChar *c = start;    ++c;    Q3TextStringChar *end = &para->string()->at(para->length()-1);    while (c <= end && !c->lineStart) {        int xp = c->x;        if (c->rightToLeft)            xp += para->string()->width(lineIdx + (c-start));        int ndiff = QABS(xp - x);        if (ndiff < diff && para->string()->validCursorPosition(lineIdx + (c-start))) {            diff = ndiff;            best = lineIdx + (c-start);        }        ++c;    }    idx = best;}// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++Q3TextDocument::Q3TextDocument(Q3TextDocument *p)    : par(p), parentPar(0)#ifndef QT_NO_TEXTCUSTOMITEM    , tc(0)#endif    , tArray(0), tStopWidth(0){    fCollection = par ? par->fCollection : new Q3TextFormatCollection;    init();}void Q3TextDocument::init(){    oTextValid = true;    mightHaveCustomItems = false;    if (par)        par->insertChild(this);    pProcessor = 0;    useFC = true;    pFormatter = 0;    indenter = 0;    fParag = 0;    txtFormat = Qt::AutoText;    preferRichText = false;    pages = false;    focusIndicator.parag = 0;    minw = 0;    wused = 0;    minwParag = curParag = 0;    align = Qt::AlignAuto;    nSelections = 1;    setStyleSheet(Q3StyleSheet::defaultSheet());#ifndef QT_NO_MIME    factory_ = Q3MimeSourceFactory::defaultFactory();#endif    contxt.clear();    underlLinks = par ? par->underlLinks : true;    backBrush = 0;    buf_pixmap = 0;    nextDoubleBuffered = false;    if (par)        withoutDoubleBuffer = par->withoutDoubleBuffer;    else        withoutDoubleBuffer = false;    lParag = fParag = createParagraph(this, 0, 0);    cx = 0;    cy = 2;    if (par)        cx = cy = 0;    cw = 600;    vw = 0;    flow_ = new Q3TextFlow;    flow_->setWidth(cw);    leftmargin = rightmargin = 4;    scaleFontsFactor = 1;    commandHistory = new Q3TextCommandHistory(100);    tStopWidth = formatCollection()->defaultFormat()->width(QLatin1Char('x')) * 8;}Q3TextDocument::~Q3TextDocument(){    delete commandHistory;    if (par)        par->removeChild(this);    clear();    delete flow_;    if (!par) {        delete pFormatter;        delete fCollection;    }    delete pProcessor;    delete buf_pixmap;    delete indenter;    delete backBrush;    delete [] tArray;}void Q3TextDocument::clear(bool createEmptyParag){    while (fParag) {        Q3TextParagraph *p = fParag->next();        delete fParag;        fParag = p;    }    if (flow_)        flow_->clear();    fParag = lParag = 0;    if (createEmptyParag)        fParag = lParag = createParagraph(this);    selections.clear();    oText.clear();    oTextValid = false;}int Q3TextDocument::widthUsed() const{    return wused + 2*border_tolerance;}int Q3TextDocument::height() const{    int h = 0;    if (lParag)        h = lParag->rect().top() + lParag->rect().height() + 1;    int fh = flow_->boundingRect().bottom();    return qMax(h, fh);}Q3TextParagraph *Q3TextDocument::createParagraph(Q3TextDocument *dc, Q3TextParagraph *pr, Q3TextParagraph *nx, bool updateIds){    return new Q3TextParagraph(dc, pr, nx, updateIds);}bool Q3TextDocument::setMinimumWidth(int needed, int used, Q3TextParagraph *p){    if (needed == -1) {        minw = 0;        wused = 0;        p = 0;    }    if (p == minwParag) {        if (minw > needed) {            Q3TextParagraph *tp = fParag;            while (tp) {                if (tp != p && tp->minwidth > needed) {                    needed = tp->minwidth;                    minwParag = tp;                }                tp = tp->n;            }        }        minw = needed;        emit minimumWidthChanged(minw);    } else if (needed > minw) {        minw = needed;        minwParag = p;        emit minimumWidthChanged(minw);    }    wused = qMax(wused, used);    wused = qMax(wused, minw);    cw = qMax(minw, cw);    return true;}void Q3TextDocument::setPlainText(const QString &text){    preferRichText = false;    clear();    oTextValid = true;    oText = text;    int lastNl = 0;    int nl = text.indexOf(QLatin1Char('\n'));    if (nl == -1) {        lParag = createParagraph(this, lParag, 0);        if (!fParag)            fParag = lParag;        QString s = text;        if (!s.isEmpty()) {            if (s[(int)s.length() - 1] == QLatin1Char('\r'))                s.remove(s.length() - 1, 1);            lParag->append(s);        }    } else {        for (;;) {            lParag = createParagraph(this, lParag, 0);            if (!fParag)                fParag = lParag;            int l = nl - lastNl;            if (l > 0) {                if (text.unicode()[nl-1] == QLatin1Char('\r'))                    l--;                QString cs = QString::fromRawData(text.unicode()+lastNl, l);                lParag->append(cs);            }            if (nl == (int)text.length())                break;            lastNl = nl + 1;            nl = text.indexOf(QLatin1Char('\n'), nl + 1);            if (nl == -1)                nl = text.length();        }    }    if (!lParag)        lParag = fParag = createParagraph(this, 0, 0);}struct Q3TextDocumentTag {    Q3TextDocumentTag(){}    Q3TextDocumentTag(const QString&n, const Q3StyleSheetItem* s, const Q3TextFormat& f)        :name(n),style(s), format(f), alignment(Qt::AlignAuto), direction(QChar::DirON),liststyle(Q3StyleSheetItem::ListDisc) {            wsm = Q3StyleSheetItem::WhiteSpaceNormal;    }    QString name;    const Q3StyleSheetItem* style;    QString anchorHref;    Q3StyleSheetItem::WhiteSpaceMode wsm;    Q3TextFormat format;    signed int alignment : 16;    signed int direction : 5;    Q3StyleSheetItem::ListStyle liststyle;    Q3TextDocumentTag( const Q3TextDocumentTag& t) {        name = t.name;        style = t.style;        anchorHref = t.anchorHref;        wsm = t.wsm;        format = t.format;        alignment = t.alignment;        direction = t.direction;        liststyle = t.liststyle;    }    Q3TextDocumentTag& operator=(const Q3TextDocumentTag& t) {        name = t.name;        style = t.style;        anchorHref = t.anchorHref;        wsm = t.wsm;        format = t.format;        alignment = t.alignment;        direction = t.direction;        liststyle = t.liststyle;        return *this;    }    Q_DUMMY_COMPARISON_OPERATOR(Q3TextDocumentTag)};#define NEWPAR \    do{ \        if (!hasNewPar) { \            if (!textEditMode && curpar && curpar->length()>1 \                 && curpar->at(curpar->length()-2)->c == QChar::LineSeparator) \                curpar->remove(curpar->length()-2, 1); \            curpar = createParagraph(this, curpar, curpar->next()); \            styles.append(vec); \            vec = 0; \        } \        hasNewPar = true; \        curpar->rtext = true;  \        curpar->align = curtag.alignment; \        curpar->lstyle = curtag.liststyle; \        curpar->litem = (curtag.style->displayMode() == Q3StyleSheetItem::DisplayListItem); \        curpar->str->setDirection((QChar::Direction)curtag.direction); \        space = true; \        tabExpansionColumn = 0; \        delete vec; \        vec = new QVector<Q3StyleSheetItem *>(); \        for (QStack<Q3TextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it) \            vec->append(const_cast<Q3StyleSheetItem *>((*it).style)); \        vec->append(const_cast<Q3StyleSheetItem *>(curtag.style)); \    } while(false);void Q3TextDocument::setRichText(const QString &text, const QString &context, const Q3TextFormat *initialFormat){    preferRichText = true;    if (!context.isEmpty())        setContext(context);    clear();    fParag = lParag = createParagraph(this);    oTextValid = true;    oText = text;    setRichTextInternal(text, 0, initialFormat);    fParag->rtext = true;}void Q3TextDocument::setRichTextInternal(const QString &text, Q3TextCursor* cursor, const Q3TextFormat *initialFormat){    Q3TextParagraph* curpar = lParag;    int pos = 0;    QStack<Q3TextDocumentTag> tags;    if (!initialFormat)        initialFormat = formatCollection()->defaultFormat();    Q3TextDocumentTag initag(QLatin1String(""), sheet_->item(QLatin1String("")), *initialFormat);    if (bodyText.isValid())        initag.format.setColor(bodyText);    Q3TextDocumentTag curtag = initag;    bool space = true;    bool canMergeLi = false;    bool textEditMode = false;    int tabExpansionColumn = 0;    const QChar* doc = text.unicode();    int length = text.length();    bool hasNewPar = curpar->length() <= 1;    QString anchorName;    // style sheet handling for margin and line spacing calculation below    Q3TextParagraph* stylesPar = curpar;    QVector<Q3StyleSheetItem *>* vec = 0;    QList< QVector<Q3StyleSheetItem *> *> styles;    if (cursor) {

⌨️ 快捷键说明

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