当前位置: 首页>>代码示例>>C++>>正文


C++ QMatrix4x4::toTransform方法代码示例

本文整理汇总了C++中QMatrix4x4::toTransform方法的典型用法代码示例。如果您正苦于以下问题:C++ QMatrix4x4::toTransform方法的具体用法?C++ QMatrix4x4::toTransform怎么用?C++ QMatrix4x4::toTransform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QMatrix4x4的用法示例。


在下文中一共展示了QMatrix4x4::toTransform方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addToGroup

void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item)
{
    if (!item) {
        qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add null item");
        return;
    }
    if (item == this) {
        qWarning("UBGraphicsGroupContainerItem::addToGroup: cannot add a group to itself");
        return;
    }

    // COMBINE
    bool ok;
    QTransform itemTransform = item->itemTransform(this, &ok);

    if (!ok) {
        qWarning("UBGraphicsGroupContainerItem::addToGroup: could not find a valid transformation from item to group coordinates");
        return;
    }

    //setting item flags to given item
    item->setSelected(false);
    item->setFlag(QGraphicsItem::ItemIsSelectable, false);
    item->setFlag( QGraphicsItem::ItemIsMovable, false);
    item->setFlag(QGraphicsItem::ItemIsFocusable, true);

    QTransform newItemTransform(itemTransform);
    item->setPos(mapFromItem(item, 0, 0));
    item->setParentItem(this);

    // removing position from translation component of the new transform
    if (!item->pos().isNull())
        newItemTransform *= QTransform::fromTranslate(-item->x(), -item->y());

    // removing additional transformations properties applied with itemTransform()
    QPointF origin = item->transformOriginPoint();
    QMatrix4x4 m;
    QList<QGraphicsTransform*> transformList = item->transformations();
    for (int i = 0; i < transformList.size(); ++i)
        transformList.at(i)->applyTo(&m);
    newItemTransform *= m.toTransform().inverted();
    newItemTransform.translate(origin.x(), origin.y());
    newItemTransform.rotate(-item->rotation());
    newItemTransform.scale(1/item->scale(), 1/item->scale());
    newItemTransform.translate(-origin.x(), -origin.y());

    // ### Expensive, we could maybe use dirtySceneTransform bit for optimization

    item->setTransform(newItemTransform);
//    item->d_func()->setIsMemberOfGroup(true);
    prepareGeometryChange();
    itemsBoundingRect |= itemTransform.mapRect(item->boundingRect() | item->childrenBoundingRect());
    update();
}
开发者ID:wdmchaft,项目名称:Sankore-3.1,代码行数:54,代码来源:UBGraphicsGroupContainerItem.cpp

示例2: init

KisPerspectiveTransformWorker::KisPerspectiveTransformWorker(KisPaintDeviceSP dev, QPointF center, double aX, double aY, double distance, KoUpdaterPtr progress)
        : m_dev(dev), m_progressUpdater(progress)

{
    QMatrix4x4 m;
    m.rotate(180. * aX / M_PI, QVector3D(1, 0, 0));
    m.rotate(180. * aY / M_PI, QVector3D(0, 1, 0));

    QTransform project = m.toTransform(distance);
    QTransform t = QTransform::fromTranslate(center.x(), center.y());

    QTransform forwardTransform = t.inverted() * project * t;

    init(forwardTransform);
}
开发者ID:TheTypoMaster,项目名称:calligra,代码行数:15,代码来源:kis_perspectivetransform_worker.cpp

示例3: removeFromGroup

void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item)
{
    if (!item) {
        qWarning("QGraphicsItemGroup::removeFromGroup: cannot remove null item");
        return;
    }

    QGraphicsItem *newParent = parentItem();

    // COMBINE
    bool ok;
    QTransform itemTransform;
    if (newParent)
        itemTransform = item->itemTransform(newParent, &ok);
    else
        itemTransform = item->sceneTransform();

    QPointF oldPos = item->mapToItem(newParent, 0, 0);
    item->setParentItem(newParent);
    item->setPos(oldPos);

    // removing position from translation component of the new transform
    if (!item->pos().isNull())
        itemTransform *= QTransform::fromTranslate(-item->x(), -item->y());

    // removing additional transformations properties applied
    // with itemTransform() or sceneTransform()
    QPointF origin = item->transformOriginPoint();
    QMatrix4x4 m;
    QList<QGraphicsTransform*> transformList = item->transformations();
    for (int i = 0; i < transformList.size(); ++i)
        transformList.at(i)->applyTo(&m);
    itemTransform *= m.toTransform().inverted();
    itemTransform.translate(origin.x(), origin.y());
    itemTransform.rotate(-item->rotation());
    itemTransform.scale(1 / item->scale(), 1 / item->scale());
    itemTransform.translate(-origin.x(), -origin.y());

    // ### Expensive, we could maybe use dirtySceneTransform bit for optimization

    item->setTransform(itemTransform);
//    item->d_func()->setIsMemberOfGroup(item->group() != 0);

    // ### Quite expensive. But removeFromGroup() isn't called very often.
    prepareGeometryChange();
    itemsBoundingRect = childrenBoundingRect();
}
开发者ID:colombc,项目名称:Sankore-3.1,代码行数:47,代码来源:ubgraphicsgroupcontaineritem.cpp

