diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-07-24 15:15:18 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2017-08-23 14:16:51 +0000 |
commit | 460925b3f1dd9d2301b9c69558bd68843cd5f978 (patch) | |
tree | 69169f8b3f35a4e6a2e124c62e416336b779ae06 /src/quick/items | |
parent | 51763b1b191c0839ea05c75855b9e09b65b80546 (diff) |
Add a way to set the default render type of text-like elements
f3446071da8357620d0c8593a04e3b4fbba88f21 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>
Diffstat (limited to 'src/quick/items')
-rw-r--r-- | src/quick/items/qquicktext.cpp | 10 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 5 | ||||
-rw-r--r-- | src/quick/items/qquicktextedit_p_p.h | 7 | ||||
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 5 | ||||
-rw-r--r-- | src/quick/items/qquicktextinput_p_p.h | 7 | ||||
-rw-r--r-- | src/quick/items/qquicktextutil_p.h | 16 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.cpp | 51 | ||||
-rw-r--r-- | src/quick/items/qquickwindow.h | 9 | ||||
-rw-r--r-- | src/quick/items/qquickwindow_p.h | 1 |
9 files changed, 91 insertions, 20 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 5ca0bb5f79..07cc1ff76e 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -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 { diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index f22c5f00be..193f804c13 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -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 { diff --git a/src/quick/items/qquicktextedit_p_p.h b/src/quick/items/qquicktextedit_p_p.h index 03bce00cb0..455fffbcbc 100644 --- a/src/quick/items/qquicktextedit_p_p.h +++ b/src/quick/items/qquicktextedit_p_p.h @@ -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) diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 06ad0a9dbf..d01d604171 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -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 { diff --git a/src/quick/items/qquicktextinput_p_p.h b/src/quick/items/qquicktextinput_p_p.h index 0bf5779a53..c3218197a4 100644 --- a/src/quick/items/qquicktextinput_p_p.h +++ b/src/quick/items/qquicktextinput_p_p.h @@ -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) diff --git a/src/quick/items/qquicktextutil_p.h b/src/quick/items/qquicktextutil_p.h index 01055c95ec..bad5e738a8 100644 --- a/src/quick/items/qquicktextutil_p.h +++ b/src/quick/items/qquicktextutil_p.h @@ -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 diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 7b331251f0..bc99f49667 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -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) @@ -3825,6 +3831,23 @@ QQmlIncubationController *QQuickWindow::incubationController() const */ /*! + \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() This signal is emitted before the scene graph is synchronized with the QML state. @@ -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 diff --git a/src/quick/items/qquickwindow.h b/src/quick/items/qquickwindow.h index d1a16fbeb6..022c4738f2 100644 --- a/src/quick/items/qquickwindow.h +++ b/src/quick/items/qquickwindow.h @@ -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); diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h index 14564a7f55..837ef11d25 100644 --- a/src/quick/items/qquickwindow_p.h +++ b/src/quick/items/qquickwindow_p.h @@ -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); |