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

📄 render_table.cpp

📁 monqueror一个很具有参考价值的源玛
💻 CPP
📖 第 1 页 / 共 4 页
字号:
        col->maxCell = _cell;        if (_colSpan>maxColSpan)            maxColSpan=_colSpan;        colInfos[_colSpan-1]->insert(_startCol,col);    }    if (_minSize > col->min)    {        col->min = _minSize;        col->minCell = _cell;    }    if (_maxSize > col->max)    {        col->max = _maxSize;        col->maxCell = _cell;    }    if (_width.type > col->type)    {        col->type = _width.type;        col->value = _width.value;    }    if (_width.type == col->type)    {        if (_width.value > col->value)        {            col->value = _width.value;        }    }    setMinMaxKnown(false);#ifdef TABLE_DEBUG    kdDebug( 6040 ) << "  end: min=" << colMinWidth[_startCol] << " max=" << colMaxWidth[_startCol] << " act=" << actColWidth[_startCol] << endl;#endif}void RenderTable::spreadSpanMinMax(int col, int span, int distmin,    int distmax, LengthType type){#ifdef TABLE_DEBUG    kdDebug( 6040 ) << "RenderTable::spreadSpanMinMax() " << type << " " << distmin << " " << distmax << endl;#endif    if (distmin<1)        distmin=0;    if (distmax<1)        distmax=0;    if (distmin<1 && distmax<1)        return;    bool hasUsableCols=false;    int tmax=distmax;    int tmin=distmin;    int c;    for (c=col; c < col+span ; ++c)    {        if (colType[c]<=type || (type == Variable && distmax==0))        {            hasUsableCols=true;            break;        }    }    if (hasUsableCols)    {        // first target unused columns        for(c=col; c<col+span; ++c)        {            if (colInfos[0]->at(c)==0)            {                                colMaxWidth[c]+=tmax;                colMinWidth[c]+=tmin;                colType[c]=type;                tmax=0;                tmin=0;                break;                            }        }                // spread span maxWidth        LengthType tt = Undefined;        bool out=false;        while (tt<=type && !out && tmax)        {            tmax = distributeMaxWidth(tmax,type,tt,col,span);            switch (tt)            {            case Undefined: tt=Variable; break;            case Variable: tt=Relative; break;            case Relative: tt=Percent; break;            case Percent: tt=Fixed; break;            case Fixed: out=true; break;            }        }         // spread span minWidth        tt = Undefined;        out=false;        while (tt<=type && !out && tmin)        {            tmin = distributeMinWidth(tmin,type,tt,col,span,true);            switch (tt)            {            case Undefined: tt=Variable; break;            case Variable: tt=Relative; break;            case Relative: tt=Percent; break;            case Percent: tt=Fixed; break;            case Fixed: out=true; break;            }        }        // force spread rest of the minWidth        tt = Undefined;        out=false;        while (!out && tmin)        {            tmin = distributeMinWidth(tmin,type,tt,col,span,false);            switch (tt)            {            case Undefined: tt=Variable; break;            case Variable: tt=Relative; break;            case Relative: tt=Percent; break;            case Percent: tt=Fixed; break;            case Fixed: out=true; break;            }        }        for (int c=col; c < col+span ; ++c)            colMaxWidth[c]=QMAX(colMinWidth[c],colMaxWidth[c]);    }}int RenderTable::distributeMinWidth(int distrib, LengthType distType,            LengthType toType, int start, int span, bool mlim ){//    kdDebug( 6040 ) << "MINDIST, " << distrib << " pixels of type " << distType << " to type " << toType << " cols sp=" << span << " " << endl;    int olddis=0;    int c=start;    int totper=0;    int tdis = distrib;        // first target unused columns    for(; c<start+span; ++c)    {        if (colInfos[0]->at(c)==0)        {                            colMinWidth[c]+=tdis;            colType[c]=distType;            tdis=0;            break;                        }    }     if (toType==Percent || toType==Relative)        for (int n=start;n<start+span;n++)            if (colType[n]==Percent || colType[n]==Relative) totper += colValue[n];    c=start;    while(tdis>0)    {//      kdDebug( 6040 ) << c << ": ct=" << colType[c] << " min=" << colMinWidth[c]//                << " max=" << colMaxWidth[c] << endl;        if (colType[c]==toType || (mlim && colMaxWidth[c]-colMinWidth[c]>0))        {            int delta = distrib/span;            if (totper)                delta=(distrib * colValue[c])/totper;            if (mlim)                delta = QMIN(delta,colMaxWidth[c]-colMinWidth[c]);            delta = QMIN(tdis,delta);            if (delta==0 && tdis && (!mlim || colMaxWidth[c]>colMinWidth[c]))                delta=1;//            kdDebug( 6040 ) << "delta=" << delta << endl;            colMinWidth[c]+=delta;            if (mlim)                colType[c]=distType;            tdis-=delta;        }        if (++c==start+span)        {            c=start;            if (olddis==tdis)                break;            olddis=tdis;        }    }    return tdis;}int RenderTable::distributeMaxWidth(int distrib, LengthType distType,            LengthType toType, int start, int span){//    kdDebug( 6040 ) << "MAXDIST, " << distrib << " pixels of type " << distType << " to type " << toType << " cols sp=" << span << " " << endl;        int olddis=0;    int c=start;    int tdis = distrib;        // spread span maxWidth evenly    c=start;    while(tdis>0)    {//      kdDebug( 6040 ) << c << ": ct=" << colType[c] << " min=" << colMinWidth[c]//                << " max=" << colMaxWidth[c] << endl;                if (colType[c]==toType)        {            colMaxWidth[c]+=distrib/span;            tdis-=distrib/span;            if (tdis<span)            {                colMaxWidth[c]+=tdis;                tdis=0;            }        }        if (++c==start+span)        {            c=start;            if (olddis==tdis)                break;            olddis=tdis;        }    }         return tdis;}    void RenderTable::calcSingleColMinMax(int c, ColInfo* col){#ifdef TABLE_DEBUG    kdDebug( 6040 ) << "RenderTable::calcSingleColMinMax()" << endl;#endif    int span=col->span;    int oldmin=0;    int oldmax=0;    for (int o=c; o<c+span; ++o)    {        oldmin+=colMinWidth[o];        oldmax+=colMaxWidth[o];    }    int smin = col->min;    int smax = col->max;    if (col->type==Fixed)        smax = QMAX(smin,col->value);    if (span==1)    {      //kdDebug( 6040 ) << "col (s=1) c=" << c << ",m=" << smin << ",x=" << smax << endl;        colMinWidth[c] = smin;        colMaxWidth[c] = smax;        colValue[c] = col->value;        colType[c] = col->type;    }    else    {        int spreadmin = smin-oldmin-(span-1)*spacing;//      int spreadmax = smax-oldmax-(span-1)*spacing;//      kdDebug( 6040 ) << "spreading span " << spreadmin  << endl;        spreadSpanMinMax            (c, span, spreadmin, 0 , col->type);    }}void RenderTable::calcFinalColMax(int c, ColInfo* col){#ifdef TABLE_DEBUG    kdDebug( 6040 ) << "RenderTable::calcPercentRelativeMax()" << endl;#endif    int span=col->span;    int oldmax=0;    int oldmin=0;    for (int o=c; o<c+span; ++o)    {        oldmax+=colMaxWidth[o];        oldmin+=colMinWidth[o];    }    int smin = col->min;    int smax = col->max;    if (col->type==Fixed)    {        smax = QMAX(smin,col->value);    }    else if (col->type == Percent)    {        smax = m_width * col->value / QMAX(100,totalPercent);    }    else if (col->type == Relative && totalRelative)    {        smax= m_width * col->value / totalRelative;    }    smax = QMAX(smax,oldmin);//    smax = QMIN(smax,m_width);//    kdDebug( 6040 ) << "smin " << smin << " smax " << smax << " span " << span << endl;    if (span==1)    {//       kdDebug( 6040 ) << "col (s=1) c=" << c << ",m=" << smin << ",x=" << smax << endl;       colMaxWidth[c] = smax;       colType[c] = col->type;    }    else    {        int spreadmax = smax-oldmax-(span-1)*spacing;//      kdDebug( 6040 ) << "spreading span " << spreadmax << endl;        spreadSpanMinMax            (c, span, 0, spreadmax, col->type);    }}void RenderTable::calcColMinMax(){// Calculate minmimum and maximum widths for all// columns.// Calculate min and max width for the table.#ifdef TABLE_DEBUG    kdDebug( 6040 ) << "RenderTable::calcColMinMax(), " << minMaxKnown() << endl;#endif    // PHASE 1, prepare//    if(minMaxKnown())//      return;    colMinWidth.fill(0);    colMaxWidth.fill(0);    int availableWidth = containingBlockWidth();    int margin=0;    int realMaxWidth=spacing;    Length ml = style()->marginLeft();    Length mr = style()->marginRight();    if (ml.type==Fixed && mr.type==Fixed)    {        margin = mr.value + ml.value;    }    else if (ml.type == Fixed)        margin = ml.value;    else if (mr.type == Fixed)        margin = mr.value;    if (margin<0) margin=0;    availableWidth -= margin;    // PHASE 2, calculate simple minimums and maximums    for ( unsigned int s=0;  (int)s<maxColSpan ; ++s)    {        ColInfoLine* spanCols = colInfos[s];        for ( unsigned int c=0; c<totalCols-s; ++c)        {            ColInfo* col;            col = spanCols->at(c);            if (!col || col->span==0)                continue;#ifdef TABLE_DEBUG            kdDebug( 6040 ) << " s=" << s << " c=" << c << " min=" << col->min << " value=" << col->value << endl;#endif            if (s==0)                realMaxWidth += col->max + spacing;            col->update();            calcSingleColMinMax(c, col);            if ( col->span>1 && m_style->width().type != Percent                && (col->type==Fixed || col->type==Variable ))            {                calcFinalColMax(c, col);            }        }    }    // PHASE 3, calculate table width    // NOT as simple as it sounds    totalPercent=0;    totalRelative=0;    int maxFixed=0;    int minPercent=0;    int percentWidest=0;    int percentWidestPercent=0;    int minRel=0;    int minVar=0;    bool hasFixed=false;    bool hasPercent=false;    bool hasRel=false;    bool hasVar=false;    m_minWidth = spacing;    m_maxWidth = spacing;    for(int i = 0; i < (int)totalCols; i++)    {        m_minWidth += colMinWidth[i] + spacing;        m_maxWidth += colMaxWidth[i] + spacing;        switch(colType[i])        {        case Fixed:            maxFixed += colMaxWidth[i] + spacing;            hasFixed=true;            break;        case Percent:            hasPercent=true;            totalPercent += colValue[i];            minPercent += colMinWidth[i] + spacing;            if (colValue[i]>0)            {                int pw =  colMaxWidth[i]*100/colValue[i];                if (  pw > percentWidest)                {                    percentWidest = pw;                    percentWidestPercent = colValue[i];                }            }            break;        case Relative:            hasRel=true;            totalRelative += colValue[i] ;            minRel += colMinWidth[i] + spacing;            break;        case Undefined:        case Variable:            hasVar=true;            minVar += colMinWidth[i] + spacing;        }    }    if(m_style->width().type > Relative) // Percent or fixed table    {        m_width = m_style->width().minWidth(availableWidth);        if(m_minWidth > m_width) m_width = m_minWidth;/*      kdDebug( 6040 ) << "1 width=" << width << " minWidth=" << minWidth << " m_availableWidth=" << m_availableWidth << " " << endl;        if (width>1000) for(int i = 0; i < totalCols; i++)        {            kdDebug( 6040 ) << "DUMP col=" << i << " type=" << colType[i] << " max=" << colMaxWidth[i] << " min=" << colMinWidth[i] << " value=" << colValue[i] << endl;        }*/    }    else if (hasPercent && !hasFixed)    {//      kdDebug( 6040 ) << "2 percentWidest=" << //         percentWidest << " percentWidestPercent=" << percentWidestPercent << " " << endl;        m_width = percentWidest;        m_width += (totalCols+1)*spacing+1;        int tot = QMIN(99,totalPercent);        m_width = QMAX(m_width, (minVar + minRel)*100/(100-tot) );        m_width = QMIN(m_width, availableWidth);        totalPercent = QMAX(totalPercent,100);    }    else if (hasPercent && hasFixed)    {        int tot = QMIN(99,totalPercent);//      kdDebug( 6040 ) << "3 maxFixed=" << maxFixed << "  totalPercent=" << totalPercent << endl;        m_width = (maxFixed + minVar + minRel) * 100 /            (100 - tot);        m_width = QMIN (m_width, availableWidth);    }    else    {        m_width = QMIN(availableWidth,m_maxWidth);

⌨️ 快捷键说明

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