PDA

View Full Version : QGraphicsTextItem AlphaColor Background to CSS2



patrik08
29th November 2007, 18:52
How i find the best way to convert AlphaColor Background qcolor to html value
HTML only having from 0.00 transparent to 1.00
and AlphaColor 1-255

and on html visible is from 0.7 to 1.0 !!
Have you a valid hack?






/* QGraphicsTextItem document() to div layer QFileInfo f destination file html
to save external image if exist..
*/
QString FloatDiagram::toDivHtml( QFileInfo f )
{
///// #define POINT_TO_MM(mm) ((mm)/2.83465058) point px mm ?? ////
#define ALPHAHTML(alpha) ((alpha)/254.99999999)
QString masterpath = f.absolutePath()+"/"+FOPIMAGEDIR;
/* Paint QGraphicsTextItem style to html css inline */
QString styles = "position:absolute; top:"+QString("%1px")
.arg(pos().y())+"; left:"+QString("%1px")
.arg(pos().x())+"; width:"+QString("%1px")
.arg(wi)+"; height:"+QString("%1px")
.arg(hi)+"; ";

if (AlphaColor < 44) {
styles.append(QString("background-color:transparent; ") );
} else {
styles.append(QString("background-color:%1; ").arg( BGColor.name() ) );
}
/* AlphaColor = backgroundqcolor.alpha(); */
int alFaCol = qBound(0,AlphaColor,256);
qreal percentos = ALPHAHTML( alFaCol );
if (percentos < 1 && AlphaColor > 44) {
QString Tnetto = QString("%1").arg(percentos, 0, 'f', 4);
styles.append(QString("opacity:%1; filter: alpha(opacity=%1); -moz-opacity:%1; ").arg( Tnetto) );
}
/* insert border having? */
if (BorderDicks > 0 ) {
styles.append(QString("border:%2px solid %1; ").arg(MarginColor.name()).arg(BorderDicks));
}
/* IE !zindex qreal play as int zValue() */
styles.append(QString("z-index:%1;").arg(QString("%1").arg(zValue()).replace(".","")));

QDomDocument doc;
QDomElement blox = doc.createElement("div");
blox.setAttribute ("id",QString("layer_%1").arg(id));
blox.setAttribute ("style",styles);
doc.appendChild(blox);

QString errorStr;
int errorLine, errorColumn;
QDomDocument exdoc;
if (!exdoc.setContent(document()->toHtml(),false, &errorStr, &errorLine, &errorColumn)) {
return doc.toString(5);
}
QDomElement root = exdoc.documentElement();
QDomNode child;
QDomElement e = root.firstChildElement("body");

ImageFindertoHtml(e,masterpath); /* rewrite image href to new qfileinfo path image folder and write svg to png */


/* import html to new QDomDocument to reformat later */
child = e.firstChild();
while ( !child.isNull() ) {
if ( child.isElement() ) {
blox.appendChild(doc.importNode(child,true).toElem ent());
} else if (child.isText()) {
blox.appendChild(doc.createTextNode(child.toText() .data()));
}
child = child.nextSibling();
}

return doc.toString(5);
}

wysota
30th November 2007, 16:17
Is the code you pasted in any way relevant and helpful to the question?