Add a way to set the default render type of text-like elements
f3446071da
introduced a build-time
way to select the default render type of text-like elements.
This patch adds also a way to select it at runtime, via a setter
on QQuickWindow. (QQuickWindow has been chosen as convenience,
rather than adding another namespace/class to just have this
setter.)
Given that QT_QUICK_DEFAULT_TEXT_RENDER_TYPE was never documented,
I've taken the liberty of changing the accepted values for it
(to match the new enumerator names in QQuickWindow, rather than
the ones in QQuickText/QQuickTextEdit/etc.).
[ChangeLog][QtQuick][QQuickWindow] It is now possible to set the
default render type of text-like elements globally via the
QQuickWindow::setTextRenderType() function. If you were using
the (undocumented) QT_QUICK_DEFAULT_TEXT_RENDER_TYPE macro
when building Qt Quick for the same purpose, note that the
macro value needs now to be set to the "NativeTextRendering"
value, instead of "NativeRendering".
Change-Id: Id4b2dc3ec823971486e445ca4173b8be848fb4e3
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
parent
51763b1b19
commit
460925b3f1
|
@ -80,11 +80,7 @@ QQuickTextPrivate::QQuickTextPrivate()
|
|||
, elideMode(QQuickText::ElideNone), hAlign(QQuickText::AlignLeft), vAlign(QQuickText::AlignTop)
|
||||
, format(QQuickText::AutoText), wrapMode(QQuickText::NoWrap)
|
||||
, style(QQuickText::Normal)
|
||||
#if defined(QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
, renderType(QQuickText::QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
#else
|
||||
, renderType(QQuickText::QtRendering)
|
||||
#endif
|
||||
, renderType(QQuickTextUtil::textRenderType<QQuickText>())
|
||||
, updateType(UpdatePaintNode)
|
||||
, maximumLineCountValid(false), updateOnComponentComplete(true), richText(false)
|
||||
, styledText(false), widthExceeded(false), heightExceeded(false), internalWidthUpdate(false)
|
||||
|
@ -2827,7 +2823,7 @@ void QQuickText::hoverLeaveEvent(QHoverEvent *event)
|
|||
|
||||
Supported render types are:
|
||||
\list
|
||||
\li Text.QtRendering - the default
|
||||
\li Text.QtRendering
|
||||
\li Text.NativeRendering
|
||||
\endlist
|
||||
|
||||
|
@ -2835,6 +2831,8 @@ void QQuickText::hoverLeaveEvent(QHoverEvent *event)
|
|||
not require advanced features such as transformation of the text. Using such features in
|
||||
combination with the NativeRendering render type will lend poor and sometimes pixelated
|
||||
results.
|
||||
|
||||
The default rendering type is determined by \l QQuickWindow::textRenderType().
|
||||
*/
|
||||
QQuickText::RenderType QQuickText::renderType() const
|
||||
{
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "qquickwindow.h"
|
||||
#include "qquicktextnode_p.h"
|
||||
#include "qquicktextnodeengine_p.h"
|
||||
#include "qquicktextutil_p.h"
|
||||
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtGui/qguiapplication.h>
|
||||
|
@ -495,7 +494,7 @@ void QQuickTextEdit::setTextFormat(TextFormat format)
|
|||
|
||||
Supported render types are:
|
||||
\list
|
||||
\li Text.QtRendering - the default
|
||||
\li Text.QtRendering
|
||||
\li Text.NativeRendering
|
||||
\endlist
|
||||
|
||||
|
@ -503,6 +502,8 @@ void QQuickTextEdit::setTextFormat(TextFormat format)
|
|||
not require advanced features such as transformation of the text. Using such features in
|
||||
combination with the NativeRendering render type will lend poor and sometimes pixelated
|
||||
results.
|
||||
|
||||
The default rendering type is determined by \l QQuickWindow::textRenderType().
|
||||
*/
|
||||
QQuickTextEdit::RenderType QQuickTextEdit::renderType() const
|
||||
{
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
|
||||
#include "qquicktextedit_p.h"
|
||||
#include "qquickimplicitsizeitem_p_p.h"
|
||||
#include "qquicktextutil_p.h"
|
||||
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QtCore/qlist.h>
|
||||
|
@ -112,11 +113,7 @@ public:
|
|||
, quickDocument(0), lastSelectionStart(0), lastSelectionEnd(0), lineCount(0)
|
||||
, hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop)
|
||||
, format(QQuickTextEdit::PlainText), wrapMode(QQuickTextEdit::NoWrap)
|
||||
#if defined(QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
, renderType(QQuickTextEdit::QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
#else
|
||||
, renderType(QQuickTextEdit::QtRendering)
|
||||
#endif
|
||||
, renderType(QQuickTextUtil::textRenderType<QQuickTextEdit>())
|
||||
, contentDirection(Qt::LayoutDirectionAuto)
|
||||
, mouseSelectionMode(QQuickTextEdit::SelectCharacters)
|
||||
#if QT_CONFIG(im)
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
#include "qquicktextinput_p.h"
|
||||
#include "qquicktextinput_p_p.h"
|
||||
#include "qquickwindow.h"
|
||||
#include "qquicktextutil_p.h"
|
||||
|
||||
#include <private/qqmlglobal_p.h>
|
||||
#include <private/qv4scopedvalue_p.h>
|
||||
|
@ -157,7 +156,7 @@ void QQuickTextInput::setText(const QString &s)
|
|||
|
||||
Supported render types are:
|
||||
\list
|
||||
\li Text.QtRendering - the default
|
||||
\li Text.QtRendering
|
||||
\li Text.NativeRendering
|
||||
\endlist
|
||||
|
||||
|
@ -165,6 +164,8 @@ void QQuickTextInput::setText(const QString &s)
|
|||
not require advanced features such as transformation of the text. Using such features in
|
||||
combination with the NativeRendering render type will lend poor and sometimes pixelated
|
||||
results.
|
||||
|
||||
The default rendering type is determined by \l QQuickWindow::textRenderType().
|
||||
*/
|
||||
QQuickTextInput::RenderType QQuickTextInput::renderType() const
|
||||
{
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "qquicktextinput_p.h"
|
||||
#include "qquicktext_p.h"
|
||||
#include "qquickimplicitsizeitem_p_p.h"
|
||||
#include "qquicktextutil_p.h"
|
||||
|
||||
#include <QtQml/qqml.h>
|
||||
#include <QtCore/qelapsedtimer.h>
|
||||
|
@ -122,11 +123,7 @@ public:
|
|||
, vAlign(QQuickTextInput::AlignTop)
|
||||
, wrapMode(QQuickTextInput::NoWrap)
|
||||
, m_echoMode(QQuickTextInput::Normal)
|
||||
#if defined(QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
, renderType(QQuickTextInput::QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
#else
|
||||
, renderType(QQuickTextInput::QtRendering)
|
||||
#endif
|
||||
, renderType(QQuickTextUtil::textRenderType<QQuickTextInput>())
|
||||
, updateType(UpdatePaintNode)
|
||||
, mouseSelectionMode(QQuickTextInput::SelectCharacters)
|
||||
, m_layoutDirection(Qt::LayoutDirectionAuto)
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
#include <QtQml/qqml.h>
|
||||
#include <QtQml/qqmlincubator.h>
|
||||
#include <QtQuick/qquickitem.h>
|
||||
#include <QtQuick/qquickwindow.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
|
@ -64,6 +65,7 @@ public:
|
|||
template <typename Private> static void setCursorDelegate(Private *d, QQmlComponent *delegate);
|
||||
template <typename Private> static void createCursor(Private *d);
|
||||
|
||||
template <typename T> static typename T::RenderType textRenderType();
|
||||
|
||||
static qreal alignedX(qreal textWidth, qreal itemWidth, int alignment);
|
||||
static qreal alignedY(qreal textHeight, qreal itemHeight, int alignment);
|
||||
|
@ -124,6 +126,20 @@ void QQuickTextUtil::createCursor(Private *d)
|
|||
parent->update();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename T::RenderType QQuickTextUtil::textRenderType()
|
||||
{
|
||||
switch (QQuickWindow::textRenderType()) {
|
||||
case QQuickWindow::QtTextRendering:
|
||||
return T::QtRendering;
|
||||
case QQuickWindow::NativeTextRendering:
|
||||
return T::NativeRendering;
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
return T::QtRendering;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,6 +93,12 @@ extern Q_GUI_EXPORT QImage qt_gl_read_framebuffer(const QSize &size, bool alpha_
|
|||
|
||||
bool QQuickWindowPrivate::defaultAlphaBuffer = false;
|
||||
|
||||
#if defined(QT_QUICK_DEFAULT_TEXT_RENDER_TYPE)
|
||||
QQuickWindow::TextRenderType QQuickWindowPrivate::textRenderType = QQuickWindow::QT_QUICK_DEFAULT_TEXT_RENDER_TYPE;
|
||||
#else
|
||||
QQuickWindow::TextRenderType QQuickWindowPrivate::textRenderType = QQuickWindow::QtTextRendering;
|
||||
#endif
|
||||
|
||||
void QQuickWindowPrivate::updateFocusItemTransform()
|
||||
{
|
||||
#if QT_CONFIG(im)
|
||||
|
@ -3824,6 +3830,23 @@ QQmlIncubationController *QQuickWindow::incubationController() const
|
|||
\since 5.3
|
||||
*/
|
||||
|
||||
/*!
|
||||
\enum QQuickWindow::TextRenderType
|
||||
\since 5.10
|
||||
|
||||
This enum describes the default render type of text-like elements in Qt
|
||||
Quick (\l Text, \l TextInput, etc.).
|
||||
|
||||
Select NativeTextRendering if you prefer text to look native on the target
|
||||
platform and do not require advanced features such as transformation of the
|
||||
text. Using such features in combination with the NativeTextRendering
|
||||
render type will lend poor and sometimes pixelated results.
|
||||
|
||||
\value QtTextRendering Use Qt's own rasterization algorithm.
|
||||
|
||||
\value NativeTextRendering Use the operating system's native rasterizer for text.
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QQuickWindow::beforeSynchronizing()
|
||||
|
||||
|
@ -4846,6 +4869,34 @@ QSGNinePatchNode *QQuickWindow::createNinePatchNode() const
|
|||
return isSceneGraphInitialized() ? d->context->sceneGraphContext()->createNinePatchNode() : nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.10
|
||||
|
||||
Returns the render type of text-like elements in Qt Quick.
|
||||
The default is QQuickWindow::QtTextRendering.
|
||||
|
||||
\sa setTextRenderType()
|
||||
*/
|
||||
QQuickWindow::TextRenderType QQuickWindow::textRenderType()
|
||||
{
|
||||
return QQuickWindowPrivate::textRenderType;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.10
|
||||
|
||||
Sets the default render type of text-like elements in Qt Quick to \a renderType.
|
||||
|
||||
\note setting the render type will only affect elements created afterwards;
|
||||
the render type of existing elements will not be modified.
|
||||
|
||||
\sa textRenderType()
|
||||
*/
|
||||
void QQuickWindow::setTextRenderType(QQuickWindow::TextRenderType renderType)
|
||||
{
|
||||
QQuickWindowPrivate::textRenderType = renderType;
|
||||
}
|
||||
|
||||
#include "moc_qquickwindow.cpp"
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
@ -100,6 +100,12 @@ public:
|
|||
};
|
||||
Q_ENUM(SceneGraphError)
|
||||
|
||||
enum TextRenderType {
|
||||
QtTextRendering,
|
||||
NativeTextRendering
|
||||
};
|
||||
Q_ENUM(TextRenderType)
|
||||
|
||||
explicit QQuickWindow(QWindow *parent = Q_NULLPTR);
|
||||
explicit QQuickWindow(QQuickRenderControl *renderControl);
|
||||
|
||||
|
@ -170,6 +176,9 @@ public:
|
|||
QSGImageNode *createImageNode() const;
|
||||
QSGNinePatchNode *createNinePatchNode() const;
|
||||
|
||||
static TextRenderType textRenderType();
|
||||
static void setTextRenderType(TextRenderType renderType);
|
||||
|
||||
Q_SIGNALS:
|
||||
void frameSwapped();
|
||||
Q_REVISION(2) void openglContextCreated(QOpenGLContext *context);
|
||||
|
|
|
@ -279,6 +279,7 @@ public:
|
|||
mutable QQuickWindowIncubationController *incubationController;
|
||||
|
||||
static bool defaultAlphaBuffer;
|
||||
static QQuickWindow::TextRenderType textRenderType;
|
||||
|
||||
static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int startDragThreshold = -1);
|
||||
|
||||
|
|
|
@ -159,6 +159,7 @@ struct Options
|
|||
, coreProfile(false)
|
||||
, verbose(false)
|
||||
, applicationType(DefaultQmlApplicationType)
|
||||
, textRenderType(QQuickWindow::textRenderType())
|
||||
{
|
||||
// QtWebEngine needs a shared context in order for the GPU thread to
|
||||
// upload textures.
|
||||
|
@ -182,6 +183,7 @@ struct Options
|
|||
QVector<Qt::ApplicationAttribute> applicationAttributes;
|
||||
QString translationFile;
|
||||
QmlApplicationType applicationType;
|
||||
QQuickWindow::TextRenderType textRenderType;
|
||||
};
|
||||
|
||||
#if defined(QMLSCENE_BUNDLE)
|
||||
|
@ -377,6 +379,7 @@ static void usage()
|
|||
#ifdef QT_WIDGETS_LIB
|
||||
puts(" --apptype [gui|widgets] ...........Select which application class to use. Default is widgets.");
|
||||
#endif
|
||||
puts(" --textrendertype [qt|native].......Select the default render type for text-like elements.");
|
||||
puts(" -I <path> ........................ Add <path> to the list of import paths");
|
||||
puts(" -P <path> ........................ Add <path> to the list of plugin paths");
|
||||
puts(" -translation <translationfile> ... Set the language to run in");
|
||||
|
@ -456,6 +459,19 @@ static QUrl parseUrlArgument(const QString &arg)
|
|||
return url;
|
||||
}
|
||||
|
||||
static QQuickWindow::TextRenderType parseTextRenderType(const QString &renderType)
|
||||
{
|
||||
if (renderType == QLatin1String("qt"))
|
||||
return QQuickWindow::QtTextRendering;
|
||||
else if (renderType == QLatin1String("native"))
|
||||
return QQuickWindow::NativeTextRendering;
|
||||
|
||||
usage();
|
||||
|
||||
Q_UNREACHABLE();
|
||||
return QQuickWindow::QtTextRendering;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
Options options;
|
||||
|
@ -536,6 +552,8 @@ int main(int argc, char ** argv)
|
|||
pluginPaths.append(arguments.at(++i));
|
||||
else if (lowerArgument == QLatin1String("--apptype"))
|
||||
++i; // Consume previously parsed argument
|
||||
else if (lowerArgument == QLatin1String("--textrendertype") && i + 1 < size)
|
||||
options.textRenderType = parseTextRenderType(arguments.at(++i));
|
||||
else if (lowerArgument == QLatin1String("--help")
|
||||
|| lowerArgument == QLatin1String("-help")
|
||||
|| lowerArgument == QLatin1String("--h")
|
||||
|
@ -564,6 +582,8 @@ int main(int argc, char ** argv)
|
|||
}
|
||||
#endif
|
||||
|
||||
QQuickWindow::setTextRenderType(options.textRenderType);
|
||||
|
||||
QUnifiedTimer::instance()->setSlowModeEnabled(options.slowAnimations);
|
||||
|
||||
if (options.url.isEmpty())
|
||||
|
|
Loading…
Reference in New Issue