Qt 4.8
Classes | Macros | Typedefs | Functions
qpainter.cpp File Reference
#include <qdebug.h>
#include <qmath.h>
#include <qmutex.h>
#include "qbitmap.h"
#include "qimage.h"
#include "qpaintdevice.h"
#include "qpaintengine.h"
#include "qpainter.h"
#include "qpainter_p.h"
#include "qpainterpath.h"
#include "qpicture.h"
#include "qpixmapcache.h"
#include "qpolygon.h"
#include "qtextlayout.h"
#include "qwidget.h"
#include "qapplication.h"
#include "qstyle.h"
#include "qthread.h"
#include "qvarlengtharray.h"
#include "qstatictext.h"
#include "qglyphrun.h"
#include <private/qfontengine_p.h>
#include <private/qpaintengine_p.h>
#include <private/qemulationpaintengine_p.h>
#include <private/qpainterpath_p.h>
#include <private/qtextengine_p.h>
#include <private/qwidget_p.h>
#include <private/qpaintengine_raster_p.h>
#include <private/qmath_p.h>
#include <private/qstatictext_p.h>
#include <private/qglyphrun_p.h>
#include <private/qstylehelper_p.h>
#include <private/qrawfont_p.h>

Go to the source code of this file.

Classes

struct  QPaintDeviceRedirection
 

Macros

#define QGradient_StretchToDevice   0x10000000
 
#define QPaintEngine_OpaqueBackground   0x40000000
 

Typedefs

typedef QList< QPaintDeviceRedirectionQPaintDeviceRedirectionList
 

Functions

static bool check_gradient (const QBrush &brush)
 
static QGradient::CoordinateMode coordinateMode (const QBrush &brush)
 
static void drawTextItemDecoration (QPainter *painter, const QPointF &pos, const QFontEngine *fe, QTextCharFormat::UnderlineStyle underlineStyle, QTextItem::RenderFlags flags, qreal width, const QTextCharFormat &charFormat)
 
static QPixmap generateWavyPixmap (qreal maxRadius, const QPen &pen)
 
static bool is_brush_transparent (const QBrush &brush)
 
static bool is_pen_transparent (const QPen &pen)
 
static uint line_emulation (uint emulation)
 
static bool needsResolving (const QBrush &brush)
 
bool qHasPixmapTexture (const QBrush &)
 
static void qt_cleanup_painter_state (QPainterPrivate *d)
 
Q_GUI_EXPORT void qt_draw_decoration_for_glyphs (QPainter *painter, const glyph_t *glyphArray, const QFixedPoint *positions, int glyphCount, QFontEngine *fontEngine, const QFont &font, const QTextCharFormat &charFormat)
 
void qt_draw_helper (QPainterPrivate *p, const QPainterPath &path, QPainterPrivate::DrawOperation operation)
 
