📄 render_table.cpp
字号:
case Undefined: tt=Variable; break; case Variable: tt=Relative; break; case Relative: tt=Percent; break; case Percent: tt=Fixed; break; default: 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; default: 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; default: out=true; break; } } for (int c=col; c < col+span ; ++c) colMaxWidth[c]=KMAX(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; if (!mlim) { // 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 = KMIN(delta,colMaxWidth[c]-colMinWidth[c]); delta = KMIN(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 smin = col->min; int smax = col->max; 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 oldmin=0; int oldmax=0; for (int o=c; o<c+span; ++o) { oldmin+=colMinWidth[o]; oldmax+=colMaxWidth[o]; } int spreadmin = smin-oldmin-(span-1)*spacing;// kdDebug( 6040 ) << "colmin " << smin << endl;// kdDebug( 6040 ) << "oldmin " << oldmin << endl;// kdDebug( 6040 ) << "oldmax " << oldmax << endl;// 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 == Percent) { smax = m_width * col->value / KMAX(100u,totalPercent); } else if (col->type == Relative && totalRelative) { smax = m_width * col->value / totalRelative; } smax = KMAX(smax,oldmin);// 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 realMaxWidth=spacing; int* spanPercent = new int[maxColSpan]; int* spanPercentMax = new int[maxColSpan]; LengthType widthType = style()->width().type; Length l; if ( ( l = style()->marginLeft() ).isFixed() ) availableWidth -= QMAX( l.value, 0 ); if ( ( l = style()->marginRight() ).isFixed() ) availableWidth -= QMAX( l.value, 0 ); availableWidth -= QMAX( style()->borderLeftWidth(), 0 ); availableWidth -= QMAX( style()->borderRightWidth(), 0 ); // PHASE 2, calculate simple minimums and maximums for ( unsigned int s=0; (int)s<maxColSpan ; ++s) { ColInfoLine* spanCols = colInfos[s]; int spanMax=0; spanPercentMax[s] = spacing; spanPercent[s] = 0; 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 << " max="<<col->max<< endl;#endif col->update(); spanMax += col->max + spacing; if (col->type==Percent) { spanPercentMax[s] += col->max+spacing; spanPercent[s] += col->value; } calcSingleColMinMax(c, col); if ( col->span>1 && widthType != Percent && (col->type==Variable || col->type==Fixed)) { calcFinalColMax(c, col); } } // this should be some sort of generic path algorithm // but we'll just hack it for now if (spanMax>realMaxWidth) realMaxWidth=spanMax; } // PHASE 3, calculate table width totalPercent=0; totalRelative=0; int minPercent=0; int maxPercent=0; int minRel=0; int minVar=0; int maxRel=0; int maxVar=0; 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 Percent: if (!hasPercent){ hasPercent=true; minPercent=maxPercent=spacing; } totalPercent += colValue[i]; minPercent += colMinWidth[i] + spacing; maxPercent += colMaxWidth[i] + spacing; break; case Relative: if (!hasRel){ hasRel=true; minRel=maxRel=spacing; } totalRelative += colValue[i] ; minRel += colMinWidth[i] + spacing; maxRel += colMaxWidth[i] + spacing; break; case Undefined: case Variable: case Fixed: default: if (!hasVar){ hasVar=true; minVar=maxVar=spacing; } minVar += colMinWidth[i] + spacing; maxVar += colMaxWidth[i] + spacing; } } for ( int s=0; s<maxColSpan ; ++s) { maxPercent = KMAX(spanPercentMax[s],maxPercent); totalPercent = KMAX(spanPercent[s],int(totalPercent)); } delete[] spanPercentMax; delete[] spanPercent; if(widthType > Relative) // Percent or fixed table { m_width = style()->width().minWidth(availableWidth); if(m_minWidth > m_width) m_width = m_minWidth; //kdDebug( 6040 ) << "1 width=" << m_width << " minWidth=" << m_minWidth << " availableWidth=" << availableWidth << " " << endl; } else if (hasPercent) { int tot = KMIN(100u, totalPercent ); if (tot>0) m_maxWidth = maxPercent*100/tot; if (tot<100) m_maxWidth = KMAX( short((maxVar+maxRel)*100/(100-tot)), m_maxWidth ); m_width = KMIN(short( availableWidth ),m_maxWidth);// kdDebug( 6040 ) << "width=" << m_width << " maxPercent=" << maxPercent << " maxVar=" << maxVar << " " << endl; } else { m_width = KMIN(short( availableWidth ),m_maxWidth); } m_width = KMAX (m_width, m_minWidth); // PHASE 4, calculate maximums for percent and relative columns 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; if (col->type==Variable || col->type==Fixed) continue; calcFinalColMax(c, col); } } // PHASE 5, set table min and max to final values if(widthType == Fixed) { m_minWidth = m_maxWidth = m_width; } else { if (realMaxWidth > m_maxWidth) m_maxWidth = realMaxWidth; } m_minWidth += borderLeft() + borderRight(); m_maxWidth += borderLeft() + borderRight(); m_width += borderLeft() + borderRight();/* kdDebug( 6040 ) << "TABLE width=" << m_width << " m_minWidth=" << m_minWidth << " m_maxWidth=" << m_maxWidth << " realMaxWidth=" << realMaxWidth << endl;*/// setMinMaxKnown(true); int cw = containingBlockWidth(); m_marginRight=0; m_marginLeft=0; calcHorizontalMargins(style()->marginLeft(),style()->marginRight(),cw);}void RenderTable::calcWidth(){ Length ml = style()->marginLeft(); Length mr = style()->marginRight(); int cw = containingBlockWidth(); m_marginLeft = ml.minWidth(cw); m_marginRight = mr.minWidth(cw);}void RenderTable::calcColWidth(void){#ifdef TABLE_DEBUG kdDebug( 6040 ) << "START calcColWidth() this = " << this << endl; kdDebug( 6040 ) << "---- " << totalColInfos << " ----" << endl; kdDebug( 6040 ) << "maxColSpan = " << maxColSpan << endl;#endif if (totalCols==0) return; /* * Calculate min and max width for every column, * and the width of the table */ calcColMinMax(); /* * Set actColWidth[] to column minimums, it will * grow from there. * Collect same statistics for future use. */ int actWidth = spacing + borderLeft() + borderRight(); int minFixed = 0; int minPercent = 0; int minRel = 0; int minVar = 0; int maxFixed = 0; int maxPercent = 0; int maxRel = 0; int maxVar = 0; int numFixed = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -