Qt 4.8
Classes | Functions
qgraphicsitem.cpp File Reference
#include "qgraphicsitem.h"
#include "qgraphicsscene.h"
#include "qgraphicsscene_p.h"
#include "qgraphicssceneevent.h"
#include "qgraphicsview.h"
#include "qgraphicswidget.h"
#include "qgraphicsproxywidget.h"
#include "qgraphicsscenebsptreeindex_p.h"
#include <QtCore/qbitarray.h>
#include <QtCore/qdebug.h>
#include <QtCore/qpoint.h>
#include <QtCore/qstack.h>
#include <QtCore/qtimer.h>
#include <QtCore/qvariant.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/qnumeric.h>
#include <QtGui/qapplication.h>
#include <QtGui/qbitmap.h>
#include <QtGui/qpainter.h>
#include <QtGui/qpainterpath.h>
#include <QtGui/qpixmapcache.h>
#include <QtGui/qstyleoption.h>
#include <QtGui/qevent.h>
#include <QtGui/qinputcontext.h>
#include <QtGui/qgraphicseffect.h>
#include "qaccessible.h"
#include <private/qgraphicsitem_p.h>
#include <private/qgraphicswidget_p.h>
#include <private/qtextcontrol_p.h>
#include <private/qtextdocumentlayout_p.h>
#include <private/qtextengine_p.h>
#include <private/qwidget_p.h>
#include <private/qapplication_p.h>
#include <private/qt_x11_p.h>
#include <private/qpixmap_x11_p.h>
#include <private/qgesturemanager_p.h>
#include <math.h>
#include "moc_qgraphicsitem.cpp"

Go to the source code of this file.

Classes

class  QAbstractGraphicsShapeItemPrivate
 
class  QGraphicsEllipseItemPrivate
 
class  QGraphicsItemCustomDataStore
 
class  QGraphicsItemGroupPrivate
 
class  QGraphicsLineItemPrivate
 
class  QGraphicsPathItemPrivate
 
class  QGraphicsPixmapItemPrivate
 
class  QGraphicsPolygonItemPrivate
 
class  QGraphicsRectItemPrivate
 
class  QGraphicsSimpleTextItemPrivate
 
class  QGraphicsTextItemPrivate
 

Functions

static void _q_adjustRect (QRect *rect)
 
static void _q_qgraphicsItemSetFlag (QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag, bool enabled)
 Sets the flag flag on item and all its children, to enabled. More...
 
bool _qt_movableAncestorIsSelected (const QGraphicsItem *item)
 obsolete More...
 
QDebug operator<< (QDebug debug, QGraphicsItem *item)
 
QDebug operator<< (QDebug debug, QGraphicsObject *item)
 
QDebug operator<< (QDebug debug, QGraphicsItem::GraphicsItemChange change)
 
QDebug operator<< (QDebug debug, QGraphicsItem::GraphicsItemFlag flag)
 
QDebug operator<< (QDebug debug, QGraphicsItem::GraphicsItemFlags flags)
 
static void qt_graphicsItem_highlightSelected (QGraphicsItem *item, QPainter *painter, const QStyleOptionGraphicsItem *option)
 Highlights item as selected. More...
 
static QPainterPath qt_graphicsItem_shapeFromPath (const QPainterPath &path, const QPen &pen)
 Returns a QPainterPath of path when stroked with the pen. More...
 
static bool qt_QGraphicsItem_isObscured (const QGraphicsItem *item, const QGraphicsItem *other, const QRectF &rect)
 Item obscurity helper function. More...
 
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath (const QRegion &region)
 
static QRectF setupTextLayout (QTextLayout *layout)
 

Function Documentation

◆ _q_adjustRect()

static void _q_adjustRect ( QRect rect)
inlinestatic

Definition at line 794 of file qgraphicsitem.cpp.

Referenced by QGraphicsItem::boundingRegion(), QGraphicsItem::collidesWithPath(), QGraphicsScenePrivate::drawItemHelper(), QGraphicsSceneIndexRectIntersector::intersect(), QGraphicsSceneIndexPointIntersector::intersect(), QGraphicsSceneIndexPathIntersector::intersect(), QGraphicsSceneIndex::items(), and QGraphicsScenePrivate::processDirtyItemsRecursive().

