本文整理汇总了C++中QTransform::mapRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QTransform::mapRect方法的具体用法?C++ QTransform::mapRect怎么用?C++ QTransform::mapRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTransform
的用法示例。
在下文中一共展示了QTransform::mapRect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scaledBoundingRect
inline QRectF scaledBoundingRect( double sx, double sy,
bool scalePens ) const
{
if ( sx == 1.0 && sy == 1.0 )
return d_boundingRect;
QTransform transform;
transform.scale( sx, sy );
QRectF rect;
if ( scalePens && d_scalablePen )
{
rect = transform.mapRect( d_boundingRect );
}
else
{
rect = transform.mapRect( d_pointRect );
const double l = qAbs( d_pointRect.left() - d_boundingRect.left() );
const double r = qAbs( d_pointRect.right() - d_boundingRect.right() );
const double t = qAbs( d_pointRect.top() - d_boundingRect.top() );
const double b = qAbs( d_pointRect.bottom() - d_boundingRect.bottom() );
rect.adjust( -l, -t, r, b );
}
return rect;
}
示例2: scale
void DisplayGroupController::scale(const QSizeF& factor)
{
const QTransform t = QTransform::fromScale(factor.width(), factor.height());
for (ContentWindowPtr window : _group.getContentWindows())
window->setCoordinates(t.mapRect(window->getCoordinates()));
_group.setCoordinates(t.mapRect(_group.getCoordinates()));
}
示例3: drawRectangles
// draw shapes
// NOTE: if drawing many shapes of same size, use drawGlyphs
void ScenePainter::drawRectangles(double *x, double *y, double *w, double *h,
int n)
{
QTransform tform = transform();
QPen pen = this->pen();
for (int i = 0; i < n; i++) {
QPointF point = QPointF(x[i], y[i]);
QRectF rect = tform.mapRect(QRectF(point, QSizeF(w[i], h[i])));
if (!tform.isRotating()) {
STORE_INDEX(_scene->addRect(tform.mapRect(rect), pen));
}
else STORE_INDEX(_scene->addPolygon(tform.map(QPolygonF(rect))));
}
}
示例4: mouseMoveEvent
void CanvasMode_EditArc::mouseMoveEvent(QMouseEvent *m)
{
const FPoint mousePointDoc = m_canvas->globalToCanvas(m->globalPos());
m->accept();
double newX = mousePointDoc.x();
double newY = mousePointDoc.y();
if (m_canvas->m_viewMode.m_MouseButtonPressed && m_view->moveTimerElapsed())
{
PageItem *currItem = m_doc->m_Selection->itemAt(0);
QTransform itemMatrix = currItem->getTransform();
QPointF sPoint = currItem->PoLine.pointQF(0);
QPointF smPoint = itemMatrix.map(sPoint);
QLineF stLinA = QLineF(smPoint, QPointF(m_Mxp, m_Myp));
QLineF stLinM = QLineF(smPoint, QPointF(newX, newY));
double deltaAngle = stLinM.angle() - stLinA.angle();
QPainterPath pp;
if (m_arcPoint == useControlStart)
m_startAngle += deltaAngle;
else if (m_arcPoint == useControlSweep)
m_endAngle += deltaAngle;
else if (m_arcPoint == useControlHeight)
m_heightPoint = QPointF(m_heightPoint.x(), m_heightPoint.y() + (newY - m_Myp));
else if (m_arcPoint == useControlWidth)
m_widthPoint = QPointF(m_widthPoint.x() + (newX - m_Mxp), m_widthPoint.y());
double nSweep = m_endAngle - m_startAngle;
if (nSweep < 0)
nSweep += 360;
double nWidth = sPoint.x() - m_widthPoint.x();
double nHeight = sPoint.y() - m_heightPoint.y();
if ((nWidth > 0) && (nHeight > 0))
{
pp.moveTo(sPoint);
pp.arcTo(QRectF(sPoint.x() - nWidth, sPoint.y() - nHeight, nWidth * 2, nHeight * 2), m_startAngle, nSweep);
pp.closeSubpath();
FPointArray ar;
ar.fromQPainterPath(pp);
if (m_arcPoint == useControlStart)
{
m_startPoint = ar.pointQF(2);
QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_startPoint));
m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle());
}
else if (m_arcPoint == useControlSweep)
{
m_endPoint = ar.pointQF(ar.size() - 4);
QLineF stLinA = QLineF(smPoint, itemMatrix.map(m_endPoint));
m_canvas->displayRotHUD(m->globalPos(), 360.0 - stLinA.angle());
}
QLineF res = QLineF(m_centerPoint, m_startPoint);
QLineF swe = QLineF(m_centerPoint, m_endPoint);
vectorDialog->setValues(res.angle(), swe.angle(), nHeight * 2, nWidth * 2);
blockUpdateFromItem(true);
currItem->update();
blockUpdateFromItem(false);
m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-nWidth, -nHeight, nWidth, nHeight));
}
}
m_Mxp = newX;
m_Myp = newY;
}
示例5: updateBoundingBox
/**
* @brief cwCaptureViewport::updateBoundingBox
*
* This will update the bounding box for the viewport capture.
*
* This is useful for displaying annotation, and interactions ontop of the item
* in qml.
*/
void cwCaptureViewport::updateBoundingBox()
{
QTransform transform = previewItem()->transform();
QRectF paperRect = previewItem()->boundingRect();
QRectF boundingBoxRect = transform.mapRect(paperRect);
setBoundingBox(boundingBoxRect);
}
示例6: setPictureRotation
void QgsComposerPicture::setPictureRotation( double r )
{
double oldRotation = mPictureRotation;
mPictureRotation = r;
if ( mResizeMode == Zoom )
{
//find largest scaling of picture with this rotation which fits in item
QSizeF currentPictureSize = pictureSize();
QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), mPictureRotation );
mPictureWidth = rotatedImageRect.width();
mPictureHeight = rotatedImageRect.height();
update();
}
else if ( mResizeMode == ZoomResizeFrame )
{
QSizeF currentPictureSize = pictureSize();
QRectF oldRect = QRectF( pos().x(), pos().y(), rect().width(), rect().height() );
//calculate actual size of image inside frame
QRectF rotatedImageRect = QgsComposerUtils::largestRotatedRectWithinBounds( QRectF( 0, 0, currentPictureSize.width(), currentPictureSize.height() ), rect(), oldRotation );
//rotate image rect by new rotation and get bounding box
QTransform tr;
tr.rotate( mPictureRotation );
QRectF newRect = tr.mapRect( QRectF( 0, 0, rotatedImageRect.width(), rotatedImageRect.height() ) );
//keep the center in the same location
newRect.moveCenter( oldRect.center() );
QgsComposerItem::setSceneRect( newRect );
emit itemChanged();
}
emit pictureRotationChanged( mPictureRotation );
}
示例7: mapSourceToTarget
void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect)
{
QRectF target = targetRect;
if (target.isNull()) {
QPaintDevice *dev = p->device();
QRectF deviceRect(0, 0, dev->width(), dev->height());
if (deviceRect.isNull()) {
if (sourceRect.isNull())
target = QRectF(QPointF(0, 0), size());
else
target = QRectF(QPointF(0, 0), sourceRect.size());
} else {
target = deviceRect;
}
}
QRectF source = sourceRect;
if (source.isNull())
source = viewBox();
if (source != target && !source.isNull()) {
QTransform transform;
transform.scale(target.width() / source.width(),
target.height() / source.height());
QRectF c2 = transform.mapRect(source);
p->translate(target.x() - c2.x(),
target.y() - c2.y());
p->scale(target.width() / source.width(),
target.height() / source.height());
}
}
示例8: pow
void
NodeGraph::wheelEventInternal(bool ctrlDown,double delta)
{
double scaleFactor = pow( NATRON_WHEEL_ZOOM_PER_DELTA, delta);
QTransform transfo = transform();
double currentZoomFactor = transfo.mapRect( QRectF(0, 0, 1, 1) ).width();
double newZoomfactor = currentZoomFactor * scaleFactor;
if ((newZoomfactor < 0.01 && scaleFactor < 1.) || (newZoomfactor > 50 && scaleFactor > 1.)) {
return;
}
if (ctrlDown && _imp->_magnifiedNode) {
if (!_imp->_magnifOn) {
_imp->_magnifOn = true;
_imp->_nodeSelectedScaleBeforeMagnif = _imp->_magnifiedNode->scale();
}
_imp->_magnifiedNode->setScale_natron(_imp->_magnifiedNode->scale() * scaleFactor);
} else {
_imp->_accumDelta += delta;
if (std::abs(_imp->_accumDelta) > 60) {
scaleFactor = pow( NATRON_WHEEL_ZOOM_PER_DELTA, _imp->_accumDelta );
// setSceneRect(NATRON_SCENE_MIN,NATRON_SCENE_MIN,NATRON_SCENE_MAX,NATRON_SCENE_MAX);
scale(scaleFactor,scaleFactor);
_imp->_accumDelta = 0;
}
_imp->_refreshOverlays = true;
}
}
示例9: beginTransparencyLayer
void GraphicsContext::beginTransparencyLayer(float opacity)
{
if (paintingDisabled())
return;
int x, y, w, h;
x = y = 0;
QPainter *p = m_data->p();
const QPaintDevice *device = p->device();
w = device->width();
h = device->height();
QRectF clip = p->clipPath().boundingRect();
bool ok;
QTransform transform = p->transform().inverted(&ok);
if (ok) {
QRectF deviceClip = transform.mapRect(clip);
x = int(qBound(qreal(0), deviceClip.x(), (qreal)w));
y = int(qBound(qreal(0), deviceClip.y(), (qreal)h));
w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2);
h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2);
}
TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h));
layer->opacity = opacity;
m_data->layers.push(layer);
}
示例10: add
void KisShapeSelectionModel::add(KoShape *child)
{
if (!m_shapeSelection) return;
if (m_shapeMap.contains(child))
return;
child->setStroke(0);
child->setBackground( QSharedPointer<KoShapeBackground>(0));
m_shapeMap.insert(child, child->boundingRect());
m_shapeSelection->shapeManager()->addShape(child);
QRect updateRect = child->boundingRect().toAlignedRect();
if (m_image.isValid()) {
QTransform matrix;
matrix.scale(m_image->xRes(), m_image->yRes());
updateRect = matrix.mapRect(updateRect);
}
if (m_shapeMap.count() == 1) {
// The shape is the first one, so the shape selection just got created
// Pixel selection provides no longer the datamanager of the selection
// so update the whole selection
requestUpdate(QRect());
} else {
requestUpdate(updateRect);
}
}
示例11: getListOfPixmapFromStripImage
ITank::ITank(TankInfo tank_info, QString nick, int rank, ColorTeam color_team):QGraphicsObject()
{
_tank_info = tank_info;
_nick = nick;
_rank = rank;
_color_team = color_team;
_max_live = _current_live = tank_info._live;
_max_mana = _current_mana = _tank_info._mana;
_base_armor = _tank_info._armor;
_base_speed = _tank_info._speed;
_base_live_regeneration = _tank_info._live_regeneration;
_base_mana_regeneration = tank_info._mana_regeneration;
_dead_time = MECH_DEAD_TIME_FOR_LEVEL;
_is_enemy = false;
_level = 1;
_updates_available = 1;
_current_experience = 0;
_next_level_experience = MECH_INIT_NEXT_LEVEL_EXPERIENCE;
_counter_millisec = 0;
_animation_dead = getListOfPixmapFromStripImage(":/gt/sprites/tank_explotion.png",160);
_frame_animation_dead = 0;
_animation_level_up = getListOfPixmapFromStripImage(":/gt/sprites/tank_level_up.png",100);
_frame_animation_level_up = 39;
QTransform transformation;
transformation.translate(-80, -80);
_default_rect = transformation.mapRect(QRect(0, 0, 160, 160));
_mini_map_tank = new QGraphicsPixmapItem(QPixmap(QString(":/gt/sprites/mini_map_tank_%1.png").arg(color_team)));
_mini_map_tank->setTransformationMode(Qt::SmoothTransformation);
_mini_map_tank->setTransformOriginPoint(_mini_map_tank->boundingRect().width()/2, _mini_map_tank->boundingRect().height()/2+2);
_mini_map_tank->setZValue(20);
_sound_explode = new SoundEngine(QUrl("qrc:/gt/sounds/explode.mp3"), MECH_MAX_DISTANCE_SOUND, this);
_sound_level_up = new SoundEngine(QUrl("qrc:/gt/sounds/level_up.mp3"), MECH_MAX_DISTANCE_SOUND, this);
//añade un efecto de sombra ligero al tanque
// QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this);
// shadow->setColor(Qt::black);
// shadow->setOffset(0);
// shadow->setBlurRadius(5);
// setGraphicsEffect(shadow);
}
示例12: mouseReleaseEvent
void CanvasMode_EditMeshGradient::mouseReleaseEvent(QMouseEvent *m)
{
m_canvas->m_viewMode.m_MouseButtonPressed = false;
m_canvas->resetRenderMode();
m->accept();
PageItem *currItem = m_doc->m_Selection->itemAt(0);
if (currItem->selectedMeshPointX >=0 && currItem->selectedMeshPointY >=0 && UndoManager::undoEnabled())
{
ScItemState<QPair<meshPoint,meshPoint> > *ss = new ScItemState<QPair<meshPoint,meshPoint> >(Um::GradPos);
ss->set("MOVE_MESH_PATCH");
ss->set("ARRAY",true);
ss->set("X",currItem->selectedMeshPointX);
ss->set("Y",currItem->selectedMeshPointY);
if((*m_old_mesh) == currItem->meshGradientArray[currItem->selectedMeshPointX][currItem->selectedMeshPointY])
{
delete ss;
ss=NULL;
}
else
ss->setItem(qMakePair(*m_old_mesh,currItem->meshGradientArray[currItem->selectedMeshPointX][currItem->selectedMeshPointY]));
if(ss)
undoManager->action(currItem,ss);
}
currItem->update();
QTransform itemMatrix = currItem->getTransform();
m_doc->regionsChanged()->update(itemMatrix.mapRect(QRectF(0, 0, currItem->width(), currItem->height())).adjusted(-currItem->width() / 2.0, -currItem->height() / 2.0, currItem->width(), currItem->height()));
}
示例13: syncWithMapObject
void MapObjectLabel::syncWithMapObject(MapRenderer *renderer)
{
const bool nameVisible = mObject->isVisible() && !mObject->name().isEmpty();
setVisible(nameVisible);
if (!nameVisible)
return;
const QFontMetricsF metrics(QGuiApplication::font());
QRectF boundingRect = metrics.boundingRect(mObject->name());
boundingRect.translate(-boundingRect.width() / 2, -labelDistance);
boundingRect.adjust(-labelMargin*2, -labelMargin, labelMargin*2, labelMargin);
QPointF pixelPos = renderer->pixelToScreenCoords(mObject->position());
QRectF bounds = objectBounds(mObject, renderer);
// Adjust the bounding box for object rotation
QTransform transform;
transform.translate(pixelPos.x(), pixelPos.y());
transform.rotate(mObject->rotation());
transform.translate(-pixelPos.x(), -pixelPos.y());
bounds = transform.mapRect(bounds);
// Center the object name on the object bounding box
QPointF pos((bounds.left() + bounds.right()) / 2, bounds.top());
setPos(pos + mObject->objectGroup()->offset());
if (mBoundingRect != boundingRect) {
prepareGeometryChange();
mBoundingRect = boundingRect;
}
}
示例14: testRotation
void KisCoordinatesConverterTest::testRotation()
{
KisImageSP image;
KisCoordinatesConverter converter;
initImage(&image, &converter);
QSize widgetSize(1000,500);
QRectF testRect(800, 100, 300, 300);
converter.setImage(image);
converter.setDocumentOffset(QPoint(0,0));
converter.setCanvasWidgetSize(widgetSize);
converter.rotate(converter.widgetCenterPoint(), 30);
converter.setZoom(1.);
QTransform viewportToWidget = converter.viewportToWidgetTransform();
QRectF boundingRect = viewportToWidget.mapRect(testRect);
QRectF directRect = converter.viewportToWidget(testRect);
QCOMPARE(boundingRect, directRect);
QRectF referenceRect(QPointF(742.82,53.5898), QSizeF(409.808,409.808));
#define FUZZY(a,b) ((a)-(b) < 0.01)
QVERIFY(FUZZY(boundingRect.top(), referenceRect.top()));
QVERIFY(FUZZY(boundingRect.left(), referenceRect.left()));
QVERIFY(FUZZY(boundingRect.width(), referenceRect.width()));
QVERIFY(FUZZY(boundingRect.height(), referenceRect.height()));
}
示例15: brushOutline
QPainterPath KisDuplicateOpSettings::brushOutline(const QPointF& pos, KisPaintOpSettings::OutlineMode mode, qreal scale, qreal rotation) const
{
QPainterPath path;
path = KisBrushBasedPaintOpSettings::brushOutline(QPointF(0.0,0.0),KisPaintOpSettings::CursorIsOutline, scale, rotation);
QPainterPath copy(path);
QRectF rect2 = copy.boundingRect();
if (m_isOffsetNotUptodate) {
copy.translate(m_position - pos);
} else {
copy.translate(-m_offset);
}
path.addPath(copy);
QTransform m;
m.scale(0.5,0.5);
rect2 = m.mapRect(rect2);
path.moveTo(rect2.topLeft());
path.lineTo(rect2.bottomRight());
path.moveTo(rect2.topRight());
path.lineTo(rect2.bottomLeft());
if (mode == CursorIsOutline){
return path.translated(pos);
} else {
// workaround?
//copy.addEllipse(QRectF(0,0,1,1));
return copy.translated(pos);
}
}