diff options
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
-rw-r--r-- | src/gui/painting/qpainter.cpp | 374 |
1 files changed, 175 insertions, 199 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 01400a0bc8..f4b9741eed 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -1,43 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // QtCore +#include <memory> #include <qdebug.h> #include <qmath.h> #include <qmutex.h> @@ -74,9 +39,15 @@ #include <private/qhexstring_p.h> #include <private/qguiapplication_p.h> #include <private/qrawfont_p.h> +#include <private/qfont_p.h> QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + +// We changed the type from QScopedPointer to unique_ptr, make sure it's binary compatible: +static_assert(sizeof(QScopedPointer<QPainterPrivate>) == sizeof(std::unique_ptr<QPainterPrivate>)); + #define QGradient_StretchToDevice 0x10000000 #define QPaintEngine_OpaqueBackground 0x40000000 @@ -180,6 +151,23 @@ static bool qt_painter_thread_test(int devType, int engineType, const char *what } #endif +static bool needsEmulation(const QBrush &brush) +{ + bool res = false; + + const QGradient *bg = brush.gradient(); + if (bg) { + res = (bg->coordinateMode() > QGradient::LogicalMode); + } else if (brush.style() == Qt::TexturePattern) { + if (qHasPixmapTexture(brush)) + res = !qFuzzyCompare(brush.texture().devicePixelRatio(), qreal(1.0)); + else + res = !qFuzzyCompare(brush.textureImage().devicePixelRatio(), qreal(1.0)); + } + + return res; +} + void QPainterPrivate::checkEmulation() { Q_ASSERT(extended); @@ -187,43 +175,34 @@ void QPainterPrivate::checkEmulation() if (state->bgMode == Qt::OpaqueMode) doEmulation = true; - const QGradient *bg = state->brush.gradient(); - if (bg && bg->coordinateMode() > QGradient::LogicalMode) + if (needsEmulation(state->brush)) doEmulation = true; - const QGradient *pg = qpen_brush(state->pen).gradient(); - if (pg && pg->coordinateMode() > QGradient::LogicalMode) + if (needsEmulation(qpen_brush(state->pen))) doEmulation = true; - if (state->brush.style() == Qt::TexturePattern) { - if (qHasPixmapTexture(state->brush)) - doEmulation |= !qFuzzyCompare(state->brush.texture().devicePixelRatio(), qreal(1.0)); - else - doEmulation |= !qFuzzyCompare(state->brush.textureImage().devicePixelRatio(), qreal(1.0)); - } - if (doEmulation && extended->flags() & QPaintEngineEx::DoNotEmulate) return; if (doEmulation) { - if (extended != emulationEngine) { + if (extended != emulationEngine.get()) { if (!emulationEngine) - emulationEngine = new QEmulationPaintEngine(extended); - extended = emulationEngine; - extended->setState(state); + emulationEngine = std::make_unique<QEmulationPaintEngine>(extended); + extended = emulationEngine.get(); + extended->setState(state.get()); } - } else if (emulationEngine == extended) { + } else if (emulationEngine.get() == extended) { extended = emulationEngine->real_engine; } } - -QPainterPrivate::~QPainterPrivate() +QPainterPrivate::QPainterPrivate(QPainter *painter) + : q_ptr(painter), txinv(0), inDestructor(false) { - delete emulationEngine; - qDeleteAll(states); } +QPainterPrivate::~QPainterPrivate() + = default; QTransform QPainterPrivate::viewTransform() const { @@ -242,7 +221,7 @@ qreal QPainterPrivate::effectiveDevicePixelRatio() const if (device->devType() == QInternal::Printer) return qreal(1); - return qMax(qreal(1), device->devicePixelRatio()); + return device->devicePixelRatio(); } QTransform QPainterPrivate::hidpiScaleTransform() const @@ -267,22 +246,10 @@ bool QPainterPrivate::attachPainterPrivate(QPainter *q, QPaintDevice *pdev) // Save the current state of the shared painter and assign // the current d_ptr to the shared painter's d_ptr. sp->save(); - if (!sp->d_ptr->d_ptrs) { - // Allocate space for 4 d-pointers (enough for up to 4 sub-sequent - // redirections within the same paintEvent(), which should be enough - // in 99% of all cases). E.g: A renders B which renders C which renders D. - sp->d_ptr->d_ptrs_size = 4; - sp->d_ptr->d_ptrs = (QPainterPrivate **)malloc(4 * sizeof(QPainterPrivate *)); - Q_CHECK_PTR(sp->d_ptr->d_ptrs); - } else if (sp->d_ptr->refcount - 1 == sp->d_ptr->d_ptrs_size) { - // However, to support corner cases we grow the array dynamically if needed. - sp->d_ptr->d_ptrs_size <<= 1; - const int newSize = sp->d_ptr->d_ptrs_size * sizeof(QPainterPrivate *); - sp->d_ptr->d_ptrs = q_check_ptr((QPainterPrivate **)realloc(sp->d_ptr->d_ptrs, newSize)); - } - sp->d_ptr->d_ptrs[++sp->d_ptr->refcount - 2] = q->d_ptr.data(); - q->d_ptr.take(); - q->d_ptr.reset(sp->d_ptr.data()); + ++sp->d_ptr->refcount; + sp->d_ptr->d_ptrs.push_back(q->d_ptr.get()); + Q_UNUSED(q->d_ptr.release()); + q->d_ptr.reset(sp->d_ptr.get()); Q_ASSERT(q->d_ptr->state); @@ -325,7 +292,9 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q) Q_ASSERT(refcount > 1); Q_ASSERT(q); - QPainterPrivate *original = d_ptrs[--refcount - 1]; + --refcount; + QPainterPrivate *original = d_ptrs.back(); + d_ptrs.pop_back(); if (inDestructor) { inDestructor = false; if (original) @@ -334,14 +303,12 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q) original = new QPainterPrivate(q); } - d_ptrs[refcount - 1] = nullptr; q->restore(); - q->d_ptr.take(); + Q_UNUSED(q->d_ptr.release()); q->d_ptr.reset(original); if (emulationEngine) { extended = emulationEngine->real_engine; - delete emulationEngine; emulationEngine = nullptr; } } @@ -414,7 +381,7 @@ void QPainterPrivate::draw_helper(const QPainterPath &originalPath, DrawOperatio if (q->hasClipping()) { bool hasPerspectiveTransform = false; - for (const QPainterClipInfo &info : qAsConst(state->clipInfo)) { + for (const QPainterClipInfo &info : std::as_const(state->clipInfo)) { if (info.matrix.type() == QTransform::TxProject) { hasPerspectiveTransform = true; break; @@ -1158,24 +1125,22 @@ void QPainterPrivate::updateState(QPainterState *newState) The QPainter class also provides a means of controlling the rendering quality through its RenderHint enum and the support for floating point precision: All the functions for drawing primitives - has a floating point version. These are often used in combination + have floating point versions. + + \snippet code/src_gui_painting_qpainter.cpp floatBased + + These are often used in combination with the \l {RenderHint}{QPainter::Antialiasing} render hint. + \snippet code/src_gui_painting_qpainter.cpp renderHint + \table 100% \row + \li Comparing concentric circles with int and float, and with or without + anti-aliased rendering. Using the floating point precision versions + produces evenly spaced rings. Anti-aliased rendering results in + smooth circles. \li \inlineimage qpainter-concentriccircles.png - \li - \b {Concentric Circles Example} - - The \l {painting/concentriccircles}{Concentric Circles} example - shows the improved rendering quality that can be obtained using - floating point precision and anti-aliasing when drawing custom - widgets. - - The application's main window displays several widgets which are - drawn using the various combinations of precision and - anti-aliasing. - \endtable The RenderHint enum specifies flags to QPainter that may or may @@ -1235,7 +1200,7 @@ void QPainterPrivate::updateState(QPainterState *newState) \li \inlineimage qpainter-affinetransformations.png \endtable - All the tranformation operations operate on the transformation + All the transformation operations operate on the transformation worldTransform(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the \l {Coordinate System} and QTransform documentation. @@ -1446,8 +1411,14 @@ void QPainterPrivate::updateState(QPainterState *newState) JPEG compression. This value was added in Qt 5.13. + \value NonCosmeticBrushPatterns When painting with a brush with one of the predefined pattern + styles, transform the pattern too, along with the object being painted. The default is to treat + the pattern as cosmetic, so that the pattern pixels will map directly to device pixels, + independently of any active transformations. + This value was added in Qt 6.4. + \sa renderHints(), setRenderHint(), {QPainter#Rendering - Quality}{Rendering Quality}, {Concentric Circles Example} + Quality}{Rendering Quality} */ @@ -1516,8 +1487,6 @@ QPainter::~QPainter() Q_ASSERT(d_ptr->inDestructor); d_ptr->inDestructor = false; Q_ASSERT(d_ptr->refcount == 1); - if (d_ptr->d_ptrs) - free(d_ptr->d_ptrs); } } @@ -1546,7 +1515,7 @@ QPaintDevice *QPainter::device() const bool QPainter::isActive() const { Q_D(const QPainter); - return d->engine; + return d->engine != nullptr; } void QPainterPrivate::initFrom(const QPaintDevice *device) @@ -1588,15 +1557,19 @@ void QPainter::save() return; } + std::unique_ptr<QPainterState> prev; if (d->extended) { - d->state = d->extended->createState(d->states.back()); - d->extended->setState(d->state); + // separate the creation of a new state from the update of d->state, since some + // engines access d->state directly (not via createState()'s argument) + std::unique_ptr<QPainterState> next(d->extended->createState(d->state.get())); + prev = std::exchange(d->state, std::move(next)); + d->extended->setState(d->state.get()); } else { d->updateState(d->state); - d->state = new QPainterState(d->states.back()); - d->engine->state = d->state; + prev = std::exchange(d->state, std::make_unique<QPainterState>(d->state.get())); + d->engine->state = d->state.get(); } - d->states.push_back(d->state); + d->savedStates.push(std::move(prev)); } /*! @@ -1613,7 +1586,7 @@ void QPainter::restore() printf("QPainter::restore()\n"); #endif Q_D(QPainter); - if (d->states.size()<=1) { + if (d->savedStates.empty()) { qWarning("QPainter::restore: Unbalanced save/restore"); return; } else if (!d->engine) { @@ -1621,15 +1594,13 @@ void QPainter::restore() return; } - QPainterState *tmp = d->state; - d->states.pop_back(); - d->state = d->states.back(); + const auto tmp = std::exchange(d->state, std::move(d->savedStates.top())); + d->savedStates.pop(); d->txinv = false; if (d->extended) { d->checkEmulation(); - d->extended->setState(d->state); - delete tmp; + d->extended->setState(d->state.get()); return; } @@ -1643,9 +1614,8 @@ void QPainter::restore() tmp->clipPath = QPainterPath(); d->engine->updateState(*tmp); // replay the list of clip states, - for (const QPainterClipInfo &info : qAsConst(d->state->clipInfo)) { + for (const QPainterClipInfo &info : std::as_const(d->state->clipInfo)) { tmp->matrix = info.matrix; - tmp->matrix *= d->state->redirectionMatrix; tmp->clipOperation = info.operation; if (info.clipType == QPainterClipInfo::RectClip) { tmp->dirtyFlags = QPaintEngine::DirtyClipRegion | QPaintEngine::DirtyTransform; @@ -1667,8 +1637,7 @@ void QPainter::restore() tmp->changeFlags |= QPaintEngine::DirtyTransform; } - d->updateState(d->state); - delete tmp; + d->updateState(d->state.get()); } @@ -1701,8 +1670,7 @@ void QPainter::restore() static inline void qt_cleanup_painter_state(QPainterPrivate *d) { - qDeleteAll(d->states); - d->states.clear(); + d->savedStates.clear(); d->state = nullptr; d->engine = nullptr; d->device = nullptr; @@ -1745,7 +1713,7 @@ bool QPainter::begin(QPaintDevice *pd) else if (pd->devType() == QInternal::Image) static_cast<QImage *>(pd)->detach(); - d->engine = pd->paintEngine(); + d->engine.reset(pd->paintEngine()); if (!d->engine) { qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType()); @@ -1754,24 +1722,23 @@ bool QPainter::begin(QPaintDevice *pd) d->device = pd; - d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : nullptr; + d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine.get()) : nullptr; if (d->emulationEngine) d->emulationEngine->real_engine = d->extended; // Setup new state... Q_ASSERT(!d->state); - d->state = d->extended ? d->extended->createState(nullptr) : new QPainterState; + d->state.reset(d->extended ? d->extended->createState(nullptr) : new QPainterState); d->state->painter = this; - d->states.push_back(d->state); d->state->redirectionMatrix.translate(-redirectionOffset.x(), -redirectionOffset.y()); d->state->brushOrigin = QPointF(); // Slip a painter state into the engine before we do any other operations if (d->extended) - d->extended->setState(d->state); + d->extended->setState(d->state.get()); else - d->engine->state = d->state; + d->engine->state = d->state.get(); switch (pd->devType()) { case QInternal::Pixmap: @@ -1798,9 +1765,12 @@ bool QPainter::begin(QPaintDevice *pd) qWarning("QPainter::begin: Cannot paint on a null image"); qt_cleanup_painter_state(d); return false; - } else if (img->format() == QImage::Format_Indexed8) { - // Painting on indexed8 images is not supported. - qWarning("QPainter::begin: Cannot paint on an image with the QImage::Format_Indexed8 format"); + } else if (img->format() == QImage::Format_Indexed8 || + img->format() == QImage::Format_CMYK8888) { + // Painting on these formats is not supported. + qWarning() << "QPainter::begin: Cannot paint on an image with the" + << img->format() + << "format"; qt_cleanup_painter_state(d); return false; } @@ -1855,7 +1825,7 @@ bool QPainter::begin(QPaintDevice *pd) Q_ASSERT(d->engine->isActive()); - if (!d->state->redirectionMatrix.isIdentity() || d->effectiveDevicePixelRatio() > 1) + if (!d->state->redirectionMatrix.isIdentity() || !qFuzzyCompare(d->effectiveDevicePixelRatio(), qreal(1.0))) d->updateMatrix(); Q_ASSERT(d->engine->isActive()); @@ -1909,22 +1879,13 @@ bool QPainter::end() } } - if (d->states.size() > 1) { - qWarning("QPainter::end: Painter ended with %d saved states", int(d->states.size())); - } - - if (d->engine->autoDestruct()) { - delete d->engine; - } - - if (d->emulationEngine) { - delete d->emulationEngine; - d->emulationEngine = nullptr; + if (d->savedStates.size() > 0) { + qWarning("QPainter::end: Painter ended with %d saved states", int(d->savedStates.size())); } - if (d->extended) { - d->extended = nullptr; - } + d->engine.reset(); + d->emulationEngine = nullptr; + d->extended = nullptr; qt_cleanup_painter_state(d); @@ -1941,7 +1902,7 @@ bool QPainter::end() QPaintEngine *QPainter::paintEngine() const { Q_D(const QPainter); - return d->engine; + return d->engine.get(); } /*! @@ -2517,7 +2478,7 @@ QRegion QPainter::clipRegion() const const_cast<QPainter *>(this)->d_ptr->updateInvMatrix(); // ### Falcon: Use QPainterPath - for (const QPainterClipInfo &info : qAsConst(d->state->clipInfo)) { + for (const QPainterClipInfo &info : std::as_const(d->state->clipInfo)) { switch (info.clipType) { case QPainterClipInfo::RegionClip: { @@ -2684,7 +2645,7 @@ QRectF QPainter::clipBoundingRect() const // fast. QRectF bounds; bool first = true; - for (const QPainterClipInfo &info : qAsConst(d->state->clipInfo)) { + for (const QPainterClipInfo &info : std::as_const(d->state->clipInfo)) { QRectF r; if (info.clipType == QPainterClipInfo::RectClip) @@ -3063,7 +3024,8 @@ void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op) return; } - if ((!d->state->clipEnabled && op != Qt::NoClip)) + bool simplifyClipOp = (paintEngine()->type() != QPaintEngine::Picture); + if (simplifyClipOp && (!d->state->clipEnabled && op != Qt::NoClip)) op = Qt::ReplaceClip; if (d->extended) { @@ -3076,7 +3038,7 @@ void QPainter::setClipPath(const QPainterPath &path, Qt::ClipOperation op) return; } - if (d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip) + if (simplifyClipOp && d->state->clipOperation == Qt::NoClip && op == Qt::IntersectClip) op = Qt::ReplaceClip; d->state->clipPath = path; @@ -3107,12 +3069,9 @@ void QPainter::strokePath(const QPainterPath &path, const QPen &pen) if (path.isEmpty()) return; - if (d->extended) { - const QGradient *g = qpen_brush(pen).gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->stroke(qtVectorPathForPath(path), pen); - return; - } + if (d->extended && !needsEmulation(pen.brush())) { + d->extended->stroke(qtVectorPathForPath(path), pen); + return; } QBrush oldBrush = d->state->brush; @@ -3150,12 +3109,9 @@ void QPainter::fillPath(const QPainterPath &path, const QBrush &brush) if (path.isEmpty()) return; - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fill(qtVectorPathForPath(path), brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fill(qtVectorPathForPath(path), brush); + return; } QBrush oldBrush = d->state->brush; @@ -3946,8 +3902,10 @@ void QPainter::drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawRoundedRect: Painter not active"); return; + } if (xRadius <= 0 || yRadius <= 0) { // draw normal rectangle drawRect(rect); @@ -4008,8 +3966,10 @@ void QPainter::drawEllipse(const QRectF &r) #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawEllipse: Painter not active"); return; + } QRectF rect(r.normalized()); @@ -4049,8 +4009,10 @@ void QPainter::drawEllipse(const QRect &r) #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawEllipse: Painter not active"); return; + } QRect rect(r.normalized()); @@ -4136,8 +4098,10 @@ void QPainter::drawArc(const QRectF &r, int a, int alen) #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawArc: Painter not active"); return; + } QRectF rect = r.normalized(); @@ -4198,8 +4162,10 @@ void QPainter::drawPie(const QRectF &r, int a, int alen) #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawPie: Painter not active"); return; + } if (a > (360*16)) { a = a % (360*16); @@ -4267,8 +4233,10 @@ void QPainter::drawChord(const QRectF &r, int a, int alen) #endif Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawChord: Painter not active"); return; + } QRectF rect = r.normalized(); @@ -5493,9 +5461,13 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText QStaticTextPrivate *staticText_d = const_cast<QStaticTextPrivate *>(QStaticTextPrivate::get(&staticText)); - if (font() != staticText_d->font) { + QFontPrivate *fp = QFontPrivate::get(font()); + QFontPrivate *stfp = QFontPrivate::get(staticText_d->font); + if (font() != staticText_d->font || fp == nullptr || stfp == nullptr || fp->dpi != stfp->dpi) { staticText_d->font = font(); staticText_d->needsRelayout = true; + } else if (stfp->engineData == nullptr || stfp->engineData->fontCacheId != QFontCache::instance()->id()) { + staticText_d->needsRelayout = true; } QFontEngine *fe = staticText_d->font.d->engineForScript(QChar::Script_Common); @@ -5633,7 +5605,7 @@ void QPainter::drawText(const QPointF &p, const QString &str, int tf, int justif } engine.itemize(); QScriptLine line; - line.length = str.length(); + line.length = str.size(); engine.shapeLine(line); int nItems = engine.layoutData->items.size(); @@ -5688,7 +5660,7 @@ void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br Q_D(QPainter); - if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) + if (!d->engine || str.size() == 0 || pen().style() == Qt::NoPen) return; if (!d->extended) @@ -5775,7 +5747,7 @@ void QPainter::drawText(const QRectF &r, int flags, const QString &str, QRectF * Q_D(QPainter); - if (!d->engine || str.length() == 0 || pen().style() == Qt::NoPen) + if (!d->engine || str.size() == 0 || pen().style() == Qt::NoPen) return; if (!d->extended) @@ -5894,7 +5866,7 @@ void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption Q_D(QPainter); - if (!d->engine || text.length() == 0 || pen().style() == Qt::NoPen) + if (!d->engine || text.size() == 0 || pen().style() == Qt::NoPen) return; if (!d->extended) @@ -5934,7 +5906,7 @@ void QPainter::drawText(const QRectF &r, const QString &text, const QTextOption It ignores the font set on the painter as the text item has one of its own. The underline and strikeout parameters of the text items font are - ignored aswell. You'll need to pass in the correct flags to get + ignored as well. You'll need to pass in the correct flags to get underlining and strikeout. */ @@ -5942,7 +5914,7 @@ static QPixmap generateWavyPixmap(qreal maxRadius, const QPen &pen) { const qreal radiusBase = qMax(qreal(1), maxRadius); - QString key = QLatin1String("WaveUnderline-") + QString key = "WaveUnderline-"_L1 % pen.color().name() % HexString<qreal>(radiusBase) % HexString<qreal>(pen.widthF()); @@ -6385,7 +6357,7 @@ QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextO { Q_D(QPainter); - if (!d->engine || text.length() == 0) + if (!d->engine || text.size() == 0) return QRectF(r.x(),r.y(), 0,0); QRectF br; @@ -6550,8 +6522,10 @@ void QPainter::drawPicture(const QPointF &p, const QPicture &picture) { Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::drawPicture: Painter not active"); return; + } if (!d->extended) d->updateState(d->state); @@ -6662,15 +6636,14 @@ void QPainter::fillRect(const QRectF &r, const QBrush &brush) { Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::fillRect: Painter not active"); return; + } - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fillRect(r, brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fillRect(r, brush); + return; } QPen oldPen = pen(); @@ -6700,15 +6673,14 @@ void QPainter::fillRect(const QRect &r, const QBrush &brush) { Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::fillRect: Painter not active"); return; + } - if (d->extended) { - const QGradient *g = brush.gradient(); - if (!g || g->coordinateMode() == QGradient::LogicalMode) { - d->extended->fillRect(r, brush); - return; - } + if (d->extended && !needsEmulation(brush)) { + d->extended->fillRect(r, brush); + return; } QPen oldPen = pen(); @@ -6741,8 +6713,10 @@ void QPainter::fillRect(const QRect &r, const QColor &color) { Q_D(QPainter); - if (!d->engine) + if (!d->engine) { + qWarning("QPainter::fillRect: Painter not active"); return; + } if (d->extended) { d->extended->fillRect(r, color); @@ -7181,19 +7155,19 @@ start_lengthVariant: // compatible behaviour to the old implementation. Replace // tabs by spaces int old_offset = offset; - for (; offset < text.length(); offset++) { + for (; offset < text.size(); offset++) { QChar chr = text.at(offset); - if (chr == QLatin1Char('\r') || (singleline && chr == QLatin1Char('\n'))) { - text[offset] = QLatin1Char(' '); - } else if (chr == QLatin1Char('\n')) { + if (chr == u'\r' || (singleline && chr == u'\n')) { + text[offset] = u' '; + } else if (chr == u'\n') { text[offset] = QChar::LineSeparator; - } else if (chr == QLatin1Char('&')) { + } else if (chr == u'&') { ++maxUnderlines; - } else if (chr == QLatin1Char('\t')) { + } else if (chr == u'\t') { if (!expandtabs) { - text[offset] = QLatin1Char(' '); + text[offset] = u' '; } else if (!tabarraylen && !tabstops) { - tabstops = qRound(fm.horizontalAdvance(QLatin1Char('x'))*8); + tabstops = qRound(fm.horizontalAdvance(u'x')*8); } } else if (chr == u'\x9c') { // string with multiple length variants @@ -7210,13 +7184,13 @@ start_lengthVariant: QChar *cin = cout; int l = length; while (l) { - if (*cin == QLatin1Char('&')) { + if (*cin == u'&') { ++cin; --length; --l; if (!l) break; - if (*cin != QLatin1Char('&') && !hidemnmemonic && !(tf & Qt::TextDontPrint)) { + if (*cin != u'&' && !hidemnmemonic && !(tf & Qt::TextDontPrint)) { QTextLayout::FormatRange range; range.start = cout - cout0; range.length = 1; @@ -7224,9 +7198,9 @@ start_lengthVariant: underlineFormats.append(range); } #ifdef Q_OS_MAC - } else if (hidemnmemonic && *cin == QLatin1Char('(') && l >= 4 && - cin[1] == QLatin1Char('&') && cin[2] != QLatin1Char('&') && - cin[3] == QLatin1Char(')')) { + } else if (hidemnmemonic && *cin == u'(' && l >= 4 && + cin[1] == u'&' && cin[2] != u'&' && + cin[3] == u')') { int n = 0; while ((cout - n) > cout0 && (cout - n - 1)->isSpace()) ++n; @@ -8191,3 +8165,5 @@ void qt_draw_helper(QPainterPrivate *p, const QPainterPath &path, QPainterPrivat } QT_END_NAMESPACE + +#include "moc_qpainter.cpp" |