795 {
796  Q_ASSERT(rect);
797  if (!rect->width())
798  rect->adjust(0, 0, 1, 0);
799  if (!rect->height())
800  rect->adjust(0, 0, 0, 1);
801 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void adjust(int x1, int y1, int x2, int y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:434

◆ _q_qgraphicsItemSetFlag()

static void _q_qgraphicsItemSetFlag ( QGraphicsItem item,
QGraphicsItem::GraphicsItemFlag  flag,
bool  enabled 
)
static

Sets the flag flag on item and all its children, to enabled.

Warning
This function is not part of the public interface.

Definition at line 1917 of file qgraphicsitem.cpp.

1919 {
1920  if (item->flags() & flag) {
1921  // If this item already has the correct flag set, we don't have to
1922  // propagate it.
1923  return;
1924  }
1925  item->setFlag(flag, enabled);
1926  foreach (QGraphicsItem *child, item->children())
1927  _q_qgraphicsItemSetFlag(child, flag, enabled);
1928 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
void setFlag(GraphicsItemFlag flag, bool enabled=true)
If enabled is true, the item flag flag is enabled; otherwise, it is disabled.
static void _q_qgraphicsItemSetFlag(QGraphicsItem *item, QGraphicsItem::GraphicsItemFlag flag, bool enabled)
Sets the flag flag on item and all its children, to enabled.
QList< QGraphicsItem * > children() const
Use childItems() instead.
#define enabled

◆ _qt_movableAncestorIsSelected()

bool _qt_movableAncestorIsSelected ( const QGraphicsItem item)

obsolete

Definition at line 7523 of file qgraphicsitem.cpp.

Referenced by QGraphicsItemPrivate::movableAncestorIsSelected().

7524 {
7525  const QGraphicsItem *parent = item->parentItem();
7526  return parent && (((parent->flags() & QGraphicsItem::ItemIsMovable) && parent->isSelected()) || _qt_movableAncestorIsSelected(parent));
7527 }
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool isSelected() const
Returns true if this item is selected; otherwise, false is returned.
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
bool _qt_movableAncestorIsSelected(const QGraphicsItem *item)
obsolete

◆ operator<<() [1/5]

QDebug operator<< ( QDebug  debug,
QGraphicsItem item 
)

Definition at line 11946 of file qgraphicsitem.cpp.

Referenced by qgraphicsitem_cast().

11947 {
11948  if (!item) {
11949  debug << "QGraphicsItem(0)";
11950  return debug;
11951  }
11952 
11953  if (QGraphicsObject *o = item->toGraphicsObject())
11954  debug << o->metaObject()->className();
11955  else
11956  debug << "QGraphicsItem";
11957  debug << "(this =" << (void*)item
11958  << ", parent =" << (void*)item->parentItem()
11959  << ", pos =" << item->pos()
11960  << ", z =" << item->zValue() << ", flags = "
11961  << item->flags() << ")";
11962  return debug;
11963 }
QPointF pos() const
Returns the position of the item in parent coordinates.
qreal zValue() const
Returns the Z-value of the item.
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
The QGraphicsObject class provides a base class for all graphics items that require signals...

◆ operator<<() [2/5]

QDebug operator<< ( QDebug  debug,
QGraphicsObject item 
)

Definition at line 11965 of file qgraphicsitem.cpp.

11966 {
11967  if (!item) {
11968  debug << "QGraphicsObject(0)";
11969  return debug;
11970  }
11971 
11972  debug.nospace() << item->metaObject()->className() << '(' << (void*)item;
11973  if (!item->objectName().isEmpty())
11974  debug << ", name = " << item->objectName();
11975  debug.nospace() << ", parent = " << ((void*)item->parentItem())
11976  << ", pos = " << item->pos()
11977  << ", z = " << item->zValue() << ", flags = "
11978  << item->flags() << ')';
11979  return debug.space();
11980 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
qreal zValue() const
Returns the Z-value of the item.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
GraphicsItemFlags flags() const
Returns this item&#39;s flags.
QPointF pos
the position of the item
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
QString objectName() const
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
virtual const QMetaObject * metaObject() const
Returns a pointer to the meta-object of this object.

◆ operator<<() [3/5]

QDebug operator<< ( QDebug  debug,
QGraphicsItem::GraphicsItemChange  change 
)

Definition at line 11982 of file qgraphicsitem.cpp.

11983 {
11984  const char *str = "UnknownChange";
11985  switch (change) {
11987  str = "ItemChildAddedChange";
11988  break;
11990  str = "ItemChildRemovedChange";
11991  break;
11993  str = "ItemCursorChange";
11994  break;
11996  str = "ItemCursorHasChanged";
11997  break;
11999  str = "ItemEnabledChange";
12000  break;
12002  str = "ItemEnabledHasChanged";
12003  break;
12005  str = "ItemFlagsChange";
12006  break;
12008  str = "ItemFlagsHaveChanged";
12009  break;
12011  str = "ItemMatrixChange";
12012  break;
12014  str = "ItemParentChange";
12015  break;
12017  str = "ItemParentHasChanged";
12018  break;
12020  str = "ItemPositionChange";
12021  break;
12023  str = "ItemPositionHasChanged";
12024  break;
12026  str = "ItemSceneChange";
12027  break;
12029  str = "ItemSceneHasChanged";
12030  break;
12032  str = "ItemSelectedChange";
12033  break;
12035  str = "ItemSelectedHasChanged";
12036  break;
12038  str = "ItemToolTipChange";
12039  break;
12041  str = "ItemToolTipHasChanged";
12042  break;
12044  str = "ItemTransformChange";
12045  break;
12047  str = "ItemTransformHasChanged";
12048  break;
12050  str = "ItemVisibleChange";
12051  break;
12053  str = "ItemVisibleHasChanged";
12054  break;
12056  str = "ItemZValueChange";
12057  break;
12059  str = "ItemZValueHasChanged";
12060  break;
12062  str = "ItemOpacityChange";
12063  break;
12065  str = "ItemOpacityHasChanged";
12066  break;
12068  str = "ItemScenePositionHasChanged";
12069  break;
12071  str = "ItemRotationChange";
12072  break;
12074  str = "ItemRotationHasChanged";
12075  break;
12077  str = "ItemScaleChange";
12078  break;
12080  str = "ItemScaleHasChanged";
12081  break;
12083  str = "ItemTransformOriginPointChange";
12084  break;
12086  str = "ItemTransformOriginPointHasChanged";
12087  break;
12088  }
12089  debug << str;
12090  return debug;
12091 }

◆ operator<<() [4/5]

QDebug operator<< ( QDebug  debug,
QGraphicsItem::GraphicsItemFlag  flag 
)

Definition at line 12093 of file qgraphicsitem.cpp.

12094 {
12095  const char *str = "UnknownFlag";
12096  switch (flag) {
12098  str = "ItemIsMovable";
12099  break;
12101  str = "ItemIsSelectable";
12102  break;
12104  str = "ItemIsFocusable";
12105  break;
12107  str = "ItemClipsToShape";
12108  break;
12110  str = "ItemClipsChildrenToShape";
12111  break;
12113  str = "ItemIgnoresTransformations";
12114  break;
12116  str = "ItemIgnoresParentOpacity";
12117  break;
12119  str = "ItemDoesntPropagateOpacityToChildren";
12120  break;
12122  str = "ItemStacksBehindParent";
12123  break;
12125  str = "ItemUsesExtendedStyleOption";
12126  break;
12128  str = "ItemHasNoContents";
12129  break;
12131  str = "ItemSendsGeometryChanges";
12132  break;
12134  str = "ItemAcceptsInputMethod";
12135  break;
12137  str = "ItemNegativeZStacksBehindParent";
12138  break;
12140  str = "ItemIsPanel";
12141  break;
12143  str = "ItemIsFocusScope";
12144  break;
12146  str = "ItemSendsScenePositionChanges";
12147  break;
12149  str = "ItemStopsClickFocusPropagation";
12150  break;
12152  str = "ItemStopsFocusHandling";
12153  break;
12154  }
12155  debug << str;
12156  return debug;
12157 }

◆ operator<<() [5/5]

QDebug operator<< ( QDebug  debug,
QGraphicsItem::GraphicsItemFlags  flags 
)

Definition at line 12159 of file qgraphicsitem.cpp.

12160 {
12161  debug << '(';
12162  bool f = false;
12163  for (int i = 0; i < 17; ++i) {
12164  if (flags & (1 << i)) {
12165  if (f)
12166  debug << '|';
12167  f = true;
12168  debug << QGraphicsItem::GraphicsItemFlag(int(flags & (1 << i)));
12169  }
12170  }
12171  debug << ')';
12172  return debug;
12173 }
GraphicsItemFlag
This enum describes different flags that you can set on an item to toggle different features in the i...
Definition: qgraphicsitem.h:92

◆ qt_graphicsItem_highlightSelected()

static void qt_graphicsItem_highlightSelected ( QGraphicsItem item,
QPainter painter,
const QStyleOptionGraphicsItem option 
)
static

Highlights item as selected.

Warning
This function is not part of the public interface.

NOTE: This function is a duplicate of qt_graphicsItem_highlightSelected() in qgraphicssvgitem.cpp!

Definition at line 8024 of file qgraphicsitem.cpp.

Referenced by QGraphicsPathItem::paint(), QGraphicsRectItem::paint(), QGraphicsEllipseItem::paint(), QGraphicsPolygonItem::paint(), QGraphicsLineItem::paint(), QGraphicsPixmapItem::paint(), QGraphicsTextItem::paint(), and QGraphicsSimpleTextItem::paint().

8026 {
8027  const QRectF murect = painter->transform().mapRect(QRectF(0, 0, 1, 1));
8028  if (qFuzzyIsNull(qMax(murect.width(), murect.height())))
8029  return;
8030 
8031  const QRectF mbrect = painter->transform().mapRect(item->boundingRect());
8032  if (qMin(mbrect.width(), mbrect.height()) < qreal(1.0))
8033  return;
8034 
8035  qreal itemPenWidth;
8036  switch (item->type()) {
8038  itemPenWidth = static_cast<QGraphicsEllipseItem *>(item)->pen().widthF();
8039  break;
8041  itemPenWidth = static_cast<QGraphicsPathItem *>(item)->pen().widthF();
8042  break;
8044  itemPenWidth = static_cast<QGraphicsPolygonItem *>(item)->pen().widthF();
8045  break;
8047  itemPenWidth = static_cast<QGraphicsRectItem *>(item)->pen().widthF();
8048  break;
8050  itemPenWidth = static_cast<QGraphicsSimpleTextItem *>(item)->pen().widthF();
8051  break;
8053  itemPenWidth = static_cast<QGraphicsLineItem *>(item)->pen().widthF();
8054  break;
8055  default:
8056  itemPenWidth = 1.0;
8057  }
8058  const qreal pad = itemPenWidth / 2;
8059 
8060  const qreal penWidth = 0; // cosmetic pen
8061 
8062  const QColor fgcolor = option->palette.windowText().color();
8063  const QColor bgcolor( // ensure good contrast against fgcolor
8064  fgcolor.red() > 127 ? 0 : 255,
8065  fgcolor.green() > 127 ? 0 : 255,
8066  fgcolor.blue() > 127 ? 0 : 255);
8067 
8068  painter->setPen(QPen(bgcolor, penWidth, Qt::SolidLine));
8069  painter->setBrush(Qt::NoBrush);
8070  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
8071 
8072  painter->setPen(QPen(option->palette.windowText(), 0, Qt::DashLine));
8073  painter->setBrush(Qt::NoBrush);
8074  painter->drawRect(item->boundingRect().adjusted(pad, pad, -pad, -pad));
8075 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double qreal
Definition: qglobal.h:1193
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene.
virtual QRectF boundingRect() const =0
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
The QGraphicsEllipseItem class provides an ellipse item that you can add to a QGraphicsScene.
ushort red
Returns the red color component of this color.
Definition: qcolor.h:243
The QGraphicsPolygonItem class provides a polygon item that you can add to a QGraphicsScene.
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
QRect mapRect(const QRect &) const
Creates and returns a QRect object that is a copy of the given rectangle, mapped into the coordinate ...
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
virtual int type() const
Returns the type of an item as an int.
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
const QBrush & windowText() const
Returns the window text (general foreground) brush of the current color group.
Definition: qpalette.h:124
The QGraphicsSimpleTextItem class provides a simple text path item that you can add to a QGraphicsSce...
The QGraphicsLineItem class provides a line item that you can add to a QGraphicsScene.
ushort blue
Returns the blue color component of this color.
Definition: qcolor.h:245
void setBrush(const QBrush &brush)
Sets the painter&#39;s brush to the given brush.
Definition: qpainter.cpp:4171
void setPen(const QColor &color)
Sets the painter&#39;s pen to have style Qt::SolidLine, width 0 and the specified color.
Definition: qpainter.cpp:4047
void drawRect(const QRectF &rect)
Draws the current rectangle with the current pen and brush.
Definition: qpainter.h:650
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043
ushort green
Returns the green color component of this color.
Definition: qcolor.h:244
The QGraphicsPathItem class provides a path item that you can add to a QGraphicsScene.

◆ qt_graphicsItem_shapeFromPath()

static QPainterPath qt_graphicsItem_shapeFromPath ( const QPainterPath path,
const QPen pen 
)
static

Returns a QPainterPath of path when stroked with the pen.

Warning
This function is not part of the public interface.

Ignoring dash pattern.

Definition at line 822 of file qgraphicsitem.cpp.

Referenced by QGraphicsPathItem::shape(), QGraphicsRectItem::shape(), QGraphicsEllipseItem::shape(), QGraphicsPolygonItem::shape(), and QGraphicsLineItem::shape().

823 {
824  // We unfortunately need this hack as QPainterPathStroker will set a width of 1.0
825  // if we pass a value of 0.0 to QPainterPathStroker::setWidth()
826  const qreal penWidthZero = qreal(0.00000001);
827 
828  if (path == QPainterPath())
829  return path;
831  ps.setCapStyle(pen.capStyle());
832  if (pen.widthF() <= 0.0)
833  ps.setWidth(penWidthZero);
834  else
835  ps.setWidth(pen.widthF());
836  ps.setJoinStyle(pen.joinStyle());
837  ps.setMiterLimit(pen.miterLimit());
838  QPainterPath p = ps.createStroke(path);
839  p.addPath(path);
840  return p;
841 }
void addPath(const QPainterPath &path)
Adds the given path to this path as a closed subpath.
double qreal
Definition: qglobal.h:1193
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setCapStyle(Qt::PenCapStyle style)
Sets the cap style of the generated outlines to style.
void setMiterLimit(qreal length)
Sets the miter limit of the generated outlines to limit.
QPainterPath createStroke(const QPainterPath &path) const
Generates a new path that is a fillable area representing the outline of the given path...
Qt::PenJoinStyle joinStyle() const
Returns the pen&#39;s join style.
Definition: qpen.cpp:736
The QPainterPathStroker class is used to generate fillable outlines for a given painter path...
Definition: qpainterpath.h:264
qreal miterLimit() const
Returns the miter limit of the pen.
Definition: qpen.cpp:589
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style of the generated outlines to style.
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
Qt::PenCapStyle capStyle() const
Returns the pen&#39;s cap style.
Definition: qpen.cpp:706
void setWidth(qreal width)
Sets the width of the generated outline painter path to width.

◆ qt_QGraphicsItem_isObscured()

static bool qt_QGraphicsItem_isObscured ( const QGraphicsItem item,
const QGraphicsItem other,
const QRectF rect 
)
static

Item obscurity helper function.

Warning
This function is not part of the public interface.

Returns true if the subrect rect of item's bounding rect is obscured by other (i.e., other's opaque area covers item's rect completely. other is assumed to already be "on top of" item wrt. stacking order.

Definition at line 5430 of file qgraphicsitem.cpp.

Referenced by QGraphicsItem::isObscured(), and QGraphicsItem::isObscuredBy().

5433 {
5434  return other->mapToItem(item, other->opaqueArea()).contains(rect);
5435 }
virtual QPainterPath opaqueArea() const
This virtual function returns a shape representing the area where this item is opaque.
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...

◆ qt_regionToPath()

Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath ( const QRegion region)

Definition at line 1160 of file qregion.cpp.

Referenced by QGraphicsLineItem::extension(), QGraphicsPixmapItemPrivate::updateShape(), and QX11PaintEngine::updateState().

1161 {
1162  QPainterPath result;
1163  if (region.rectCount() == 1) {
1164  result.addRect(region.boundingRect());
1165  return result;
1166  }
1167 
1168  const QVector<QRect> rects = region.rects();
1169 
1170  QVarLengthArray<Segment> segments;
1171  segments.resize(4 * rects.size());
1172 
1173  const QRect *rect = rects.constData();
1174  const QRect *end = rect + rects.size();
1175 
1176  int lastRowSegmentCount = 0;
1177  Segment *lastRowSegments = 0;
1178 
1179  int lastSegment = 0;
1180  int lastY = 0;
1181  while (rect != end) {
1182  const int y = rect[0].y();
1183  int count = 0;
1184  while (&rect[count] != end && rect[count].y() == y)
1185  ++count;
1186 
1187  for (int i = 0; i < count; ++i) {
1188  int offset = lastSegment + i;
1189  segments[offset] = Segment(rect[i].topLeft());
1190  segments[offset += count] = Segment(rect[i].topRight() + QPoint(1, 0));
1191  segments[offset += count] = Segment(rect[i].bottomRight() + QPoint(1, 1));
1192  segments[offset += count] = Segment(rect[i].bottomLeft() + QPoint(0, 1));
1193 
1194  offset = lastSegment + i;
1195  for (int j = 0; j < 4; ++j)
1196  segments[offset + j * count].connect(segments[offset + ((j + 1) % 4) * count]);
1197  }
1198 
1199  if (lastRowSegments && lastY == y)
1200  mergeSegments(lastRowSegments, lastRowSegmentCount, &segments[lastSegment], count);
1201 
1202  lastRowSegments = &segments[lastSegment + 2 * count];
1203  lastRowSegmentCount = count;
1204  lastSegment += 4 * count;
1205  lastY = y + rect[0].height();
1206  rect += count;
1207  }
1208 
1209  for (int i = 0; i < lastSegment; ++i) {
1210  Segment *segment = &segments[i];
1211  if (!segment->added)
1212  addSegmentsToPath(segment, result);
1213  }
1214 
1215  return result;
1216 }
void resize(int size)
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
int rectCount() const
Returns the number of rectangles that will be returned in rects().
Definition: qregion.cpp:4461
void addRect(const QRectF &rect)
Adds the given rectangle to this path as a closed subpath.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
const T * constData() const
Returns a const pointer to the data stored in the vector.
Definition: qvector.h:154
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ setupTextLayout()

static QRectF setupTextLayout ( QTextLayout layout)
static

Definition at line 11269 of file qgraphicsitem.cpp.

Referenced by QGraphicsSimpleTextItem::paint(), QGraphicsSimpleTextItemPrivate::updateBoundingRect(), and QDeclarativeTextPrivate::updateSize().

11270 {
11271  layout->setCacheEnabled(true);
11272  layout->beginLayout();
11273  while (layout->createLine().isValid())
11274  ;
11275  layout->endLayout();
11276  qreal maxWidth = 0;
11277  qreal y = 0;
11278  for (int i = 0; i < layout->lineCount(); ++i) {
11279  QTextLine line = layout->lineAt(i);
11280  maxWidth = qMax(maxWidth, line.naturalTextWidth());
11281  line.setPosition(QPointF(0, y));
11282  y += line.height();
11283  }
11284  return QRectF(0, 0, maxWidth, y);
11285 }
double qreal
Definition: qglobal.h:1193
void setPosition(const QPointF &pos)
Moves the line to position pos.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QTextLine class represents a line of text inside a QTextLayout.
Definition: qtextlayout.h:197
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
QTextLine lineAt(int i) const
Returns the {i}-th line of text in this text layout.
QTextLine createLine()
Returns a new text line to be laid out if there is text to be inserted into the layout; otherwise ret...
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
void setCacheEnabled(bool enable)
Enables caching of the complete layout information if enable is true; otherwise disables layout cachi...
void endLayout()
Ends the layout process.
qreal height() const
Returns the line&#39;s height.
void beginLayout()
Begins the layout process.
int lineCount() const
Returns the number of lines in this text layout.