void VGradientEx::transform( const QTransform &m )
{
	double mx, my;
	mx = m.m11() * m_origin.x() + m.m21() * m_origin.y() + m.dx();
	my = m.m22() * m_origin.y() + m.m12() * m_origin.x() + m.dy();
	m_origin = FPoint(mx, my);
	mx = m.m11() * m_focalPoint.x() + m.m21() * m_focalPoint.y() + m.dx();
	my = m.m22() * m_focalPoint.y() + m.m12() * m_focalPoint.x() + m.dy();
	m_focalPoint = FPoint(mx, my);
	mx = m.m11() * m_vector.x() + m.m21() * m_vector.y() + m.dx();
	my = m.m22() * m_vector.y() + m.m12() * m_vector.x() + m.dy();
	m_vector = FPoint(mx, my);
}
static QLineF preciselyMap( const QTransform& transform, const QLineF& line )
{
    qreal fx1 = line.x1();
    qreal fy1 = line.y1();
    qreal fx2 = line.x2();
    qreal fy2 = line.y2();

    qreal x1 = transform.m11() * fx1 + transform.m21() * fy1 + transform.dx();
    qreal y1 = transform.m12() * fx1 + transform.m22() * fy1 + transform.dy();
    qreal x2 = transform.m11() * fx2 + transform.m21() * fy2 + transform.dx();
    qreal y2 = transform.m12() * fx2 + transform.m22() * fy2 + transform.dy();

    return QLineF( x1, y1, x2, y2 );
}
void QFontEngineQPF::draw(QPaintEngine *p, qreal _x, qreal _y, const QTextItemInt &si)
{
    QPaintEngineState *pState = p->state;
    QRasterPaintEngine *paintEngine = static_cast<QRasterPaintEngine*>(p);

    QTransform matrix = pState->transform();
    matrix.translate(_x, _y);
    QFixed x = QFixed::fromReal(matrix.dx());
    QFixed y = QFixed::fromReal(matrix.dy());

    QVarLengthArray<QFixedPoint> positions;
    QVarLengthArray<glyph_t> glyphs;
    getGlyphPositions(si.glyphs, si.num_glyphs, matrix, si.flags, glyphs, positions);
    if (glyphs.size() == 0)
        return;

    for(int i = 0; i < glyphs.size(); i++) {
        const Glyph *glyph = findGlyph(glyphs[i]);
        if (!glyph)
            continue;

        const bool mono = false; // ###

        paintEngine->alphaPenBlt(reinterpret_cast<const uchar *>(glyph) + sizeof(Glyph), glyph->bytesPerLine, mono,
                                     qRound(positions[i].x) + glyph->x,
                                     qRound(positions[i].y) + glyph->y,
                                     glyph->width, glyph->height);
    }
}
void MGLES2Renderer::draw(const QRect &rectangle)
{
    GLfloat *vertices = d_ptr->m_vertices.data();
    vertices[0] = rectangle.left();  vertices[1] = rectangle.top();
    vertices[2] = rectangle.left();  vertices[3] = rectangle.top() + rectangle.height();
    vertices[4] = rectangle.left() + rectangle.width(); vertices[5] = rectangle.top() + rectangle.height();
    vertices[6] = rectangle.left() + rectangle.width(); vertices[7] = rectangle.top();

    QTransform transform;
    GLfloat o = 1.0;
    if (d_ptr->m_activePainter) {
        transform = d_ptr->m_activePainter->combinedTransform();
        o = d_ptr->m_activePainter->opacity();
    }
    d_ptr->m_matWorld[0][0] = transform.m11();
    d_ptr->m_matWorld[0][1] = transform.m12();
    d_ptr->m_matWorld[0][3] = transform.m13();
    d_ptr->m_matWorld[1][0] = transform.m21();
    d_ptr->m_matWorld[1][1] = transform.m22();
    d_ptr->m_matWorld[1][3] = transform.m23();
    d_ptr->m_matWorld[3][0] = transform.dx();
    d_ptr->m_matWorld[3][1] = transform.dy();
    d_ptr->m_matWorld[3][3] = transform.m33();
    d_ptr->m_activeProgram->setUniformValue("matWorld", d_ptr->m_matWorld);
    d_ptr->m_activeProgram->setUniformValue("opacity", o);

    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
Exemple #5
0
void ellipse::rotate(qreal angle)
{

    this->transformationRotate = this->transformationRotate.rotate(angle);

    QPointF translatePoint(this->transformationTranslate.dx(),this->transformationTranslate.dy());

    QTransform tempRotate(1, 0, 0, 1, 0, 0);
    tempRotate.rotate(angle);
    QPointF rotatedPoint = tempRotate.map(translatePoint);
    this->transformationTranslate = QTransform(1, 0, 0, 1, rotatedPoint.x(), rotatedPoint.y());

    this->transformationMatrix = this->transformationScale* this->transformationRotate * this->transformationTranslate;

	if(!this->transformationMatrix.isInvertible())
	{
        //qDebug() << "Notinvertible";
	}
    QTransform inverted = this->transformationMatrix.inverted();
    data.scaleX = (cl_float) inverted.m11();
    data.scaleY = (cl_float) inverted.m22();
    data.angleX = (cl_float) inverted.m21();
    data.angleY = (cl_float) inverted.m12();
    data.dx = (cl_float) inverted.dx();
    data.dy = (cl_float) inverted.dy();
}
Exemple #6
0
void QgsComposition::alignSelectedItemsHCenter()
{
  QList<QgsComposerItem*> selectedItems = selectedComposerItems();
  if ( selectedItems.size() < 2 )
  {
    return;
  }

  QRectF selectedItemBBox;
  if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
  {
    return;
  }

  double averageXCoord = ( selectedItemBBox.left() + selectedItemBBox.right() ) / 2.0;

  //place items
  QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items hcenter" ) );
  QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
  for ( ; align_it != selectedItems.end(); ++align_it )
  {
    QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand );
    subcommand->savePreviousState();
    QTransform itemTransform = ( *align_it )->transform();
    itemTransform.translate( averageXCoord - itemTransform.dx() - ( *align_it )->rect().width() / 2.0, 0 );
    ( *align_it )->setTransform( itemTransform );
    subcommand->saveAfterState();
  }
  mUndoStack.push( parentCommand );
}
void KisTransformProcessingVisitor::transformClones(KisLayer *layer, KisUndoAdapter *undoAdapter)
{
    QList<KisCloneLayerWSP> clones = layer->registeredClones();

    foreach(KisCloneLayerSP clone, clones) {
        // we have just casted an object from a weak pointer,
        // so check validity first
        if(!clone) continue;

        KisTransformWorker tw(clone->projection(), m_sx, m_sy, m_shearx, m_sheary,
                              m_shearOrigin.x(), m_shearOrigin.y(),
                              m_angle, m_tx, m_ty, 0,
                              m_filter);

        QTransform trans  = tw.transform();
        QTransform offsetTrans = QTransform::fromTranslate(clone->x(), clone->y());

        QTransform newTrans = trans.inverted() * offsetTrans * trans;

        QPoint oldPos(clone->x(), clone->y());
        QPoint newPos(newTrans.dx(), newTrans.dy());
        KUndo2Command *command = new KisNodeMoveCommand2(clone, oldPos, newPos, undoAdapter);
        undoAdapter->addCommand(command);
    }
}
Exemple #8
0
void ZebraPaintEngine::drawText ( const QPointF &p, const QString & text, const QFont &font )
{
  QTransform transform = painter()->worldTransform();

  int xInDots = (int)(transform.dx());
  int yInDots = (int)(transform.dy());

  int carHeight = (font.pointSize() * resolution()) / 72;
  const int minSize = 10;
  if(carHeight < minSize) {
    carHeight = minSize;
  }
  int carWidth = qRound((carHeight * 15.0) / 28.0); // fixed width/height ratio for the scalable A0 font

  QString rotation = transformRotationCmd();
  if(rotation == rotation90Cmd()) {
    xInDots -= carHeight;
  }
  else if(rotation == rotation180Cmd()) {
    yInDots -= carHeight;
    xInDots -= (carWidth * text.length());
  }
  else if(rotation == rotation270Cmd()) {
    yInDots -= (carWidth * text.length());
  }

  QString output = QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "FW%3").arg(xInDots).arg(yInDots).arg(rotation);
  output += QString(m_CmdPrefix + "A0,%1,0" + m_CmdPrefix + "FD" + text + m_CmdPrefix + "FS\n").arg(carHeight);

  QTextCodec *codec = QTextCodec::codecForName("IBM 850");
  m_printBuffer.append(codec->fromUnicode(output));
}
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 QgsComposerRuler::setSceneTransform( const QTransform& transform )
{
  QString debug = QString::number( transform.dx() ) + "," + QString::number( transform.dy() ) + ","
                  + QString::number( transform.m11() ) + "," + QString::number( transform.m22() );
  mTransform = transform;
  update();
}
void MGLES2Renderer::draw(const QList<QRect>& targets, const QList<QRect>& sources)
{
    GLuint num = d_ptr->setupVertices(d_ptr->m_boundTexSize, sources, targets);


    QTransform transform;
    GLfloat o = 1.0;
    if (d_ptr->m_activePainter) {
        transform = d_ptr->m_activePainter->combinedTransform();
        o = d_ptr->m_activePainter->opacity();
    }

    d_ptr->m_matWorld[0][0] = transform.m11();
    d_ptr->m_matWorld[0][1] = transform.m12();
    d_ptr->m_matWorld[0][3] = transform.m13();
    d_ptr->m_matWorld[1][0] = transform.m21();
    d_ptr->m_matWorld[1][1] = transform.m22();
    d_ptr->m_matWorld[1][3] = transform.m23();
    d_ptr->m_matWorld[3][0] = transform.dx();
    d_ptr->m_matWorld[3][1] = transform.dy();
    d_ptr->m_matWorld[3][3] = transform.m33();
    d_ptr->m_activeProgram->setUniformValue("matWorld", d_ptr->m_matWorld);
    d_ptr->m_activeProgram->setUniformValue("opacity", o);

    glDrawElements(GL_TRIANGLES, num, GL_UNSIGNED_SHORT, d_ptr->m_indices.data());
}
Exemple #12
0
void QgsComposition::alignSelectedItemsRight()
{
  QList<QgsComposerItem*> selectedItems = selectedComposerItems();
  if ( selectedItems.size() < 2 )
  {
    return;
  }

  QRectF selectedItemBBox;
  if ( boundingRectOfSelectedItems( selectedItemBBox ) != 0 )
  {
    return;
  }

  double maxXCoordinate = selectedItemBBox.right();

  //align items right to maximum x coordinate
  QUndoCommand* parentCommand = new QUndoCommand( tr( "Aligned items right" ) );
  QList<QgsComposerItem*>::iterator align_it = selectedItems.begin();
  for ( ; align_it != selectedItems.end(); ++align_it )
  {
    QgsComposerItemCommand* subcommand = new QgsComposerItemCommand( *align_it, "", parentCommand );
    subcommand->savePreviousState();
    QTransform itemTransform = ( *align_it )->transform();
    itemTransform.translate( maxXCoordinate - itemTransform.dx() - ( *align_it )->rect().width(), 0 );
    ( *align_it )->setTransform( itemTransform );
    subcommand->saveAfterState();
  }
  mUndoStack.push( parentCommand );
}
 void updateVertices(const QTransform &t) 
 {
     worldMatrix[0][0] = t.m11();
     worldMatrix[0][1] = t.m12();
     worldMatrix[0][3] = t.m13();
     worldMatrix[1][0] = t.m21();
     worldMatrix[1][1] = t.m22();
     worldMatrix[1][3] = t.m23();
     worldMatrix[3][0] = t.dx();
     worldMatrix[3][1] = t.dy();
     worldMatrix[3][3] = t.m33();
 }
