From 45e5fe098532b1cdd3100879a3cb9136ea52507d Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 3 Jan 2022 23:39:25 +0200 Subject: [PATCH] drop support for static text [ci reset] Signed-off-by: Ivailo Monev --- package/freebsd/pkg-plist | 2 - package/netbsd/PLIST | 2 - package/openbsd/pkg/PLIST | 2 - scripts/namefsck.py | 1 - src/gui/CMakeLists.txt | 4 - src/gui/painting/qpaintengine_raster.cpp | 12 - src/gui/painting/qpaintengine_raster_p.h | 2 - src/gui/painting/qpaintengineex.cpp | 33 - src/gui/painting/qpaintengineex_p.h | 3 - src/gui/painting/qpainter.cpp | 181 +----- src/gui/painting/qpainter.h | 15 - src/gui/text/qstatictext.cpp | 668 --------------------- src/gui/text/qstatictext.h | 75 --- src/gui/text/qstatictext_p.h | 144 ----- src/gui/text/qtextlayout.cpp | 2 - src/tools/uic/cpp/cppwriteincludes.cpp | 1 - .../gui/painting/qtbench/benchmarktests.h | 34 +- 17 files changed, 28 insertions(+), 1153 deletions(-) delete mode 100644 src/gui/text/qstatictext.cpp delete mode 100644 src/gui/text/qstatictext.h delete mode 100644 src/gui/text/qstatictext_p.h diff --git a/package/freebsd/pkg-plist b/package/freebsd/pkg-plist index 61990b18a..29d58498a 100644 --- a/package/freebsd/pkg-plist +++ b/package/freebsd/pkg-plist @@ -827,7 +827,6 @@ include/katie/QtGui/QStackedWidget include/katie/QtGui/QStandardItem include/katie/QtGui/QStandardItemEditorCreator include/katie/QtGui/QStandardItemModel -include/katie/QtGui/QStaticText include/katie/QtGui/QStatusBar include/katie/QtGui/QStatusTipEvent include/katie/QtGui/QStringListModel @@ -1116,7 +1115,6 @@ include/katie/QtGui/qsplitter.h include/katie/QtGui/qstackedlayout.h include/katie/QtGui/qstackedwidget.h include/katie/QtGui/qstandarditemmodel.h -include/katie/QtGui/qstatictext.h include/katie/QtGui/qstatusbar.h include/katie/QtGui/qstringlistmodel.h include/katie/QtGui/qstyle.h diff --git a/package/netbsd/PLIST b/package/netbsd/PLIST index d5e829d1f..bf12f7a53 100644 --- a/package/netbsd/PLIST +++ b/package/netbsd/PLIST @@ -830,7 +830,6 @@ include/katie/QtGui/QStackedWidget include/katie/QtGui/QStandardItem include/katie/QtGui/QStandardItemEditorCreator include/katie/QtGui/QStandardItemModel -include/katie/QtGui/QStaticText include/katie/QtGui/QStatusBar include/katie/QtGui/QStatusTipEvent include/katie/QtGui/QStringListModel @@ -1119,7 +1118,6 @@ include/katie/QtGui/qsplitter.h include/katie/QtGui/qstackedlayout.h include/katie/QtGui/qstackedwidget.h include/katie/QtGui/qstandarditemmodel.h -include/katie/QtGui/qstatictext.h include/katie/QtGui/qstatusbar.h include/katie/QtGui/qstringlistmodel.h include/katie/QtGui/qstyle.h diff --git a/package/openbsd/pkg/PLIST b/package/openbsd/pkg/PLIST index 21d2648d3..bac35cce9 100644 --- a/package/openbsd/pkg/PLIST +++ b/package/openbsd/pkg/PLIST @@ -835,7 +835,6 @@ include/katie/QtGui/QStackedWidget include/katie/QtGui/QStandardItem include/katie/QtGui/QStandardItemEditorCreator include/katie/QtGui/QStandardItemModel -include/katie/QtGui/QStaticText include/katie/QtGui/QStatusBar include/katie/QtGui/QStatusTipEvent include/katie/QtGui/QStringListModel @@ -1124,7 +1123,6 @@ include/katie/QtGui/qsplitter.h include/katie/QtGui/qstackedlayout.h include/katie/QtGui/qstackedwidget.h include/katie/QtGui/qstandarditemmodel.h -include/katie/QtGui/qstatictext.h include/katie/QtGui/qstatusbar.h include/katie/QtGui/qstringlistmodel.h include/katie/QtGui/qstyle.h diff --git a/scripts/namefsck.py b/scripts/namefsck.py index 16469aa0e..7390db704 100755 --- a/scripts/namefsck.py +++ b/scripts/namefsck.py @@ -574,7 +574,6 @@ classlist = [ "QStandardItemEditorCreator", "QStandardItemModel", "QStandardPaths", - "QStaticText", "QStatusBar", "QStatusTipEvent", "QString", diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 9cc803a23..0fefcc6bf 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -159,7 +159,6 @@ set(GUI_PUBLIC_HEADERS QStackedLayout QStackedWidget QStandardItemModel - QStaticText QStatusBar QStringListModel QStyle @@ -506,8 +505,6 @@ set(GUI_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/text/qtextdocumentwriter.h ${CMAKE_CURRENT_SOURCE_DIR}/text/qcssparser_p.h ${CMAKE_CURRENT_SOURCE_DIR}/text/qtexttable_p.h - ${CMAKE_CURRENT_SOURCE_DIR}/text/qstatictext_p.h - ${CMAKE_CURRENT_SOURCE_DIR}/text/qstatictext.h ${CMAKE_CURRENT_SOURCE_DIR}/text/qharfbuzz_p.h ${CMAKE_CURRENT_SOURCE_DIR}/text/qfontengine_ft_p.h ${CMAKE_CURRENT_SOURCE_DIR}/text/qfontdatabase_x11_p.h @@ -828,7 +825,6 @@ set(GUI_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/text/qtextdocumentwriter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/text/qsyntaxhighlighter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/text/qcssparser.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/text/qstatictext.cpp ${CMAKE_CURRENT_SOURCE_DIR}/text/qfont_x11.cpp ${CMAKE_CURRENT_SOURCE_DIR}/text/qunicodetables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/util/qsystemtrayicon.cpp diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index f584f0b19..8213e040b 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -29,7 +29,6 @@ #include "qmath.h" #include "qpixmap_raster_p.h" #include "qimage_p.h" -#include "qstatictext_p.h" #include "qpaintengine_raster_p.h" #include "qoutlinemapper_p.h" #include "qguicommon_p.h" @@ -1874,17 +1873,6 @@ QRasterPaintEnginePrivate::getBrushFunc(const QRectF &rect, } /*! - \reimp -*/ -void QRasterPaintEngine::drawStaticTextItem(QStaticTextItem *textItem) -{ - ensurePen(); - ensureRasterState(); - - QPaintEngineEx::drawStaticTextItem(textItem); -} - -/*! \reimp */ void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem) diff --git a/src/gui/painting/qpaintengine_raster_p.h b/src/gui/painting/qpaintengine_raster_p.h index 290ad6bfd..48cdd5818 100644 --- a/src/gui/painting/qpaintengine_raster_p.h +++ b/src/gui/painting/qpaintengine_raster_p.h @@ -163,8 +163,6 @@ public: void clip(const QRect &rect, Qt::ClipOperation op); void clip(const QRegion ®ion, Qt::ClipOperation op); - void drawStaticTextItem(QStaticTextItem *textItem); - #ifdef Q_NO_USING_KEYWORD inline void drawEllipse(const QRect &rect) { QPaintEngineEx::drawEllipse(rect); } #else diff --git a/src/gui/painting/qpaintengineex.cpp b/src/gui/painting/qpaintengineex.cpp index b3a17af32..4d2c9995d 100644 --- a/src/gui/painting/qpaintengineex.cpp +++ b/src/gui/painting/qpaintengineex.cpp @@ -23,7 +23,6 @@ #include "qpainter_p.h" #include "qstroker_p.h" #include "qpainterpath_p.h" -#include "qstatictext_p.h" #include "qvarlengtharray.h" #include "qdebug.h" #include "qcorecommon_p.h" @@ -843,38 +842,6 @@ void QPaintEngineEx::updateState(const QPaintEngineState &) // do nothing... } -void QPaintEngineEx::drawStaticTextItem(QStaticTextItem *staticTextItem) -{ - QPainterPath path; - path.setFillRule(Qt::WindingFill); - - if (staticTextItem->numGlyphs == 0) - return; - - QFontEngine *fontEngine = staticTextItem->fontEngine(); - fontEngine->addGlyphsToPath(staticTextItem->glyphs, staticTextItem->glyphPositions, - staticTextItem->numGlyphs, &path, 0); - if (!path.isEmpty()) { - QPainterState *s = state(); - QPainter::RenderHints oldHints = s->renderHints; - bool changedHints = false; - if (bool(oldHints & QPainter::TextAntialiasing) - && !bool(fontEngine->fontDef.styleStrategy & QFont::NoAntialias) - && !bool(oldHints & QPainter::Antialiasing)) { - s->renderHints |= QPainter::Antialiasing; - renderHintsChanged(); - changedHints = true; - } - - fill(qtVectorPathForPath(path), s->pen.color()); - - if (changedHints) { - s->renderHints = oldHints; - renderHintsChanged(); - } - } -} - bool QPaintEngineEx::supportsTransformations(const qreal pixelSize, const QTransform &m) const { Q_UNUSED(pixelSize); diff --git a/src/gui/painting/qpaintengineex_p.h b/src/gui/painting/qpaintengineex_p.h index f34b9076c..2098ccc78 100644 --- a/src/gui/painting/qpaintengineex_p.h +++ b/src/gui/painting/qpaintengineex_p.h @@ -47,7 +47,6 @@ QT_BEGIN_NAMESPACE class QPainterState; class QPaintEngineExPrivate; -class QStaticTextItem; struct StrokeHandler; class QRectVectorPath : public QVectorPath { @@ -161,8 +160,6 @@ public: virtual void updateState(const QPaintEngineState &state); - virtual void drawStaticTextItem(QStaticTextItem *); - virtual void setState(QPainterState *s); inline QPainterState *state() { return static_cast(QPaintEngine::state); } inline const QPainterState *state() const { return static_cast(QPaintEngine::state); } diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 21180160f..80bb3d6f0 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -36,12 +36,10 @@ #include "qstyle.h" #include "qthread.h" #include "qvarlengtharray.h" -#include "qstatictext.h" #include "qpaintengine_p.h" #include "qpainterpath_p.h" #include "qwidget_p.h" #include "qpaintengine_raster_p.h" -#include "qstatictext_p.h" #include "qstylehelper_p.h" QT_BEGIN_NAMESPACE @@ -4732,28 +4730,6 @@ void QPainter::drawImage(const QRectF &targetRect, const QImage &image, const QR } /*! - - \fn void QPainter::drawStaticText(const QPoint &topLeftPosition, const QStaticText &staticText) - \since 4.7 - \overload - - Draws the \a staticText at the \a topLeftPosition. - - \note The y-position is used as the top of the font. - -*/ - -/*! - \fn void QPainter::drawStaticText(int left, int top, const QStaticText &staticText) - \since 4.7 - \overload - - Draws the \a staticText at coordinates \a left and \a top. - - \note The y-position is used as the top of the font. -*/ - -/*! \fn void QPainter::drawText(const QPointF &position, const QString &text) Draws the given \a text with the currently defined text direction, @@ -4781,143 +4757,40 @@ void QPainter::drawText(const QPointF &p, const QString &str) if (!d->engine || str.isEmpty() || pen().style() == Qt::NoPen) return; - QStaticText statictext(str); - QTextOption textoption = statictext.textOption(); - textoption.setTextDirection(d->state->layoutDirection); - statictext.setTextOption(textoption); - statictext.prepare(d->state->matrix, d->state->font); - - qreal fontheight = d->state->font.pointSizeF(); - if (fontheight <= 0.0) { - fontheight = d->state->font.pixelSize(); - } - // do not ask what the magic 0.8 division is for, it is just visually right for any point size - drawStaticText(QPointF(p.x(), p.y() - (fontheight / 0.8)), statictext); -} - -/*! - \since 4.7 - - Draws the given \a staticText at the given \a topLeftPosition. - - The text will be drawn using the font and the transformation set on the painter. If the - font and/or transformation set on the painter are different from the ones used to initialize - the layout of the QStaticText, then the layout will have to be recalculated. Use - QStaticText::prepare() to initialize \a staticText with the font and transformation with which - it will later be drawn. - - If \a topLeftPosition is not the same as when \a staticText was initialized, or when it was - last drawn, then there will be a slight overhead when translating the text to its new position. - - \note If the painter's transformation is not affine, then \a staticText will be drawn using - regular calls to drawText(), losing any potential for performance improvement. - - \note The y-position is used as the top of the font. - - \sa QStaticText -*/ -void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText) -{ - Q_D(QPainter); - if (!d->engine || staticText.text().isEmpty() || pen().style() == Qt::NoPen) - return; - - QStaticTextPrivate *staticText_d = - const_cast(QStaticTextPrivate::get(&staticText)); + QStackTextEngine engine(str, d->state->font); + engine.option.setTextDirection(d->state->layoutDirection); + engine.itemize(); + QScriptLine line; + line.length = str.length(); + engine.shapeLine(line); - if (font() != staticText_d->font) { - staticText_d->font = font(); - staticText_d->needsRelayout = true; - } + int nItems = engine.layoutData->items.size(); - // If we don't have an extended paint engine, or if the painter is projected, - // we go through standard code path - if (d->extended == nullptr || !d->state->matrix.isAffine()) { - staticText_d->paintText(topLeftPosition, this); - return; - } + QFixed x = QFixed::fromReal(p.x()); - bool supportsTransformations = d->extended->supportsTransformations(staticText_d->font.pixelSize(), - d->state->matrix); - if (supportsTransformations && !staticText_d->untransformedCoordinates) { - staticText_d->untransformedCoordinates = true; - staticText_d->needsRelayout = true; - } else if (!supportsTransformations && staticText_d->untransformedCoordinates) { - staticText_d->untransformedCoordinates = false; - staticText_d->needsRelayout = true; - } - - // Don't recalculate entire layout because of translation, rather add the dx and dy - // into the position to move each text item the correct distance. - QPointF transformedPosition = topLeftPosition; - if (!staticText_d->untransformedCoordinates) - transformedPosition = transformedPosition * d->state->matrix; - QTransform oldMatrix; - - // The translation has been applied to transformedPosition. Remove translation - // component from matrix. - if (d->state->matrix.isTranslating() && !staticText_d->untransformedCoordinates) { - qreal m11 = d->state->matrix.m11(); - qreal m12 = d->state->matrix.m12(); - qreal m13 = d->state->matrix.m13(); - qreal m21 = d->state->matrix.m21(); - qreal m22 = d->state->matrix.m22(); - qreal m23 = d->state->matrix.m23(); - qreal m33 = d->state->matrix.m33(); - - oldMatrix = d->state->matrix; - d->state->matrix.setMatrix(m11, m12, m13, - m21, m22, m23, - 0.0, 0.0, m33); - } - - // If the transform is not identical to the text transform, - // we have to relayout the text (for other transformations than plain translation) - bool staticTextNeedsReinit = staticText_d->needsRelayout; - if (!staticText_d->untransformedCoordinates && staticText_d->matrix != d->state->matrix) { - staticText_d->matrix = d->state->matrix; - staticTextNeedsReinit = true; - } - - // Recreate the layout of the static text because the matrix or font has changed - if (staticTextNeedsReinit) - staticText_d->init(); - - if (transformedPosition != staticText_d->position) { // Translate to actual position - QFixed fx = QFixed::fromReal(transformedPosition.x()); - QFixed fy = QFixed::fromReal(transformedPosition.y()); - QFixed oldX = QFixed::fromReal(staticText_d->position.x()); - QFixed oldY = QFixed::fromReal(staticText_d->position.y()); - for (int item=0; itemitemCount;++item) { - QStaticTextItem *textItem = staticText_d->items + item; - for (int i=0; inumGlyphs; ++i) { - textItem->glyphPositions[i].x += fx - oldX; - textItem->glyphPositions[i].y += fy - oldY; - } + for (int i = 0; i < nItems; ++i) { + const QScriptItem &si = engine.layoutData->items.at(i); + if (si.analysis.flags >= QScriptAnalysis::TabOrObject) { + x += si.width; + continue; } - - staticText_d->position = transformedPosition; - } - - QPen oldPen = d->state->pen; - QColor currentColor = oldPen.color(); - for (int i=0; iitemCount; ++i) { - QStaticTextItem *item = staticText_d->items + i; - if (item->color.isValid() && currentColor != item->color) { - setPen(item->color); - currentColor = item->color; + QFont f = engine.font(si); + QTextItemInt gf(si, &f); + gf.glyphs = engine.shapedGlyphs(&si); + gf.chars = engine.layoutData->string.unicode() + si.position; + gf.num_chars = engine.length(i); + if (engine.forceJustification) { + for (int j=0; jextended->drawStaticTextItem(item); + gf.logClusters = engine.logClusters(&si); - qt_draw_decoration_for_glyphs(this, item->glyphs, item->glyphPositions, - item->numGlyphs, item->fontEngine(), staticText_d->font, - QTextCharFormat()); - } - if (currentColor != oldPen.color()) - setPen(oldPen); + drawTextItem(QPointF(x.toReal(), p.y()), gf); - if (!staticText_d->untransformedCoordinates && oldMatrix.isTranslating()) - d->state->matrix = oldMatrix; + x += gf.width; + } } void QPainter::drawText(const QRect &r, int flags, const QString &str, QRect *br) diff --git a/src/gui/painting/qpainter.h b/src/gui/painting/qpainter.h index ae2b3f451..d06adf9c2 100644 --- a/src/gui/painting/qpainter.h +++ b/src/gui/painting/qpainter.h @@ -46,7 +46,6 @@ class QPolygon; class QTextItem; class QMatrix; class QTransform; -class QStaticText; class Q_GUI_EXPORT QPainter { @@ -321,10 +320,6 @@ public: void setLayoutDirection(Qt::LayoutDirection direction); Qt::LayoutDirection layoutDirection() const; - void drawStaticText(const QPointF &topLeftPosition, const QStaticText &staticText); - inline void drawStaticText(const QPoint &topLeftPosition, const QStaticText &staticText); - inline void drawStaticText(int left, int top, const QStaticText &staticText); - void drawText(const QPointF &p, const QString &s); inline void drawText(const QPoint &p, const QString &s); inline void drawText(int x, int y, const QString &s); @@ -761,16 +756,6 @@ inline void QPainter::drawImage(int x, int y, const QImage &image, int sx, int s drawImage(QRectF(x, y, -1, -1), image, QRectF(sx, sy, sw, sh), flags); } -inline void QPainter::drawStaticText(const QPoint &p, const QStaticText &staticText) -{ - drawStaticText(QPointF(p), staticText); -} - -inline void QPainter::drawStaticText(int x, int y, const QStaticText &staticText) -{ - drawStaticText(QPointF(x, y), staticText); -} - inline void QPainter::drawTextItem(const QPoint &p, const QTextItem &ti) { drawTextItem(QPointF(p), ti); diff --git a/src/gui/text/qstatictext.cpp b/src/gui/text/qstatictext.cpp deleted file mode 100644 index 6bd6d41e8..000000000 --- a/src/gui/text/qstatictext.cpp +++ /dev/null @@ -1,668 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2016 Ivailo Monev -** -** This file is part of the test suite of the Katie Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qstatictext.h" -#include "qstatictext_p.h" -#include "qtextengine_p.h" -#include "qfontengine_p.h" -#include "qfontmetrics.h" -#include "qabstracttextdocumentlayout.h" -#include "qapplication.h" -#include "qx11info_x11.h" - -QT_BEGIN_NAMESPACE - -/*! - \class QStaticText - \brief The QStaticText class enables optimized drawing of text when the text and its layout - is updated rarely. - \since 4.7 - - \ingroup multimedia - \ingroup text - \mainclass - - QStaticText provides a way to cache layout data for a block of text so that it can be drawn - more efficiently than by using QPainter::drawText() in which the layout information is - recalculated with every call. - - The class primarily provides an optimization for cases where the text, its font and the - transformations on the painter are static over several paint events. If the text or its layout - is changed for every iteration, QPainter::drawText() is the more efficient alternative, since - the static text's layout would have to be recalculated to take the new state into consideration. - - Translating the painter will not cause the layout of the text to be recalculated, but will cause - a very small performance impact on drawStaticText(). Altering any other parts of the painter's - transformation or the painter's font will cause the layout of the static text to be - recalculated. This should be avoided as often as possible to maximize the performance - benefit of using QStaticText. - - In addition, only affine transformations are supported by drawStaticText(). Calling - drawStaticText() on a projected painter will perform slightly worse than using the regular - drawText() call, so this should be avoided. - - \code - class MyWidget: public QWidget - { - public: - MyWidget(QWidget *parent = nullptr) : QWidget(parent), m_staticText("This is static text") - - protected: - void paintEvent(QPaintEvent *) - { - QPainter painter(this); - painter.drawStaticText(0, 0, m_staticText); - } - - private: - QStaticText m_staticText; - }; - \endcode - - The QStaticText class can be used to mimic the behavior of QPainter::drawText() to a specific - point with no boundaries, and also when QPainter::drawText() is called with a bounding - rectangle. - - If a bounding rectangle is not required, create a QStaticText object without setting a preferred - text width. The text will then occupy a single line. - - If you set a text width on the QStaticText object, this will bound the text. The text will - be formatted so that no line exceeds the given width. The text width set for QStaticText will - not automatically be used for clipping. To achieve clipping in addition to line breaks, use - QPainter::setClipRect(). The position of the text is decided by the argument passed to - QPainter::drawStaticText() and can change from call to call with a minimal impact on - performance. - - For extra convenience, it is possible to apply formatting to the text using the HTML subset - supported by QTextDocument. QStaticText will attempt to guess the format of the input text using - Qt::mightBeRichText(), and interpret it as rich text if this function returns true. To force - QStaticText to display its contents as either plain text or rich text, use the function - QStaticText::setTextFormat() and pass in, respectively, Qt::PlainText and Qt::RichText. - - QStaticText can only represent text, so only HTML tags which alter the layout or appearance of - the text will be respected. Adding an image to the input HTML, for instance, will cause the - image to be included as part of the layout, affecting the positions of the text glyphs, but it - will not be displayed. The result will be an empty area the size of the image in the output. - Similarly, using tables will cause the text to be laid out in table format, but the borders - will not be drawn. - - If it's the first time the static text is drawn, or if the static text, or the painter's font - has been altered since the last time it was drawn, the text's layout has to be - recalculated. On some paint engines, changing the matrix of the painter will also cause the - layout to be recalculated. In particular, this will happen for any paint engine. Recalculating - the layout will impose an overhead on the QPainter::drawStaticText() call where it occurs. To - avoid this overhead in the paint event, you can call prepare() ahead of time to ensure that - the layout is calculated. - - \sa QPainter::drawText(), QPainter::drawStaticText(), QTextLayout, QTextDocument -*/ - -/*! - Constructs an empty QStaticText -*/ -QStaticText::QStaticText() - : data(new QStaticTextPrivate) -{ -} - -/*! - Constructs a QStaticText object with the given \a text. -*/ -QStaticText::QStaticText(const QString &text) - : data(new QStaticTextPrivate) -{ - data->text = text; - data->invalidate(); -} - -/*! - Constructs a QStaticText object which is a copy of \a other. -*/ -QStaticText::QStaticText(const QStaticText &other) -{ - data = other.data; -} - -/*! - Destroys the QStaticText. -*/ -QStaticText::~QStaticText() -{ - Q_ASSERT(!data || data->ref >= 1); -} - -/*! - \internal -*/ -void QStaticText::detach() -{ - if (data->ref != 1) - data.detach(); -} - -/*! - Prepares the QStaticText object for being painted with the given \a matrix and the given \a font - to avoid overhead when the actual drawStaticText() call is made. - - When drawStaticText() is called, the layout of the QStaticText will be recalculated if any part - of the QStaticText object has changed since the last time it was drawn. It will also be - recalculated if the painter's font is not the same as when the QStaticText was last drawn, or, - on any other paint engine, if the painter's matrix has been altered since the static text was - last drawn. - - To avoid the overhead of creating the layout the first time you draw the QStaticText after - making changes, you can use the prepare() function and pass in the \a matrix and \a font you - expect to use when drawing the text. - - \sa QPainter::setFont(), QPainter::setMatrix() -*/ -void QStaticText::prepare(const QTransform &matrix, const QFont &font) -{ - data->matrix = matrix; - data->font = font; - data->init(); -} - - -/*! - Assigns \a other to this QStaticText. -*/ -QStaticText &QStaticText::operator=(const QStaticText &other) -{ - data = other.data; - return *this; -} - -/*! - Compares \a other to this QStaticText. Returns true if the texts, fonts and text widths - are equal. -*/ -bool QStaticText::operator==(const QStaticText &other) const -{ - return (data == other.data - || (data->text == other.data->text - && data->font == other.data->font - && data->textWidth == other.data->textWidth)); -} - -/*! - Compares \a other to this QStaticText. Returns true if the texts, fonts or maximum sizes - are different. -*/ -bool QStaticText::operator!=(const QStaticText &other) const -{ - return !(*this == other); -} - -/*! - Sets the text of the QStaticText to \a text. - - \note This function will cause the layout of the text to require recalculation. - - \sa text() -*/ -void QStaticText::setText(const QString &text) -{ - detach(); - data->text = text; - data->invalidate(); -} - -/*! - Sets the text format of the QStaticText to \a textFormat. If \a textFormat is set to - Qt::AutoText (the default), the format of the text will try to be determined using the - function Qt::mightBeRichText(). If the text format is Qt::PlainText, then the text will be - displayed as is, whereas it will be interpreted as HTML if the format is Qt::RichText. HTML tags - that alter the font of the text, its color, or its layout are supported by QStaticText. - - \note This function will cause the layout of the text to require recalculation. - - \sa textFormat(), setText(), text() -*/ -void QStaticText::setTextFormat(Qt::TextFormat textFormat) -{ - detach(); - data->textFormat = textFormat; - data->invalidate(); -} - -/*! - Returns the text format of the QStaticText. - - \sa setTextFormat(), setText(), text() -*/ -Qt::TextFormat QStaticText::textFormat() const -{ - return data->textFormat; -} - -/*! - Returns the text of the QStaticText. - - \sa setText() -*/ -QString QStaticText::text() const -{ - return data->text; -} - -/*! - Sets the text option structure that controls the layout process to the given \a textOption. - - \sa textOption() -*/ -void QStaticText::setTextOption(const QTextOption &textOption) -{ - detach(); - data->textOption = textOption; - data->invalidate(); -} - -/*! - Returns the current text option used to control the layout process. -*/ -QTextOption QStaticText::textOption() const -{ - return data->textOption; -} - -/*! - Sets the preferred width for this QStaticText. If the text is wider than the specified width, - it will be broken into multiple lines and grow vertically. If the text cannot be split into - multiple lines, it will be larger than the specified \a textWidth. - - Setting the preferred text width to a negative number will cause the text to be unbounded. - - Use size() to get the actual size of the text. - - \note This function will cause the layout of the text to require recalculation. - - \sa textWidth(), size() -*/ -void QStaticText::setTextWidth(qreal textWidth) -{ - detach(); - data->textWidth = textWidth; - data->invalidate(); -} - -/*! - Returns the preferred width for this QStaticText. - - \sa setTextWidth() -*/ -qreal QStaticText::textWidth() const -{ - return data->textWidth; -} - -/*! - Returns the size of the bounding rect for this QStaticText. - - \sa textWidth() -*/ -QSizeF QStaticText::size() const -{ - if (data->needsRelayout) - data->init(); - return data->actualSize; -} - -QStaticTextPrivate::QStaticTextPrivate() - : textWidth(-1.0), items(0), itemCount(0), glyphPool(0), positionPool(0), charPool(0), - needsRelayout(true), textFormat(Qt::AutoText), - untransformedCoordinates(false) -{ -} - -QStaticTextPrivate::QStaticTextPrivate(const QStaticTextPrivate &other) - : text(other.text), font(other.font), textWidth(other.textWidth), matrix(other.matrix), - items(0), itemCount(0), glyphPool(0), positionPool(0), charPool(0), textOption(other.textOption), - needsRelayout(true), textFormat(other.textFormat), - untransformedCoordinates(other.untransformedCoordinates) -{ -} - -QStaticTextPrivate::~QStaticTextPrivate() -{ - delete[] items; - delete[] glyphPool; - delete[] positionPool; - delete[] charPool; -} - -QStaticTextPrivate *QStaticTextPrivate::get(const QStaticText *q) -{ - return q->data.data(); -} - -namespace { - - class DrawTextItemRecorder: public QPaintEngine - { - public: - DrawTextItemRecorder(bool untransformedCoordinates) - : m_dirtyPen(false), m_untransformedCoordinates(untransformedCoordinates), - m_currentColor(Qt::black) - { - } - - virtual void updateState(const QPaintEngineState &newState) - { - if (newState.state() & QPaintEngine::DirtyPen - && newState.pen().color() != m_currentColor) { - m_dirtyPen = true; - m_currentColor = newState.pen().color(); - } - } - - virtual void drawTextItem(const QPointF &position, const QTextItem &textItem) - { - const QTextItemInt &ti = static_cast(textItem); - - QStaticTextItem currentItem; - currentItem.setFontEngine(ti.fontEngine); - currentItem.font = ti.font(); - currentItem.charOffset = m_chars.size(); - currentItem.numChars = ti.num_chars; - currentItem.glyphOffset = m_glyphs.size(); // Store offset into glyph pool - currentItem.positionOffset = m_glyphs.size(); // Offset into position pool - if (m_dirtyPen) - currentItem.color = m_currentColor; - - QTransform matrix = m_untransformedCoordinates ? QTransform() : state->transform(); - matrix.translate(position.x(), position.y()); - - QVarLengthArray glyphs; - QVarLengthArray positions; - ti.fontEngine->getGlyphPositions(ti.glyphs, matrix, ti.flags, glyphs, positions); - - int size = glyphs.size(); - Q_ASSERT(size == positions.size()); - currentItem.numGlyphs = size; - - m_glyphs.resize(m_glyphs.size() + size); - m_positions.resize(m_glyphs.size()); - m_chars.resize(m_chars.size() + ti.num_chars); - - glyph_t *glyphsDestination = m_glyphs.data() + currentItem.glyphOffset; - memcpy(glyphsDestination, glyphs.constData(), sizeof(glyph_t) * currentItem.numGlyphs); - - QFixedPoint *positionsDestination = m_positions.data() + currentItem.positionOffset; - memcpy(positionsDestination, positions.constData(), sizeof(QFixedPoint) * currentItem.numGlyphs); - - QChar *charsDestination = m_chars.data() + currentItem.charOffset; - memcpy(charsDestination, ti.chars, sizeof(QChar) * currentItem.numChars); - - m_items.append(currentItem); - } - - virtual void drawPolygon(const QPointF *, int , PolygonDrawMode ) - { - /* intentionally empty */ - } - - virtual bool begin(QPaintDevice *) { return true; } - virtual bool end() { return true; } - virtual void drawPixmap(const QRectF &, const QPixmap &, const QRectF &) {} - virtual Type type() const - { - return User; - } - - QVector items() const - { - return m_items; - } - - QVector positions() const - { - return m_positions; - } - - QVector glyphs() const - { - return m_glyphs; - } - - QVector chars() const - { - return m_chars; - } - - private: - QVector m_items; - QVector m_positions; - QVector m_glyphs; - QVector m_chars; - - bool m_dirtyPen; - bool m_untransformedCoordinates; - QColor m_currentColor; - }; - - class DrawTextItemDevice: public QPaintDevice - { - public: - DrawTextItemDevice(bool untransformedCoordinates) - { - m_paintEngine = new DrawTextItemRecorder(untransformedCoordinates); - } - - ~DrawTextItemDevice() - { - delete m_paintEngine; - } - - int metric(PaintDeviceMetric m) const - { - int val; - switch (m) { - case PdmWidth: - case PdmHeight: - case PdmWidthMM: - case PdmHeightMM: - val = 0; - break; - case PdmDpiX: - case PdmPhysicalDpiX: - val = QX11Info::appDpiX(); - break; - case PdmDpiY: - case PdmPhysicalDpiY: - val = QX11Info::appDpiY(); - break; - case PdmNumColors: - val = 16777216; - break; - case PdmDepth: - val = 24; - break; - default: - val = 0; - qWarning("DrawTextItemDevice::metric: Invalid metric command"); - } - return val; - } - - virtual QPaintEngine *paintEngine() const - { - return m_paintEngine; - } - - QVector glyphs() const - { - return m_paintEngine->glyphs(); - } - - QVector positions() const - { - return m_paintEngine->positions(); - } - - QVector items() const - { - return m_paintEngine->items(); - } - - QVector chars() const - { - return m_paintEngine->chars(); - } - - private: - DrawTextItemRecorder *m_paintEngine; - }; -} - -void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p) -{ - bool preferRichText = textFormat == Qt::RichText - || (textFormat == Qt::AutoText && Qt::mightBeRichText(text)); - - if (!preferRichText) { - QTextLayout textLayout; - textLayout.setText(text); - textLayout.setFont(font); - textLayout.setTextOption(textOption); - - qreal leading = QFontMetricsF(font).leading(); - qreal height = -leading; - - textLayout.beginLayout(); - while (1) { - QTextLine line = textLayout.createLine(); - if (!line.isValid()) - break; - - if (textWidth >= 0.0) - line.setLineWidth(textWidth); - height += leading; - line.setPosition(QPointF(0.0, height)); - height += line.height(); - } - textLayout.endLayout(); - - actualSize = textLayout.boundingRect().size(); - textLayout.draw(p, topLeftPosition); - } else { - QTextDocument document; -#ifndef QT_NO_CSSPARSER - const QColor color = p->pen().color(); - document.setDefaultStyleSheet(QString::fromLatin1("body { color: %1 }") - .arg(color.name())); -#endif - document.setDefaultFont(font); - document.setDocumentMargin(0.0); -#ifndef QT_NO_TEXTHTMLPARSER - document.setHtml(text); -#else - document.setPlainText(text); -#endif - if (textWidth >= 0.0) - document.setTextWidth(textWidth); - else - document.adjustSize(); - document.setDefaultTextOption(textOption); - - p->save(); - p->translate(topLeftPosition); - QAbstractTextDocumentLayout::PaintContext ctx; - ctx.palette.setColor(QPalette::Text, p->pen().color()); - document.documentLayout()->draw(p, ctx); - p->restore(); - - if (textWidth >= 0.0) - document.adjustSize(); // Find optimal size - - actualSize = document.size(); - } -} - -void QStaticTextPrivate::init() -{ - delete[] items; - delete[] glyphPool; - delete[] positionPool; - delete[] charPool; - - position = QPointF(0, 0); - - DrawTextItemDevice device(untransformedCoordinates); - { - QPainter painter(&device); - painter.setFont(font); - painter.setTransform(matrix); - - paintText(QPointF(0, 0), &painter); - } - - QVector deviceItems = device.items(); - QVector positions = device.positions(); - QVector glyphs = device.glyphs(); - QVector chars = device.chars(); - - itemCount = deviceItems.size(); - items = new QStaticTextItem[itemCount]; - - glyphPool = new glyph_t[glyphs.size()]; - memcpy(glyphPool, glyphs.constData(), glyphs.size() * sizeof(glyph_t)); - - positionPool = new QFixedPoint[positions.size()]; - memcpy(positionPool, positions.constData(), positions.size() * sizeof(QFixedPoint)); - - Q_ASSERT(chars.size() >= 1); - charPool = new QChar[chars.size()]; - memcpy(charPool, chars.constData(), chars.size() * sizeof(QChar)); - - for (int i=0; iref.deref(); - } -} - -void QStaticTextItem::setFontEngine(QFontEngine *fe) -{ - m_fontEngine = fe; - if (m_fontEngine) { - m_fontEngine->ref.ref(); - } -} - -QT_END_NAMESPACE - - - - - - diff --git a/src/gui/text/qstatictext.h b/src/gui/text/qstatictext.h deleted file mode 100644 index b41852d69..000000000 --- a/src/gui/text/qstatictext.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2016 Ivailo Monev -** -** This file is part of the test suite of the Katie Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSTATICTEXT_H -#define QSTATICTEXT_H - -#include -#include -#include -#include - - -QT_BEGIN_NAMESPACE - - -class QStaticTextPrivate; -class Q_GUI_EXPORT QStaticText -{ -public: - QStaticText(); - QStaticText(const QString &text); - QStaticText(const QStaticText &other); - ~QStaticText(); - - void setText(const QString &text); - QString text() const; - - void setTextFormat(Qt::TextFormat textFormat); - Qt::TextFormat textFormat() const; - - void setTextWidth(qreal textWidth); - qreal textWidth() const; - - void setTextOption(const QTextOption &textOption); - QTextOption textOption() const; - - QSizeF size() const; - - void prepare(const QTransform &matrix = QTransform(), const QFont &font = QFont()); - - QStaticText &operator=(const QStaticText &); - bool operator==(const QStaticText &) const; - bool operator!=(const QStaticText &) const; - -private: - void detach(); - - QExplicitlySharedDataPointer data; - friend class QStaticTextPrivate; -}; - -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QStaticText) - - -#endif // QSTATICTEXT_H diff --git a/src/gui/text/qstatictext_p.h b/src/gui/text/qstatictext_p.h deleted file mode 100644 index 98413b1db..000000000 --- a/src/gui/text/qstatictext_p.h +++ /dev/null @@ -1,144 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2016 Ivailo Monev -** -** This file is part of the test suite of the Katie Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QSTATICTEXT_P_H -#define QSTATICTEXT_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Katie API. It exists for the convenience -// of internal files. This header file may change from version to version -// without notice, or even be removed. -// -// We mean it. -// - -#include "qstatictext.h" - -#include "qfontengine_p.h" -#include - -QT_BEGIN_NAMESPACE - -class Q_GUI_EXPORT QStaticTextItem -{ -public: - QStaticTextItem() : chars(nullptr), numChars(0), m_fontEngine(nullptr) {} - - QStaticTextItem(const QStaticTextItem &other) - { - operator=(other); - } - - void operator=(const QStaticTextItem &other) - { - glyphPositions = other.glyphPositions; - glyphs = other.glyphs; - chars = other.chars; - numGlyphs = other.numGlyphs; - numChars = other.numChars; - font = other.font; - color = other.color; - - m_fontEngine = nullptr; - setFontEngine(other.fontEngine()); - } - - ~QStaticTextItem(); - - void setFontEngine(QFontEngine *fe); - QFontEngine *fontEngine() const { return m_fontEngine; } - - union { - QFixedPoint *glyphPositions; // 8 bytes per glyph - int positionOffset; - }; - union { - glyph_t *glyphs; // 4 bytes per glyph - int glyphOffset; - }; - union { - QChar *chars; // 2 bytes per glyph - int charOffset; - }; - // ================= - // 14 bytes per glyph - - // 12 bytes for pointers - int numGlyphs; // 4 bytes per item - int numChars; // 4 bytes per item - QFont font; // 8 bytes per item - QColor color; // 10 bytes per item - // ================ - // 51 bytes per item - -private: // Needs special handling in setters, so private to avoid abuse - QFontEngine *m_fontEngine; // 4 bytes per item -}; - -class QStaticText; -class Q_AUTOTEST_EXPORT QStaticTextPrivate -{ -public: - QStaticTextPrivate(); - QStaticTextPrivate(const QStaticTextPrivate &other); - ~QStaticTextPrivate(); - - void init(); - void paintText(const QPointF &pos, QPainter *p); - - void invalidate() - { - needsRelayout = true; - } - - QAtomicInt ref; // 4 bytes per text - - QString text; // 4 bytes per text - QFont font; // 8 bytes per text - qreal textWidth; // 8 bytes per text - QSizeF actualSize; // 16 bytes per text - QPointF position; // 16 bytes per text - - QTransform matrix; // 80 bytes per text - QStaticTextItem *items; // 4 bytes per text - int itemCount; // 4 bytes per text - - glyph_t *glyphPool; // 4 bytes per text - QFixedPoint *positionPool; // 4 bytes per text - QChar *charPool; // 4 bytes per text - - QTextOption textOption; // 28 bytes per text - - bool needsRelayout; // 1 byte per text - Qt::TextFormat textFormat; - bool untransformedCoordinates; - // ================ - // 195 bytes per text - - static QStaticTextPrivate *get(const QStaticText *q); -}; - -QT_END_NAMESPACE - -#endif // QSTATICTEXT_P_H diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 10bb72621..85f7bcd3a 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -270,8 +270,6 @@ Qt::LayoutDirection QTextInlineObject::textDirection() const The QTextLayout itself can be positioned with setPosition(); it has a boundingRect(), and a minimumWidth() and a maximumWidth(). - - \sa QStaticText */ /*! diff --git a/src/tools/uic/cpp/cppwriteincludes.cpp b/src/tools/uic/cpp/cppwriteincludes.cpp index d1f472da8..9af02cee3 100644 --- a/src/tools/uic/cpp/cppwriteincludes.cpp +++ b/src/tools/uic/cpp/cppwriteincludes.cpp @@ -535,7 +535,6 @@ static const struct ClassTblData { { QLatin1String("QStandardItem"), QLatin1String("QtGui/qstandarditemmodel.h") }, { QLatin1String("QStandardItemModel"), QLatin1String("QtGui/qstandarditemmodel.h") }, { QLatin1String("QStandardPaths"), QLatin1String("QtCore/qstandardpaths.h") }, - { QLatin1String("QStaticText"), QLatin1String("QtGui/qstatictext.h") }, { QLatin1String("QStatusBar"), QLatin1String("QtGui/qstatusbar.h") }, { QLatin1String("QStatusTipEvent"), QLatin1String("QtGui/qevent.h") }, { QLatin1String("QString"), QLatin1String("QtCore/qstring.h") }, diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h index a29d93245..d76c10ef1 100644 --- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h +++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h @@ -28,7 +28,6 @@ #include #include #include -#include class Benchmark { @@ -449,9 +448,7 @@ public: PainterQPointMode, LayoutMode, DocumentMode, - PixmapMode, - StaticTextMode, - StaticTextWithMaximumSizeMode + PixmapMode }; DrawText(const QString &text, Mode mode) @@ -460,7 +457,6 @@ public: } virtual void begin(QPainter *p, int iterations) { - m_staticTexts.clear(); m_pixmaps.clear(); m_currentPixmap = 0; QRect m_bounds = QRect(0,0,p->device()->width(), p->device()->height()); @@ -501,26 +497,6 @@ public: m_layout.endLayout(); m_layout.setCacheEnabled(true); m_size = m_layout.boundingRect().toRect().size(); - break; } - - case StaticTextWithMaximumSizeMode: { - QStaticText staticText; - m_size = (p->boundingRect(m_bounds, 0, m_text)).size(); - staticText.setTextWidth(m_size.width() + 10); - staticText.setText(m_text); - staticText.prepare(p->transform(), p->font()); - m_staticTexts.append(staticText); - break; - } - case StaticTextMode: { - QStaticText staticText; - staticText.setText(m_text); - staticText.prepare(p->transform(), p->font()); - m_staticTexts.append(staticText); - - QFontMetrics fm(p->font()); - m_size = QSize(fm.width(m_text, m_text.length()), fm.height()); - break; } @@ -554,10 +530,6 @@ public: case LayoutMode: m_layout.draw(p, rect.topLeft()); break; - case StaticTextWithMaximumSizeMode: - case StaticTextMode: - p->drawStaticText(rect.topLeft(), m_staticTexts.at(0)); - break; } } @@ -573,8 +545,6 @@ public: case LayoutMode: type = QLatin1String("layout.draw()"); break; case DocumentMode: type = QLatin1String("doc.drawContents()"); break; case PixmapMode: type = QLatin1String("pixmap cached text"); break; - case StaticTextMode: type = QLatin1String("drawStaticText()"); break; - case StaticTextWithMaximumSizeMode: type = QLatin1String("drawStaticText() w/ maxsize"); break; } return QString::fromLatin1("%3, len=%1, lines=%2") @@ -591,8 +561,6 @@ private: QList m_pixmaps; int m_currentPixmap; - - QList m_staticTexts; }; -- 2.11.0