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

📄 qsvgstyle.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        opacity->apply(p, rect, node);    }    if (compop) {        compop->apply(p, rect, node);    }}void QSvgStyle::revert(QPainter *p){    if (quality) {        quality->revert(p);    }    if (fill) {        fill->revert(p);    }    if (viewportFill) {        viewportFill->revert(p);    }    if (font) {        font->revert(p);    }    if (stroke) {        stroke->revert(p);    }    if (solidColor) {        solidColor->revert(p);    }    if (gradient) {        gradient->revert(p);    }    //animated transforms need to be reverted _before_    //the native transforms    if (!animateTransforms.isEmpty()) {        QList<QSvgRefCounter<QSvgAnimateTransform> >::const_iterator itr;        itr = animateTransforms.constBegin();        //only need to rever the first one because that        //one has the original world matrix for the primitve        if (itr != animateTransforms.constEnd()) {            (*itr)->revert(p);        }    }    if (transform) {        transform->revert(p);    }    if (animateColor) {        animateColor->revert(p);    }    if (opacity) {        opacity->revert(p);    }    if (compop) {        compop->revert(p);    }}QSvgAnimateTransform::QSvgAnimateTransform(int startMs, int endMs, int byMs )    : QSvgStyleProperty(),      m_from(startMs), m_to(endMs), m_by(byMs),      m_type(Empty), m_count(0), m_finished(false){    m_totalRunningTime = m_to - m_from;}void QSvgAnimateTransform::setArgs(TransformType type, const QVector<qreal> &args){    m_type = type;    m_args = args;    Q_ASSERT(!(args.count()%3));    m_count = args.count() / 3;}void QSvgAnimateTransform::apply(QPainter *p, const QRectF &, QSvgNode *node){    m_oldWorldMatrix = p->matrix();    resolveMatrix(node);    if (!m_finished || m_freeze)        p->setMatrix(m_transform, true);}void QSvgAnimateTransform::revert(QPainter *p){    if (!m_finished || m_freeze) {        p->setMatrix(m_oldWorldMatrix, false);//don't combine    }}void QSvgAnimateTransform::resolveMatrix(QSvgNode *node){    static const qreal deg2rad = qreal(0.017453292519943295769);    qreal elapsed = node->document()->currentElapsed();    qreal percent = (elapsed - m_from) / m_to;    if (elapsed < m_from || m_finished)        return;    if (percent > 1) {        percent -= ((int)percent);    }    qreal currentPosition = percent * (m_count-1); //array offset    int startElem = static_cast<int>(floor(currentPosition));    int endElem   = static_cast<int>(ceil(currentPosition));    switch(m_type)    {    case Translate: {        startElem *= 3;        endElem   *= 3;        qreal from1, from2, from3;        qreal to1, to2, to3;        from1 = m_args[startElem++];        from2 = m_args[startElem++];        from3 = m_args[startElem++];        to1   = m_args[endElem++];        to2   = m_args[endElem++];        to3   = m_args[endElem++];        qreal transXDiff = (to1-from1) * percent;        qreal transX = from1 + transXDiff;        qreal transYDiff = (to2-from2) * percent;        qreal transY = from2 + transYDiff;        m_transform = QMatrix();        m_transform.translate(transX, transY);        break;    }    case Scale: {        startElem *= 3;        endElem   *= 3;        qreal from1, from2, from3;        qreal to1, to2, to3;        from1 = m_args[startElem++];        from2 = m_args[startElem++];        from3 = m_args[startElem++];        to1   = m_args[endElem++];        to2   = m_args[endElem++];        to3   = m_args[endElem++];        qreal transXDiff = (to1-from1) * percent;        qreal transX = from1 + transXDiff;        qreal transYDiff = (to2-from2) * percent;        qreal transY = from2 + transYDiff;        if (transY == 0)            transY = transX;        m_transform = QMatrix();        m_transform.scale(transX, transY);        break;    }    case Rotate: {        startElem *= 3;        endElem   *= 3;        qreal from1, from2, from3;        qreal to1, to2, to3;        from1 = m_args[startElem++];        from2 = m_args[startElem++];        from3 = m_args[startElem++];        to1   = m_args[endElem++];        to2   = m_args[endElem++];        to3   = m_args[endElem++];        qreal rotationDiff = (to1-from1) * percent;        //qreal rotation = from1 + rotationDiff;        qreal transXDiff = (to2-from2) * percent;        qreal transX = from2 + transXDiff;        qreal transYDiff = (to3-from3) * percent;        qreal transY = from3 + transYDiff;        m_transform = QMatrix();        m_transform.translate(transX, transY);        m_transform.rotate(rotationDiff);        m_transform.translate(-transX, -transY);        break;    }    case SkewX: {        startElem *= 3;        endElem   *= 3;        qreal from1, from2, from3;        qreal to1, to2, to3;        from1 = m_args[startElem++];        from2 = m_args[startElem++];        from3 = m_args[startElem++];        to1   = m_args[endElem++];        to2   = m_args[endElem++];        to3   = m_args[endElem++];        qreal transXDiff = (to1-from1) * percent;        qreal transX = from1 + transXDiff;        m_transform = QMatrix();        m_transform.shear(tan(transX*deg2rad), 0);        break;    }    case SkewY: {        startElem *= 3;        endElem   *= 3;        qreal from1, from2, from3;        qreal to1, to2, to3;        from1 = m_args[startElem++];        from2 = m_args[startElem++];        from3 = m_args[startElem++];        to1   = m_args[endElem++];        to2   = m_args[endElem++];        to3   = m_args[endElem++];        qreal transYDiff = (to1-from1) * percent;        qreal transY = from1 + transYDiff;        m_transform = QMatrix();        m_transform.shear(0, tan(transY*deg2rad));        break;    }    default:        break;    }    if (m_repeatCount < 0)        return;    if (elapsed > m_to) {        if (m_repeatCount > 1) {            --m_repeatCount;        } else if (m_repeatCount > 0 && m_repeatCount < 1) {            if (m_repeatCount <= percent) {                m_finished = true;            }        }    } else if (m_repeatCount > 0 && m_repeatCount < 1) {        //this happens if m_repeatCount < 1 from the start        if (m_repeatCount <= percent) {            m_finished = true;        }    }}QSvgStyleProperty::Type QSvgAnimateTransform::type() const{    return ANIMATE_TRANSFORM;}void QSvgAnimateTransform::setFreeze(bool freeze){    m_freeze = freeze;}void QSvgAnimateTransform::setRepeatCount(qreal repeatCount){    m_repeatCount = repeatCount;}QSvgAnimateColor::QSvgAnimateColor(int startMs, int endMs, int byMs)    : QSvgStyleProperty(),      m_from(startMs), m_to(endMs), m_by(byMs),      m_finished(false){    m_totalRunningTime = m_to - m_from;}void QSvgAnimateColor::setArgs(bool fill,                               const QList<QColor> &colors){    m_fill = fill;    m_colors = colors;}void QSvgAnimateColor::setFreeze(bool freeze){    m_freeze = freeze;}void QSvgAnimateColor::setRepeatCount(qreal repeatCount){    m_repeatCount = repeatCount;}void QSvgAnimateColor::apply(QPainter *p, const QRectF &, QSvgNode *node){    qreal elapsed = node->document()->currentElapsed();    qreal percent = (elapsed - m_from) / m_to;    if (elapsed < m_from || m_finished)        return;    if (percent > 1) {        percent -= ((int)percent);    }    qreal currentPosition = percent * (m_colors.count()-1); //array offset    percent *= (m_colors.count() - 1);    if (percent > 1) {        percent -= ((int)percent);    }    int startElem = static_cast<int>(floor(currentPosition));    int endElem   = static_cast<int>(ceil(currentPosition));    QColor start = m_colors[startElem];    QColor end = m_colors[endElem];    qreal aDiff = (end.alpha() - start.alpha()) * percent;    qreal rDiff = (end.red()   - start.red()) * percent;    qreal gDiff = (end.green() - start.green()) * percent;    qreal bDiff = (end.blue()  - start.blue()) * percent;    int alpha  = int(start.alpha() + aDiff);    int red    = int(start.red() + rDiff);    int green  = int(start.green() + gDiff);    int blue   = int(start.blue() + bDiff);    QColor color(red, green, blue, alpha);    if (m_fill) {        QBrush b = p->brush();        m_oldBrush = b;        b.setColor(color);        p->setBrush(b);    } else {        QPen pen = p->pen();        m_oldPen = pen;        pen.setColor(color);        p->setPen(pen);    }    if (m_repeatCount < 0)        return;    if (elapsed > m_to) {        if (m_repeatCount > 1) {            --m_repeatCount;        } else if (m_repeatCount > 0 && m_repeatCount < 1) {            if (m_repeatCount <= percent) {                m_finished = true;            }        }    } else if (m_repeatCount > 0 && m_repeatCount < 1) {        //this happens if m_repeatCount < 1 from the start        if (m_repeatCount <= percent) {            m_finished = true;        }    }}void QSvgAnimateColor::revert(QPainter *p){    if (m_fill) {        p->setBrush(m_oldBrush);    } else {        p->setPen(m_oldPen);    }}QSvgStyleProperty::Type QSvgAnimateColor::type() const{    return ANIMATE_COLOR;}QString QSvgFontStyle::textAnchor() const{    return m_textAnchor;}void QSvgFontStyle::setTextAnchor(const QString &anchor){    m_textAnchor = anchor;}QSvgOpacityStyle::QSvgOpacityStyle(qreal opacity)    : m_opacity(opacity){}void QSvgOpacityStyle::apply(QPainter *p, const QRectF &, QSvgNode *){    m_oldOpacity = p->opacity();    p->setOpacity(m_opacity);}void QSvgOpacityStyle::revert(QPainter *p){    p->setOpacity(m_oldOpacity);}QSvgStyleProperty::Type QSvgOpacityStyle::type() const{    return OPACITY;}void QSvgGradientStyle::setStopLink(const QString &link, QSvgTinyDocument *doc){    m_link = link;    m_doc  = doc;}void QSvgGradientStyle::resolveStops(){    if (!m_link.isEmpty() && m_doc) {        QSvgStyleProperty *prop = m_doc->scopeStyle(m_link);        if (prop) {            if (prop->type() == QSvgStyleProperty::GRADIENT) {                QSvgGradientStyle *st =                    static_cast<QSvgGradientStyle*>(prop);                st->resolveStops();                m_gradient->setStops(st->qgradient()->stops());            }        }        m_link = QString();    }}

⌨️ 快捷键说明

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