void Plansza::rysuj_mape(QPainter& painter, QRect rect) { double margines = sqrt(pow(this->czolg.rozmiar.width(), 2) + pow(this->czolg.rozmiar.height(), 2)); if(this->czolg.pozycja.x() < this->widok.x() + margines) this->widok.setX(this->czolg.pozycja.x() - margines); else if(this->czolg.pozycja.x() > this->widok.x() + rect.width() - margines) this->widok.setX(this->czolg.pozycja.x() - rect.width() + margines); if(this->czolg.pozycja.y() < this->widok.y() + margines) this->widok.setY(this->czolg.pozycja.y() - margines); else if(this->czolg.pozycja.y() > this->widok.y() + rect.height() - margines) this->widok.setY(this->czolg.pozycja.y() - rect.height() + margines); int start; painter.setPen(0x004040); if(this->widok.x() > 0) start = this->widok.x() % 50 > 0 ? 50 - this->widok.x() % 50 : 0; else start = -this->widok.x() % 50; for(int i = 0; start + i * 50 < rect.width(); i++) painter.drawLine(rect.topLeft() + QPoint(start + i * 50, 0), rect.topLeft() + QPoint(start + i * 50, rect.height() - 1)); if(this->widok.y() > 0) start = this->widok.y() % 50 > 0 ? 50 - this->widok.y() % 50 : 0; else start = -this->widok.y() % 50; for(int i = 0; start + i * 50 < rect.height(); i++) painter.drawLine(rect.topLeft() + QPoint(0, start + i * 50), rect.topLeft() + QPoint(rect.width() - 1, start + i * 50)); painter.setPen(0xFF0000); for(int i = 0; i < this->ilosc_odcinkow; i++) painter.drawLine(this->odcinki[i].translated(rect.topLeft() - this->widok)); QTransform t; t.rotateRadians(M_PI_2 - this->czolg.kierunek); QPixmap korpus = this->czolg.korpus.transformed(t); painter.drawPixmap(rect.topLeft() + this->czolg.pozycja - this->widok - QPoint(korpus.width() / 2, korpus.height() / 2), korpus); t.rotateRadians(-this->czolg.kierunek_wiezy); QPixmap wieza = this->czolg.wieza.transformed(t); QPointF przesuniecie_osi_wiezy_dla_korpusu(this->czolg.przesuniecie_osi_wiezy_dla_korpusu * -cos(this->czolg.kierunek), this->czolg.przesuniecie_osi_wiezy_dla_korpusu * sin(this->czolg.kierunek)); QPointF przesuniecie_osi_wiezy_dla_wiezy(this->czolg.przesuniecie_osi_wiezy_dla_wiezy * cos(this->czolg.kierunek + this->czolg.kierunek_wiezy), this->czolg.przesuniecie_osi_wiezy_dla_wiezy * -sin(this->czolg.kierunek + this->czolg.kierunek_wiezy)); painter.drawPixmap(rect.topLeft() - this->widok + this->czolg.pozycja + przesuniecie_osi_wiezy_dla_korpusu + przesuniecie_osi_wiezy_dla_wiezy - QPoint(wieza.width() / 2, wieza.height() / 2), wieza); if(this->strzal) { this->pociski << Pocisk(this->czolg.pozycja + przesuniecie_osi_wiezy_dla_korpusu + przesuniecie_osi_wiezy_dla_wiezy + QPointF(this->czolg.wieza.height() * cos(this->czolg.kierunek + this->czolg.kierunek_wiezy) / 2, this->czolg.wieza.height() * -sin(this->czolg.kierunek + this->czolg.kierunek_wiezy) / 2), QVector2D(cos(this->czolg.kierunek + this->czolg.kierunek_wiezy), -sin(this->czolg.kierunek + this->czolg.kierunek_wiezy)), 500); this->strzal = false; } painter.setBrush(QColor(Qt::white)); for(int i = 0; i < this->pociski.size(); i++) { this->pociski[i].pozycja += this->pociski[i].kierunek.toPointF() * this->pociski[i].predkosc * 0.02; painter.drawEllipse(rect.topLeft() - this->widok + this->pociski[i].pozycja.toPoint(), 3, 3); } if(this->o.width() > 0) { painter.setPen(0x000080); painter.setBrush(QBrush(QColor(0, 0, 255, 32))); this->o.moveTopLeft(this->o.topLeft() + rect.topLeft() - this->widok); painter.drawEllipse(this->o); } }
QPainterPath KisLiquifyPaintop::brushOutline(const KisLiquifyProperties &props, const KisPaintInformation &info) { const qreal diameter = props.size(); const qreal reverseCoeff = props.reverseDirection() ? -1.0 : 1.0; QPainterPath outline; outline.addEllipse(-0.5 * diameter, -0.5 * diameter, diameter, diameter); switch (props.mode()) { case KisLiquifyProperties::MOVE: case KisLiquifyProperties::SCALE: break; case KisLiquifyProperties::ROTATE: { QPainterPath p; p.lineTo(-3.0, 4.0); p.moveTo(0.0, 0.0); p.lineTo(-3.0, -4.0); QTransform S; if (diameter < 15.0) { const qreal scale = diameter / 15.0; S = QTransform::fromScale(scale, scale); } QTransform R; R.rotateRadians(-reverseCoeff * 0.5 * M_PI); QTransform T = QTransform::fromTranslate(0.5 * diameter, 0.0); p = (S * R * T).map(p); outline.addPath(p); break; } case KisLiquifyProperties::OFFSET: { qreal normalAngle = info.drawingAngle() + reverseCoeff * 0.5 * M_PI; QPainterPath p = KisAlgebra2D::smallArrow(); const qreal offset = qMax(0.8 * diameter, 15.0); QTransform R; R.rotateRadians(normalAngle); QTransform T = QTransform::fromTranslate(offset, 0.0); p = (T * R).map(p); outline.addPath(p); break; } case KisLiquifyProperties::UNDO: break; case KisLiquifyProperties::N_MODES: qFatal("Not supported mode"); } return outline; }
void SprayBrush::paintRectangle(KisPainter* painter, qreal x, qreal y, int width, int height, qreal angle) { QPainterPath path; QTransform transform; qreal halfWidth = width * 0.5; qreal halfHeight = height * 0.5; qreal tx, ty; transform.reset(); transform.rotateRadians(angle); // top left transform.map(- halfWidth, - halfHeight, &tx, &ty); path.moveTo(QPointF(tx + x, ty + y)); // top right transform.map(+ halfWidth, - halfHeight, &tx, &ty); path.lineTo(QPointF(tx + x, ty + y)); // bottom right transform.map(+ halfWidth, + halfHeight, &tx, &ty); path.lineTo(QPointF(tx + x, ty + y)); // botom left transform.map(- halfWidth, + halfHeight, &tx, &ty); path.lineTo(QPointF(tx + x, ty + y)); path.closeSubpath(); painter->fillPainterPath(path); }
void SprayBrush::paintRectangle(KisPainter& painter, qreal x, qreal y, int width, int height, qreal angle, int steps) { QVector <QPointF> points; QTransform transform; qreal halfWidth = width / 2.0; qreal halfHeight = height / 2.0; qreal tx, ty; transform.reset(); transform.rotateRadians( angle ); // top left transform.map( - halfWidth, - halfHeight, &tx, &ty); points.append(QPointF(tx + x,ty + y)); // top right transform.map( + halfWidth, - halfHeight, &tx, &ty); points.append(QPointF(tx + x,ty + y)); // bottom right transform.map( + halfWidth, + halfHeight, &tx, &ty); points.append(QPointF(tx + x,ty + y)); // botom left transform.map( - halfWidth, + halfHeight, &tx, &ty); points.append(QPointF(tx + x,ty + y)); painter.setOpacity( int( ( 255 * drand48() ) + 0.5 ) ); painter.setFillStyle(KisPainter::FillStyleForegroundColor); painter.paintPolygon( points ); }
void AbstractGroupPrivate::addChild(QGraphicsWidget *child) { QPointF newPos = q->mapFromItem(child->parentItem(), child->pos()); if (groupType == AbstractGroup::ConstrainedGroup) { child->setTransform(QTransform()); } else { QTransform t(child->itemTransform(q)); if (t.m11() != 0) { qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11())); QTransform at; QSizeF size(child->size()); at.translate(size.width() / 2, size.height() / 2); at.rotateRadians(angle); at.translate(-size.width() / 2, -size.height() / 2); child->setTransform(at); newPos -= QPointF(at.dx(), at.dy()); } } child->setParentItem(q); child->setProperty("group", QVariant::fromValue(q)); child->setPos(newPos); if (groupType == AbstractGroup::FreeGroup) { q->connect(child, SIGNAL(geometryChanged()), q, SLOT(onChildGeometryChanged())); } }
void KisTransformMaskTest::testSafeTransformSingleVanishingPoint() { // rotation around 0X has a single vanishing point for 0Y axis QTransform transform(1, 0, 0, -0.870208, -0.414416, -0.000955222, 132.386, 1082.91, 1.99439); QTransform R; R.rotateRadians(M_PI / 4.0); //transform *= R; QRectF testRect(1536, 1024, 512, 512); KisSafeTransform t2(transform, QRect(0, 0, 2048, 2048), testRect.toRect()); QPolygonF fwdPoly = t2.mapForward(testRect); QRectF fwdRect = t2.mapRectForward(testRect); QPolygonF bwdPoly = t2.mapBackward(fwdPoly); QRectF bwdRect = t2.mapRectBackward(fwdRect); /** * A special weird rect that crosses the vanishing point, * which is (911.001, 433.84) in this case */ QRectF fwdNastyRect(800, 100, 400, 600); //QRectF fwdNastyRect(100, 400, 1000, 800); QRectF bwdNastyRect = t2.mapRectBackward(fwdNastyRect); /* dbgKrita << ppVar(testRect); dbgKrita << ppVar(fwdPoly); dbgKrita << ppVar(fwdRect); dbgKrita << ppVar(bwdPoly); dbgKrita << ppVar(bwdRect); dbgKrita << ppVar(bwdNastyRect); */ QPolygon ref; ref.clear(); ref << QPoint(765,648); ref << QPoint(1269, 648); ref << QPoint(1601, 847); ref << QPoint(629, 847); ref << QPoint(765, 648); QCOMPARE(fwdPoly.toPolygon(), ref); QCOMPARE(fwdRect.toRect(), QRect(629,648,971,199)); ref.clear(); ref << QPoint(1536,1024); ref << QPoint(2048,1024); ref << QPoint(2048,1536); ref << QPoint(1536,1536); ref << QPoint(1536,1024); QCOMPARE(bwdPoly.toPolygon(), ref); QCOMPARE(bwdRect.toRect(), QRect(1398,1024,650,512)); QCOMPARE(bwdNastyRect.toRect(), QRect(1463,0,585,1232)); }
void HairpinSegment::layout() { QTransform t; qreal _spatium = spatium(); qreal h1 = score()->styleS(ST_hairpinHeight).val() * _spatium * .5; qreal h2 = score()->styleS(ST_hairpinContHeight).val() * _spatium * .5; rypos() = 0.0; qreal len; qreal x = pos2().x(); if (x < _spatium) // minimum size of hairpin x = _spatium; qreal y = pos2().y(); len = sqrt(x * x + y * y); t.rotateRadians(asin(y/len)); if (hairpin()->hairpinType() == 0) { // crescendo switch (spannerSegmentType()) { case SEGMENT_SINGLE: case SEGMENT_BEGIN: l1.setLine(.0, .0, len, h1); l2.setLine(.0, .0, len, - h1); break; case SEGMENT_MIDDLE: case SEGMENT_END: l1.setLine(.0, h2, len, h1); l2.setLine(.0, -h2, len, - h1); break; } } else { // decrescendo switch(spannerSegmentType()) { case SEGMENT_SINGLE: case SEGMENT_END: l1.setLine(.0, h1, len, 0.0); l2.setLine(.0, -h1, len, 0.0); break; case SEGMENT_BEGIN: case SEGMENT_MIDDLE: l1.setLine(.0, h1, len, + h2); l2.setLine(.0, -h1, len, - h2); break; } } l1 = t.map(l1); l2 = t.map(l2); QRectF r = QRectF(l1.p1(), l1.p2()).normalized() | QRectF(l2.p1(), l2.p2()).normalized(); qreal w = point(score()->styleS(ST_hairpinWidth)); setbbox(r.adjusted(-w*.5, -w*.5, w, w)); if (parent()) rypos() += score()->styleS(ST_hairpinY).val() * _spatium; adjustReadPos(); }
void SprayBrush::paintRectangle(KisPainter* painter, qreal x, qreal y, qreal width, qreal height, qreal angle) { QPainterPath path; path.addRect(QRectF(-0.5 * width, -0.5 * height, width, height)); QTransform t; t.translate(x, y); t.rotateRadians(angle); path = t.map(path); painter->fillPainterPath(path); }
void SprayBrush::paintEllipse(KisPainter* painter, qreal x, qreal y, qreal a, qreal b, qreal angle) { QPainterPath path; path.addEllipse(QPointF(), a, b); QTransform t; t.translate(x, y); t.rotateRadians(angle); path = t.map(path); painter->fillPainterPath(path); }
void TWorldDisplay::DrawShip(QPainter& painter, const NSpace::TShip& ship) { int x = ship.X * World->Scale + World->OffsetX; int y = ship.Y * World->Scale + World->OffsetY; QColor shipColor = GetQColor(World->IdToPlayer[ship.PlayerID]->Color); QImage shipImage = GraphicManager.GetShip(World->Scale, shipColor); QTransform transform; transform.rotateRadians(float(ship.Angle) / 100.0 + M_PI_2); shipImage = shipImage.transformed(transform); painter.drawImage(x - shipImage.width() / 2, y - shipImage.height() / 2, shipImage); }
void dmz::QtPluginCanvasObject::ObjectStruct::update () { if (item) { QTransform trans; trans.translate (posX, posY); trans.rotateRadians (heading); if (scaleX && scaleY) { trans.scale (scaleX, scaleY); } item->setTransform (trans); } }
Pocisk::Pocisk(const SpecyfikacjaPocisku* specyfikacja, bool pociskGracza, QPointF punktStartowy, QVector2D wektorKierunku, float dystansCalkowity): Obiekt(punktStartowy), specyfikacja(specyfikacja), status(true), pociskGracza(pociskGracza), punktStartowy(punktStartowy), wektorKierunku(wektorKierunku), dystansCalkowity(dystansCalkowity), dystansAktualny(0.0), czasMilisekundy(0){ QTransform transformacja; transformacja.rotateRadians(M_PI_2 + atan2(this->wektorKierunku.y(), this->wektorKierunku.x())); this->tekstura = new Tekstura(this->specyfikacja->tekstura.teksturaOryginalna.transformed(transformacja)); }
QPainterPath KisPaintOpSettings::brushOutline(const QPointF& pos, OutlineMode mode, qreal scale, qreal rotation) const { QPainterPath path; if (mode == CursorIsOutline){ QRectF rc(-5,-5, 10, 10); path.moveTo(rc.topLeft()); path.lineTo(rc.bottomRight()); path.moveTo(rc.topRight()); path.lineTo(rc.bottomLeft()); QTransform m; m.reset(); m.scale(scale,scale); m.rotateRadians(rotation); path = m.map(path); path.translate(pos); } return path; }
void DkRotatingRect::getTransform(QTransform& tForm, QPointF& size) const { if (rect.size() < 4) return; // default upper left corner is 0 DkVector xV = DkVector(rect[3] - rect[0]).round(); DkVector yV = DkVector(rect[1] - rect[0]).round(); QPointF ul = QPointF(qRound(rect[0].x()), qRound(rect[0].y())); size = QPointF(xV.norm(), yV.norm()); qDebug() << xV.toQPointF(); qDebug() << "size: " << size; double angle = xV.angle(); angle = DkMath::normAngleRad(angle, -CV_PI, CV_PI); if (std::abs(angle) > DBL_EPSILON) qDebug() << "angle is > eps..."; // switch width/height for /\ and \/ quadrants if (std::abs(angle) > CV_PI*0.25 && std::abs(angle) < CV_PI*0.75) { float x = (float)size.x(); size.setX(size.y()); size.setY(x); } // invariance -> user does not want to make a difference between an upside down rect if (angle > CV_PI*0.25 && angle < CV_PI*0.75) { angle -= CV_PI*0.5; ul = rect[1]; } else if (angle > -CV_PI*0.75 && angle < -CV_PI*0.25) { angle += CV_PI*0.5; ul = rect[3]; } else if (angle >= CV_PI*0.75 || angle <= -CV_PI*0.75) { angle += CV_PI; ul = rect[2]; } tForm.rotateRadians(-angle); tForm.translate(qRound(-ul.x()), qRound(-ul.y())); // round guarantees that pixels are not interpolated }
void Selection::rotate(float angle) { if(qAbs(angle) < 0.0001) return; const QPointF origin = m_shape.boundingRect().center(); QTransform t; t.translate(origin.x(), origin.y()); t.rotateRadians(angle); for(int i=0; i<m_shape.size(); ++i) { QPointF p = m_shape[i] - origin; m_shape[i] = t.map(p); } emit shapeChanged(m_shape); }
// ============================================================================ // Renders AA battery void AntiAirBattery::render ( QPainter& painter, const QRectF& rect, const RenderingOptions& options ) { Machine::render( painter, rect, options ); QTransform t = _bodyMain->transform(); // get angle double currentAngle = _sysOperator->currentAngle(); double lastSign = _lastDisplayedAngle > 0 ? 1 : -1; // limit angle to min/max if ( fabs( currentAngle ) < _sysOperator->minAngle() ) { currentAngle = _sysOperator->minAngle() * lastSign; // don't change sign while outside range } if ( fabs( currentAngle ) > _sysOperator->maxAngle() ) { currentAngle = _sysOperator->maxAngle() * lastSign; } // check if sign changed if ( ( lastSign * currentAngle) < 0 ) { double x = _bodyMain->position().x; _bodyMain->flip( QPointF( x, 1 ), QPointF( x, -1 ) ); // flip around vertical axis } _lastDisplayedAngle = currentAngle; double sign = currentAngle > 0 ? 1 : -1; // calculate screen angle double screenAngle = M_PI/2 - currentAngle; painter.save(); QImage barrel = TextureProvider::loadTexture("installations/flak1-barrel.png").image(Texture::Normal); QPointF textureAxis = QPointF( 13, 8 ); // axis in texture coords double scale = 0.05; // TODO this has to go with texture somehow t.rotateRadians( screenAngle ); t.scale( scale * sign, -scale * sign ); t.translate( -textureAxis.x(), -textureAxis.y() ); painter.setTransform( t, true ); painter.drawImage( 0, 0, barrel ); painter.restore(); }
void LinkBox::repos() { int x1m = m1->x(); int y1m = m1->y(); int x2m = m2->x(); int y2m = m2->y(); float dx = float(x2m - x1m); float dy = float(y2m - y1m); float dd = sqrt(dx * dx + dy * dy); float xx = x1m + dx / 2; float yy = y1m + dy / 2; float rad; if (dx != 0) { rad = atan(dy / dx); } else { rad = atan(dy / 0.00001); } if (dx < 0) { if (dx > 0) { rad += 3.14; } else { rad -= 3.14; } } QTransform *transform = new QTransform(); transform->translate(xx, yy); transform->rotateRadians(rad); setTransform(*transform); QPainterPath *path = new QPainterPath(); path->moveTo(10, 0); path->lineTo(dd / 2, 0); path->moveTo(-5, 0); path->lineTo(-dd / 2, 0); path->addPath(basePath); setPath(*path); }
void AbstractGroupPrivate::removeChild(QGraphicsWidget *child) { QPointF newPos = child->scenePos(); QGraphicsItem *parent = q->parentItem(); QTransform t(child->itemTransform(parent)); if (t.m11() != 0) { qreal angle = (t.m12() > 0 ? acos(t.m11()) : -acos(t.m11())); QTransform at; QSizeF size(child->size()); at.translate(size.width() / 2, size.height() / 2); at.rotateRadians(angle); at.translate(-size.width() / 2, -size.height() / 2); child->setTransform(at); } child->setParentItem(parent); child->setPos(parent->mapFromScene(newPos)); child->disconnect(q); }
/** * Draw the arrow triangle. * * @param[in] painter Painter that must be used. * @param[in] plot Plot where arrow must be plotted. */ void Arrow2D::drawArrow(QPainter &painter, Plot2D *plot){ painter.setPen(m_arrowLinePen); painter.setBrush(m_arrowBrush); const auto initialPoint = getScaledPosition(m_pivot, plot); const auto finalPoint = getScaledPosition(m_finalPoint, plot); const double angle = atan2(finalPoint.y() - initialPoint.y(), finalPoint.x() - initialPoint.x()); const double arrowLength = getScaledDimensionX(m_arrowLength, plot); const double arrowWidth = getScaledDimensionX(m_arrowWidth, plot); const QPointF p1(-m_arrowLength + finalPoint.x(), -m_arrowWidth * 0.5 + finalPoint.y()); const QPointF p2(-m_arrowLength + finalPoint.x(), m_arrowWidth * 0.5 + finalPoint.y()); QPolygonF arrow; arrow << finalPoint << p1 << p2; QTransform transform; transform.rotateRadians(angle); const QPolygonF rotatedArrow = transform.map(arrow); const auto deltaPosition = arrow.front() - rotatedArrow.front(); QTransform translateTransform; translateTransform.translate(deltaPosition.x(), deltaPosition.y()); const QPolygonF rotoTranslatedArros = translateTransform.map(rotatedArrow); painter.drawPolygon(rotoTranslatedArros); }
void LabelItem::applyDataLockedDimensions() { PlotRenderItem *render_item = dynamic_cast<PlotRenderItem *>(parentViewItem()); if (render_item) { qreal parentWidth = render_item->width(); qreal parentHeight = render_item->height(); qreal parentX = render_item->rect().x(); qreal parentY = render_item->rect().y(); qreal parentDX = render_item->plotItem()->xMax() - render_item->plotItem()->xMin(); qreal parentDY = render_item->plotItem()->yMax() - render_item->plotItem()->yMin(); QPointF drP1 = _dataRelativeRect.topLeft(); QPointF drP2 = _dataRelativeRect.bottomRight(); QPointF P1(parentX + parentWidth*(drP1.x()-render_item->plotItem()->xMin())/parentDX, parentY + parentHeight*(render_item->plotItem()->yMax() - drP1.y())/parentDY); QPointF P2(parentX + parentWidth*(drP2.x()-render_item->plotItem()->xMin())/parentDX, parentY + parentHeight*(render_item->plotItem()->yMax() - drP2.y())/parentDY); qreal theta = atan2(P2.y() - P1.y(), P2.x() - P1.x()); qreal height = rect().height(); qreal width = rect().width(); if (_fixleft) { setPos(P1); setViewRect(0, -height, width, height); } else { setPos(P2); setViewRect(-width, -height, width, height); } QTransform transform; transform.rotateRadians(theta); setTransform(transform); updateRelativeSize(); } else { qDebug() << "apply data locked dimensions called without a render item (!)"; } }
void RasterWindow::render(QPainter* painter) { auto& swarm = SwarmApplication::instance()->swarm_; auto& world = SwarmApplication::instance()->world_; double xscale = double(this->width()) / world.get_dimensions()[0]; double yscale = double(this->height()) / world.get_dimensions()[1]; painter->translate(this->width() / 2, this->height() / 2); painter->scale(xscale, -yscale); QBrush brush(Qt::black); painter->setPen(QPen(brush, 0.5)); boids::Boid::Coord x_axis; x_axis << 1.0, 0.0, 0.0; for (boids::Boid& boid : swarm) { QTransform rotate; double phi = acos(x_axis.dot(boid.get_forward())); auto axis = boid.get_forward().cross(x_axis); phi = (axis[2] < 0) ? phi : -phi; rotate.rotateRadians(phi); QTransform translate; translate.translate(boid.get_x()[0], boid.get_x()[1]); QPolygonF boid_poly = rotate.map(this->boid_poly_); boid_poly = translate.map(boid_poly); QPainterPath path; path.addPolygon(boid_poly); painter->setPen(QColor(Qt::black)); painter->drawPolygon(boid_poly); painter->fillPath(path, brush); painter->setPen(QPen(QBrush(Qt::blue), 0.5)); this->drawViewRange(painter, boid, boid.view_angle(), boid.sight_range()); painter->setPen(QPen(QBrush(Qt::red), 0.5)); this->drawViewRange(painter, boid, boid.view_angle(), boid.min_dist()); } }
void HairpinSegment::updateGrips(Grip* defaultGrip, QVector<QRectF>& grip) const { *defaultGrip = Grip::END; QPointF pp(pagePos()); qreal _spatium = spatium(); qreal x = pos2().x(); if (x < _spatium) // minimum size of hairpin x = _spatium; qreal y = pos2().y(); QPointF p(x, y); // Calc QPointF for Grip Aperture QTransform doRotation; QPointF gripLineAperturePoint; qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5; qreal len = sqrt( x * x + y * y ); doRotation.rotateRadians( asin(y/len) ); qreal lineApertureX; qreal offsetX = 10; // Horizontal offset for x Grip if(len < offsetX * 3 ) // For small hairpin, offset = 30% of len offsetX = len/3; // else offset is fixed to 10 if( hairpin()->hairpinType() == Hairpin::Type::CRESCENDO ) lineApertureX = len - offsetX; // End of CRESCENDO - Offset else lineApertureX = offsetX; // Begin of DECRESCENDO + Offset qreal lineApertureH = ( len - offsetX ) * h1/len; // Vertical position for y grip gripLineAperturePoint.setX( lineApertureX ); gripLineAperturePoint.setY( lineApertureH ); gripLineAperturePoint = doRotation.map( gripLineAperturePoint ); // End calc position grip aperture grip[int(Grip::START)].translate( pp ); grip[int(Grip::END)].translate( p + pp ); grip[int(Grip::MIDDLE)].translate( p * .5 + pp ); grip[int(Grip::APERTURE)].translate( gripLineAperturePoint + pp ); }
void Tie::computeBezier(SlurSegment* ss, QPointF p6o) { qreal _spatium = spatium(); qreal shoulderW; // height as fraction of slur-length qreal shoulderH; // // pp1 start of slur // pp2 end of slur // pp3 bezier 1 // pp4 bezier 2 // pp5 drag // pp6 shoulder // QPointF pp1 = ss->ups[GRIP_START].p + ss->ups[GRIP_START].off * _spatium; QPointF pp2 = ss->ups[GRIP_END].p + ss->ups[GRIP_END].off * _spatium; QPointF p2 = pp2 - pp1; // normalize to zero if (p2.x() == 0.0) { qDebug("zero tie"); return; } qreal sinb = atan(p2.y() / p2.x()); QTransform t; t.rotateRadians(-sinb); p2 = t.map(p2); p6o = t.map(p6o); double smallH = 0.38; qreal d = p2.x() / _spatium; shoulderH = d * 0.4 * smallH; if (shoulderH > 1.3) // maximum tie shoulder height shoulderH = 1.3; shoulderH *= _spatium; shoulderW = .6; if (!up()) shoulderH = -shoulderH; qreal c = p2.x(); qreal c1 = (c - c * shoulderW) * .5 + p6o.x(); qreal c2 = c1 + c * shoulderW + p6o.x(); QPointF p5 = QPointF(c * .5, 0.0); QPointF p3(c1, -shoulderH); QPointF p4(c2, -shoulderH); qreal w = (score()->styleS(ST_SlurMidWidth).val() - score()->styleS(ST_SlurEndWidth).val()) * _spatium; QPointF th(0.0, w); // thickness of slur QPointF p3o = p6o + t.map(ss->ups[GRIP_BEZIER1].off * _spatium); QPointF p4o = p6o + t.map(ss->ups[GRIP_BEZIER2].off * _spatium); // ss->ups[GRIP_BEZIER1].off = t.inverted().map(p3o) / _spatium; // ss->ups[GRIP_BEZIER2].off = t.inverted().map(p4o) / _spatium; //-----------------------------------calculate p6 QPointF pp3 = p3 + p3o; QPointF pp4 = p4 + p4o; QPointF ppp4 = pp4 - pp3; qreal r2 = atan(ppp4.y() / ppp4.x()); t.reset(); t.rotateRadians(-r2); QPointF p6 = QPointF(t.map(ppp4).x() * .5, 0.0); t.rotateRadians(2 * r2); p6 = t.map(p6) + pp3; // - p6o; //----------------------------------- ss->path = QPainterPath(); ss->path.moveTo(QPointF()); ss->path.cubicTo(p3 + p3o - th, p4 + p4o - th, p2); if (lineType() == 0) ss->path.cubicTo(p4 +p4o + th, p3 + p3o + th, QPointF()); th = QPointF(0.0, 3.0 * w); ss->shapePath = QPainterPath(); ss->shapePath.moveTo(QPointF()); ss->shapePath.cubicTo(p3 + p3o - th, p4 + p4o - th, p2); ss->shapePath.cubicTo(p4 +p4o + th, p3 + p3o + th, QPointF()); // translate back t.reset(); t.translate(pp1.x(), pp1.y()); t.rotateRadians(sinb); ss->path = t.map(ss->path); ss->shapePath = t.map(ss->shapePath); ss->ups[GRIP_BEZIER1].p = t.map(p3); ss->ups[GRIP_BEZIER2].p = t.map(p4); ss->ups[GRIP_END].p = t.map(p2) - ss->ups[GRIP_END].off * _spatium; ss->ups[GRIP_DRAG].p = t.map(p5); ss->ups[GRIP_SHOULDER].p = t.map(p6); }
void Slur::computeBezier(SlurSegment* ss, QPointF p6o) { qreal _spatium = spatium(); qreal shoulderW; // height as fraction of slur-length qreal shoulderH; // // p1 and p2 are the end points of the slur // QPointF pp1 = ss->ups[GRIP_START].p + ss->ups[GRIP_START].off * _spatium; QPointF pp2 = ss->ups[GRIP_END].p + ss->ups[GRIP_END].off * _spatium; QPointF p2 = pp2 - pp1; if (p2.x() == 0.0) { qDebug("zero slur"); Measure* m1 = startChord()->segment()->measure(); Measure* m2 = endChord()->segment()->measure(); Page* page = m1->system()->page(); qDebug(" at tick %d in measure %d-%d page %d", m1->tick(), m1->no(), m2->no(), page->no()); return; } qreal sinb = atan(p2.y() / p2.x()); QTransform t; t.rotateRadians(-sinb); p2 = t.map(p2); p6o = t.map(p6o); double smallH = 0.5; qreal d = p2.x() / _spatium; if (d <= 2.0) { shoulderH = d * 0.5 * smallH * _spatium; shoulderW = .6; } else { qreal dd = log10(1.0 + (d - 2.0) * .5) * 2.0; if (dd > 3.0) dd = 3.0; shoulderH = (dd + smallH) * _spatium; if (d > 18.0) shoulderW = 0.8; else if (d > 10) shoulderW = 0.7; else shoulderW = 0.6; } if (!up()) shoulderH = -shoulderH; // shoulderH -= p6o.y(); qreal c = p2.x(); qreal c1 = (c - c * shoulderW) * .5 + p6o.x(); qreal c2 = c1 + c * shoulderW + p6o.x(); QPointF p5 = QPointF(c * .5, 0.0); QPointF p3(c1, -shoulderH); QPointF p4(c2, -shoulderH); qreal w = (score()->styleS(ST_SlurMidWidth).val() - score()->styleS(ST_SlurEndWidth).val()) * _spatium; if (((c2 - c1) / _spatium) <= _spatium) w *= .5; QPointF th(0.0, w); // thickness of slur QPointF p3o = p6o + t.map(ss->ups[GRIP_BEZIER1].off * _spatium); QPointF p4o = p6o + t.map(ss->ups[GRIP_BEZIER2].off * _spatium); //?? ss->ups[GRIP_BEZIER1].off = t.inverted().map(p3o) / _spatium; //?? ss->ups[GRIP_BEZIER2].off = t.inverted().map(p4o) / _spatium; //-----------------------------------calculate p6 QPointF pp3 = p3 + p3o; QPointF pp4 = p4 + p4o; QPointF ppp4 = pp4 - pp3; qreal r2 = atan(ppp4.y() / ppp4.x()); t.reset(); t.rotateRadians(-r2); QPointF p6 = QPointF(t.map(ppp4).x() * .5, 0.0); t.rotateRadians(2 * r2); p6 = t.map(p6) + pp3; // - p6o; //----------------------------------- ss->path = QPainterPath(); ss->path.moveTo(QPointF()); ss->path.cubicTo(p3 + p3o - th, p4 + p4o - th, p2); if (lineType() == 0) ss->path.cubicTo(p4 +p4o + th, p3 + p3o + th, QPointF()); th = QPointF(0.0, 3.0 * w); ss->shapePath = QPainterPath(); ss->shapePath.moveTo(QPointF()); ss->shapePath.cubicTo(p3 + p3o - th, p4 + p4o - th, p2); ss->shapePath.cubicTo(p4 +p4o + th, p3 + p3o + th, QPointF()); // translate back t.reset(); t.translate(pp1.x(), pp1.y()); t.rotateRadians(sinb); ss->path = t.map(ss->path); ss->shapePath = t.map(ss->shapePath); ss->ups[GRIP_BEZIER1].p = t.map(p3); ss->ups[GRIP_BEZIER2].p = t.map(p4); ss->ups[GRIP_END].p = t.map(p2) - ss->ups[GRIP_END].off * _spatium; ss->ups[GRIP_DRAG].p = t.map(p5); ss->ups[GRIP_SHOULDER].p = t.map(p6); }
QPainterPath KisCurrentOutlineFetcher::fetchOutline(const KisPaintInformation &info, const KisPaintOpSettings *settings, const QPainterPath &originalOutline, qreal additionalScale, qreal additionalRotation, bool tilt, qreal tiltcenterx, qreal tiltcentery) const { if (d->isDirty) { if (d->sizeOption) { d->sizeOption->readOptionSetting(settings); d->sizeOption->resetAllSensors(); } if (d->rotationOption) { d->rotationOption->readOptionSetting(settings); d->rotationOption->resetAllSensors(); } if (d->mirrorOption) { d->mirrorOption->readOptionSetting(settings); d->mirrorOption->resetAllSensors(); } d->isDirty = false; } qreal scale = additionalScale; qreal rotation = additionalRotation; MirrorProperties mirrorProperties; bool needsUpdate = false; // Randomized rotation at full speed looks noisy, so slow it down if (d->lastUpdateTime.elapsed() > NOISY_UPDATE_SPEED) { needsUpdate = true; d->lastUpdateTime.restart(); } if (d->sizeOption && tilt == false) { if (!d->sizeOption->isRandom() || needsUpdate) { d->lastSizeApplied = d->sizeOption->apply(info); } scale *= d->lastSizeApplied; } if (d->rotationOption && tilt == false) { if (!d->rotationOption->isRandom() || needsUpdate) { d->lastRotationApplied = d->rotationOption->apply(info); } rotation += d->lastRotationApplied; } else if (d->rotationOption && tilt == true) { rotation += settings->getDouble("runtimeCanvasRotation", 0.0) * M_PI / 180.0; } qreal xFlip = 1.0; qreal yFlip = 1.0; if (d->mirrorOption) { if (!d->mirrorOption->isRandom() || needsUpdate) { d->lastMirrorApplied = d->mirrorOption->apply(info); } if (d->lastMirrorApplied.coordinateSystemFlipped) { rotation = 2 * M_PI - rotation; } if (d->lastMirrorApplied.horizontalMirror) { xFlip = -1.0; } if (d->lastMirrorApplied.verticalMirror) { yFlip = -1.0; } } QTransform rot; rot.rotateRadians(-rotation); QPointF hotSpot = originalOutline.boundingRect().center(); if (tilt==true) { hotSpot.setX(tiltcenterx);hotSpot.setY(tiltcentery); } QTransform T1 = QTransform::fromTranslate(-hotSpot.x(), -hotSpot.y()); QTransform T2 = QTransform::fromTranslate(info.pos().x(), info.pos().y()); QTransform S = QTransform::fromScale(xFlip * scale, yFlip * scale); return (T1 * rot * S * T2).map(originalOutline); }
void HairpinSegment::layout() { if (hairpin()->useTextLine()) { if (parent()) rypos() += score()->styleS(StyleIdx::hairpinY).val() * spatium(); TextLineSegment::layout(); return; } QTransform t; qreal _spatium = spatium(); qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5; qreal h2 = hairpin()->hairpinContHeight().val() * spatium() * .5; qreal len; qreal x = pos2().x(); if (x < _spatium) // minimum size of hairpin x = _spatium; qreal y = pos2().y(); len = sqrt(x * x + y * y); t.rotateRadians(asin(y/len)); drawCircledTip = hairpin()->hairpinCircledTip(); circledTipRadius = 0; if( drawCircledTip ) circledTipRadius = 0.6 * _spatium * .5; if (hairpin()->hairpinType() == Hairpin::Type::CRESCENDO) { // crescendo switch (spannerSegmentType()) { case SpannerSegmentType::SINGLE: case SpannerSegmentType::BEGIN: l1.setLine(.0 + circledTipRadius*2, .0, len, h1); l2.setLine(.0 + circledTipRadius*2, .0, len, -h1); circledTip.setX( 0 + circledTipRadius ); circledTip.setY( 0 ); break; case SpannerSegmentType::MIDDLE: case SpannerSegmentType::END: drawCircledTip = false; l1.setLine(.0, h2, len, h1); l2.setLine(.0, -h2, len, -h1); break; } } else { // decrescendo switch(spannerSegmentType()) { case SpannerSegmentType::SINGLE: case SpannerSegmentType::END: l1.setLine(.0, h1, len - circledTipRadius*2, 0.0); l2.setLine(.0, -h1, len - circledTipRadius*2, 0.0); circledTip.setX( len - circledTipRadius ); circledTip.setY( 0 ); break; case SpannerSegmentType::BEGIN: case SpannerSegmentType::MIDDLE: drawCircledTip = false; l1.setLine(.0, h1, len, + h2); l2.setLine(.0, -h1, len, - h2); break; } } // Do Coord rotation l1 = t.map(l1); l2 = t.map(l2); if( drawCircledTip ) circledTip = t.map(circledTip); QRectF r = QRectF(l1.p1(), l1.p2()).normalized() | QRectF(l2.p1(), l2.p2()).normalized(); qreal w = point(score()->styleS(StyleIdx::hairpinLineWidth)); setbbox(r.adjusted(-w*.5, -w*.5, w, w)); if (parent()) rypos() += score()->styleS(StyleIdx::hairpinY).val() * _spatium; adjustReadPos(); }
void SprayBrush::paint(KisPaintDeviceSP dab, KisPaintDeviceSP source, const KisPaintInformation& info, qreal rotation, qreal scale, const KoColor &color, const KoColor &bgColor) { // initializing painter if (!m_painter) { m_painter = new KisPainter(dab); m_painter->setFillStyle(KisPainter::FillStyleForegroundColor); m_painter->setMaskImageSize(m_shapeProperties->width, m_shapeProperties->height); m_dabPixelSize = dab->colorSpace()->pixelSize(); if (m_colorProperties->useRandomHSV) { m_transfo = dab->colorSpace()->createColorTransformation("hsv_adjustment", QHash<QString, QVariant>()); } m_brushQImage = m_shapeProperties->image; if (!m_brushQImage.isNull()) { m_brushQImage = m_brushQImage.scaled(m_shapeProperties->width, m_shapeProperties->height); } m_imageDevice = new KisPaintDevice(dab->colorSpace()); } qreal x = info.pos().x(); qreal y = info.pos().y(); KisRandomAccessorSP accessor = dab->createRandomAccessorNG(qRound(x), qRound(y)); Q_ASSERT(color.colorSpace()->pixelSize() == dab->pixelSize()); m_inkColor = color; KisCrossDeviceColorPicker colorPicker(source, m_inkColor); // apply size sensor m_radius = m_properties->radius * scale; // jitter movement if (m_properties->jitterMovement) { x = x + ((2 * m_radius * drand48()) - m_radius) * m_properties->amount; y = y + ((2 * m_radius * drand48()) - m_radius) * m_properties->amount; } // this is wrong for every shape except pixel and anti-aliased pixel if (m_properties->useDensity) { m_particlesCount = (m_properties->coverage * (M_PI * m_radius * m_radius)); } else { m_particlesCount = m_properties->particleCount; } QHash<QString, QVariant> params; qreal nx, ny; int ix, iy; qreal angle; qreal length; qreal rotationZ = 0.0; qreal particleScale = 1.0; bool shouldColor = true; if (m_colorProperties->fillBackground) { m_painter->setPaintColor(bgColor); paintCircle(m_painter, x, y, m_radius); } QTransform m; m.reset(); m.rotateRadians(-rotation + deg2rad(m_properties->brushRotation)); m.scale(m_properties->scale, m_properties->scale); for (quint32 i = 0; i < m_particlesCount; i++) { // generate random angle angle = drand48() * M_PI * 2; // generate random length if (m_properties->gaussian) { length = qBound<qreal>(0.0, m_rand->nextGaussian(0.0, 0.50) , 1.0); } else { length = drand48(); } if (m_shapeDynamicsProperties->enabled) { // rotation rotationZ = rotationAngle(); if (m_shapeDynamicsProperties->followCursor) { rotationZ = linearInterpolation(rotationZ, angle, m_shapeDynamicsProperties->followCursorWeigth); } if (m_shapeDynamicsProperties->followDrawingAngle) { rotationZ = linearInterpolation(rotationZ, info.drawingAngle(), m_shapeDynamicsProperties->followDrawingAngleWeight); } // random size - scale if (m_shapeDynamicsProperties->randomSize) { particleScale = drand48(); } } // generate polar coordinate nx = (m_radius * cos(angle) * length); ny = (m_radius * sin(angle) * length); // compute the height of the ellipse ny *= m_properties->aspect; // transform m.map(nx, ny, &nx, &ny); // color transformation if (shouldColor) { if (m_colorProperties->sampleInputColor) { colorPicker.pickOldColor(nx + x, ny + y, m_inkColor.data()); } // mix the color with background color if (m_colorProperties->mixBgColor) { KoMixColorsOp * mixOp = dab->colorSpace()->mixColorsOp(); const quint8 *colors[2]; colors[0] = m_inkColor.data(); colors[1] = bgColor.data(); qint16 colorWeights[2]; int MAX_16BIT = 255; qreal blend = info.pressure(); colorWeights[0] = static_cast<quint16>(blend * MAX_16BIT); colorWeights[1] = static_cast<quint16>((1.0 - blend) * MAX_16BIT); mixOp->mixColors(colors, colorWeights, 2, m_inkColor.data()); } if (m_colorProperties->useRandomHSV && m_transfo) { params["h"] = (m_colorProperties->hue / 180.0) * drand48(); params["s"] = (m_colorProperties->saturation / 100.0) * drand48(); params["v"] = (m_colorProperties->value / 100.0) * drand48(); m_transfo->setParameters(params); m_transfo->transform(m_inkColor.data(), m_inkColor.data() , 1); } if (m_colorProperties->useRandomOpacity) { quint8 alpha = qRound(drand48() * OPACITY_OPAQUE_U8); m_inkColor.setOpacity(alpha); m_painter->setOpacity(alpha); } if (!m_colorProperties->colorPerParticle) { shouldColor = false; } m_painter->setPaintColor(m_inkColor); } qreal jitteredWidth = qMax(qreal(1.0), m_shapeProperties->width * particleScale); qreal jitteredHeight = qMax(qreal(1.0), m_shapeProperties->height * particleScale); if (m_shapeProperties->enabled){ switch (m_shapeProperties->shape){ // ellipse case 0: { if (m_shapeProperties->width == m_shapeProperties->height){ paintCircle(m_painter, nx + x, ny + y, qRound(jitteredWidth * 0.5)); } else { paintEllipse(m_painter, nx + x, ny + y, qRound(jitteredWidth * 0.5) , qRound(jitteredHeight * 0.5), rotationZ); } break; } // rectangle case 1: { paintRectangle(m_painter, nx + x, ny + y, qRound(jitteredWidth) , qRound(jitteredHeight), rotationZ); break; } // wu-particle case 2: { paintParticle(accessor, m_inkColor, nx + x, ny + y); break; } // pixel case 3: { ix = qRound(nx + x); iy = qRound(ny + y); accessor->moveTo(ix, iy); memcpy(accessor->rawData(), m_inkColor.data(), m_dabPixelSize); break; } case 4: { if (!m_brushQImage.isNull()) { QTransform m; m.rotate(rad2deg(rotationZ)); if (m_shapeDynamicsProperties->randomSize) { m.scale(particleScale, particleScale); } m_transformed = m_brushQImage.transformed(m, Qt::SmoothTransformation); m_imageDevice->convertFromQImage(m_transformed, 0); KisRandomAccessorSP ac = m_imageDevice->createRandomAccessorNG(0, 0); QRect rc = m_transformed.rect(); if (m_colorProperties->useRandomHSV && m_transfo) { for (int y = rc.y(); y < rc.y() + rc.height(); y++) { for (int x = rc.x(); x < rc.x() + rc.width(); x++) { ac->moveTo(x, y); m_transfo->transform(ac->rawData(), ac->rawData() , 1); } } } ix = qRound(nx + x - rc.width() * 0.5); iy = qRound(ny + y - rc.height() * 0.5); m_painter->bitBlt(QPoint(ix, iy), m_imageDevice, rc); m_imageDevice->clear(); break; } } } // Auto-brush } else { QPointF hotSpot = m_brush->hotSpot(particleScale, particleScale, -rotationZ, info); QPointF pos(nx + x, ny + y); QPointF pt = pos - hotSpot; qint32 ix; qreal xFraction; qint32 iy; qreal yFraction; KisPaintOp::splitCoordinate(pt.x(), &ix, &xFraction); KisPaintOp::splitCoordinate(pt.y(), &iy, &yFraction); //KisFixedPaintDeviceSP dab; if (m_brush->brushType() == IMAGE || m_brush->brushType() == PIPE_IMAGE) { m_fixedDab = m_brush->paintDevice(m_fixedDab->colorSpace(), particleScale, -rotationZ, info, xFraction, yFraction); if (m_colorProperties->useRandomHSV && m_transfo) { quint8 * dabPointer = m_fixedDab->data(); int pixelCount = m_fixedDab->bounds().width() * m_fixedDab->bounds().height(); m_transfo->transform(dabPointer, dabPointer, pixelCount); } } else { m_brush->mask(m_fixedDab, m_inkColor, particleScale, particleScale, -rotationZ, info, xFraction, yFraction); } m_painter->bltFixed(QPoint(ix, iy), m_fixedDab, m_fixedDab->bounds()); } } // recover from jittering of color, // m_inkColor.opacity is recovered with every paint }
void HairpinSegment::layout() { Dynamic* sd = 0; Dynamic* ed = 0; qreal _spatium = spatium(); if (autoplace()) { setUserOff(QPointF()); setUserOff2(QPointF()); } if (isSingleType() || isBeginType()) { sd = lookupDynamic(hairpin()->startElement()); if (sd) { if (autoplace()) { qreal dx = sd->bbox().right() + sd->pos().x() + sd->segment()->pos().x() + sd->measure()->pos().x(); // hardcoded distance between Dynamic and Hairpin: 0.5sp qreal dist = dx - pos().x() + score()->styleP(StyleIdx::autoplaceHairpinDynamicsDistance); rUserXoffset() = dist; rUserXoffset2() = -dist; } else sd->doAutoplace(); } } if (isSingleType() || isEndType()) { ed = lookupDynamic(hairpin()->endElement()); if (ed) { if (autoplace()) { rUserXoffset2() -= ed->bbox().width(); qreal dx = ed->bbox().left() + ed->pos().x() + ed->segment()->pos().x() + ed->measure()->pos().x(); // hardcoded distance between Hairpin and Dynamic: 0.5sp ed->rUserXoffset() = pos2().x() + pos().x() - dx + score()->styleP(StyleIdx::autoplaceHairpinDynamicsDistance); } else ed->doAutoplace(); } } Hairpin::Type type = hairpin()->hairpinType(); if (type == Hairpin::Type::DECRESC_LINE || type == Hairpin::Type::CRESC_LINE) { twoLines = false; TextLineSegment::layout(); drawCircledTip = false; if (parent()) rypos() += score()->styleP(StyleIdx::hairpinY); } else { delete _text; delete _endText; _text = 0; _endText = 0; QTransform t; qreal h1 = hairpin()->hairpinHeight().val() * spatium() * .5; qreal h2 = hairpin()->hairpinContHeight().val() * spatium() * .5; qreal len; qreal x = pos2().x(); if (x < _spatium) // minimum size of hairpin x = _spatium; qreal y = pos2().y(); len = sqrt(x * x + y * y); t.rotateRadians(asin(y/len)); drawCircledTip = hairpin()->hairpinCircledTip(); circledTipRadius = drawCircledTip ? 0.6 * _spatium * .5 : 0.0; QLine l1, l2; twoLines = true; switch (type) { case Hairpin::Type::CRESC_HAIRPIN: { switch (spannerSegmentType()) { case SpannerSegmentType::SINGLE: case SpannerSegmentType::BEGIN: l1.setLine(circledTipRadius * 2.0, 0.0, len, h1); l2.setLine(circledTipRadius * 2.0, 0.0, len, -h1); circledTip.setX(circledTipRadius ); circledTip.setY(0.0); break; case SpannerSegmentType::MIDDLE: case SpannerSegmentType::END: drawCircledTip = false; l1.setLine(.0, h2, len, h1); l2.setLine(.0, -h2, len, -h1); break; } } break; case Hairpin::Type::DECRESC_HAIRPIN: { switch(spannerSegmentType()) { case SpannerSegmentType::SINGLE: case SpannerSegmentType::END: l1.setLine(0.0, h1, len - circledTipRadius * 2, 0.0); l2.setLine(0.0, -h1, len - circledTipRadius * 2, 0.0); circledTip.setX(len - circledTipRadius); circledTip.setY(0.0); break; case SpannerSegmentType::BEGIN: case SpannerSegmentType::MIDDLE: drawCircledTip = false; l1.setLine(.0, h1, len, + h2); l2.setLine(.0, -h1, len, - h2); break; } } break; default: break; } // Do Coord rotation l1 = t.map(l1); l2 = t.map(l2); if (drawCircledTip ) circledTip = t.map(circledTip); points[0] = l1.p1(); points[1] = l1.p2(); points[2] = l2.p1(); points[3] = l2.p2(); npoints = 4; QRectF r = QRectF(l1.p1(), l1.p2()).normalized() | QRectF(l2.p1(), l2.p2()).normalized(); qreal w = score()->styleP(StyleIdx::hairpinLineWidth); setbbox(r.adjusted(-w*.5, -w*.5, w, w)); if (parent()) rypos() += score()->styleP(StyleIdx::hairpinY); } if (autoplace() && parent()) { qreal minDistance = spatium() * .7; Shape s1 = shape().translated(pos()); qreal d = system()->bottomDistance(staffIdx(), s1); qreal ymax = pos().y(); if (d > -minDistance) ymax += d + minDistance; qreal sdy; if (sd) { sdy = -sd->bbox().top() * .4; sd->doAutoplace(); if (sd->pos().y() - sdy > ymax) ymax = sd->pos().y() - sdy; } qreal edy; if (ed) { edy = -ed->bbox().top() * .4; ed->doAutoplace(); if (ed->pos().y() - edy > ymax) ymax = ed->pos().y() - edy; } rUserYoffset() = ymax - pos().y(); if (sd) moveDynamic(sd, ymax - sd->ipos().y() + sdy); if (ed) moveDynamic(ed, ymax - ed->ipos().y() + edy); } else adjustReadPos(); }
QPointF Body::toLocal( const QPointF& p ) const { QTransform transform; //transform.translate(-position().x(),-position().y()); transform.rotateRadians(-angle()); return transform.map(p-position()); }
QPointF Body::fromLocal( const QPointF& p ) const { QTransform transform; transform.translate(position().x(),position().y()); transform.rotateRadians(-angle()); return transform.map(p); }