bool QtSkin::convertAttributesToColor(const QString& aName, const QXmlAttributes& theAttributes, QColor& aColor) { int redIndex=theAttributes.index("red"); int greenIndex=theAttributes.index("green"); int blueIndex=theAttributes.index("blue"); if(redIndex<0 || greenIndex<0 || blueIndex<0) { setErrorMessage("Invalid attributes for color "+aName); return false; } else { int red, green, blue; if(!convertStringToInteger(theAttributes.value(redIndex), red)) { setErrorMessage("Invalid red: "+theAttributes.value(redIndex)+" for "+aName); return false; } if(!convertStringToInteger(theAttributes.value(greenIndex), green)) { setErrorMessage("Invalid green: "+theAttributes.value(greenIndex)+" for "+aName); return false; } if(!convertStringToInteger(theAttributes.value(blueIndex), blue)) { setErrorMessage("Invalid blue: "+theAttributes.value(blueIndex)+" for "+aName); return false; } aColor.setRgb(red, green, blue); } return true; }
bool QtSkin::convertAttributesToRectangle(const QString& aName, const QXmlAttributes& theAttributes, QRect& aRectangle) { int xIndex = theAttributes.index("x"); int yIndex = theAttributes.index("y"); int widthIndex = theAttributes.index("width"); int heightIndex = theAttributes.index("height"); if (xIndex<0 || yIndex<0 || widthIndex < 0 || heightIndex < 0) { setErrorMessage("Invalid rectangle attributes for "+aName); return false; } else { int x; if (!convertStringToInteger(theAttributes.value(xIndex), x)) { setErrorMessage("Invalid x " + theAttributes.value(xIndex)+ " for "+aName); return false; } int y; if (!convertStringToInteger(theAttributes.value(yIndex), y)) { setErrorMessage("Invalid y " + theAttributes.value(yIndex)+ " for "+aName); return false; } int width; if (!convertStringToInteger(theAttributes.value(widthIndex), width)) { setErrorMessage("Invalid witdh " + theAttributes.value(widthIndex)+ " for "+aName); return false; } int height; if (!convertStringToInteger(theAttributes.value(heightIndex), height)) { setErrorMessage("Invalid height " + theAttributes.value(heightIndex)+ " for "+aName); return false; } aRectangle.setRect(x, y, width, height); return true; } }
/******************************************************************************** * Function Name : processDataReceived * Description : This function process the command received from client and replies. * Param : cmd [in] - command received from client reply [out] - Response to the command * Return : No Return ********************************************************************************/ static void processDataReceived(char cmd[], char reply[]) { int num; strlwr(cmd); if (!strcmp(cmd, "hello")) { strcpy(reply, "WELCOME"); } else if(!strcmp(cmd, "bye")) { strcpy(reply, "BYE BYE"); } else if(convertStringToInteger(cmd, &num)) { num *= num; sprintf(reply, "%d", num); } cout<<"\n**** Command Received: "<<cmd<<" ****\n"; cout<<"\n**** Reply: "<<reply<<" ****\n"; }