void qt_format_text (const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
 
void qt_format_text (const QFont &fnt, const QRectF &_r, int tf, const QString &str, QRectF *brect, int tabstops, int *ta, int tabarraylen, QPainter *painter)
 
Q_GUI_EXPORT bool qt_isExtendedRadialGradient (const QBrush &brush)
 
void qt_painter_removePaintDevice (QPaintDevice *dev)
 
static bool qt_painter_thread_test (int devType, const char *what, bool extraCondition=false)
 
QPixmap qt_pixmapForBrush (int style, bool invert)
 
Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath (const QRegion &region)
 
static QPointF roundInDeviceCoordinates (const QPointF &p, const QTransform &m)
 
static QBrush stretchGradientToUserSpace (const QBrush &brush, const QRectF &boundingRect)
 

Macro Definition Documentation

◆ QGradient_StretchToDevice

#define QGradient_StretchToDevice   0x10000000

◆ QPaintEngine_OpaqueBackground

#define QPaintEngine_OpaqueBackground   0x40000000

Typedef Documentation

◆ QPaintDeviceRedirectionList

Definition at line 8262 of file qpainter.cpp.

Function Documentation

◆ check_gradient()

static bool check_gradient ( const QBrush brush)
inlinestatic

Definition at line 120 of file qpainter.cpp.

121 {
123 }
static QGradient::CoordinateMode coordinateMode(const QBrush &brush)
Definition: qpainter.cpp:106

◆ coordinateMode()

static QGradient::CoordinateMode coordinateMode ( const QBrush brush)
inlinestatic

Definition at line 106 of file qpainter.cpp.

Referenced by check_gradient(), QPainterPrivate::drawStretchedGradient(), QGradient::spread(), and QPainterPrivate::updateEmulationSpecifier().

107 {
108  switch (brush.style()) {
112  return brush.gradient()->coordinateMode();
113  default:
114  ;
115  }
116  return QGradient::LogicalMode;
117 }
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182

◆ drawTextItemDecoration()

static void drawTextItemDecoration ( QPainter painter,
const QPointF pos,
const QFontEngine fe,
QTextCharFormat::UnderlineStyle  underlineStyle,
QTextItem::RenderFlags  flags,
qreal  width,
const QTextCharFormat charFormat 
)
static

Definition at line 6738 of file qpainter.cpp.

Referenced by QPainterPrivate::drawGlyphs(), QPainter::drawTextItem(), and qt_draw_decoration_for_glyphs().

6742 {
6743  if (underlineStyle == QTextCharFormat::NoUnderline
6744  && !(flags & (QTextItem::StrikeOut | QTextItem::Overline)))
6745  return;
6746 
6747  const QPen oldPen = painter->pen();
6748  const QBrush oldBrush = painter->brush();
6749  painter->setBrush(Qt::NoBrush);
6750  QPen pen = oldPen;
6751  pen.setStyle(Qt::SolidLine);
6752  pen.setWidthF(fe->lineThickness().toReal());
6753  pen.setCapStyle(Qt::FlatCap);
6754 
6755  QLineF line(pos.x(), pos.y(), pos.x() + qFloor(width), pos.y());
6756 
6757  qreal underlineOffset = fe->underlinePosition().toReal();
6758  qreal y = pos.y();
6759  // compensate for different rounding rule in Core Graphics paint engine,
6760  // ideally code like this should be moved to respective engines.
6761  if (painter->paintEngine()->type() == QPaintEngine::CoreGraphics) {
6762  y = qCeil(y);
6763  }
6764  // deliberately ceil the offset to avoid the underline coming too close to
6765  // the text above it.
6766  const qreal underlinePos = y + qCeil(underlineOffset);
6767 
6768  if (underlineStyle == QTextCharFormat::SpellCheckUnderline) {
6770  }
6771 
6772  if (underlineStyle == QTextCharFormat::WaveUnderline) {
6773  painter->save();
6774  painter->translate(0, pos.y() + 1);
6775 
6776  QColor uc = charFormat.underlineColor();
6777  if (uc.isValid())
6778  pen.setColor(uc);
6779 
6780  // Adapt wave to underlineOffset or pen width, whatever is larger, to make it work on all platforms
6781  const QPixmap wave = generateWavyPixmap(qMax(underlineOffset, pen.widthF()), pen);
6782  const int descent = (int) fe->descent().toReal();
6783 
6784  painter->setBrushOrigin(painter->brushOrigin().x(), 0);
6785  painter->fillRect(pos.x(), 0, qCeil(width), qMin(wave.height(), descent), wave);
6786  painter->restore();
6787  } else if (underlineStyle != QTextCharFormat::NoUnderline) {
6788  QLineF underLine(line.x1(), underlinePos, line.x2(), underlinePos);
6789 
6790  QColor uc = charFormat.underlineColor();
6791  if (uc.isValid())
6792  pen.setColor(uc);
6793 
6794  pen.setStyle((Qt::PenStyle)(underlineStyle));
6795  painter->setPen(pen);
6796  painter->drawLine(underLine);
6797  }
6798 
6799  pen.setStyle(Qt::SolidLine);
6800  pen.setColor(oldPen.color());
6801 
6802  if (flags & QTextItem::StrikeOut) {
6803  QLineF strikeOutLine = line;
6804  strikeOutLine.translate(0., - fe->ascent().toReal() / 3.);
6805  painter->setPen(pen);
6806  painter->drawLine(strikeOutLine);
6807  }
6808 
6809  if (flags & QTextItem::Overline) {
6810  QLineF overLine = line;
6811  overLine.translate(0., - fe->ascent().toReal());
6812  painter->setPen(pen);
6813  painter->drawLine(overLine);
6814  }
6815 
6816  painter->setPen(oldPen);
6817  painter->setBrush(oldBrush);
6818 }
virtual QFixed lineThickness() const
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
int qCeil(qreal v)
Definition: qmath.h:63
QColor underlineColor() const
Returns the color used to underline the characters with this format.
Definition: qtextformat.h:448
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
int qFloor(qreal v)
Definition: qmath.h:73
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
static QStyle * style()
Returns the application&#39;s style object.
void drawLine(const QLineF &line)
Draws a line defined by line.
Definition: qpainter.h:573
The QPen class defines how a QPainter should draw lines and outlines of shapes.
Definition: qpen.h:64
void setBrushOrigin(int x, int y)
Sets the brush&#39;s origin to point (x, y).
Definition: qpainter.h:825
PenStyle
Definition: qnamespace.h:1134
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:212
void setColor(const QColor &color)
Sets the color of this pen&#39;s brush to the given color.
Definition: qpen.cpp:787
void translate(const QPointF &p)
Translates this line by the given offset.
Definition: qline.h:339
const QPen & pen() const
Returns the painter&#39;s current pen.
Definition: qpainter.cpp:4152
UnderlineStyle
This enum describes the different ways drawing underlined text.
Definition: qtextformat.h:384
QPoint brushOrigin() const
Returns the currently set brush origin.
Definition: qpainter.cpp:2168
virtual QFixed ascent() const =0
virtual Type type() const =0
Reimplement this function to return the paint engine Type.
virtual QFixed descent() const =0
const char * styleHint(const QFontDef &request)
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
const QBrush & brush() const
Returns the painter&#39;s current brush.
Definition: qpainter.cpp:4232
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
void setWidthF(qreal width)
Sets the pen width to the given width in pixels with floating point precision.
Definition: qpen.cpp:690
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
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
qreal toReal() const
Definition: qfixed_p.h:77
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen)
Definition: qpainter.cpp:6687
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool isValid() const
Returns true if the color is valid; otherwise returns false.
Definition: qcolor.h:295
virtual QFixed underlinePosition() const
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
Definition: qpainter.cpp:7420
void setStyle(Qt::PenStyle)
Sets the pen style to the given style.
Definition: qpen.cpp:450
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
Definition: qpainter.cpp:3311

