Example #1
0
    /**
     * Loads gradient from xmi. The gradient pointer should be null
     * and the new gradient object will be created inside this method.
     * The gradient should later be deleted externally.
     *
     * @param gradientElement The DOM element from which gradient should be
     *                        loaded.
     *
     * @param gradient The pointer to gradient into which the gradient
     *                 should be loaded. (Allocated inside this
     *                 method)
     *
     * @return True or false based on success or failure of this method.
     */
    bool loadGradientFromXMI(QDomElement &gradientElement, QGradient *&gradient)
    {
        if(gradientElement.isNull()) {
            return false;
        }

        int type_as_int;
        QGradient::Type type;
        QGradientStops stops;
        QGradient::CoordinateMode cmode = QGradient::LogicalMode;
        QGradient::Spread spread = QGradient::PadSpread;

        type_as_int = gradientElement.attribute(QLatin1String("type")).toInt();
        type = QGradient::Type(type_as_int);
        type_as_int = gradientElement.attribute(QLatin1String("spread")).toInt();
        spread = QGradient::Spread(type_as_int);
        type_as_int = gradientElement.attribute(QLatin1String("coordinatemode")).toInt();
        cmode = QGradient::CoordinateMode(type_as_int);

        QDomElement stopElement = gradientElement.firstChildElement(QLatin1String("stops"));
        if(stopElement.isNull()) {
            return false;
        }
        for(QDomNode node = stopElement.firstChild(); !node.isNull(); node = node.nextSibling()) {
            QDomElement ele = node.toElement();
            if(ele.tagName() != QLatin1String("stop")) {
                continue;
            }

            qreal posn = ele.attribute(QLatin1String("position")).toDouble();
            QColor color = QColor(ele.attribute(QLatin1String("color")));
            stops << QGradientStop(posn, color);
        }

        if (type == QGradient::LinearGradient) {
            QPointF p1 = stringToPoint(gradientElement.attribute(QLatin1String("start")));
            QPointF p2 = stringToPoint(gradientElement.attribute(QLatin1String("finalstop")));
            gradient = new QLinearGradient(p1, p2);
        }
        else if (type == QGradient::RadialGradient) {
            QPointF center = stringToPoint(gradientElement.attribute(QLatin1String("center")));
            QPointF focal = stringToPoint(gradientElement.attribute(QLatin1String("focalpoint")));
            double radius = gradientElement.attribute(QLatin1String("radius")).toDouble();
            gradient = new QRadialGradient(center, radius, focal);
        }
        else { // type == QGradient::ConicalGradient
            QPointF center = stringToPoint(gradientElement.attribute(QLatin1String("center")));
            double angle = gradientElement.attribute(QLatin1String("angle")).toDouble();
            gradient = new QConicalGradient(center, angle);
        }

        if(gradient) {
            gradient->setStops(stops);
            gradient->setSpread(spread);
            gradient->setCoordinateMode(cmode);
            return true;
        }

        return false;
    }
Example #2
0
// QC:G
GraphicalEffects Factory::loadEffects(TiXmlElement *xmlData) {
	GraphicalEffects effects;

	const char* aVal;
	bool b;
	int i;
	coord c;
	Rect r;
	Point p;

	if((aVal=xmlData->Attribute("effects"))) {
		effects.setEffects(aVal);
	}

	if(stringToPoint(xmlData->Attribute("scale"), p))
		effects.setScale(p);
		
	if(stringToPoint(xmlData->Attribute("sectionPointStart"), p))
		effects.setSectionPointStart(p);
	
	if(stringToPoint(xmlData->Attribute("sectionWidthHeight"), p))
		effects.setSectionWidthHeight(p);
	
	if(stringToRect(xmlData->Attribute("section"), r))
		effects.setSection(r);

	if(stringToCoord(xmlData->Attribute("rotation"), &c))
		effects.setRotation(c);

	if(stringToInt(xmlData->Attribute("opacity"), &i))
		effects.setOpacity(i);

	if(stringToInt(xmlData->Attribute("redFilter"), &i))
		effects.setIntegerEffect("RFIL", i);

	if(stringToInt(xmlData->Attribute("greenFilter"), &i))
		effects.setIntegerEffect("GFIL", i);

	if(stringToInt(xmlData->Attribute("blueFilter"), &i))
		effects.setIntegerEffect("BFIL", i);

	effects.setBlendMode(xmlData->Attribute("blend"));

	if(stringToBool(xmlData->Attribute("renderCache"), &b))
		effects.setRenderCache(b);
	
	if((aVal=xmlData->Attribute("preProcess"))) {
		effects.setPreProcess(aVal, NULL);
	}

	if((aVal=xmlData->Attribute("postProcess"))) {
		effects.setPostProcess(aVal, NULL);
	}

	return effects;
}