PDA

View Full Version : QTextTableCell border 1pt bottom append.



patrik08
15th November 2007, 10:43
How i can subclass QTextTableCell to paint only border bottom 1pt black solid? ( or only left , top .... )
ist this possibel ?

I suppose to append after on HTML QTextDocument tohtml td style
border-bottom:1px solid black;



void Fop_Handler::ParserTable( const QDomElement e , QTextDocument * d , Fop_Layer * layer , int CursorPositon )
{

if (FoTag(e) != TABLE_TAG) {
return;
}

Fop_Block *foppi = new Fop_Block(imagecounter,e,"fo:table"); /* grep current source to play */
qreal tableborderborder = TakeOneBorder(e);
qreal tablewidth = Unit(e.attribute ("width",QString("0")));
QDomElement co = e.parentNode().toElement();
QTextCursor Tcursor = QTextCursor(d);
bool IsCorrectCursor = Tcursor.movePosition(QTextCursor::End);
int mappos = Tcursor.position(); /* last position from last cursor on class ! */

QTextCursor cellCursor; /* new cursor only for cell tabbing */
QString tatype = e.attribute( "table-layout" ); /* on attribute root table */
QStringList coolsizes; /* grep column size in pt cm mm ecc... */
coolsizes.clear();
QDomElement bodytable = e.firstChildElement("fo:table-body");
int rowCounter = 0;
int columnCounter = 0;
QDomElement column = e.firstChildElement("fo:table-column");
while (!column.isNull()) {
const QString sizefromcool = column.attribute( "column-width" );
if (sizefromcool.size() > 0) {
coolsizes.append(sizefromcool); /* append unit widht string 22pt */
}
column = column.nextSiblingElement("fo:table-column");
}

if (coolsizes.size() > 0) {
columnCounter = coolsizes.size();
}

QDomElement rows = bodytable.firstChildElement("fo:table-row");
while (!rows.isNull()) {
rowCounter++;
rows = rows.nextSiblingElement("fo:table-row");
}
if (rowCounter < 1) {
//////qDebug() << "### false row? " << columnCounter << " list" << coolsizes;
return;
}
////////qDebug() << "### true row " << columnCounter << " list" << coolsizes;
/* #########################base table #######################################*/
QTextTable *qtable = Tcursor.insertTable( rowCounter, columnCounter );
///////qDebug() << "### parse table... ";
////////qDebug() << "### rowCounter " << rowCounter;
////////qDebug() << "### columnCounter " << columnCounter;
QTextTableFormat tableFormat;
QString tbg = bodytable.attribute("background-color");

if (tablewidth !=0) {
tableFormat.setWidth ( QTextLength ( QTextLength::FixedLength, tablewidth ) );
///////tableFormat.setHeight ( QTextLength ( QTextLength::FixedLength, tablewidth ) );
}
qreal borderDik = TakeOneBorder(bodytable);
////////qDebug() << "### table borderDik " << borderDik; /* qt4 4.3 bug unable to set table border on QGraphicsTextItem */
if (!tbg.isEmpty()) {
tableFormat.setBackground ( QColor(tbg) );
}
tableFormat.setBorder(borderDik);
tableFormat.setCellSpacing(Unit(bodytable.attribut e ("cell-space",QString("0"))));
tableFormat.setCellPadding(TakeOnePadding(bodytabl e));


/* colums on mm cm pt <-> */
if (coolsizes.size() > 0) {
tableFormat.clearColumnWidthConstraints();
QVector<QTextLength> constraints;
for (int i = 0; i < coolsizes.size(); ++i) {
const qreal cellmesure = Unit(coolsizes.at(i));
constraints.insert(i,QTextLength(QTextLength::Fixe dLength, cellmesure ));
}
tableFormat.setColumnWidthConstraints(constraints) ;
}

if (tatype == "fixed") {
tableFormat.setAlignment ( Qt::AlignLeft );
} else {
tableFormat.setAlignment ( Qt::AlignJustify );
}

int qlistlargeNr = -1; /* cell and row count from 0 */
QDomElement setrows = bodytable.firstChildElement("fo:table-row");
while (!setrows.isNull()) {
int is_spancol = 0;
int startStorno = 0;
int stopStorno = 0;
bool bypassisactive = false;
qlistlargeNr++;
QTextBlockFormat tdformat;
tdformat.setBottomMargin(0);
tdformat.setTopMargin(0);
QDomElement columnElement = setrows.firstChildElement(); /* sub element from row */
int columnCounter = -1; /* cell and row count from 0 */

while ( !columnElement.isNull() ) {
if ( columnElement.tagName().toLower() == "fo:table-cell" ) {
columnCounter++;

QTextTableCell cell;


is_spancol = columnElement.attribute( "number-columns-spanned" ).trimmed().toInt();
if (is_spancol > 1) {
for (int i = 0; i < is_spancol; ++i) {
QTextTableCell cellstart = qtable->cellAt( qlistlargeNr , columnCounter + i);
QTextCharFormat firster = cellstart.format();
if (!columnElement.attribute("background-color").isEmpty()) {
firster.setBackground(QColor(columnElement.attribu te("background-color")));
}
cellstart.setFormat(firster);
}
/* point to last cell number-columns-spanned to fill text */
qtable->mergeCells ( qlistlargeNr ,columnCounter,1,is_spancol);
cell = qtable->cellAt( qlistlargeNr , columnCounter );

} else {
cell = qtable->cellAt( qlistlargeNr , columnCounter );
}

Tcursor = cell.firstCursorPosition();
const qreal cellpadding = Unit(columnElement.attribute ("padding",QString("0")));
const qreal cellwidht = Get_Cell_Width(tableFormat,columnCounter);


/* paint cell Background and table border here */
QTextCharFormat existformat = cell.format();
if (!columnElement.attribute("background-color").isEmpty()) {
existformat.setBackground(QColor(columnElement.att ribute("background-color")));
}
existformat.setToolTip ( foppi->Get_XML() );
cell.setFormat(existformat);

Tcursor = cell.firstCursorPosition();
int FirstcellInitCursor = Tcursor.position();

int blocksDD = 0;
QDomElement cellinside = columnElement.firstChildElement("fo:block");
while ( !cellinside.isNull() ) {
blocksDD++;
if (blocksDD == 1) {
ParserParagraph(cellinside,d,layer,FirstcellInitCu rsor,true);
} else {
ParserParagraph(cellinside,d,layer,CursorStatement Position,true);
}

cellinside = cellinside.nextSiblingElement("fo:block");
}


}
columnElement = columnElement.nextSiblingElement();
}



setrows = setrows.nextSiblingElement("fo:table-row");
}



qtable->setFormat( tableFormat );
ActualBackgroundColor = QString(default_background); /* reset color background */
CursorStatementPosition = 0; /* go to end document ! */

}

wysota
22nd November 2007, 11:19
Have you tried applying a text format on the cell?