QDomElement KWDWriter::fetchTableCell(int tableno, int rowno, int colno) { QDomNodeList e=docroot().elementsByTagName("FRAMESET"); for (unsigned int i=0;i<e.count();i++) { QDomElement k=e.item(i).toElement(); if (k.attribute("grpMgr") == QString("Table %1").arg(tableno)) if (k.attribute("row") == QString("%1").arg(rowno)) if (k.attribute("col") == QString("%1").arg(colno)) return k; } QDomElement dummy; return dummy; }
QDomElement KWDWriter::createTableCell(int tableno, int nrow, int ncol, int colspan, QRect rect) { QDomElement parent=docroot().elementsByTagName("FRAMESETS").item(0).toElement(); QDomElement fs=addFrameSet(parent,1,0, QString("Table %1 - %2,%3").arg(tableno).arg(nrow).arg(ncol), 1); fs.setAttribute("grpMgr",QString("Table %1").arg(tableno)); fs.setAttribute("row",nrow); fs.setAttribute("col",ncol); fs.setAttribute("cols",colspan); // FIXME do colspan in finishTable // so we don't have to give it as an argument fs.setAttribute("rows",1); // FIXME support rowspan ? addFrame(fs,rect); return fs; }
void KWDWriter::finishTable(int tableno, QRect rect) { int ncols = 0; int nrows = 0; insidetable = false; int x = rect.x(); int y = rect.y(); int w = rect.width(); int h = rect.height(); QDomNodeList nl = docroot().elementsByTagName("FRAMESET"); //FIXME calculate nrows and stuff. //and add empty cells for missing ones. // first, see how big the table is (cols & rows) for (int i = 0;i < nl.count();i++) { QDomElement k = nl.item(i).toElement(); if (k.attribute("grpMgr") == QString("Table %1").arg(tableno)) { ncols = MAX(ncols, k.attribute("col").toInt() + 1); nrows = MAX(nrows, k.attribute("row").toInt() + 1); } } int curcol = 0; int currow = 0; int currow_inc = 0; if (ncols == 0) ncols = 1; // FIXME (floating point division by zero) if (nrows == 0) nrows = 1; int step_x = (w - x) / ncols; int step_y = (h - y) / nrows; // then, let's create the missing cells and resize them if needed. bool must_resize = false; if (x > 0) must_resize = true; while (currow < nrows) { curcol = 0; while (curcol < ncols) { QDomElement e = fetchTableCell(tableno, currow, curcol); if (e.isNull()) { // a missing cell ! kDebug(30503) << QString("creating %1 %2").arg(currow).arg(curcol).toLatin1(); createTableCell(tableno, currow, curcol, 1, QRect(x + step_x*curcol, y + step_y*currow, step_x, step_y) ); // fixme: what to do if we don't have to resize ? } // resize this one FIXME optimize this routine if (must_resize == true) { QDomElement ee = e.firstChild().toElement(); // the frame in the frameset int cs = e.attribute("cols").toInt(); int rs = e.attribute("rows").toInt(); kDebug(30503) << "resizing"; addRect(ee, QRect(x + step_x*curcol, 0, step_x*cs, step_y*rs)); } if (curcol == 0) currow_inc = e.attribute("rows").toInt(); curcol += e.attribute("cols").toInt(); } currow += currow_inc; } }