本文整理汇总了C++中QRectF::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::translate方法的具体用法?C++ QRectF::translate怎么用?C++ QRectF::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRectF
的用法示例。
在下文中一共展示了QRectF::translate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Padding
QRectF
dmz::QtCanvasObjectText::_outline_rect () const {
QRectF rect;
if (_text.length ()) {
const int Padding (8);
QFontMetricsF metrics = qApp->font ();
rect.setSize (metrics.size (0, _text));
if (_drawBackground) {
rect.adjust (-Padding, -Padding, Padding, Padding);
}
if (_alignment == Qt::AlignLeft) {
rect.translate (0, -rect.center ().y ());
}
else if (_alignment == Qt::AlignRight) {
rect.translate (-rect.width (), -rect.center ().y ());
}
else {
rect.translate (-rect.center ());
}
}
return rect;
}
示例2: switch
QPainterPath
Shapes::max(const QRectF &bound, Style style)
{
_S(3) _S(4) _S(8)
QPainterPath path;
switch (style)
{
case Square:
path.addRect(bound);
path.addRect(bound.adjusted(0, s4, -s4, 0));
path.addRect(bound.adjusted(0, 2*s3, -2*s3, 0));
break;
case LasseKongo:
{
_S(5);
const float d = 3*s5;
QRectF rect = bound.adjusted(0,0,-d,-d);
QRectF rect2(0,0,d,d);
path.addRect(rect);
rect2.moveCenter(rect.bottomRight());
path.moveTo(rect2.center()); path.arcTo(rect2, 90, 90); path.closeSubpath();
rect.translate(d,0);
path.addRect(rect);
rect2.moveCenter(rect.bottomLeft());
path.moveTo(rect2.center()); path.arcTo(rect2, 0, 90); path.closeSubpath();
rect.translate(0,d);
path.addRect(rect);
rect2.moveCenter(rect.topLeft());
path.moveTo(rect2.center()); path.arcTo(rect2, -90, 90); path.closeSubpath();
rect.translate(-d,0);
path.addRect(rect);
rect2.moveCenter(rect.topRight());
path.moveTo(rect2.center()); path.arcTo(rect2, -180, 90); path.closeSubpath();
break;
}
default:
case Round:
//path.moveTo(bound.center());
//path.arcTo(bound, 0, 180);
//path.closeSubpath();
break;
case TheRob:
path.moveTo(bound.center());
path.arcTo(bound, 0, 180);
path.closeSubpath();
path.moveTo(bound.center());
path.arcTo(bound.adjusted(s8,s8,-s8,-s8), 0, 180);
path.closeSubpath();
path.addEllipse(bound.adjusted(s4,s4,-s4,-s4));
break;
}
return path;
}
示例3: intersectShapeWithLine
bool DiagramItem::intersectShapeWithLine(const QLineF &line, QPointF *intersectionPoint, QLineF *intersectionLine) const
{
QPolygonF polygon;
if (m_customIcon) {
// TODO use customIcon path as shape
QRectF rect = object()->rect();
rect.translate(object()->pos());
polygon << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.bottomLeft() << rect.topLeft();
} else {
QRectF rect = object()->rect();
rect.translate(object()->pos());
polygon << rect.topLeft() << rect.topRight() << rect.bottomRight() << rect.bottomLeft() << rect.topLeft();
}
return GeometryUtilities::intersect(polygon, line, intersectionPoint, intersectionLine);
}
示例4: 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;
}
}
示例5: syncWithMapObject
void MapObjectItem::syncWithMapObject()
{
// Update the whole object when the name or type has changed
if (mObject->name() != mName || mObject->type() != mType) {
mName = mObject->name();
mType = mObject->type();
update();
mResizeHandle->update();
}
QString toolTip = mName;
if (!mType.isEmpty())
toolTip += QLatin1String(" (") + mType + QLatin1String(")");
setToolTip(toolTip);
MapRenderer *renderer = mMapDocument->renderer();
const QPointF pixelPos = renderer->tileToPixelCoords(mObject->position());
QRectF bounds = renderer->boundingRect(mObject);
bounds.translate(-pixelPos);
mSyncing = true;
setPos(pixelPos);
if (mBoundingRect != bounds) {
// Notify the graphics scene about the geometry change in advance
prepareGeometryChange();
mBoundingRect = bounds;
const QPointF bottomRight = mObject->bounds().bottomRight();
const QPointF handlePos = renderer->tileToPixelCoords(bottomRight);
mResizeHandle->setPos(handlePos - pixelPos);
}
mSyncing = false;
}
示例6: boundingRect
/*!
Returns the smallest rectangle that contains all glyphs in this QGlyphRun. If a bounding rect
has been set using setBoundingRect(), then this will be returned. Otherwise the bounding rect
will be calculated based on the font metrics of the glyphs in the glyph run.
\since 5.0
*/
QRectF QGlyphRun::boundingRect() const
{
if (!d->boundingRect.isEmpty() || !d->rawFont.isValid())
return d->boundingRect;
qreal minX, minY, maxX, maxY;
minX = minY = maxX = maxY = 0;
for (int i = 0, n = qMin(d->glyphIndexDataSize, d->glyphPositionDataSize); i < n; ++i) {
QRectF glyphRect = d->rawFont.boundingRect(d->glyphIndexData[i]);
glyphRect.translate(d->glyphPositionData[i]);
if (i == 0) {
minX = glyphRect.left();
minY = glyphRect.top();
maxX = glyphRect.right();
maxY = glyphRect.bottom();
} else {
minX = qMin(glyphRect.left(), minX);
minY = qMin(glyphRect.top(), minY);
maxX = qMax(glyphRect.right(),maxX);
maxY = qMax(glyphRect.bottom(), maxY);
}
}
return QRectF(QPointF(minX, minY), QPointF(maxX, maxY));
}
示例7: addTeteToMinMax
void ChatNode::addTeteToMinMax(Tete* tete,
float* min_x, float* min_y,
float* max_x, float* max_y) {
//return;
if(tete == NULL)
return;
if(tete->tete_node() == NULL)
return;
QRectF local_bound = tete->tete_node()->boundingRect();
QRectF bound = local_bound;
bound.moveTo(tete->tete_node()->pos());
bound.translate(-local_bound.width()/2,-local_bound.height()/2);
//std::cerr << bound.topLeft().y() << " " << *min_y << std::endl;
if(bound.topLeft().x() < *min_x)
*min_x = bound.topLeft().x();
if(bound.topLeft().y() < *min_y)
*min_y = bound.topLeft().y();
if(bound.bottomRight().x() > *max_x)
*max_x = bound.bottomRight().x();
if(bound.bottomRight().y() > *max_y)
*max_y = bound.bottomRight().y();
}
示例8: updateAllTetesRect
void ChatNode::updateAllTetesRect(){
std::vector<Tete*> tetes = chat_->tetes();
if(tetes.empty()){
all_tetes_rect_ = QRectF(-1, -1, 2, 2);
return;
}
TeteNode* first_node = NULL;
// Find the first non-null node
for(unsigned int i = 0u; first_node == NULL; i++){
first_node = tetes[i]->tete_node();
}
QRectF local_bound = first_node->boundingRect();
QRectF bound = local_bound;
bound.moveTo(first_node->pos());
// Translate more due to text
bound.translate(-local_bound.width()/2,-local_bound.height()/2);
float min_x = bound.topLeft().x();
float min_y = bound.topLeft().y();
float max_x = bound.bottomRight().x();
float max_y = bound.bottomRight().y();
for(std::vector<Tete*>::const_iterator it = tetes.begin(); it != tetes.end(); ++it){
addTeteToMinMax(*it, &min_x, &min_y, &max_x, &max_y);
}
all_tetes_rect_ = QRectF(QPointF(min_x, min_y),
QPointF(max_x, max_y)).normalized();
}
示例9: frameRect
QRectF frameRect(const QRectF &area, const QPoint &off = {0, 0}, QRectF *letterbox = nullptr) {
QRectF rect = area;
if (p->hasFrame()) {
const double aspect = p->targetAspectRatio();
QSizeF frame(aspect, 1.0), letter(p->targetCropRatio(aspect), 1.0);
letter.scale(area.width(), area.height(), Qt::KeepAspectRatio);
frame.scale(letter, Qt::KeepAspectRatioByExpanding);
QPointF pos(area.x(), area.y());
pos.rx() += (area.width() - frame.width())*0.5;
pos.ry() += (area.height() - frame.height())*0.5;
rect = {pos, frame};
QPointF xy(area.width(), area.height());
xy.rx() -= letter.width(); xy.ry() -= letter.height(); xy *= 0.5;
QPointF offset = off;
offset.rx() *= letter.width()/100.0;
offset.ry() *= letter.height()/100.0;
if (alignment & Qt::AlignLeft)
offset.rx() -= xy.x();
else if (alignment & Qt::AlignRight)
offset.rx() += xy.x();
if (alignment & Qt::AlignTop)
offset.ry() -= xy.y();
else if (alignment & Qt::AlignBottom)
offset.ry() += xy.y();
rect.translate(offset);
xy += offset;
if (letterbox)
*letterbox = {xy, letter};
}
return rect;
}
示例10: expandByChildren
void ResizeHandler::expandByChildren(QRectF &contents) const
{
QVector<int> const sizeOfForestalling = mElementType.sizeOfForestalling();
for (const QGraphicsItem * const childItem : mTargetNode.childItems()) {
QRectF curChildItemBoundingRect = childBoundingRect(childItem, contents);
if (curChildItemBoundingRect.width() == 0 || curChildItemBoundingRect.height() == 0) {
continue;
}
// it seems to be more appropriate to use childItem->pos() but it causes
// bad behaviour when dropping one element to another
curChildItemBoundingRect.translate(childItem->scenePos() - mTargetNode.scenePos());
contents.setLeft(qMin(curChildItemBoundingRect.left() - sizeOfForestalling[0]
, contents.left()));
contents.setRight(qMax(curChildItemBoundingRect.right() + sizeOfForestalling[2]
, contents.right()));
contents.setTop(qMin(curChildItemBoundingRect.top() - sizeOfForestalling[1]
, contents.top()));
contents.setBottom(qMax(curChildItemBoundingRect.bottom() + sizeOfForestalling[3]
, contents.bottom()));
}
}
示例11: paint
void QAttribute::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Rettangolo
if (selct)// se selezionato allora .
painter->fillRect(boundingRect(),QColor(255,19,0,125)); // riempo tutto il rettangolo di rosso.
QRectF Rect = boundingRect();// ottengo il rettangolo
qreal bx =(Rect.width()/6)+(Rect.width()/8);
qreal by =(Rect.height()*(80))/100 ;
qreal ox =(Rect.left()+Rect.width()/2.8);
qreal oy =Rect.topLeft().y()+Rect.height()-by ;
painter->fillRect(ox+1,oy+11,bx-1,by-12,Qt::white);
// Testo
QRectF *typetext = new QRectF();
painter->drawText(QRectF(Rect.x(),oy-25,Rect.width(),30),Qt::AlignCenter,attribute->Caption(),typetext);
qreal px = typetext->left()+this->attribute->getCaptionWidth();
qreal py = typetext->top()+this->attribute->getCaptionHeight();
typetext->translate(20,typetext->height()+1);
typetext->setLeft(Rect.x()+16);
painter->drawText(*typetext,attribute->GetattributeTypeStr(),QTextOption(Qt::AlignVCenter));
painter->drawRect(ox,oy+10,bx,by-11);
if (this->grabRefer->GrabberItem()==this)
painter->drawLine(px,py,px+5,py);
// inserire tipo ....
// draw right and left arrow that permit to change type.
}
示例12: boundingRect
QRectF OrthogonalRenderer::boundingRect(const MapObject *object) const
{
const QRectF bounds = object->bounds();
const QRectF rect(tileToPixelCoords(bounds.topLeft()),
tileToPixelCoords(bounds.bottomRight()));
///如果有路径就取路径的外框盒
if(object->getPoly()!=NULL)
{
QRectF rect= object->getPoly()->boundingRect();
rect.translate(this->tileToPixelCoords(object->position()));
return rect;
}
// The -2 and +3 are to account for the pen width and shadow
if (object->tile()) {
const QPointF bottomLeft = rect.topLeft();
const QPixmap &img = object->tile()->image();
return QRectF(bottomLeft.x(),
bottomLeft.y() - img.height(),
img.width(),
img.height()).adjusted(-1, -1, 1, 1);
} else if (rect.isNull()) {
return rect.adjusted(-10 - 2, -10 - 2, 10 + 3, 10 + 3);
} else {
const int nameHeight = object->name().isEmpty() ? 0 : 15;
return rect.adjusted(-2, -nameHeight - 2, 3, 3);
}
}
示例13: insert
void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState,
QQuickTextNode::Decorations decorations, const QColor &textColor,
const QColor &backgroundColor, const QPointF &position)
{
QRectF searchRect = glyphRun.boundingRect();
searchRect.translate(position);
if (qFuzzyIsNull(searchRect.width()) || qFuzzyIsNull(searchRect.height()))
return;
decorations |= (glyphRun.underline() ? QQuickTextNode::Underline : QQuickTextNode::NoDecoration);
decorations |= (glyphRun.overline() ? QQuickTextNode::Overline : QQuickTextNode::NoDecoration);
decorations |= (glyphRun.strikeOut() ? QQuickTextNode::StrikeOut : QQuickTextNode::NoDecoration);
decorations |= (backgroundColor.isValid() ? QQuickTextNode::Background : QQuickTextNode::NoDecoration);
qreal ascent = glyphRun.rawFont().ascent();
insert(binaryTree, BinaryTreeNode(glyphRun,
selectionState,
searchRect,
decorations,
textColor,
backgroundColor,
position,
ascent));
}
示例14: layout
void SquareRootElement::layout( const AttributeManager* am )
{
RowElement::layout( am );
qreal thinSpace = am->layoutSpacing( this );
qreal symbolHeight = baseLine();
if( height() > symbolHeight*1.3 ) symbolHeight = height();
symbolHeight += thinSpace;
qreal tickWidth = symbolHeight / 3.0;
m_lineThickness = am->lineThickness(this);
// Set the sqrt dimensions
QPointF childOffset( tickWidth + thinSpace, thinSpace + m_lineThickness );
setWidth( width() + childOffset.x());
setHeight( height() + childOffset.y());
setBaseLine( baseLine() + childOffset.y());
// Adapt the children's positions to the new offset
foreach( BasicElement* element, childElements() )
element->setOrigin( element->origin() + childOffset );
QRectF rect = childrenBoundingRect();
rect.translate(childOffset);
setChildrenBoundingRect(rect);
// Draw the sqrt symbol into a QPainterPath as buffer
m_rootSymbol = QPainterPath();
m_rootSymbol.moveTo( m_lineThickness, 2.0 * symbolHeight / 3.0 );
m_rootSymbol.lineTo( 0 + tickWidth/2.0, symbolHeight-m_lineThickness/2 );
m_rootSymbol.lineTo( 0 + tickWidth, m_lineThickness/2 );
m_rootSymbol.lineTo( width() - m_lineThickness/2, m_lineThickness/2 );
}
示例15: editedRoleChanged
void KStandardItemListWidget::editedRoleChanged(const QByteArray& current, const QByteArray& previous)
{
Q_UNUSED(previous);
QGraphicsView* parent = scene()->views()[0];
if (current.isEmpty() || !parent || current != "text") {
if (m_roleEditor) {
emit roleEditingCanceled(index(), current, data().value(current));
disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
m_roleEditor->deleteLater();
m_roleEditor = 0;
}
return;
}
Q_ASSERT(!m_roleEditor);
const TextInfo* textInfo = m_textInfo.value("text");
m_roleEditor = new KItemListRoleEditor(parent);
m_roleEditor->setIndex(index());
m_roleEditor->setRole(current);
m_roleEditor->setFont(styleOption().font);
const QString text = data().value(current).toString();
m_roleEditor->setPlainText(text);
QTextOption textOption = textInfo->staticText.textOption();
m_roleEditor->document()->setDefaultTextOption(textOption);
const int textSelectionLength = selectionLength(text);
if (textSelectionLength > 0) {
QTextCursor cursor = m_roleEditor->textCursor();
cursor.movePosition(QTextCursor::StartOfBlock);
cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, textSelectionLength);
m_roleEditor->setTextCursor(cursor);
}
connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
// Adjust the geometry of the editor
QRectF rect = roleEditingRect(current);
const int frameWidth = m_roleEditor->frameWidth();
rect.adjust(-frameWidth, -frameWidth, frameWidth, frameWidth);
rect.translate(pos());
if (rect.right() > parent->width()) {
rect.setWidth(parent->width() - rect.left());
}
m_roleEditor->setGeometry(rect.toRect());
m_roleEditor->show();
m_roleEditor->setFocus();
}