📄 htmltable.cpp
字号:
// DEBUG: Show the results :)#if 0 //printf("---- %d ----\n", totalColInfos); for(i = 0; i < totalColInfos; i++) { //printf("col #%d: %d - %d, min: %3d pref: %3d max: %3d type: %d\n", i, colInfo[i].startCol, colInfo[i].colSpan, colInfo[i].minSize, colInfo[i].prefSize, colInfo[i].maxSize, (int) colInfo[i].colType); } for(i = 0; i < totalRowInfos; i++) { //printf("row #%d: ", i); for(j = 0; j < rowInfo[i].nrEntries; j++) { if (j == 0) //printf("%d", rowInfo[i].entry[j]); else //printf("- %d", rowInfo[i].entry[j]); } //printf(" ! %d : %d\n", rowInfo[i].minSize, rowInfo[i].prefSize); }#endif}void HTMLTable::calcRowHeights(){ unsigned int r, c; int indx, borderExtra = border ? 1 : 0; HTMLTableCell *cell; rowHeights.resize( totalRows+1 ); rowHeights[0] = border + spacing; for ( r = 0; r < totalRows; r++ ) { rowHeights[r+1] = 0; for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( ( indx = r - cell->rowSpan() + 1 ) < 0 ) indx = 0; int rowPos = rowHeights[ indx ] + cell->getHeight() + padding + padding + spacing + borderExtra; if ( rowPos > rowHeights[r+1] ) rowHeights[r+1] = rowPos; } if ( rowHeights[r+1] < rowHeights[r] ) rowHeights[r+1] = rowHeights[r]; }}int HTMLTable::calcMinWidth(){ return _minWidth;}int HTMLTable::calcPreferredWidth(){ return _prefWidth;}void HTMLTable::setMaxWidth( int _max_width ){ max_width = _max_width; if (!isFixedWidth()) { if ( percent > 0 ) width = max_width * percent / 100; else width = max_width; calcColumnWidths(); }}void HTMLTable::setMaxAscent( int _a ){ ascent = _a;}HTMLObject *HTMLTable::checkPoint( int _x, int _y ){ unsigned int r, c; HTMLObject *obj; HTMLTableCell *cell; if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent) return 0L; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ((obj = cell->checkPoint( _x-x, _y-(y - ascent) )) != 0) return obj; } } return 0L;}HTMLObject *HTMLTable::mouseEvent( int _x, int _y, int button, int state ){ unsigned int r, c; HTMLObject *obj; HTMLTableCell *cell; if ( _x < x || _x > x + width || _y > y + descent || _y < y - ascent) return 0; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( ( obj = cell->mouseEvent( _x-x, _y-(y - ascent), button, state ) ) != 0 ) return obj; } } return 0;}void HTMLTable::selectByURL( KHTMLWidget *_htmlw, HTMLChain *_chain, const char *_url, bool _select, int _tx, int _ty ){ unsigned int r, c; HTMLTableCell *cell; _tx += x; _ty += y - ascent; _chain->push( this ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->selectByURL( _htmlw, _chain, _url, _select, _tx, _ty ); } } _chain->pop();}void HTMLTable::select( KHTMLWidget *_htmlw, HTMLChain *_chain, QRegExp& _pattern, bool _select, int _tx, int _ty ){ unsigned int r, c; HTMLTableCell *cell; _tx += x; _ty += y - ascent; _chain->push( this ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->select( _htmlw, _chain, _pattern, _select, _tx, _ty ); } } _chain->pop();}void HTMLTable::select( KHTMLWidget *_htmlw, HTMLChain *_chain, bool _select, int _tx, int _ty ){ unsigned int r, c; HTMLTableCell *cell; _tx += x; _ty += y - ascent; _chain->push( this ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->select( _htmlw, _chain, _select, _tx, _ty ); } } _chain->pop();}void HTMLTable::select( KHTMLWidget *_htmlw, HTMLChain *_chain, QRect & _rect, int _tx, int _ty ){ unsigned int r, c; HTMLTableCell *cell; _tx += x; _ty += y - ascent; _chain->push( this ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->select( _htmlw, _chain, _rect, _tx, _ty ); } } _chain->pop();}void HTMLTable::select( bool _select ){ unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->select( _select ); } }}bool HTMLTable::selectText( KHTMLWidget *_htmlw, HTMLChain *_chain, int _x1, int _y1, int _x2, int _y2, int _tx, int _ty ){ bool isSel = false; unsigned int r, c; HTMLTableCell *cell; _tx += x; _ty += y - ascent; _chain->push( this ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( _y1 < y - ascent && _y2 > y ) { isSel = cell->selectText( _htmlw, _chain, 0, _y1 - ( y - ascent ), width + 1, _y2 - ( y - ascent ), _tx, _ty ) || isSel; } else if ( _y1 < y - ascent ) { isSel = cell->selectText( _htmlw, _chain, 0, _y1 - ( y - ascent ), _x2 - x, _y2 - ( y - ascent ), _tx, _ty ) || isSel; } else if ( _y2 > y ) { isSel = cell->selectText( _htmlw, _chain, _x1 - x, _y1 - ( y - ascent ), width + 1, _y2 - ( y - ascent ), _tx, _ty ) || isSel; } else if ( (_x1 - x < cell->getXPos() + cell->getWidth() && _x2 - x > cell->getXPos() ) ) { isSel = cell->selectText( _htmlw, _chain, _x1 - x, _y1 - ( y - ascent ), _x2 - x, _y2 - ( y - ascent ), _tx, _ty ) || isSel; } else { cell->selectText( _htmlw, _chain, 0, 0, 0, 0, _tx, _ty ); } } } _chain->pop(); return isSel;}void HTMLTable::getSelected( QStrList &_list ){ unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->getSelected( _list ); } }}void HTMLTable::getSelectedText( QString &_str ){ unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->getSelectedText( _str ); } }}int HTMLTable::findPageBreak( int _y ){ if ( _y > y ) return -1; unsigned int r, c; HTMLTableCell *cell; int pos, minpos = 0x7FFFFFFF; QArray<bool> colsDone( totalCols ); colsDone.fill( false ); for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( colsDone[c] ) continue; pos = cell->findPageBreak( _y - ( y - ascent ) ); if ( pos >= 0 && pos < minpos ) { colsDone[c] = true; minpos = pos; } } } if ( minpos != 0x7FFFFFFF ) return ( minpos + y - ascent ); return -1;}void HTMLTable::findCells( int _tx, int _ty, QList<HTMLCellInfo> &_list ){ _tx += x; _ty += y - ascent; unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->findCells( _tx, _ty, _list ); } }}bool HTMLTable::print( QPainter *_painter, int _x, int _y, int _width, int _height, int _tx, int _ty, bool toPrinter ){ if ( _y + _height < y - getAscent() || _y > y + descent ) return false; _tx += x; _ty += y - ascent; unsigned int r, c; int cindx, rindx; HTMLTableCell *cell; QArray<bool> colsDone( totalCols ); colsDone.fill( false ); if ( caption ) { caption->print( _painter, _x - x, _y - (y - ascent), _width, _height, _tx, _ty, toPrinter ); } // draw the cells for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( colsDone[c] ) continue; if ( cell->print( _painter, _x - x, _y - (y - ascent), _width, _height, _tx, _ty, toPrinter ) ) colsDone[c] = true; } } // draw the border - needs work to print to printer if ( border && !toPrinter ) { int capOffset = 0; if ( caption && capAlign == HTMLClue::Top ) capOffset = caption->getHeight(); QColorGroup colorGrp( black, lightGray, white, darkGray, gray, black, white ); qDrawShadePanel( _painter, _tx, _ty + capOffset, width, rowHeights[totalRows] + border, colorGrp, false, border ); // draw borders around each cell for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; if ( ( cindx = c-cell->colSpan()+1 ) < 0 ) cindx = 0; if ( ( rindx = r-cell->rowSpan()+1 ) < 0 ) rindx = 0; qDrawShadePanel(_painter, _tx + columnOpt[cindx], _ty + rowHeights[rindx] + capOffset, columnOpt[c+1] - columnOpt[cindx] - spacing, rowHeights[r+1] - rowHeights[rindx] - spacing, colorGrp, TRUE, 1 ); } } } for ( c = 0; c < totalCols; c++ ) { if ( colsDone[c] == true ) return true; } return false;}void HTMLTable::print( QPainter *_painter, HTMLChain *_chain,int _x, int _y, int _width, int _height, int _tx, int _ty ){ _tx += x; _ty += y - ascent; _chain->next(); if ( _chain->current() ) { _chain->current()->print( _painter, _chain, _x - x, _y - (y - ascent), _width, _height, _tx, _ty ); }} void HTMLTable::print( QPainter *_painter, HTMLObject *_obj, int _x, int _y, int _width, int _height, int _tx, int _ty ){ if ( _y + _height < y - getAscent() || _y > y + descent ) return; _tx += x; _ty += y - ascent; unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; if ( c < totalCols - 1 && cell == cells[r][c+1] ) continue; if ( r < totalRows - 1 && cells[r+1][c] == cell ) continue; cell->print( _painter, _obj, _x - x, _y - (y - ascent), _width, _height, _tx, _ty ); } }}void HTMLTable::print( QPainter *_painter, int _tx, int _ty ){ print( _painter, 0, 0, 0xFFFF, 0xFFFF, _tx, _ty, false );}HTMLTable::~HTMLTable(){ unsigned int r, c; HTMLTableCell *cell; for ( r = 0; r < totalRows; r++ ) { for ( c = 0; c < totalCols; c++ ) { if ( ( cell = cells[r][c] ) == 0 ) continue; cell->unlink(); } delete [] cells[r]; } delete [] cells; delete caption;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -