Qt 4.8
Macros | Functions | Variables
qmatrix.cpp File Reference
#include "qdatastream.h"
#include "qdebug.h"
#include "qmatrix.h"
#include "qregion.h"
#include "qpainterpath.h"
#include "qvariant.h"
#include <qmath.h>
#include <limits.h>

Go to the source code of this file.

Macros

#define MAPDOUBLE(x, y, nx, ny)
 
#define MAPINT(x, y, nx, ny)
 

Functions

Q_GUI_EXPORT QPainterPath operator* (const QPainterPath &p, const QMatrix &m)
 
QDataStreamoperator<< (QDataStream &s, const QMatrix &m)
 
QDebug operator<< (QDebug dbg, const QMatrix &m)
 
QDataStreamoperator>> (QDataStream &s, QMatrix &m)
 
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath (const QRegion &region)
 

Variables

const qreal deg2rad = qreal(0.017453292519943295769)
 

Macro Definition Documentation

◆ MAPDOUBLE

#define MAPDOUBLE (   x,
  y,
  nx,
  ny 
)
Value:
{ \
qreal fx = x; \
qreal fy = y; \
nx = _m11*fx + _m21*fy + _dx; \
ny = _m12*fx + _m22*fy + _dy; \
}

Definition at line 183 of file qmatrix.cpp.

Referenced by QMatrix::map(), QMatrix::mapRect(), and QMatrix::mapToPolygon().

◆ MAPINT

#define MAPINT (   x,
  y,
  nx,
  ny 
)
Value:
{ \
qreal fx = x; \
qreal fy = y; \
nx = qRound(_m11*fx + _m21*fy + _dx); \
ny = qRound(_m12*fx + _m22*fy + _dy); \
}
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

Definition at line 191 of file qmatrix.cpp.

Referenced by QMatrix::map().

Function Documentation

◆ operator*()

Q_GUI_EXPORT QPainterPath operator* ( const QPainterPath p,
const QMatrix m 
)
related

Definition at line 1200 of file qmatrix.cpp.

1201 {
1202  return m.map(p);
1203 }
void map(int x, int y, int *tx, int *ty) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qmatrix.cpp:384

◆ operator<<() [1/2]

QDataStream& operator<< ( QDataStream s,
const QMatrix m 
)
related

Definition at line 1223 of file qmatrix.cpp.

Referenced by qFuzzyCompare().

1224 {
1225  if (s.version() == 1) {
1226  s << (float)m.m11() << (float)m.m12() << (float)m.m21()
1227  << (float)m.m22() << (float)m.dx() << (float)m.dy();
1228  } else {
1229  s << double(m.m11())
1230  << double(m.m12())
1231  << double(m.m21())
1232  << double(m.m22())
1233  << double(m.dx())
1234  << double(m.dy());
1235  }
1236  return s;
1237 }
qreal dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
qreal m12() const
Returns the vertical shearing factor.
Definition: qmatrix.h:74
qreal m11() const
Returns the horizontal scaling factor.
Definition: qmatrix.h:73
qreal m21() const
Returns the horizontal shearing factor.
Definition: qmatrix.h:75
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
qreal m22() const
Returns the vertical scaling factor.
Definition: qmatrix.h:76

◆ operator<<() [2/2]

QDebug operator<< ( QDebug  dbg,
const QMatrix m 
)

Definition at line 1275 of file qmatrix.cpp.

1276 {
1277  dbg.nospace() << "QMatrix("
1278  << "11=" << m.m11()
1279  << " 12=" << m.m12()
1280  << " 21=" << m.m21()
1281  << " 22=" << m.m22()
1282  << " dx=" << m.dx()
1283  << " dy=" << m.dy()
1284  << ')';
1285  return dbg.space();
1286 }
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 dx() const
Returns the horizontal translation factor.
Definition: qmatrix.h:77
qreal m12() const
Returns the vertical shearing factor.
Definition: qmatrix.h:74
qreal m11() const
Returns the horizontal scaling factor.
Definition: qmatrix.h:73
qreal m21() const
Returns the horizontal shearing factor.
Definition: qmatrix.h:75
qreal dy() const
Returns the vertical translation factor.
Definition: qmatrix.h:78
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
qreal m22() const
Returns the vertical scaling factor.
Definition: qmatrix.h:76

◆ operator>>()

QDataStream& operator>> ( QDataStream s,
QMatrix m 
)
related

Definition at line 1252 of file qmatrix.cpp.

Referenced by qFuzzyCompare().

1253 {
1254  if (s.version() == 1) {
1255  float m11, m12, m21, m22, dx, dy;
1256  s >> m11; s >> m12; s >> m21; s >> m22;
1257  s >> dx; s >> dy;
1258  m.setMatrix(m11, m12, m21, m22, dx, dy);
1259  }
1260  else {
1261  double m11, m12, m21, m22, dx, dy;
1262  s >> m11;
1263  s >> m12;
1264  s >> m21;
1265  s >> m22;
1266  s >> dx;
1267  s >> dy;
1268  m.setMatrix(m11, m12, m21, m22, dx, dy);
1269  }
1270  return s;
1271 }
void setMatrix(qreal m11, qreal m12, qreal m21, qreal m22, qreal dx, qreal dy)
Sets the matrix elements to the specified values, m11, m12, m21, m22, dx and dy.
Definition: qmatrix.cpp:269
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212

◆ qt_regionToPath()

Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath ( const QRegion region)

Definition at line 1160 of file qregion.cpp.

Referenced by QMatrix::map().

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

Variable Documentation

◆ deg2rad

const qreal deg2rad = qreal(0.017453292519943295769)