本文整理汇总了C++中QRectF::moveCenter方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::moveCenter方法的具体用法?C++ QRectF::moveCenter怎么用?C++ QRectF::moveCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRectF
的用法示例。
在下文中一共展示了QRectF::moveCenter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rangeOfAttachedObjects
void Guideline::rangeOfAttachedObjects(double& min, double& max) const
{
min = DBL_MAX;
max = -DBL_MAX;
for (RelsList::const_iterator curr = relationships.begin(); curr != relationships.end(); ++curr)
{
QRectF itemRect;
if ((*curr)->shape)
{
itemRect = (*curr)->shape->boundingRect();
itemRect.moveCenter((*curr)->shape->pos());
}
else if ((*curr)->distro)
{
itemRect = (*curr)->distro->boundingRect();
itemRect.moveCenter((*curr)->distro->pos());
}
else if ((*curr)->separation)
{
itemRect = (*curr)->separation->boundingRect();
itemRect.moveCenter((*curr)->separation->pos());
}
if (itemRect.isValid())
{
if (get_dir() == GUIDE_TYPE_HORI)
{
min = qMin(min, itemRect.left());
max = qMax(max, itemRect.right());
}
else
{
min = qMin(min, itemRect.top());
max = qMax(max, itemRect.bottom());
}
}
}
// Cope with the case where there are no attached objects.
if ((min == DBL_MAX) && (max = -DBL_MAX) && canvas())
{
QRectF sceneBounds = canvas()->combinedViewsRect();
if (get_dir() == GUIDE_TYPE_HORI)
{
min = sceneBounds.left();
max = sceneBounds.right();
}
else
{
min = sceneBounds.top();
max = sceneBounds.bottom();
}
}
}
示例2: paintEvent
void ScreenRuler::paintEvent(QPaintEvent * event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
// --- brush 1 ----
QBrush brush(painter.brush());
brush.setColor(QColor(Qt::yellow));
// --- brush 2 ----
//QRadialGradient gradient(50, 50, 50, 50, 50);
//gradient.setColorAt(0, QColor::fromRgbF(0, 1, 0, 1));
//gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
//QBrush brush(gradient);
painter.setBrush(brush);
painter.fillRect(0, 0, width(),height(), QColor(Qt::yellow));
//»Íâ¿ò
QPen pen(painter.pen());
pen.setStyle(Qt::SolidLine);
pen.setWidth(2);
pen.setBrush(Qt::darkGreen);
painter.setPen(pen);
painter.drawPath(m_framePath);
//»¿Ì¶ÈÏß
pen.setWidth(1);
pen.setBrush(Qt::black);
painter.setPen(pen);
painter.drawPath(m_graduationPath);
//»¿Ì¶ÈÎÄ×Ö
QRectF rectText = QRectF(0, 0, 1000, 1000);
for (int i=0; i<m_textPos.size(); i++)
{
rectText.moveCenter(m_textPos[i]);
painter.drawText(rectText, Qt::AlignCenter, QString(tr("%1").arg(i)));
}
//
if (m_bHorizontalRuler)
{
rectText.moveCenter(QPointF(width()/2, height()*3/4));
painter.drawText(rectText, Qt::AlignCenter, m_rulerDescription + tr(" Unit: cm"));
}
else
{
rectText.moveCenter(QPointF(width()/2, height()*3/4));
painter.drawText(rectText, Qt::AlignCenter, tr("Unit: cm"));
}
}
示例3: drawCrossInEllipse
/**
* Calculates and draws a cross inside an ellipse
* @param p Pointer to a QPainter object.
* @param r The rectangle describing the ellipse.
*/
void drawCrossInEllipse(QPainter *p, const QRectF& r)
{
QRectF ellipse = r;
ellipse.moveCenter(QPointF(0, 0));
qreal a = ellipse.width() * 0.5;
qreal b = ellipse.height() * .5;
qreal xc = ellipse.center().x();
qreal yc = ellipse.center().y();
// The first point's x value is chosen to be center.x() + 70% of x radius.
qreal x1 = ellipse.center().x() + .7 * .5 * ellipse.width();
// Calculate y1 corresponding to x1 using formula.
qreal y1_sqr = b*b*(1 - (x1 * x1) / (a*a));
qreal y1 = std::sqrt(y1_sqr);
// Mirror x1, y1 along both the axes to get 4 points for the cross.
QPointF p1(xc + x1, yc + y1);
QPointF p2(xc - x1, yc + y1);
QPointF p3(xc + x1, yc - y1);
QPointF p4(xc - x1, yc - y1);
// Translate as we calculate for ellipse with (0, 0) as center.
p->translate(r.center().x(), r.center().y());
// Draw the cross now
p->drawLine(QLineF(p1, p4));
p->drawLine(QLineF(p2, p3));
// Restore the translate on painter.
p->translate(-r.center().x(), -r.center().y());
}
示例4: 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 );
}
示例5: paintEvent
void SkDrawCommandGeometryWidget::paintEvent(QPaintEvent* event) {
this->QFrame::paintEvent(event);
if (!fSurface) {
return;
}
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
SkImageInfo info;
size_t rowBytes;
if (const void* pixels = fSurface->peekPixels(&info, &rowBytes)) {
SkASSERT(info.width() > 0);
SkASSERT(info.height() > 0);
QRectF resultRect;
if (this->width() < this->height()) {
float ratio = this->width() / info.width();
resultRect = QRectF(0, 0, this->width(), ratio * info.height());
} else {
float ratio = this->height() / info.height();
resultRect = QRectF(0, 0, ratio * info.width(), this->height());
}
resultRect.moveCenter(this->contentsRect().center());
QImage image(reinterpret_cast<const uchar*>(pixels),
info.width(),
info.height(),
rowBytes,
QImage::Format_ARGB32_Premultiplied);
painter.drawImage(resultRect, image);
}
}
示例6: paintEvent
/*!
\brief Paint event
Repaint the grabbed pixmap on its current position and
fill the empty spaces by the background of the parent widget.
\param event Paint event
*/
void QwtPanner::paintEvent( QPaintEvent *event )
{
int dx = d_data->pos.x() - d_data->initialPos.x();
int dy = d_data->pos.y() - d_data->initialPos.y();
QRectF r;
r.setSize( d_data->pixmap.size() / QwtPainter::devicePixelRatio( &d_data->pixmap ) );
r.moveCenter( QPointF( r.center().x() + dx, r.center().y() + dy ) );
QPixmap pm = QwtPainter::backingStore( this, size() );
QwtPainter::fillPixmap( parentWidget(), pm );
QPainter painter( &pm );
if ( !d_data->contentsMask.isNull() )
{
QPixmap masked = d_data->pixmap;
masked.setMask( d_data->contentsMask );
painter.drawPixmap( r.toRect(), masked );
}
else
{
painter.drawPixmap( r.toRect(), d_data->pixmap );
}
painter.end();
if ( !d_data->contentsMask.isNull() )
pm.setMask( d_data->contentsMask );
painter.begin( this );
painter.setClipRegion( event->region() );
painter.drawPixmap( 0, 0, pm );
}
示例7: end
/*!
Expand the selected rectangle to minZoomSize() and zoom in
if accepted.
\sa accept(), minZoomSize()
*/
bool QwtPlotZoomer::end( bool ok )
{
ok = QwtPlotPicker::end( ok );
if ( !ok )
return false;
QwtPlot *plot = QwtPlotZoomer::plot();
if ( !plot )
return false;
const QPolygon &pa = selection();
if ( pa.count() < 2 )
return false;
QRect rect = QRect( pa[0], pa[int( pa.count() - 1 )] );
rect = rect.normalized();
QRectF zoomRect = invTransform( rect ).normalized();
const QSizeF minSize = minZoomSize();
if ( minSize.isValid() )
{
const QPointF center = zoomRect.center();
zoomRect.setSize( zoomRect.size().expandedTo( minZoomSize() ) );
zoomRect.moveCenter( center );
}
zoom( zoomRect );
return true;
}
示例8: renderFormula
void FormulaView::renderFormula( QPainter *painter ) const
{
QwtMathMLDocument doc;
doc.setContent( d_formula );
doc.setBaseFontPointSize( d_fontSize );
QRectF docRect;
docRect.setSize( doc.size() );
docRect.moveCenter( rect().center() );
if ( d_transformation )
{
const double scaleF = d_scale ? 2.0 : 1.0;
painter->save();
painter->translate( docRect.center() );
painter->rotate( d_rotation );
painter->scale( scaleF, scaleF );
painter->translate( docRect.topLeft() - docRect.center() );
doc.paint( painter, QPointF( 0, 0 ) );
painter->restore();
}
else
{
doc.paint( painter, docRect.topLeft().toPoint() );
}
}
示例9: setHighlights
void GraphicsBoard::setHighlights(const QList<Chess::Square>& squares)
{
clearHighlights();
if (squares.isEmpty())
return;
TargetHighlights* targets = new TargetHighlights(this);
QRectF rect;
rect.setSize(QSizeF(m_squareSize / 3, m_squareSize / 3));
rect.moveCenter(QPointF(0, 0));
QPen pen(Qt::white, m_squareSize / 20);
QBrush brush(Qt::black);
for (const auto& sq : squares)
{
QGraphicsEllipseItem* dot = new QGraphicsEllipseItem(rect, targets);
dot->setCacheMode(DeviceCoordinateCache);
dot->setPen(pen);
dot->setBrush(brush);
dot->setPos(squarePos(sq));
}
m_highlightAnim = new QPropertyAnimation(targets, "opacity");
targets->setParent(m_highlightAnim);
m_highlightAnim->setStartValue(0.0);
m_highlightAnim->setEndValue(1.0);
m_highlightAnim->setDuration(500);
m_highlightAnim->setEasingCurve(QEasingCurve::InOutQuad);
m_highlightAnim->start(QAbstractAnimation::KeepWhenStopped);
}
示例10: update
bool DrawingTouch::update(QBrush *color)
{
bool wasVisible = false;
if (ellipse) {
wasVisible = ellipse->isVisible();
ellipse->setVisible(TrackingId() >= 0);
}
else {
ellipse = scene->addEllipse(QRectF(Cx() - radius, Cy() - radius,
2 * radius, 2 * radius));
}
if (TrackingId() >= 0) {
QRectF rect = ellipse->rect();
rect.moveCenter(QPointF(Cx(), Cy()));
ellipse->setRect(rect);
ellipse->setPen(Pressed() ? pressedPen : releasedPen);
if (!wasVisible) {
ellipse->setBrush(*color);
ellipse->show();
return true;
}
}
return false;
}
示例11: positionChanged
void TeachableCirlce::positionChanged(QGraphicsEllipseItem *item, const QPointF &position)
{
QRectF rect = m_ellipseItem->rect();
if (item == m_center)
{
QPointF delta = position - rect.center();
m_teachedPointOnCircle += delta;
rect.moveCenter(position);
}
else if (item == m_pointOnCircle)
{
m_teachedPointOnCircle = position;
QPointF center = rect.center();
QPointF delta = position - center;
double r = sqrt(delta.x() * delta.x() + delta.y() * delta.y());
QPointF p1(center.x() - r, center.y() - r);
QPointF p2(center.x() + r, center.y() + r);
rect = QRectF(p1, p2);
}
m_ellipseItem->setRect(rect);
}
示例12: end
bool PlotZoomer::end(bool ok)
{
// Code here is taken from QwtPlotZoomer. The only modification is around the _zoomMode handling.
ok = QwtPlotPicker::end(ok);
if (!ok)
{
return false;
}
QwtPlot *plot = QwtPlotZoomer::plot();
if (!plot)
{
return false;
}
const QPolygon &pa = selection();
if (pa.count() < 2)
{
return false;
}
QRect rect = QRect(pa[0], pa[int(pa.count() - 1)]);
rect = rect.normalized();
QRectF currentZoomRect = zoomRect();
QRectF zoomRect = invTransform(rect).normalized();
switch (_zoomMode)
{
default:
case ZoomBoth:
// nothing.
break;
case ZoomX:
// Maintain current zoom y and height.
zoomRect.setY(currentZoomRect.y());
zoomRect.setHeight(currentZoomRect.height());
break;
case ZoomY:
// Maintain current zoom x and width.
zoomRect.setX(currentZoomRect.x());
zoomRect.setWidth(currentZoomRect.width());
break;
}
const QSizeF minSize = minZoomSize();
if (minSize.isValid())
{
const QPointF center = zoomRect.center();
zoomRect.setSize(zoomRect.size().expandedTo(minZoomSize()));
zoomRect.moveCenter(center);
}
zoom(zoomRect);
return true;
}
示例13: setObjectSize
void EllipseObject::setObjectSize(qreal width, qreal height)
{
QRectF elRect = rect();
elRect.setWidth(width);
elRect.setHeight(height);
elRect.moveCenter(QPointF(0,0));
setRect(elRect);
}
示例14: setObjectDiameter
void CircleObject::setObjectDiameter(qreal diameter)
{
QRectF circRect;
circRect.setWidth(diameter);
circRect.setHeight(diameter);
circRect.moveCenter(QPointF(0,0));
setRect(circRect);
}
示例15: boundingRect
QRectF Annotation::boundingRect() const
{
QFontMetricsF metrics(font);
QRectF rect = metrics.boundingRect(str);
rect.moveCenter(QPointF(0, y));
rect.adjust(-4, 0, +4, 0);
return rect;
}