js代码
function rgbToHex(color){
return Qt.rgba(color.r,color.g,color.b,1.0)
}
function hexToRgb(hex) {
var ret;
if(hex.length === 4 || hex.length === 7){
if(hex.length === 4){
var sColorNew = "#";
for(var i=1; i<4; i+=1){
sColorNew += hex.slice(i,i+1).concat(hex.slice(i,i+1));
}
hex = sColorNew;
}
ret = getRgb(hex);
}else if(hex.length === 9){
var opacity = parseInt("0x" + hex.slice(1, 3)) / 255;
opacity = opacity.toFixed(2);
ret = getRgba(hex,opacity);
}else{
ret = "---> Error format color!";
}
return ret ;
}
function getRgba(hex,opacity){
return "rgba(" + parseInt("0x" + hex.slice(1, 3))
+ "," + parseInt("0x" + hex.slice(3, 5)) + ","
+ parseInt("0x" + hex.slice(5, 7)) + ","
+ opacity.toString() + ")";
}
function getRgb(hex){
return "rgba(" + parseInt("0x" + hex.slice(1, 3))
+ "," + parseInt("0x" + hex.slice(3, 5)) + ","
+ parseInt("0x" + hex.slice(5, 7)) + ")";
}
是ES5语法。QML使用的