void Animator::SetDegree(const double& dg){ Degree=dg; double ScaleGrade; while(Degree>360.0) Degree-=360.0; while(Degree<0) Degree+=360.0; if(tipoAnimazione==RotateIn){ QTransform transform; ScaleGrade=-((Degree/360.0)-1.0); transform.scale(ScaleGrade,ScaleGrade); transform.shear(0, (Degree/180.0)*((double)WidImage->height())/((double)WidImage->width())); Immagine->setTransform(transform); if(baseParent==0) setGeometry(Posizione.x()+(QApplication::desktop()->width()*(1-ScaleGrade)),Posizione.y(),WidImage->width()*ScaleGrade,WidImage->height()); else setGeometry(Posizione.x()+(baseParent->width()*(1-ScaleGrade)),Posizione.y(),WidImage->width()*ScaleGrade,WidImage->height()); } if(tipoAnimazione==RotateOut){ QTransform transform; ScaleGrade=Degree/360.0; transform.scale(ScaleGrade,ScaleGrade); transform.shear(0, ((Degree/180.0)-2.0)*((double)WidImage->height())/((double)WidImage->width())); Immagine->setTransform(transform); setGeometry( Posizione.x()*ScaleGrade, Posizione.y()-(WidImage->height())*(ScaleGrade-1.0), WidImage->width()*ScaleGrade, WidImage->height()+(WidImage->height())*(ScaleGrade-1.0)); } }
QTransform QgsTransformEffect::createTransform( const QgsRenderContext &context ) const { QTransform t; if ( !source() ) return t; int width = source()->boundingRect().width(); int height = source()->boundingRect().height(); int top = source()->boundingRect().top(); int left = source()->boundingRect().left(); //remember that the below operations are effectively performed in the opposite order //so, first the reflection applies, then scale, shear, rotate and lastly translation double translateX = context.convertToPainterUnits( mTranslateX, mTranslateUnit, mTranslateMapUnitScale ); double translateY = context.convertToPainterUnits( mTranslateY, mTranslateUnit, mTranslateMapUnitScale ); t.translate( translateX + left + width / 2.0, translateY + top + height / 2.0 ); t.rotate( mRotation ); t.shear( mShearX, mShearY ); t.scale( mScaleX, mScaleY ); if ( mReflectX || mReflectY ) { t.scale( mReflectX ? -1 : 1, mReflectY ? -1 : 1 ); } t.translate( -left - width / 2.0, -top - height / 2.0 ); return t; }
QTransform TransformDialog::getTransformMatrix() { QTransform ret = QTransform(); for (int a = 0; a < transformSelector->count(); a++) { QListWidgetItem *it = transformSelector->item(a); TransformItem *ite = (TransformItem*)it; switch (it->type()) { case 1001: ret.scale(ite->firstValue / 100.0, ite->secondValue / 100.0); break; case 1002: ret.translate(ite->firstValue / m_unitRatio, ite->secondValue / m_unitRatio); break; case 1003: ret.rotate(ite->firstValue); break; case 1004: ret.shear(-sin(ite->firstValue / 180.0 * M_PI), -sin(ite->secondValue / 180.0 * M_PI)); break; default: break; } } return ret; }
void BoxItem::updateTransform() { QTransform transform; transform.shear(m_shearHorizontal, m_shearVertical); transform.rotate(m_angle); setTransform(transform); }
QBrush creatQTextureBrush() { QBrush qbrush(QImage("Penguins.jpg")); QTransform transform; transform.translate(10, 10); transform.scale(0.30, 0.40); transform.shear(0.50, 0.50); transform.rotate(45); qbrush.setTransform(transform); return qbrush; }
QTransform GraphicsWidget::getCurrentTransform(void) const { QTransform t; if (grid != nullptr) { //each hexagon is composed of 6 equilateral triangles. we don't explicitly draw the triangles //but it helps to know the side length of those triangles //this comes from the pythagorean theorem. if the height of an equilateral triangle is h, then //the side length is 2*h / sqrt(h). in this case h is 0.5, so the side length is 1 / sqrt(3) float triangleSide = 1 / sqrt(3); float lineHeight = triangleSide * 1.5; float lineWidth = 1; //the columnhs shift left/right every other row, //so the "actual" width is one half wider than the stated width float gridWidth = (grid->getWidth() + 0.5) * lineWidth; //the cells are regular hexagons, so the tips point above/below the actual row //0.5 of a unit above, and 0.5 of a unit below float gridHeight = (grid->getHeight() + 1) * lineHeight; float screenFill = 0.98; float screenWidth = width() * screenFill; float screenHeight = height() * screenFill; //find the ratio from screen width to grid width, and screen height to grid height float widthRatio = screenWidth / gridWidth; float heightRatio = screenHeight / gridHeight; float scale = qMin(widthRatio, heightRatio); //vertically and horizontally center the resulting data float resultHeight = gridHeight * scale; float resultWidth = gridWidth * scale; float translateX = (width() - resultWidth) / 2 + lineWidth*scale * 2; float translateY = (height() - resultHeight) / 2 + lineHeight*scale; //apply the transformations to the matrix t.shear(-triangleSide, 0); t.translate(translateX, translateY); t.scale(scale, scale * lineHeight); } return t; }
QBrush newLineGradientBrush() { QLinearGradient gradientBrush(QPointF(0, 0), QPointF(200, 400)); gradientBrush.setColorAt(0, QColor(Qt::red)); gradientBrush.setColorAt(0.2, QColor(Qt::white)); gradientBrush.setColorAt(0.7, QColor(Qt::black)); gradientBrush.setColorAt(1, QColor(Qt::blue)); QBrush brush(gradientBrush); QTransform transform; transform.translate(100, 0); transform.shear(0.15, 0.3); transform.scale(0.4, 0.2); transform.rotate(0.5); brush.setTransform(transform); return brush; }
QBrush newPathGradientBrush() { QPainterPath path; path.addEllipse(QPointF(10, 10), 100, 100); path.addRect(100, 100, 200, 250); QPathGradient pathGradient(path); pathGradient.setColorAt(0, QColor(255, 0, 0)); pathGradient.setColorAt(0.5, QColor(0, 255, 0)); pathGradient.setColorAt(0.8,QColor(Qt::black)); pathGradient.setColorAt(1, QColor(0, 0, 255)); QBrush brush(pathGradient); QTransform transform; transform.translate(100, 0); transform.shear(0.15, 0.10); transform.scale(10, 5.2); transform.rotate(0.5); brush.setTransform(transform); return brush; }
void ShapeShearStrategy::handleMouseMove(const QPointF &point, Qt::KeyboardModifiers modifiers) { Q_UNUSED(modifiers); QPointF shearVector = point - m_start; QTransform m; m.rotate(-m_initialSelectionAngle); shearVector = m.map(shearVector); qreal shearX=0, shearY=0; if(m_top || m_left) shearVector = - shearVector; if(m_top || m_bottom) shearX = shearVector.x() / m_initialSize.height(); if(m_left || m_right) shearY = shearVector.y() / m_initialSize.width(); // if selection is mirrored invert the shear values if( m_isMirrored ) { shearX *= -1.0; shearY *= -1.0; } QTransform matrix; matrix.translate(m_solidPoint.x(), m_solidPoint.y()); matrix.rotate(m_initialSelectionAngle); matrix.shear(shearX, shearY); matrix.rotate(-m_initialSelectionAngle); matrix.translate(-m_solidPoint.x(), -m_solidPoint.y()); QTransform applyMatrix = matrix * m_shearMatrix.inverted(); foreach( KoShape *shape, m_selectedShapes ) { shape->update(); shape->applyAbsoluteTransformation( applyMatrix ); shape->update(); }
void Tremolo::layout() { qreal _spatium = spatium() * mag(); qreal w2 = _spatium * score()->styleS(StyleIdx::tremoloWidth).val() * .5; qreal lw = _spatium * score()->styleS(StyleIdx::tremoloStrokeWidth).val(); qreal td = _spatium * score()->styleS(StyleIdx::tremoloDistance).val(); path = QPainterPath(); qreal ty = 0.0; for (int i = 0; i < _lines; i++) { path.addRect(-w2, ty, 2.0 * w2, lw); ty += td; } // QRectF rect = path.boundingRect(); // if ((parent() == 0) && !twoNotes()) // rect.setHeight(rect.height() + _spatium); _chord1 = static_cast<Chord*>(parent()); if (_chord1 == 0) { // just for the palette QTransform shearTransform; shearTransform.shear(0.0, -(lw / 2.0) / w2); path = shearTransform.map(path); setbbox(path.boundingRect()); addbbox(QRectF(bbox().x(), bbox().bottom(), bbox().width(), _spatium)); return; } Note* anchor1 = _chord1->upNote(); Stem* stem = _chord1->stem(); qreal x, y, h; if (stem) { x = stem->pos().x(); y = stem->pos().y(); h = stem->stemLen(); } else { // center tremolo above note x = anchor1->x() + anchor1->headWidth() * .5; y = anchor1->y(); h = 2.0 * _spatium + bbox().height(); if (anchor1->line() > 4) h *= -1; } if (!twoNotes()) { // // single note tremolos // bool up = _chord1->up(); int line = up ? _chord1->upLine() : _chord1->downLine(); static const qreal t[3][2][4][2] = { // normal stem { // DOWN { // even line odd line { 6, 5 }, // line 1 { 6 - 2 * .8, 5 - 2 * .8 }, // line 2 { 6 - 4 * .8, 3 }, // line 3 { 2 , 3 } // line 4 }, // UP { // even line odd line { -6, -5 }, // line 1 { -6, -5 }, // line 2 { -6, -3 - 4 * .8 }, // line 3 { -2 - 6 * .8, -3 - 6 * .8 } // line 4 } }, // stem with hook { // DOWN { // even line odd line { 3, 3 }, // line 1 { 2, 2 }, // line 2 { 2, 2 }, // line 3 { 2, 2 } // line 4 }, // UP { // even line odd line { -3, -3 }, // line 1 { -2 - 2 * .8, -2 - 2 * .8 }, // line 2 { -2 - 4 * .8, -2 - 4 * .8 }, // line 3 { -2 - 6 * .8, -2 - 6 * .8 } // line 4 } }, // stem with beam { // DOWN { // even line odd line { 3, 3 }, // line 1 { 2, 2 }, // line 2 { 2, 2 }, // line 3 { 2, 2 } // line 4 }, // UP { // even line odd line { -3, -3 }, // line 1 { -2 - 2 * .8, -2 - 2 * .8 }, // line 2 { -2 - 4 * .8, -2 - 4 * .8 }, // line 3 { -2 - 6 * .8, -2 - 6 * .8 } // line 4 } }, }; int idx = _chord1->hook() ? 1 : (_chord1->beam() ? 2 : 0); y = (line + t[idx][up][_lines-1][line & 1]) * spatium() * .5; QTransform shearTransform; shearTransform.shear(0.0, -(lw / 2.0) / w2); path = shearTransform.map(path); setbbox(path.boundingRect()); setPos(x, y); adjustReadPos(); return; } y += (h - bbox().height()) * .5; // // two chord tremolo // Segment* s = _chord1->segment()->next(); while (s) { if (s->element(track()) && (s->element(track())->type() == Element::Type::CHORD)) break; s = s->next(); } if (s == 0) { qDebug("no second note of tremolo found"); return; } _chord2 = static_cast<Chord*>(s->element(track())); _chord2->setTremolo(this); Stem* stem1 = _chord1->stem(); Stem* stem2 = _chord2->stem(); // compute the y coordinates of the tips of the stems qreal y1, y2; qreal firstChordStaffY; if (stem2 && stem1) { // stemPageYOffset variable is used for the case when the first // chord is cross-staff firstChordStaffY = stem1->pagePos().y() - stem1->y(); // y coordinate of the staff of the first chord y1 = stem1->y() + stem1->p2().y(); y2 = stem2->pagePos().y() - firstChordStaffY + stem2->p2().y(); // ->p2().y() is better than ->stemLen() } else { firstChordStaffY = _chord1->pagePos().y() - _chord1->y(); // y coordinate of the staff of the first chord y1 = _chord1->stemPosBeam().y() - firstChordStaffY + _chord1->defaultStemLength(); y2 = _chord2->stemPosBeam().y() - firstChordStaffY + _chord2->defaultStemLength(); } // improve the case when one stem is up and another is down if (_chord1->beams() == 0 && _chord2->beams() == 0 && _chord1->up() != _chord2->up()) { qreal meanNote1Y = .5 * (_chord1->upNote()->pagePos().y() - firstChordStaffY + _chord1->downNote()->pagePos().y() - firstChordStaffY); qreal meanNote2Y = .5 * (_chord2->upNote()->pagePos().y() - firstChordStaffY + _chord2->downNote()->pagePos().y() - firstChordStaffY); y1 = .5 * (y1 + meanNote1Y); y2 = .5 * (y2 + meanNote2Y); } y = (y1 + y2) * .5; if (!_chord1->up()) { y -= path.boundingRect().height() * .5; } if (!_chord2->up()) { y -= path.boundingRect().height() * .5; } // compute the x coordinates of the inner edge of the stems qreal x2 = _chord2->stemPosBeam().x(); if (_chord2->up() && stem2) x2 -= stem2->lineWidth(); qreal x1 = _chord1->stemPosBeam().x(); if (!_chord1->up() && stem1) x1 += stem1->lineWidth(); x = (x1 + x2) * .5 - _chord1->pagePos().x(); QTransform xScaleTransform; // TODO const qreal H_MULTIPLIER = score()->styleS(StyleIdx::tremoloBeamLengthMultiplier).val(); const qreal H_MULTIPLIER = 0.62; // TODO const qreal MAX_H_LENGTH = _spatium * score()->styleS(StyleIdx::tremoloBeamLengthMultiplier).val(); const qreal MAX_H_LENGTH = _spatium * 12.0; qreal xScaleFactor = qMin(H_MULTIPLIER * (x2 - x1), MAX_H_LENGTH); xScaleFactor /= (2.0 * w2); xScaleTransform.scale(xScaleFactor, 1.0); path = xScaleTransform.map(path); qreal beamYOffset = 0.0; if (_chord1->beams() == _chord2->beams() && _chord1->beam()) { int beams = _chord1->beams(); qreal beamHalfLineWidth = point(score()->styleS(StyleIdx::beamWidth)) * .5 * mag(); beamYOffset = beams * _chord1->beam()->beamDist() - beamHalfLineWidth; if (_chord1->up() != _chord2->up()) { // cross-staff beamYOffset += beamYOffset + beamHalfLineWidth; } else if (!_chord1->up() && !_chord2->up()) { beamYOffset = -beamYOffset; } } QTransform shearTransform; if (_chord1->beams() == 0 && _chord2->beams() == 0) { if (_chord1->up() && !_chord2->up()) shearTransform.shear(0.0, (y2 - y1 - path.boundingRect().height()) / (x2 - x1)); else if (!_chord1->up() && _chord2->up()) shearTransform.shear(0.0, (y2 - y1 + path.boundingRect().height()) / (x2 - x1)); else shearTransform.shear(0.0, (y2 - y1) / (x2 - x1)); } else { shearTransform.shear(0.0, (y2 - y1) / (x2 - x1)); } path = shearTransform.map(path); setbbox(path.boundingRect()); setPos(x, y + beamYOffset); adjustReadPos(); }
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 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()); } } } } } }