◆ generateWavyPixmap()

static QPixmap generateWavyPixmap ( qreal  maxRadius,
const QPen pen 
)
static

Definition at line 6687 of file qpainter.cpp.

Referenced by drawTextItemDecoration().

6688 {
6689  const qreal radiusBase = qMax(qreal(1), maxRadius);
6690 
6691  QString key = QLatin1Literal("WaveUnderline-")
6692  % pen.color().name()
6693  % HexString<qreal>(radiusBase);
6694 
6695  QPixmap pixmap;
6696  if (QPixmapCache::find(key, pixmap))
6697  return pixmap;
6698 
6699  const qreal halfPeriod = qMax(qreal(2), qreal(radiusBase * 1.61803399)); // the golden ratio
6700  const int width = qCeil(100 / (2 * halfPeriod)) * (2 * halfPeriod);
6701  const int radius = qFloor(radiusBase);
6702 
6703  QPainterPath path;
6704 
6705  qreal xs = 0;
6706  qreal ys = radius;
6707 
6708  while (xs < width) {
6709  xs += halfPeriod;
6710  ys = -ys;
6711  path.quadTo(xs - halfPeriod / 2, ys, xs, 0);
6712  }
6713 
6714  pixmap = QPixmap(width, radius * 2);
6715  pixmap.fill(Qt::transparent);
6716  {
6717  QPen wavePen = pen;
6718  wavePen.setCapStyle(Qt::SquareCap);
6719 
6720  // This is to protect against making the line too fat, as happens on Mac OS X
6721  // due to it having a rather thick width for the regular underline.
6722  const qreal maxPenWidth = .8 * radius;
6723  if (wavePen.widthF() > maxPenWidth)
6724  wavePen.setWidth(maxPenWidth);
6725 
6726  QPainter imgPainter(&pixmap);
6727  imgPainter.setPen(wavePen);
6728  imgPainter.setRenderHint(QPainter::Antialiasing);
6729  imgPainter.translate(0, radius);
6730  imgPainter.drawPath(path);
6731  }
6732 
6733  QPixmapCache::insert(key, pixmap);
6734 
6735  return pixmap;
6736 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
double qreal
Definition: qglobal.h:1193
int qCeil(qreal v)
Definition: qmath.h:63
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen&#39;s cap style to the given style.
Definition: qpen.cpp:723
int qFloor(qreal v)
Definition: qmath.h:73
QColor color() const
Returns the color of this pen&#39;s brush.
Definition: qpen.cpp:771
The QString class provides a Unicode character string.
Definition: qstring.h:83
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
static QPixmap * find(const QString &key)
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
qreal widthF() const
Returns the pen width with floating point precision.
Definition: qpen.cpp:645
void quadTo(const QPointF &ctrlPt, const QPointF &endPt)
Adds a quadratic Bezier curve between the current position and the given endPoint with the control po...
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
QString name() const
Returns the name of the color in the format "#RRGGBB"; i.e.
Definition: qcolor.cpp:529
void setWidth(int width)
Sets the pen width to the given width in pixels with integer precision.
Definition: qpen.cpp:667

◆ is_brush_transparent()

static bool is_brush_transparent ( const QBrush brush)
inlinestatic

Definition at line 127 of file qpainter.cpp.

Referenced by is_pen_transparent(), and QPainterPrivate::updateEmulationSpecifier().

127  {
128  Qt::BrushStyle s = brush.style();
129  bool brushBitmap = qHasPixmapTexture(brush)
130  ? brush.texture().isQBitmap()
131  : (brush.textureImage().depth() == 1);
132  return ((s >= Qt::Dense1Pattern && s <= Qt::DiagCrossPattern)
133  || (s == Qt::TexturePattern && brushBitmap));
134 }
BrushStyle
Definition: qnamespace.h:1162
bool qHasPixmapTexture(const QBrush &)
Definition: qbrush.cpp:223
bool isQBitmap() const
Returns true if this is a QBitmap; otherwise returns false.
Definition: qpixmap.cpp:599
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
QPixmap texture() const
Returns the custom brush pattern, or a null pixmap if no custom brush pattern has been set...
Definition: qbrush.cpp:785
QImage textureImage() const
Returns the custom brush pattern, or a null image if no custom brush pattern has been set...
Definition: qbrush.cpp:829

◆ is_pen_transparent()

static bool is_pen_transparent ( const QPen pen)
inlinestatic

Definition at line 136 of file qpainter.cpp.

Referenced by QPainterPrivate::updateEmulationSpecifier().

136  {
137  return pen.style() > Qt::SolidLine || is_brush_transparent(pen.brush());
138 }
static bool is_brush_transparent(const QBrush &brush)
Definition: qpainter.cpp:127
Qt::PenStyle style() const
Returns the pen style.
Definition: qpen.cpp:428
QBrush brush() const
Returns the brush used to fill strokes generated with this pen.
Definition: qpen.cpp:797

◆ line_emulation()

static uint line_emulation ( uint  emulation)
inlinestatic

◆ needsResolving()

static bool needsResolving ( const QBrush brush)
inlinestatic

Definition at line 7339 of file qpainter.cpp.

Referenced by QPaintEngineState::brushNeedsResolving(), QPaintEngineState::penNeedsResolving(), and QOpenGLPaintEnginePrivate::setGLBrush().

7340 {
7341  Qt::BrushStyle s = brush.style();
7342  return ((s == Qt::LinearGradientPattern || s == Qt::RadialGradientPattern ||
7345 }
BrushStyle
Definition: qnamespace.h:1162
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
CoordinateMode coordinateMode() const
Returns the coordinate mode of this gradient.
Definition: qbrush.cpp:1563
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182

◆ qHasPixmapTexture()

bool qHasPixmapTexture ( const QBrush )

Definition at line 223 of file qbrush.cpp.

Referenced by check_gradient(), is_brush_transparent(), and QPainterPrivate::updateEmulationSpecifier().

224 {
225  if (brush.style() != Qt::TexturePattern)
226  return false;
227  QTexturedBrushData *tx_data = static_cast<QTexturedBrushData *>(brush.d.data());
228  return tx_data->m_has_pixmap_texture;
229 }
bool m_has_pixmap_texture
Definition: qbrush.cpp:218

◆ qt_cleanup_painter_state()

static void qt_cleanup_painter_state ( QPainterPrivate d)
inlinestatic

Definition at line 1714 of file qpainter.cpp.

Referenced by QPainter::begin(), and QPainter::end().

1715 {
1716  d->states.clear();
1717  delete d->state;
1718  d->state = 0;
1719  d->engine = 0;
1720  d->device = 0;
1721 }
QPainterState * state
Definition: qpainter_p.h:204
QVector< QPainterState * > states
Definition: qpainter_p.h:205
void clear()
Removes all the elements from the vector and releases the memory used by the vector.
Definition: qvector.h:347
QPaintDevice * device
Definition: qpainter_p.h:258
QPaintEngine * engine
Definition: qpainter_p.h:261

◆ qt_draw_decoration_for_glyphs()

Q_GUI_EXPORT void qt_draw_decoration_for_glyphs ( QPainter painter,
const glyph_t glyphArray,
const QFixedPoint positions,
int  glyphCount,
QFontEngine fontEngine,
const QFont font,
const QTextCharFormat charFormat 
)

Definition at line 6820 of file qpainter.cpp.

Referenced by QDeclarativeTextLayout::draw(), QPainter::drawStaticText(), and QDeclarativeTextLayout::prepare().

6824 {
6825  if (!(font.underline() || font.strikeOut() || font.overline()))
6826  return;
6827 
6828  QFixed leftMost;
6829  QFixed rightMost;
6830  QFixed baseLine;
6831  for (int i=0; i<glyphCount; ++i) {
6832  glyph_metrics_t gm = fontEngine->boundingBox(glyphArray[i]);
6833  if (i == 0 || leftMost > positions[i].x)
6834  leftMost = positions[i].x;
6835 
6836  // We don't support glyphs that do not share a common baseline. If this turns out to
6837  // be a relevant use case, then we need to find clusters of glyphs that share a baseline
6838  // and do a drawTextItemDecorations call per cluster.
6839  if (i == 0 || baseLine < positions[i].y)
6840  baseLine = positions[i].y;
6841 
6842  // We use the advance rather than the actual bounds to match the algorithm in drawText()
6843  if (i == 0 || rightMost < positions[i].x + gm.xoff)
6844  rightMost = positions[i].x + gm.xoff;
6845  }
6846 
6847  QFixed width = rightMost - leftMost;
6848  QTextItem::RenderFlags flags = 0;
6849 
6850  if (font.underline())
6851  flags |= QTextItem::Underline;
6852  if (font.overline())
6853  flags |= QTextItem::Overline;
6854  if (font.strikeOut())
6855  flags |= QTextItem::StrikeOut;
6856 
6857  drawTextItemDecoration(painter, QPointF(leftMost.toReal(), baseLine.toReal()),
6858  fontEngine,
6861  width.toReal(), charFormat);
6862 }
bool underline() const
Returns true if underline has been set; otherwise returns false.
Definition: qfont.cpp:1320
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QFixed y
Definition: qfixed_p.h:191
bool overline() const
Returns true if overline has been set; otherwise returns false.
Definition: qfont.cpp:1344
virtual glyph_metrics_t boundingBox(const QGlyphLayout &glyphs)=0
QFixed x
Definition: qfixed_p.h:190
qreal toReal() const
Definition: qfixed_p.h:77
bool strikeOut() const
Returns true if strikeout has been set; otherwise returns false.
Definition: qfont.cpp:1367
static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const QFontEngine *fe, QTextCharFormat::UnderlineStyle underlineStyle, QTextItem::RenderFlags flags, qreal width, const QTextCharFormat &charFormat)
Definition: qpainter.cpp:6738

◆ qt_draw_helper()

void qt_draw_helper ( QPainterPrivate p,
const QPainterPath path,
QPainterPrivate::DrawOperation  operation 
)

Definition at line 9937 of file qpainter.cpp.

Referenced by QVGPaintEngine::fill(), and QOpenGLPaintEngine::fill().

9938 {
9939  p->draw_helper(path, operation);
9940 }
void draw_helper(const QPainterPath &path, DrawOperation operation=StrokeAndFillDraw)
Definition: qpainter.cpp:355

◆ qt_format_text() [1/2]

void qt_format_text ( const QFont font,
const QRectF _r,
int  tf,
const QTextOption option,
const QString str,
QRectF brect,
int  tabstops,
int *  tabarray,
int  tabarraylen,
QPainter painter 
)

Definition at line 8458 of file qpainter.cpp.

Referenced by QPainter::boundingRect(), QPainter::drawText(), QPicture::exec(), QPainterReplayer::process(), and qt_format_text().

8462 {
8463 
8464  Q_ASSERT( !((tf & ~Qt::TextDontPrint)!=0 && option!=0) ); // we either have an option or flags
8465 
8466  if (option) {
8467  tf |= option->alignment();
8468  if (option->wrapMode() != QTextOption::NoWrap)
8469  tf |= Qt::TextWordWrap;
8470 
8471  if (option->flags() & QTextOption::IncludeTrailingSpaces)
8473 
8474  if (option->tabStop() >= 0 || !option->tabArray().isEmpty())
8475  tf |= Qt::TextExpandTabs;
8476  }
8477 
8478  // we need to copy r here to protect against the case (&r == brect).
8479  QRectF r(_r);
8480 
8481  bool dontclip = (tf & Qt::TextDontClip);
8482  bool wordwrap = (tf & Qt::TextWordWrap) || (tf & Qt::TextWrapAnywhere);
8483  bool singleline = (tf & Qt::TextSingleLine);
8484  bool showmnemonic = (tf & Qt::TextShowMnemonic);
8485  bool hidemnmemonic = (tf & Qt::TextHideMnemonic);
8486 
8488  if (tf & Qt::TextForceLeftToRight)
8489  layout_direction = Qt::LeftToRight;
8490  else if (tf & Qt::TextForceRightToLeft)
8491  layout_direction = Qt::RightToLeft;
8492  else if (option)
8493  layout_direction = option->textDirection();
8494  else if (painter)
8495  layout_direction = painter->layoutDirection();
8496  else
8497  layout_direction = Qt::LeftToRight;
8498 
8499  tf = QStyle::visualAlignment(layout_direction, QFlag(tf));
8500 
8501  bool isRightToLeft = layout_direction == Qt::RightToLeft;
8502  bool expandtabs = ((tf & Qt::TextExpandTabs) &&
8503  (((tf & Qt::AlignLeft) && !isRightToLeft) ||
8504  ((tf & Qt::AlignRight) && isRightToLeft)));
8505 
8506  if (!painter)
8507  tf |= Qt::TextDontPrint;
8508 
8509  uint maxUnderlines = 0;
8510  int numUnderlines = 0;
8511  QVarLengthArray<int, 32> underlinePositions(1);
8512 
8513  QFontMetricsF fm(fnt);
8514  QString text = str;
8515  int offset = 0;
8516 start_lengthVariant:
8517  bool hasMoreLengthVariants = false;
8518  // compatible behaviour to the old implementation. Replace
8519  // tabs by spaces
8520  int old_offset = offset;
8521  for (; offset < text.length(); offset++) {
8522  QChar chr = text.at(offset);
8523  if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) {
8524  text[offset] = QLatin1Char(' ');
8525  } else if (chr == QLatin1Char('\n')) {
8526  text[offset] = QChar::LineSeparator;
8527  } else if (chr == QLatin1Char('&')) {
8528  ++maxUnderlines;
8529  } else if (chr == QLatin1Char('\t')) {
8530  if (!expandtabs) {
8531  text[offset] = QLatin1Char(' ');
8532  } else if (!tabarraylen && !tabstops) {
8533  tabstops = qRound(fm.width(QLatin1Char('x'))*8);
8534  }
8535  } else if (chr == QChar(ushort(0x9c))) {
8536  // string with multiple length variants
8537  hasMoreLengthVariants = true;
8538  break;
8539  }
8540  }
8541 
8542  int length = offset - old_offset;
8543  if ((hidemnmemonic || showmnemonic) && maxUnderlines > 0) {
8544  underlinePositions.resize(maxUnderlines + 1);
8545 
8546  QChar *cout = text.data() + old_offset;
8547  QChar *cin = cout;
8548  int l = length;
8549  while (l) {
8550  if (*cin == QLatin1Char('&')) {
8551  ++cin;
8552  --length;
8553  --l;
8554  if (!l)
8555  break;
8556  if (*cin != QLatin1Char('&') && !hidemnmemonic)
8557  underlinePositions[numUnderlines++] = cout - text.data() - old_offset;
8558  }
8559  *cout = *cin;
8560  ++cout;
8561  ++cin;
8562  --l;
8563  }
8564  }
8565 
8566  // no need to do extra work for underlines if we don't paint
8567  if (tf & Qt::TextDontPrint)
8568  numUnderlines = 0;
8569 
8570  underlinePositions[numUnderlines] = -1;
8571  qreal height = 0;
8572  qreal width = 0;
8573 
8574  QString finalText = text.mid(old_offset, length);
8575  QStackTextEngine engine(finalText, fnt);
8576  if (option) {
8577  engine.option = *option;
8578  }
8579 
8580  if (engine.option.tabStop() < 0 && tabstops > 0)
8581  engine.option.setTabStop(tabstops);
8582 
8583  if (engine.option.tabs().isEmpty() && ta) {
8584  QList<qreal> tabs;
8585  for (int i = 0; i < tabarraylen; i++)
8586  tabs.append(qreal(ta[i]));
8587  engine.option.setTabArray(tabs);
8588  }
8589 
8590  engine.option.setTextDirection(layout_direction);
8591  if (tf & Qt::AlignJustify)
8592  engine.option.setAlignment(Qt::AlignJustify);
8593  else
8594  engine.option.setAlignment(Qt::AlignLeft); // do not do alignment twice
8595 
8596  if (!option && (tf & Qt::TextWrapAnywhere))
8597  engine.option.setWrapMode(QTextOption::WrapAnywhere);
8598 
8599  if (tf & Qt::TextJustificationForced)
8600  engine.forceJustification = true;
8601  QTextLayout textLayout(&engine);
8602  textLayout.setCacheEnabled(true);
8603  textLayout.engine()->underlinePositions = underlinePositions.data();
8604 
8605  if (finalText.isEmpty()) {
8606  height = fm.height();
8607  width = 0;
8608  tf |= Qt::TextDontPrint;
8609  } else {
8610  qreal lineWidth = 0x01000000;
8611  if (wordwrap || (tf & Qt::TextJustificationForced))
8612  lineWidth = qMax<qreal>(0, r.width());
8613  if(!wordwrap)
8615  textLayout.engine()->ignoreBidi = bool(tf & Qt::TextDontPrint);
8616  textLayout.beginLayout();
8617 
8618  qreal leading = fm.leading();
8619  height = -leading;
8620 
8621  while (1) {
8622  QTextLine l = textLayout.createLine();
8623  if (!l.isValid())
8624  break;
8625 
8626  l.setLineWidth(lineWidth);
8627  height += leading;
8628  l.setPosition(QPointF(0., height));
8629  height += l.height();
8630  width = qMax(width, l.naturalTextWidth());
8631  if (!dontclip && !brect && height >= r.height())
8632  break;
8633  }
8634  textLayout.endLayout();
8635  }
8636 
8637  qreal yoff = 0;
8638  qreal xoff = 0;
8639  if (tf & Qt::AlignBottom) {
8640  yoff = r.height() - height;
8641  } else if (tf & Qt::AlignVCenter) {
8642  yoff = (r.height() - height)/2;
8643  if (painter) {
8645  if (type <= QTransform::TxScale) {
8646  // do the rounding manually to work around inconsistencies
8647  // in the paint engines when drawing on floating point offsets
8648  const qreal scale = painter->transform().m22();
8649  if (scale != 0)
8650  yoff = -qRound(-yoff * scale) / scale;
8651  }
8652  }
8653  }
8654  if (tf & Qt::AlignRight) {
8655  xoff = r.width() - width;
8656  } else if (tf & Qt::AlignHCenter) {
8657  xoff = (r.width() - width)/2;
8658  if (painter) {
8659  QTransform::TransformationType type = painter->transform().type();
8660  if (type <= QTransform::TxScale) {
8661  // do the rounding manually to work around inconsistencies
8662  // in the paint engines when drawing on floating point offsets
8663  const qreal scale = painter->transform().m11();
8664  if (scale != 0)
8665  xoff = qRound(xoff * scale) / scale;
8666  }
8667  }
8668  }
8669  QRectF bounds = QRectF(r.x() + xoff, r.y() + yoff, width, height);
8670 
8671  if (hasMoreLengthVariants && !(tf & Qt::TextLongestVariant) && !r.contains(bounds)) {
8672  offset++;
8673  goto start_lengthVariant;
8674  }
8675  if (brect)
8676  *brect = bounds;
8677 
8678  if (!(tf & Qt::TextDontPrint)) {
8679  bool restore = false;
8680  if (!dontclip && !r.contains(bounds)) {
8681  restore = true;
8682  painter->save();
8683  painter->setClipRect(r, Qt::IntersectClip);
8684  }
8685 
8686  for (int i = 0; i < textLayout.lineCount(); i++) {
8687  QTextLine line = textLayout.lineAt(i);
8688 
8689  qreal advance = line.horizontalAdvance();
8690  xoff = 0;
8691  if (tf & Qt::AlignRight) {
8692  QTextEngine *eng = textLayout.engine();
8693  xoff = r.width() - advance -
8694  eng->leadingSpaceWidth(eng->lines[line.lineNumber()]).toReal();
8695  }
8696  else if (tf & Qt::AlignHCenter)
8697  xoff = (r.width() - advance) / 2;
8698 
8699  line.draw(painter, QPointF(r.x() + xoff, r.y() + yoff));
8700  }
8701 
8702  if (restore) {
8703  painter->restore();
8704  }
8705  }
8706 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
const QTransform & transform() const
Returns the world transformation matrix.
Definition: qpainter.cpp:9558
qreal horizontalAdvance() const
Returns the horizontal advance of the text.
void setPosition(const QPointF &pos)
Moves the line to position pos.
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
The QFlag class is a helper data type for QFlags.
Definition: qglobal.h:2289
void setClipRect(const QRectF &, Qt::ClipOperation op=Qt::ReplaceClip)
Enables clipping, and sets the clip region to the given rectangle using the given clip operation...
Definition: qpainter.cpp:2801
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
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
void restore()
Restores the current painter state (pops a saved state off the stack).
Definition: qpainter.cpp:1620
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
Flags flags() const
Returns the flags associated with the option.
Definition: qtextoption.h:121
void setLineWidth(qreal width)
Lays out the line with the given width.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QList< qreal > tabArray() const
Returns a list of tab positions defined for the text layout.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
TransformationType type() const
Returns the transformation type of this matrix.
bool isValid() const
Returns true if this text line is valid; otherwise returns false.
Definition: qtextlayout.h:201
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
qreal tabStop() const
Returns the distance in device units between tab stops.
Definition: qtextoption.h:124
void save()
Saves the current painter state (pushes the state onto a stack).
Definition: qpainter.cpp:1590
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
TransformationType
Definition: qtransform.h:68
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
static Qt::LayoutDirection layout_direction
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
int lineNumber() const
Returns the position of the line in the text engine.
Definition: qtextlayout.h:243
LayoutDirection
Definition: qnamespace.h:1580
unsigned int uint
Definition: qglobal.h:996
QScriptLineArray lines
Qt::LayoutDirection layoutDirection() const
Returns the layout direction used by the painter when drawing text.
Definition: qpainter.cpp:8729
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
The QTextLayout class is used to lay out and render text.
Definition: qtextlayout.h:105
static Qt::Alignment visualAlignment(Qt::LayoutDirection direction, Qt::Alignment alignment)
Transforms an alignment of Qt::AlignLeft or Qt::AlignRight without Qt::AlignAbsolute into Qt::AlignLe...
Definition: qstyle.cpp:2149
unsigned short ushort
Definition: qglobal.h:995
Qt::LayoutDirection textDirection() const
Returns the direction of the text layout defined by the option.
Definition: qtextoption.h:100
qreal naturalTextWidth() const
Returns the width of the line that is occupied by text.
WrapMode wrapMode() const
Returns the text wrap mode defined by the option.
Definition: qtextoption.h:110
QFactoryLoader * l
Qt::Alignment alignment() const
Returns the text alignment defined by the option.
Definition: qtextoption.h:97
The QFontMetricsF class provides font metrics information.
Definition: qfontmetrics.h:145
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection=0) const
Draws a line on the given painter at the specified position.
qreal height() const
Returns the line&#39;s height.
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
void setTabStop(qreal tabStop)
Sets the default distance in device units between tab stops to the value specified by tabStop...
Definition: qtextoption.h:154
QFixed leadingSpaceWidth(const QScriptLine &line)
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237
#define text
Definition: qobjectdefs.h:80
static qreal toReal(Register *reg, int type, bool *ok=0)
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
QFixed width(int charFrom, int numChars) const

◆ qt_format_text() [2/2]

void qt_format_text ( const QFont fnt,
const QRectF _r,
int  tf,
const QString str,
QRectF brect,
int  tabstops,
int *  ta,
int  tabarraylen,
QPainter painter 
)

Definition at line 8448 of file qpainter.cpp.

Referenced by QFontMetrics::boundingRect(), and QFontMetricsF::boundingRect().

8452 {
8453  qt_format_text(fnt, _r,
8454  tf, 0, str, brect,
8455  tabstops, ta, tabarraylen,
8456  painter);
8457 }
void qt_format_text(const QFont &font, const QRectF &_r, int tf, const QTextOption *option, const QString &str, QRectF *brect, int tabstops, int *tabarray, int tabarraylen, QPainter *painter)
Definition: qpainter.cpp:8458

◆ qt_isExtendedRadialGradient()

Q_GUI_EXPORT bool qt_isExtendedRadialGradient ( const QBrush brush)

Definition at line 881 of file qbrush.cpp.

Referenced by QPainterPrivate::updateEmulationSpecifier(), and QPainterPrivate::updateInvMatrix().

882 {
883  if (brush.style() == Qt::RadialGradientPattern) {
884  const QGradient *g = brush.gradient();
885  const QRadialGradient *rg = static_cast<const QRadialGradient *>(g);
886 
887  if (!qFuzzyIsNull(rg->focalRadius()))
888  return true;
889 
890  QPointF delta = rg->focalPoint() - rg->center();
891  if (delta.x() * delta.x() + delta.y() * delta.y() > rg->radius() * rg->radius())
892  return true;
893  }
894 
895  return false;
896 }
qreal focalRadius() const
Returns the focal radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2211
QPointF focalPoint() const
Returns the focal point of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2251
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QRadialGradient class is used in combination with QBrush to specify a radial gradient brush...
Definition: qbrush.h:297
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal radius() const
Returns the radius of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2150
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QPointF center() const
Returns the center of this radial gradient in logical coordinates.
Definition: qbrush.cpp:2102
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
Definition: qglobal.h:2043

◆ qt_painter_removePaintDevice()

void qt_painter_removePaintDevice ( QPaintDevice dev)

Definition at line 8419 of file qpainter.cpp.

Referenced by QPaintDevice::~QPaintDevice().

8420 {
8421  if (!globalRedirectionAtomic() || *globalRedirectionAtomic() == 0)
8422  return;
8423 
8424  QMutex *mutex = 0;
8425  QT_TRY {
8426  mutex = globalRedirectionsMutex();
8427  } QT_CATCH(...) {
8428  // ignore the missing mutex, since we could be called from
8429  // a destructor, and destructors shall not throw
8430  }
8431  QMutexLocker locker(mutex);
8432  QPaintDeviceRedirectionList *redirections = 0;
8433  QT_TRY {
8434  redirections = globalRedirections();
8435  } QT_CATCH(...) {
8436  // do nothing - code below is safe with redirections being 0.
8437  }
8438  if (redirections) {
8439  for (int i = 0; i < redirections->size(); ) {
8440  if(redirections->at(i) == dev || redirections->at(i).replacement == dev)
8441  redirections->removeAt(i);
8442  else
8443  ++i;
8444  }
8445  }
8446 }
The QMutex class provides access serialization between threads.
Definition: qmutex.h:60
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define QT_CATCH(A)
Definition: qglobal.h:1537
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
#define QT_TRY
Definition: qglobal.h:1536
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ qt_painter_thread_test()

static bool qt_painter_thread_test ( int  devType,
const char *  what,
bool  extraCondition = false 
)
static

Definition at line 156 of file qpainter.cpp.

Referenced by QPainter::drawPixmap(), QPainter::drawTextItem(), and QPainter::drawTiledPixmap().

157 {
158  switch (devType) {
159  case QInternal::Image:
160  case QInternal::Printer:
161  case QInternal::Picture:
162  // can be drawn onto these devices safely from any thread
163 #ifndef Q_WS_WIN
164  if (extraCondition)
165 #endif
166  break;
167  default:
168 #ifdef Q_WS_X11
170  return true;
171 #endif
172  if (!extraCondition && QThread::currentThread() != qApp->thread()) {
173  qWarning("QPainter: It is not safe to use %s outside the GUI thread", what);
174  return false;
175  }
176  break;
177  }
178  return true;
179 }
static QThread * currentThread()
Returns a pointer to a QThread which manages the currently executing thread.
Definition: qthread.cpp:419
#define qApp
Q_CORE_EXPORT void qWarning(const char *,...)
static bool testAttribute(Qt::ApplicationAttribute attribute)
Returns true if attribute attribute is set; otherwise returns false.

◆ qt_pixmapForBrush()

QPixmap qt_pixmapForBrush ( int  style,
bool  invert 
)

Definition at line 99 of file qbrush.cpp.

100 {
101 
102  QPixmap pm;
103  QString key = QLatin1Literal("$qt-brush$")
104  % HexString<uint>(brushStyle)
105  % QLatin1Char(invert ? '1' : '0');
106  if (!QPixmapCache::find(key, pm)) {
107  pm = QBitmap::fromData(QSize(8, 8), qt_patternForBrush(brushStyle, invert),
109  QPixmapCache::insert(key, pm);
110  }
111 
112  return pm;
113 }
The QLatin1Literal class provides a thin wrapper around string literals used in source code...
static QBitmap fromData(const QSize &size, const uchar *bits, QImage::Format monoFormat=QImage::Format_MonoLSB)
Constructs a bitmap with the given size, and sets the contents to the bits supplied.
Definition: qbitmap.cpp:318
const uchar * qt_patternForBrush(int brushStyle, bool invert)
Definition: qbrush.cpp:56
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QPixmap * find(const QString &key)
static bool insert(const QString &key, const QPixmap &pixmap)
Inserts a copy of the pixmap pixmap associated with the key into the cache.
int key
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qt_regionToPath()

Q_AUTOTEST_EXPORT QPainterPath qt_regionToPath ( const QRegion region)

Definition at line 1160 of file qregion.cpp.

Referenced by QPainter::clipPath(), and QPainter::clipRegion().

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

◆ roundInDeviceCoordinates()

static QPointF roundInDeviceCoordinates ( const QPointF p,
const QTransform m 
)
inlinestatic

Definition at line 5518 of file qpainter.cpp.

Referenced by QPainter::drawImage(), QPainter::drawPixmap(), and QPainter::drawTiledPixmap().

5519 {
5520  return m.inverted().map(QPointF(m.map(p).toPoint()));
5521 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QTransform inverted(bool *invertible=0) const
Returns an inverted copy of this matrix.
Definition: qtransform.cpp:364
QPoint map(const QPoint &p) const
Creates and returns a QPoint object that is a copy of the given point, mapped into the coordinate sys...

◆ stretchGradientToUserSpace()

static QBrush stretchGradientToUserSpace ( const QBrush brush,
const QRectF boundingRect 
)
inlinestatic

Definition at line 531 of file qpainter.cpp.

Referenced by QPainterPrivate::drawStretchedGradient().

532 {
534  && brush.style() <= Qt::ConicalGradientPattern);
535 
536  QTransform gradientToUser(boundingRect.width(), 0, 0, boundingRect.height(),
537  boundingRect.x(), boundingRect.y());
538 
539  QGradient g = *brush.gradient();
541 
542  QBrush b(g);
543  b.setTransform(gradientToUser * b.transform());
544  return b;
545 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
const QGradient * gradient() const
Returns the gradient describing this brush.
Definition: qbrush.cpp:871
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
Qt::BrushStyle style() const
Returns the brush style.
Definition: qbrush.h:182
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
The QGradient class is used in combination with QBrush to specify gradient fills. ...
Definition: qbrush.h:201
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
void setCoordinateMode(CoordinateMode mode)
Sets the coordinate mode of this gradient to mode.
Definition: qbrush.cpp:1578
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65