示例4: paintEvent


//.........这里部分代码省略.........
		painter.setPen( QPen(lineColor,BORDER) );
		painter.drawRoundedRect(r, ROUNDED, ROUNDED);
	
		if( m_Ticks.empty() )
			m_Points.clear();
		else
			m_Points.resize(m_Ticks.size() + 1);	// end point
	
		if( !m_Points.empty() )
		{
			float lineHeight = (r.height() * 0.8f);
			float lineX = (r.right() + HALF_BORDER);
			float lineY = (r.bottom() - 0.5f*(r.height()-lineHeight));
			float lineWidth = (r.width() + BORDER);
		
			float toPercent = 1.0f/PEDAL_TIMEFRAME;

			for(size_t i=0; i<m_Ticks.size(); i++)
			{
				const sTick &t = m_Ticks[i];
				QPointF &p = m_Points[i];	// end point
			
				float percent = (t.elapsed * toPercent);
				p.setX(lineX - lineWidth*percent);
				p.setY(lineY - lineHeight*t.value);
			}
		
			// end point
			m_Points[m_Points.size()-1] = QPointF(lineX, m_Points[m_Points.size()-2].y());
		
			painter.drawPolyline(m_Points);
		}
	
		if(m_Hover > 0)
		{
			qreal dy = (-m_Hover * BUTTON_RAISE);
			if(dy != 0)
				r.adjust(0, 0, 0, dy);
		}
	
		QColor textColor( palette().color(QPalette::ButtonText) );
		if( !isEnabled() )
			textColor = textColor.darker(150);

		if( !text().isEmpty() )
		{
			if( m_Label.isEmpty() )
			{
				// just text centered
				painter.setFont( font() );
				painter.setPen(textColor);
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, text());
			}
			else
			{
				// both text and label text
				QRectF textRect;
				painter.setFont( font() );
				painter.setPen(textColor);
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, text(), &textRect);

				QRectF labelRect;
				painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap|Qt::TextDontPrint, m_Label, &labelRect);

				qreal h = (r.height() * 0.5 * (textRect.height()/labelRect.height()));
				painter.drawText(QRectF(r.x(),r.y(),r.width(),h), Qt::AlignCenter|Qt::TextWordWrap, text());
				painter.drawText(QRectF(r.x(),r.y()+h,r.width(),r.height()-h), Qt::AlignCenter|Qt::TextWordWrap, m_Label);
			}
		}
		else if( !m_Label.isEmpty() )
		{
			// just label text centered
			painter.setFont( font() );
			painter.setPen(textColor);
			painter.drawText(r, Qt::AlignCenter|Qt::TextWordWrap, m_Label);
		}

		painter.end();
	}

	if( painter.begin(this) )
	{
		if(angle > 0.00001)
		{
			qreal center = (m_Canvas.width() * 0.5);
			QMatrix4x4 matrix;
			matrix.translate(-center, m_Canvas.height());
			matrix.rotate(angle, 1.0, 0, 0);

			painter.translate(center, 0);
			painter.setTransform(matrix.toTransform(300.0), /*combine*/true);
			painter.setRenderHint(QPainter::SmoothPixmapTransform);
			painter.drawImage(0, -m_Canvas.height(), m_Canvas);
		}
		else
			painter.drawImage(0, 0, m_Canvas);

		painter.end();
	}
}
开发者ID:richardwilliamson,项目名称:OSCWidgets,代码行数:101,代码来源:ToyPedal.cpp


注:本文中的QMatrix4x4::toTransform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。