void UBGraphicsDelegateFrame::initializeTransform()
{
    QTransform itemTransform = delegated()->sceneTransform();
    QRectF itemRect = delegated()->boundingRect();
    QPointF topLeft = itemTransform.map(itemRect.topLeft());
    QPointF topRight = itemTransform.map(itemRect.topRight());
    QPointF  bottomLeft = itemTransform.map(itemRect.bottomLeft());

    qreal horizontalFlip = (topLeft.x() > topRight.x()) ? -1 : 1;
    mMirrorX = horizontalFlip < 0 ;
    if(horizontalFlip < 0) {
        // why this is because of the way of calculating the translations that checks which side is the most is the
        // nearest instead of checking which one is the left side.
        QPointF tmp = topLeft;
        topLeft = topRight;
        topRight = tmp;

        // because of the calculation of the height is done by lenght and not deltaY
        bottomLeft = itemTransform.map(itemRect.bottomRight());
    }

    qreal verticalFlip = (bottomLeft.y() < topLeft.y()) ? -1 : 1;
    // not sure that is usefull
    mMirrorY = verticalFlip < 0;
    if(verticalFlip < 0 && !mMirrorX) {
        topLeft = itemTransform.map(itemRect.bottomLeft());
        topRight = itemTransform.map(itemRect.bottomRight());
        bottomLeft = itemTransform.map(itemRect.topLeft());
    }

    QLineF topLine(topLeft, topRight);
    QLineF leftLine(topLeft, bottomLeft);
    qreal width = topLine.length();
    qreal height = leftLine.length();

    mAngle = topLine.angle();

    // the fact the the length is used we loose the horizontalFlip information
    // a better way to do this is using DeltaX that preserve the direction information.
    mTotalScaleX = (width / itemRect.width()) * horizontalFlip;
    mTotalScaleY = height / itemRect.height() * verticalFlip;

    QTransform tr;
    QPointF center = delegated()->boundingRect().center();
    tr.translate(center.x() * mTotalScaleX, center.y() * mTotalScaleY);
    tr.rotate(-mAngle);
    tr.translate(-center.x() * mTotalScaleX, -center.y() * mTotalScaleY);
    tr.scale(mTotalScaleX, mTotalScaleY);

    mTotalTranslateX = delegated()->transform().dx() - tr.dx();
    mTotalTranslateY = delegated()->transform().dy() - tr.dy();
}
static QTransform preciselyInverted( const QTransform& transform )
{
    QTransform inverted;

    switch ( transform.type() ) {
        case QTransform::TxNone:
            break;

        case QTransform::TxTranslate:
            inverted.translate( -transform.dx(), -transform.dy() );
            break;

        case QTransform::TxScale:
            inverted.scale( 1.0 / transform.m11(), 1.0 / transform.m22() );
            inverted.translate( -transform.dx(), -transform.dy() );
            break;

        default:
            inverted = transform.inverted();
    }

    return inverted;
}
void QJsonPaintEngine::updateMatrix(const QTransform &matrix)
{
	Q_D(QJsonPaintEngine);
#ifdef QT_PICTURE_DEBUG
	qDebug() << " -> updateMatrix():" << matrix;
#endif
	d->s << QString("\t{\"m\": {\"m11\": %1, \"m12\": %2, \"m21\": %3, \"m22\": %4, \"dx\": %5, \"dy\": %6}},\r\n")
			.arg(matrix.m11())
			.arg(matrix.m12())
			.arg(matrix.m21())
			.arg(matrix.m22())
			.arg(matrix.dx())
			.arg(matrix.dy());
}
Exemple #17
0
void ZebraPaintEngine::drawBarcode ( const QPointF & p, const QString &format, int height, int width, int narrowBar, QString barcodeData )
{
  QString barcodeFont;
  if(format == "3of9" || format == "3of9+")
    barcodeFont = "B3";
  else if(format == "128")
    barcodeFont = "BC,,N,N,N,A";
  else if(format == "ean13" || format == "upc-a")
    barcodeFont = "B8";
  else if(format == "ean8")
    barcodeFont = "B8";
  else if(format == "upc-e")
    barcodeFont = "B9";
  else if(format == "i2of5")
    barcodeFont = "BI";
  else if(format.contains("datamatrix"))
  {
    DmtxInfos dmtxInfos = extractInfosDtmx(format);
    int eltSize = qRound (qBound((qreal)2.0, (qreal)height / (qreal)dmtxInfos.ySize, (qreal)20.0));
    barcodeFont = QString("BX,%1,200,%2,%3").arg(eltSize).arg(dmtxInfos.xSize).arg(dmtxInfos.ySize);
  }
  else {
    drawText(p, "ERR: " + format);
  }

  QTransform transform = painter()->worldTransform();

  int yInDots = (int)(transform.dy());
  int xInDots = (int)(transform.dx());

  QString rotation = transformRotationCmd();
  if(rotation == rotation90Cmd()) {
    xInDots -= height;
  }
  else if(rotation == rotation180Cmd()) {
    yInDots -= height;
    // we can't calculate the printed barcode width, so we can't print 180� and 270� correctly! Well done Zebra!
    // we use the TextItem's width instead as a fallback
    xInDots -= width;
  }
  else if(rotation == rotation270Cmd()) {
    yInDots -= width;
  }

  qreal narrowWidthRatio = 2.5;

  m_printBuffer += QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "FW%3").arg(xInDots).arg(yInDots).arg(transformRotationCmd());
  m_printBuffer += QString(m_CmdPrefix + "BY%1,%2,%3" + m_CmdPrefix + barcodeFont + m_CmdPrefix + "FD" + barcodeData + m_CmdPrefix + "FS\n").arg(narrowBar).arg(narrowWidthRatio).arg(height);
}
Exemple #18
0
void ReportView::scaleView(qreal factor)
{
	qreal f = matrix().scale(factor, factor).mapRect(QRectF(0, 0, 1, 1)).width();
	if (f < 0.07 || f > 100)
		return;

	Report *report = (Report*)scene();
	int dpiX = report ? report->dpiX() : 96;
	int dpiY = report ? report->dpiY() : 96;

	QTransform oldTransform = transform();
	resetTransform();
	translate(oldTransform.dx(), oldTransform.dy());
	scale(factor * physicalDpiX() / dpiX, factor * physicalDpiY() / dpiY);;
}
Exemple #19
0
void XPDFRenderer::render(QPainter *p, int pageNumber, const QRectF &bounds)
{
    if (isValid())
    {
        qreal xscale = p->worldTransform().m11();
        qreal yscale = p->worldTransform().m22();

        QImage *pdfImage = createPDFImage(pageNumber, xscale, yscale, bounds);
        QTransform savedTransform = p->worldTransform();
        p->resetTransform();
        p->drawImage(QPointF(savedTransform.dx() + mSliceX, savedTransform.dy() + mSliceY), *pdfImage);
        p->setWorldTransform(savedTransform);
        delete pdfImage;
	}
}
void QgsComposerMapWidget::on_mHeightLineEdit_editingFinished()
{
  if ( mComposerMap )
  {
    bool conversionSuccess = true;
    double newHeight = mHeightLineEdit->text().toDouble( &conversionSuccess );
    if ( !conversionSuccess )
    {
      return;
    }
    QRectF composerMapRect = mComposerMap->rect();
    QTransform composerMapTransform = mComposerMap->transform();

    QRectF newRect( composerMapTransform.dx(), composerMapTransform.dy(), composerMapRect.width(), newHeight );
    mComposerMap->beginCommand( tr( "Change item height" ) );
    mComposerMap->setSceneRect( newRect );
    mComposerMap->endCommand();
  }
}
Exemple #21
0
/*!
    The main paint function for the Viewport class.  It takes a  QPainter \a p, which performs the
    painting of objects in the 3d environment.

    The paint function is responsible for setting up the viewing transform, as well as other display
    options, before calling the draw function to perform the actual drawing of the scene.

    Note, currently \a style and \a widget are unused, but are reserved for later development.
*/
void Viewport::paint(QPainter *p, const QStyleOptionGraphicsItem * style, QWidget *widget)
{
    Q_UNUSED(style);

    if (!d->viewWidget)
        d->viewWidget = widget;
    d->needsPick = true;

    QGLPainter painter;
    if (!painter.begin(p)) {
        qWarning("GL graphics system is not active; cannot use 3D items");
        return;
    }

    // Initialize the objects in the scene if this is the first paint.
    if (!d->itemsInitialized) {
        initialize(0);
        initializeGL(&painter);
    }

    // Modify the GL viewport to only cover the extent of this QDeclarativeItem.
    QTransform transform = p->transform();
    painter.setViewport(QRect(qRound(transform.dx()), qRound(transform.dy()),
                              width(), height()));

    // Perform early drawing operations.
    earlyDraw(&painter);

    // Set up the camera the way QGLView would if we were using it.
    if (d->camera) {
        painter.setCamera(d->camera);
    } else {
        QGLCamera defCamera;
        painter.setCamera(&defCamera);
    }

    // Draw the Item3d children.
    draw(&painter);
    painter.setPicking(false);
}
Exemple #22
0
void ellipse::translateOrigin(qreal x, qreal y)
{

    this->transformationTranslate = this->transformationTranslate.translate(x, y);
    this->transformationMatrix = this->transformationScale* this->transformationRotate * this->transformationTranslate;


    this->transformationMatrix = transformationScale * transformationRotate * transformationTranslate;

	if(!this->transformationMatrix.isInvertible())
	{
        //qDebug() << "Notinvertible";
	}
    QTransform inverted = this->transformationMatrix.inverted();
    data.scaleX = (cl_float) inverted.m11();
    data.scaleY = (cl_float) inverted.m22();
    data.angleX = (cl_float) inverted.m21();
    data.angleY = (cl_float) inverted.m12();
    data.dx = (cl_float) inverted.dx();
    data.dy = (cl_float) inverted.dy();

}
Exemple #23
0
QDomElement TupSerializer::properties(const QGraphicsItem *item, QDomDocument &doc)
{
    QDomElement properties = doc.createElement("properties");
    
    QString strMatrix = "matrix(";
    QTransform m = item->transform();
    qreal a = m.m11();
    qreal b = m.m12();
    qreal c = m.m21();
    qreal d = m.m22();
    qreal e = m.dx();
    qreal f = m.dy();
    
    strMatrix += QString::number(a) + "," + QString::number(b) + "," + QString::number(c) + "," + QString::number(d) + "," + QString::number(e) + "," + QString::number(f) + ")" ; 
    
    properties.setAttribute("transform", strMatrix);
    properties.setAttribute("pos", "(" + QString::number(item->pos().x()) + "," + QString::number(item->pos().y()) + ")");
    properties.setAttribute("enabled", item->isEnabled());
    properties.setAttribute("flags", item->flags());

    return properties;
}
Exemple #24
0
/*
 * m11 m12 0
 * m21 m22 0
 * dx  dy  1
 *
 * m11 = horizontale Skalierung
 * m22 = vertikale Skalierung
 *
 * m21 = horizontale drehung
 * m12 = vertikale drehung
 *
 * dx = translation x
 * dy = translation y
 */
