void TupItemTweener::fromXml(const QString &xml) { #ifdef K_DEBUG QString msg = "TupItemTweener::fromXml() - Tween content: "; #ifdef Q_OS_WIN qWarning() << msg; qWarning() << xml; #else tWarning() << msg; tWarning() << xml; #endif #endif QDomDocument doc; if (doc.setContent(xml)) { QDomElement root = doc.documentElement(); k->name = root.attribute("name"); k->type = TupItemTweener::Type(root.attribute("type").toInt()); k->initFrame = root.attribute("initFrame").toInt(); k->initLayer = root.attribute("initLayer").toInt(); k->initScene = root.attribute("initScene").toInt(); k->frames = root.attribute("frames").toInt(); QString origin = root.attribute("origin"); // [x,y] QStringList list = origin.split(","); double x = list.first().toDouble(); double y = list.last().toDouble(); k->originPoint = QPointF(x, y); if (k->type == TupItemTweener::Composed) { QDomElement settings = root.firstChildElement("settings"); QDomNode node = settings.firstChild(); while (!node.isNull()) { QDomElement e = node.toElement(); if (!e.isNull()) { if (e.tagName() == "position") { // tError() << "TupItemTweener::fromXml() - Processing position settings"; k->tweenList.append(TupItemTweener::Position); k->compPositionInitFrame = e.attribute("init").toInt(); k->compPositionFrames = e.attribute("frames").toInt(); k->path = e.attribute("coords"); k->intervals = e.attribute("intervals"); } if (e.tagName() == "rotation") { // tError() << "TupItemTweener::fromXml() - Processing rotation settings"; k->tweenList.append(TupItemTweener::Rotation); k->compRotationInitFrame = e.attribute("init").toInt(); k->compRotationFrames = e.attribute("frames").toInt(); k->rotationType = TupItemTweener::RotationType(root.attribute("rotationType").toInt()); k->rotateSpeed = root.attribute("rotateSpeed").toInt(); k->rotateDirection = TupItemTweener::RotateDirection(root.attribute("rotateDirection").toInt()); if (k->rotationType == TupItemTweener::Partial) { k->rotateLoop = root.attribute("rotateLoop").toInt(); k->rotateStartDegree = root.attribute("rotateStartDegree").toInt(); k->rotateEndDegree = root.attribute("rotateEndDegree").toInt(); k->rotateReverseLoop = root.attribute("rotateReverseLoop").toInt(); } } if (e.tagName() == "scale") { // tError() << "TupItemTweener::fromXml() - Processing scale settings"; k->tweenList.append(TupItemTweener::Scale); k->compScaleInitFrame = e.attribute("init").toInt(); k->compScaleFrames = e.attribute("frames").toInt(); } if (e.tagName() == "shear") { // tError() << "TupItemTweener::fromXml() - Processing shear settings"; k->tweenList.append(TupItemTweener::Shear); k->compShearInitFrame = e.attribute("init").toInt(); k->compShearFrames = e.attribute("frames").toInt(); } if (e.tagName() == "opacity") { // tError() << "TupItemTweener::fromXml() - Processing opacity settings"; k->tweenList.append(TupItemTweener::Opacity); k->compOpacityInitFrame = e.attribute("init").toInt(); k->compOpacityFrames = e.attribute("frames").toInt(); } if (e.tagName() == "coloring") { // tError() << "TupItemTweener::fromXml() - Processing coloring settings"; k->tweenList.append(TupItemTweener::Coloring); k->colorFillType = FillType(e.attribute("fillType").toInt()); k->compColoringInitFrame = e.attribute("init").toInt(); k->compColoringFrames = e.attribute("frames").toInt(); } } node = node.nextSibling(); } } else { if (k->type == TupItemTweener::Position) { k->path = root.attribute("coords"); k->intervals = root.attribute("intervals"); } if (k->type == TupItemTweener::Rotation) { k->rotationType = TupItemTweener::RotationType(root.attribute("rotationType").toInt()); k->rotateSpeed = root.attribute("rotateSpeed").toInt(); k->rotateDirection = TupItemTweener::RotateDirection(root.attribute("rotateDirection").toInt()); if (k->rotationType == TupItemTweener::Partial) { k->rotateLoop = root.attribute("rotateLoop").toInt(); k->rotateStartDegree = root.attribute("rotateStartDegree").toInt(); k->rotateEndDegree = root.attribute("rotateEndDegree").toInt(); k->rotateReverseLoop = root.attribute("rotateReverseLoop").toInt(); } } if (k->type == TupItemTweener::Scale) { k->scaleAxes = TupItemTweener::TransformAxes(root.attribute("scaleAxes").toInt()); k->scaleFactor = root.attribute("scaleFactor").toDouble(); k->scaleIterations = root.attribute("scaleIterations").toInt(); k->scaleLoop = root.attribute("scaleLoop").toInt(); k->scaleReverseLoop = root.attribute("scaleReverseLoop").toInt(); } if (k->type == TupItemTweener::Shear) { k->shearAxes = TupItemTweener::TransformAxes(root.attribute("shearAxes").toInt()); k->shearFactor = root.attribute("shearFactor").toDouble(); k->shearIterations = root.attribute("shearIterations").toInt(); k->shearLoop = root.attribute("shearLoop").toInt(); k->shearReverseLoop = root.attribute("shearReverseLoop").toInt(); } if (k->type == TupItemTweener::Opacity) { k->initOpacityFactor = root.attribute("initOpacityFactor").toDouble(); k->endOpacityFactor = root.attribute("endOpacityFactor").toDouble(); k->opacityIterations = root.attribute("opacityIterations").toInt(); k->opacityLoop = root.attribute("opacityLoop").toInt(); k->opacityReverseLoop = root.attribute("opacityReverseLoop").toInt(); } if (k->type == TupItemTweener::Coloring) { k->colorFillType = FillType(root.attribute("fillType").toInt()); QString colorText = root.attribute("initialColor"); QStringList list = colorText.split(","); int red = list.at(0).toInt(); int green = list.at(1).toInt(); int blue = list.at(2).toInt(); k->initialColor = QColor(red, green, blue); colorText = root.attribute("endingColor"); list = colorText.split(","); red = list.at(0).toInt(); green = list.at(1).toInt(); blue = list.at(2).toInt(); k->endingColor = QColor(red, green, blue); k->colorIterations = root.attribute("colorIterations").toInt(); k->colorLoop = root.attribute("colorLoop").toInt(); k->colorReverseLoop = root.attribute("colorReverseLoop").toInt(); } } QDomNode node = root.firstChildElement("step"); while (!node.isNull()) { QDomElement e = node.toElement(); if (!e.isNull()) { if (e.tagName() == "step") { QString stepDoc; { QTextStream ts(&stepDoc); ts << node; } TupTweenerStep *step = new TupTweenerStep(0); step->fromXml(stepDoc); addStep(*step); delete step; } } node = node.nextSibling(); } } }
void TupItemTweener::addStep(const TupTweenerStep &step) { int counter = step.index(); #ifdef K_DEBUG #ifdef Q_OS_WIN qWarning() << "TupItemTweener::addStep() - counter: " << counter; #else VERIFY_STEP(counter); #endif #endif if (step.has(TupTweenerStep::Position)) setPosAt(counter, step.position()); if (step.has(TupTweenerStep::Rotation)) setRotationAt(counter, step.rotation()); if (step.has(TupTweenerStep::Scale)) setScaleAt(counter, step.horizontalScale(), step.verticalScale()); if (step.has(TupTweenerStep::Shear)) setShearAt(counter, step.horizontalShear(), step.verticalShear()); if (step.has(TupTweenerStep::Opacity)) setOpacityAt(counter, step.opacity()); if (step.has(TupTweenerStep::Coloring)) setColorAt(counter, step.color()); }
void TupGraphicsScene::addSvgTweeningObjects(int photogram) { QList<TupSvgItem *> svgList = k->scene->tweeningSvgObjects(); for (int i=0; i < svgList.count(); i++) { TupSvgItem *object = svgList.at(i); if (object->frame()->layer()->isVisible()) { int origin = object->frame()->index(); if (TupItemTweener *tween = object->tween()) { int adjustX = object->boundingRect().width()/2; int adjustY = object->boundingRect().height()/2; if (origin == photogram) { TupTweenerStep *stepItem = tween->stepAt(0); object->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: 0")); if (stepItem->has(TupTweenerStep::Position)) { object->setPos(tween->transformOriginPoint()); QPointF offset = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + offset); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->setTransformOriginPoint(tween->transformOriginPoint()); object->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); object->setTransformOriginPoint(point); object->setScale(1.0); } if (stepItem->has(TupTweenerStep::Shear)) { QTransform transform; transform.shear(0, 0); object->setTransform(transform); } if (stepItem->has(TupTweenerStep::Opacity)) object->setOpacity(stepItem->opacity()); } else if ((origin < photogram) && (photogram < origin + tween->frames())) { int step = photogram - origin; TupTweenerStep *stepItem = tween->stepAt(step); object->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: ") + QString::number(step)); if (stepItem->has(TupTweenerStep::Position)) { qreal dx = stepItem->position().x() - (object->lastTweenPos().x() + adjustX); qreal dy = stepItem->position().y() - (object->lastTweenPos().y() + adjustY); object->moveBy(dx, dy); QPointF offset = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + offset); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); double scaleX = stepItem->horizontalScale(); double scaleY = stepItem->verticalScale(); QTransform transform; transform.translate(point.x(), point.y()); transform.scale(scaleX, scaleY); transform.translate(-point.x(), -point.y()); object->setTransform(transform); } if (stepItem->has(TupTweenerStep::Shear)) { QPointF point = tween->transformOriginPoint(); double shearX = stepItem->horizontalShear(); double shearY = stepItem->verticalShear(); QTransform transform; transform.translate(point.x(), point.y()); transform.shear(shearX, shearY); transform.translate(-point.x(), -point.y()); object->setTransform(transform); } addSvgObject(object); if (stepItem->has(TupTweenerStep::Opacity)) object->setOpacity(stepItem->opacity()); } } else { #ifdef K_DEBUG tFatal() << "TupGraphicsScene::addSvgTweeningObjects() - No tween found!"; #endif } } } }
void TupItemTweener::addStep(const TupTweenerStep &step) { int counter = step.index(); VERIFY_STEP(counter); if (step.has(TupTweenerStep::Position)) setPosAt(counter, step.position()); if (step.has(TupTweenerStep::Rotation)) setRotationAt(counter, step.rotation()); if (step.has(TupTweenerStep::Scale)) setScaleAt(counter, step.horizontalScale(), step.verticalScale()); if (step.has(TupTweenerStep::Shear)) setShearAt(counter, step.horizontalShear(), step.verticalShear()); if (step.has(TupTweenerStep::Opacity)) setOpacityAt(counter, step.opacity()); if (step.has(TupTweenerStep::Coloring)) setColorAt(counter, step.color()); }
void TupGraphicsScene::addTweeningObjects(int photogram) { QList<TupGraphicObject *> tweenList = k->scene->tweeningGraphicObjects(); for (int i=0; i < tweenList.count(); i++) { TupGraphicObject *object = tweenList.at(i); if (object->frame()->layer()->isVisible()) { int origin = object->frame()->index(); if (TupItemTweener *tween = object->tween()) { int adjustX = object->item()->boundingRect().width()/2; int adjustY = object->item()->boundingRect().height()/2; if (origin == photogram) { TupTweenerStep *stepItem = tween->stepAt(0); object->item()->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: 0")); if (tween->type() == TupItemTweener::Compound) { object->item()->setTransformOriginPoint(tween->transformOriginPoint()); if (stepItem->has(TupTweenerStep::Position)) { // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying position..."; QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); object->item()->setPos(tween->transformOriginPoint()); } if (stepItem->has(TupTweenerStep::Rotation)) { QRectF rect = object->item()->sceneBoundingRect(); object->item()->setTransformOriginPoint(rect.center()); double angle = stepItem->rotation(); object->item()->setRotation(angle); // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying rotation - Angle: " << angle; } else { // tFatal() << "TupGraphicsScene::addTweeningObjects() - No rotation parameter!"; } } else { if (stepItem->has(TupTweenerStep::Position)) { QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); object->item()->setPos(tween->transformOriginPoint()); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setTransformOriginPoint(tween->transformOriginPoint()); object->item()->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); object->item()->setTransformOriginPoint(point); object->item()->setScale(1.0); } if (stepItem->has(TupTweenerStep::Shear)) { QTransform transform; transform.shear(0, 0); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Coloring)) { QColor itemColor = stepItem->color(); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(object->item())) { QPen pen = path->pen(); pen.setColor(itemColor); path->setPen(pen); } else if (TupEllipseItem *ellipse = qgraphicsitem_cast<TupEllipseItem *>(object->item())) { QPen pen = ellipse->pen(); pen.setColor(itemColor); ellipse->setPen(pen); } else if (TupLineItem *line = qgraphicsitem_cast<TupLineItem *>(object->item())) { QPen pen = line->pen(); pen.setColor(itemColor); line->setPen(pen); } else if (TupRectItem *rect = qgraphicsitem_cast<TupRectItem *>(object->item())) { QPen pen = rect->pen(); pen.setColor(itemColor); rect->setPen(pen); } } if (stepItem->has(TupTweenerStep::Opacity)) object->item()->setOpacity(stepItem->opacity()); } } else if ((origin < photogram) && (photogram < origin + tween->frames())) { int step = photogram - origin; TupTweenerStep *stepItem = tween->stepAt(step); object->item()->setToolTip(tween->tweenType() + ": " + tween->name() + tr("/Step: ") + QString::number(step)); if (tween->type() == TupItemTweener::Compound) { if (stepItem->has(TupTweenerStep::Position)) { qreal dx = stepItem->position().x() - (object->lastTweenPos().x() + adjustX); qreal dy = stepItem->position().y() - (object->lastTweenPos().y() + adjustY); object->item()->moveBy(dx, dy); QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setRotation(angle); // tFatal() << "TupGraphicsScene::addTweeningObjects() - Applying rotation - Angle: " << angle; } addGraphicObject(object); } else { if (stepItem->has(TupTweenerStep::Position)) { qreal dx = stepItem->position().x() - (object->lastTweenPos().x() + adjustX); qreal dy = stepItem->position().y() - (object->lastTweenPos().y() + adjustY); object->item()->moveBy(dx, dy); QPointF point = QPoint(-adjustX, -adjustY); object->setLastTweenPos(stepItem->position() + point); } if (stepItem->has(TupTweenerStep::Rotation)) { double angle = stepItem->rotation(); object->item()->setRotation(angle); } if (stepItem->has(TupTweenerStep::Scale)) { QPointF point = tween->transformOriginPoint(); double scaleX = stepItem->horizontalScale(); double scaleY = stepItem->verticalScale(); QTransform transform; transform.translate(point.x(), point.y()); transform.scale(scaleX, scaleY); transform.translate(-point.x(), -point.y()); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Shear)) { QPointF point = tween->transformOriginPoint(); double shearX = stepItem->horizontalShear(); double shearY = stepItem->verticalShear(); QTransform transform; transform.translate(point.x(), point.y()); transform.shear(shearX, shearY); transform.translate(-point.x(), -point.y()); object->item()->setTransform(transform); } if (stepItem->has(TupTweenerStep::Coloring)) { QColor itemColor = stepItem->color(); if (TupPathItem *path = qgraphicsitem_cast<TupPathItem *>(object->item())) { QPen pen = path->pen(); pen.setColor(itemColor); path->setPen(pen); } else if (TupEllipseItem *ellipse = qgraphicsitem_cast<TupEllipseItem *>(object->item())) { QPen pen = ellipse->pen(); pen.setColor(itemColor); ellipse->setPen(pen); } else if (TupLineItem *line = qgraphicsitem_cast<TupLineItem *>(object->item())) { QPen pen = line->pen(); pen.setColor(itemColor); line->setPen(pen); } else if (TupRectItem *rect = qgraphicsitem_cast<TupRectItem *>(object->item())) { QPen pen = rect->pen(); pen.setColor(itemColor); rect->setPen(pen); } } addGraphicObject(object); if (stepItem->has(TupTweenerStep::Opacity)) object->item()->setOpacity(stepItem->opacity()); } } } } } }