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
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
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
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
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
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
"QStandardItemEditorCreator",
"QStandardItemModel",
"QStandardPaths",
- "QStaticText",
"QStatusBar",
"QStatusTipEvent",
"QString",
QStackedLayout
QStackedWidget
QStandardItemModel
- QStaticText
QStatusBar
QStringListModel
QStyle
${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
${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
#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"
}
/*!
- \reimp
-*/
-void QRasterPaintEngine::drawStaticTextItem(QStaticTextItem *textItem)
-{
- ensurePen();
- ensureRasterState();
-
- QPaintEngineEx::drawStaticTextItem(textItem);
-}
-
-/*!
\reimp
*/
void QRasterPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
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
#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"
// 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);
class QPainterState;
class QPaintEngineExPrivate;
-class QStaticTextItem;
struct StrokeHandler;
class QRectVectorPath : public QVectorPath {
virtual void updateState(const QPaintEngineState &state);
- virtual void drawStaticTextItem(QStaticTextItem *);
-
virtual void setState(QPainterState *s);
inline QPainterState *state() { return static_cast<QPainterState *>(QPaintEngine::state); }
inline const QPainterState *state() const { return static_cast<const QPainterState *>(QPaintEngine::state); }
#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
}
/*!
-
- \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,
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 *>(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; item<staticText_d->itemCount;++item) {
- QStaticTextItem *textItem = staticText_d->items + item;
- for (int i=0; i<textItem->numGlyphs; ++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; i<staticText_d->itemCount; ++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; j<gf.glyphs.numGlyphs; ++j)
+ gf.width += gf.glyphs.effectiveAdvance(j);
+ } else {
+ gf.width = si.width;
}
- d->extended->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)
class QTextItem;
class QMatrix;
class QTransform;
-class QStaticText;
class Q_GUI_EXPORT QPainter
{
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);
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);
+++ /dev/null
-/****************************************************************************
-**
-** 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<const QTextItemInt &>(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<glyph_t> glyphs;
- QVarLengthArray<QFixedPoint> 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<QStaticTextItem> items() const
- {
- return m_items;
- }
-
- QVector<QFixedPoint> positions() const
- {
- return m_positions;
- }
-
- QVector<glyph_t> glyphs() const
- {
- return m_glyphs;
- }
-
- QVector<QChar> chars() const
- {
- return m_chars;
- }
-
- private:
- QVector<QStaticTextItem> m_items;
- QVector<QFixedPoint> m_positions;
- QVector<glyph_t> m_glyphs;
- QVector<QChar> 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<glyph_t> glyphs() const
- {
- return m_paintEngine->glyphs();
- }
-
- QVector<QFixedPoint> positions() const
- {
- return m_paintEngine->positions();
- }
-
- QVector<QStaticTextItem> items() const
- {
- return m_paintEngine->items();
- }
-
- QVector<QChar> 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<QStaticTextItem> deviceItems = device.items();
- QVector<QFixedPoint> positions = device.positions();
- QVector<glyph_t> glyphs = device.glyphs();
- QVector<QChar> 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; i<itemCount; ++i) {
- items[i] = deviceItems.at(i);
-
- items[i].glyphs = glyphPool + items[i].glyphOffset;
- items[i].glyphPositions = positionPool + items[i].positionOffset;
- items[i].chars = charPool + items[i].charOffset;
- }
-
- needsRelayout = false;
-}
-
-QStaticTextItem::~QStaticTextItem()
-{
- if (m_fontEngine) {
- m_fontEngine->ref.deref();
- }
-}
-
-void QStaticTextItem::setFontEngine(QFontEngine *fe)
-{
- m_fontEngine = fe;
- if (m_fontEngine) {
- m_fontEngine->ref.ref();
- }
-}
-
-QT_END_NAMESPACE
-
-
-
-
-
-
+++ /dev/null
-/****************************************************************************
-**
-** 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 <QtCore/qsize.h>
-#include <QtGui/qtransform.h>
-#include <QtGui/qfont.h>
-#include <QtGui/qtextoption.h>
-
-
-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<QStaticTextPrivate> data;
- friend class QStaticTextPrivate;
-};
-
-QT_END_NAMESPACE
-
-Q_DECLARE_METATYPE(QStaticText)
-
-
-#endif // QSTATICTEXT_H
+++ /dev/null
-/****************************************************************************
-**
-** 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 <QtGui/qcolor.h>
-
-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
The QTextLayout itself can be positioned with setPosition(); it has a
boundingRect(), and a minimumWidth() and a maximumWidth().
-
- \sa QStaticText
*/
/*!
{ 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") },
#include <QTextLayout>
#include <QFontMetrics>
#include <QDebug>
-#include <QStaticText>
class Benchmark
{
PainterQPointMode,
LayoutMode,
DocumentMode,
- PixmapMode,
- StaticTextMode,
- StaticTextWithMaximumSizeMode
+ PixmapMode
};
DrawText(const QString &text, Mode mode)
}
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());
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;
}
case LayoutMode:
m_layout.draw(p, rect.topLeft());
break;
- case StaticTextWithMaximumSizeMode:
- case StaticTextMode:
- p->drawStaticText(rect.topLeft(), m_staticTexts.at(0));
- break;
}
}
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")
QList<QPixmap> m_pixmaps;
int m_currentPixmap;
-
- QList<QStaticText> m_staticTexts;
};