ellipse::ellipse(qreal midPointX, qreal midPointY, qreal radiusX, qreal radiusY)
{
	//Constructor vertikale Skalierung, vertikale Drehung, horizontale Drehung, horizontale Skalierung, translate X, translate Y

    this->transformationRotate = QTransform(1, 0, 0, 1, 0, 0);
    this->transformationScale = QTransform(radiusX, 0, 0, radiusY, 0, 0);

    this->transformationTranslate = QTransform(1, 0, 0, 1, midPointX, midPointY);
    this->transformationMatrix = this->transformationScale * this->transformationRotate * this->transformationTranslate;

	if(!this->transformationMatrix.isInvertible())
	{
        //qDebug() << "Notinvertible";
	}
    QTransform inverted = this->transformationMatrix.inverted();
    data.scaleX = (cl_float) inverted.m11();
    data.scaleY = (cl_float) inverted.m22();
    data.angleX = (cl_float) inverted.m21();
    data.angleY = (cl_float) inverted.m12();
    data.dx = (cl_float) inverted.dx();
    data.dy = (cl_float) inverted.dy();

}
Exemple #25
0
void ScoreTab::setCurrent(int n)
{
    if (n == -1) {
        clearTab2();
        tab2->setVisible(false);
        // clearTab2();      //??
        emit currentScoreViewChanged(0);
        return;
    }
    TabScoreView* tsv = static_cast<TabScoreView*>(tab->tabData(n).value<void*>());
    QSplitter* vs = viewSplitter(n);

    ScoreView* v;
    if (!vs) {
        vs = new QSplitter;
        v  = new ScoreView;
        tab2->blockSignals(true);
        tab2->setCurrentIndex(0);
        tab2->blockSignals(false);
        vs->addWidget(v);
        v->setScore(scoreList->value(n));
        stack->addWidget(vs);
    }
    else {
        v = static_cast<ScoreView*>(vs->widget(0));
    }
#ifdef OMR
    if (v) {
        Score* score = v->score();
        if (score->showOmr() && score->omr()) {
            if (vs->count() < 2) {
                Omr* omr    = score->omr();
                OmrView* sv = omr->newOmrView(v);
                v->setOmrView(sv);
                vs->addWidget(sv);
                connect(v, SIGNAL(scaleChanged(double)), sv, SLOT(setScale(double)));
                connect(v, SIGNAL(offsetChanged(double,double)), sv, SLOT(setOffset(double,double)));
                const QTransform _matrix = v->matrix();
                double _spatium = score->spatium();
                double scale = _matrix.m11() * _spatium;
                sv->setScale(scale);
                sv->setOffset(_matrix.dx(), _matrix.dy());
                QList<int> sizes;
                sizes << 100 << 100;
                vs->setSizes(sizes);
            }
        }
        else {
            if (vs->count() > 1) {
                QWidget* w = vs->widget(1);
                delete w;
            }
        }
    }
#endif
    stack->setCurrentWidget(vs);
    clearTab2();
    if (v) {
        Score* score = v->score();
        if (score->parentScore())
            score = score->parentScore();
        QList<Excerpt*>& excerpts = score->excerpts();
        if (!excerpts.isEmpty()) {
            tab2->blockSignals(true);
            tab2->addTab(score->name().replace("&","&&"));
            foreach(const Excerpt* excerpt, excerpts) {
                tab2->addTab(excerpt->partScore()->name().replace("&","&&"));
            }
            tab2->setCurrentIndex(tsv->part);
            tab2->blockSignals(false);
            tab2->setVisible(true);
        }
Exemple #26
0
void GlslPainter::paint(QPainter *painter,
                        QRectF target,
                        QQuickWindow *window)
{
    // Need to reenable those after native painting has begun, otherwise we might
    // not be able to paint anything.
    bool stencilTestEnabled = glIsEnabled(GL_STENCIL_TEST);
    bool scissorTestEnabled = glIsEnabled(GL_SCISSOR_TEST);

    painter->beginNativePainting();

    if (stencilTestEnabled)
        glEnable(GL_STENCIL_TEST);
    if (scissorTestEnabled)
        glEnable(GL_SCISSOR_TEST);

    //////////////////////////////////////////////////////////////
    initTextures();
    //////////////////////////////////////////////////////////////

    // As seen on the telly
#ifdef __GNUC__
#warning DUPLICATED CODE
#endif

    const float textureCoordinates[] = {
        0, 1, // bottom left
        1, 1, // bottom right
        0, 0, // top left
        1, 0, // top right
    };

    const GLfloat targetVertex[] =
    {
        GLfloat(target.left()), GLfloat(target.bottom()),
        GLfloat(target.right()), GLfloat(target.bottom()),
        GLfloat(target.left()) , GLfloat(target.top()),
        GLfloat(target.right()), GLfloat(target.top())
    };
    //

    const int width = window->width();
    const int height = window->height();

    const QTransform transform = painter->deviceTransform();

    const GLfloat wfactor = 2.0 / width;
    const GLfloat hfactor = -2.0 / height;

    const GLfloat positionMatrix[4][4] = {
        {
            GLfloat(wfactor * transform.m11() - transform.m13()),
            GLfloat(hfactor * transform.m12() + transform.m13()),
            0.0,
            GLfloat(transform.m13())
        }, {
            GLfloat(wfactor * transform.m21() - transform.m23()),
            GLfloat(hfactor * transform.m22() + transform.m23()),
            0.0,
            GLfloat(transform.m23())
        }, {
            0.0,
            0.0,
            -1.0,
            0.0
        }, {
            GLfloat(wfactor * transform.dx() - transform.m33()),
            GLfloat(hfactor * transform.dy() + transform.m33()),
            0.0,
            GLfloat(transform.m33())
        }
    };

    _program->bind();

    _program->enableAttributeArray("targetVertex");
    _program->enableAttributeArray("textureCoordinates");
    _program->setAttributeArray("targetVertex", targetVertex, 2);
    _program->setAttributeArray("textureCoordinates", textureCoordinates, 2);
    _program->setUniformValue("positionMatrix", positionMatrix);

    if (_textureCount == 3) {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, _textureIds[0]);
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, _textureIds[1]);
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, _textureIds[2]);
        glActiveTexture(GL_TEXTURE0);

        _program->setUniformValue("texY", 0);
        _program->setUniformValue("texU", 1);
        _program->setUniformValue("texV", 2);
    }
    _program->setUniformValue("colorMatrix", _colorMatrix);
    _program->setUniformValue("opacity", GLfloat(painter->opacity()));

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    _program->release();
    painter->endNativePainting();

#if !defined(Q_OS_WIN)
    // TODO: FPS optional
    calculateFPS();
    addFPSOverlay();
#endif
}
Exemple #27
0
        imageByte >>= 8-validPix;
        imageByte <<= 8-validPix;
      }
      grfImage.append(QString().sprintf("%02X",imageByte));
    }
  }

  int bytesPerLine = (width+7)/8;
  m_printBuffer += QString("~DGR:IMG.GRF,%1,%2,").arg(bytesPerLine*nbOfLines).arg(bytesPerLine);
  m_printBuffer += compressedHexa(grfImage);

  m_printBuffer += "\n";

  QTransform transform = painter()->worldTransform();

  int xInDots = (int)(rectangle.top() + transform.dx());
  int yInDots = (int)(rectangle.left() + transform.dy());

  m_printBuffer += QString(m_CmdPrefix + "FO%1,%2" + m_CmdPrefix + "XGR:IMG.GRF,1,1" + m_CmdPrefix + "FS\n").arg(xInDots).arg(yInDots);
}


void 	ZebraPaintEngine::drawLines ( const QLineF * lines, int lineCount )
{
  for (int i=0; i< lineCount; i++) {

    QTransform transform = painter()->worldTransform();

    int xInDots = (int)(lines[i].x1() + transform.dx());
    int yInDots = (int)(lines[i].y1() + transform.dy());
Exemple #28
0
void PropertiesPalette_XYZ::handleNewX()
{
	if (!m_ScMW || m_ScMW->scriptIsRunning())
		return;
	if ((m_haveDoc) && (m_haveItem))
	{
		double x,y,w,h, gx, gy, gh, gw, base;
		QTransform ma;
		x = xposSpin->value() / m_unitRatio;
		y = yposSpin->value() / m_unitRatio;
		w = widthSpin->value() / m_unitRatio;
		h = heightSpin->value() / m_unitRatio;
		base = 0;
		x += m_doc->rulerXoffset;
		y += m_doc->rulerYoffset;
		if (m_doc->guidesPrefs().rulerMode)
		{
			x += m_doc->currentPage()->xOffset();
			y += m_doc->currentPage()->yOffset();
		}
		if (m_doc->m_Selection->isMultipleSelection())
		{
			m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
			int bp = basePointWidget->checkedId();
			if ((bp == 0) || (bp == 3))
				base = gx;
			else if (bp == 2)
				base = gx + gw / 2.0;
			else if ((bp == 1) || (bp == 4))
				base = gx + gw;
			if (!_userActionOn)
				m_ScMW->view->startGroupTransaction();
			m_doc->moveGroup(x - base, 0, true);
			if (!_userActionOn)
			{
				m_ScMW->view->endGroupTransaction();
			}
			m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
			displayXY(gx, gy);
		}
		else
		{
			if ((m_item->asLine()) && (m_lineMode))
			{
				w += m_doc->rulerXoffset;
				h += m_doc->rulerYoffset;
				if (m_doc->guidesPrefs().rulerMode)
				{
					w += m_doc->currentPage()->xOffset();
					h += m_doc->currentPage()->yOffset();
				}
				double r = atan2(h-y,w-x)*(180.0/M_PI);
				w = sqrt(pow(w-x,2)+pow(h-y,2));
				m_item->setXYPos(x, m_item->yPos(), true);
				m_item->setRotation(r, true);
				m_doc->SizeItem(w, m_item->height(), m_item, true);
			}
			else
			{
				ma.translate(m_item->xPos(), m_item->yPos());
				ma.rotate(m_item->rotation());
				int bp = basePointWidget->checkedId();
				if (bp == 0)
					base = m_item->xPos();
				else if (bp == 2)
					base = ma.m11() * (m_item->width() / 2.0) + ma.m21() * (m_item->height() / 2.0) + ma.dx();
				else if (bp == 1)
					base = ma.m11() * m_item->width() + ma.m21() * 0.0 + ma.dx();
				else if (bp == 4)
					base = ma.m11() * m_item->width() + ma.m21() * m_item->height() + ma.dx();
				else if (bp == 3)
					base = ma.m11() * 0.0 + ma.m21() * m_item->height() + ma.dx();
				m_doc->MoveItem(x - base, 0, m_item, true);
			}
		}
		m_doc->regionsChanged()->update(QRect());
		emit DocChanged();
	}
}
Exemple #29
0
void QgsComposerItem::move( double dx, double dy )
{
    QTransform t = transform();
    QRectF newSceneRect( t.dx() + dx, t.dy() + dy, rect().width(), rect().height() );
    setSceneRect( newSceneRect );
}
WMatrix transform(const QTransform& matrix)
{
	return WMatrix(matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(), matrix.dx(), matrix.dy());
}