Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickmnemoniclabel.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6#include <QtQuick/private/qquicktext_p_p.h>
7
9
14
16{
17 return m_fullText;
18}
19
21{
22 if (m_fullText == text)
23 return;
24
25 m_fullText = text;
26 updateMnemonic();
27}
28
30{
31 return m_mnemonicVisible;
32}
33
35{
36 if (m_mnemonicVisible == visible)
37 return;
38
39 m_mnemonicVisible = visible;
40 updateMnemonic();
41
43 forceLayout();
44}
45
47{
50 range.length = length;
51 range.format.setFontUnderline(true);
52 return range;
53}
54
55// based on QPlatformTheme::removeMnemonics()
56void QQuickMnemonicLabel::updateMnemonic()
57{
58 QString text(m_fullText.size(), QChar::Null);
59 int idx = 0;
60 int pos = 0;
61 int len = m_fullText.size();
62 QList<QTextLayout::FormatRange> formats;
63 while (len) {
64 if (m_fullText.at(pos) == QLatin1Char('&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char('&'))) {
65 if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char('&')))
67 ++pos;
68 --len;
69 if (len == 0)
70 break;
71 } else if (m_fullText.at(pos) == QLatin1Char('(') && len >= 4 &&
72 m_fullText.at(pos + 1) == QLatin1Char('&') &&
73 m_fullText.at(pos + 2) != QLatin1Char('&') &&
74 m_fullText.at(pos + 3) == QLatin1Char(')')) {
75 // a mnemonic with format "\s*(&X)"
76 if (m_mnemonicVisible) {
78 } else {
79 int n = 0;
80 while (idx > n && text.at(idx - n - 1).isSpace())
81 ++n;
82 idx -= n;
83 pos += 4;
84 len -= 4;
85 continue;
86 }
87 }
88 text[idx] = m_fullText.at(pos);
89 ++pos;
90 ++idx;
91 --len;
92 }
93 text.truncate(idx);
94
95 QQuickTextPrivate::get(this)->layout.setFormats(formats);
97}
98
100
101#include "moc_qquickmnemoniclabel_p.cpp"
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
bool visible
\qmlproperty bool QtQuick::Item::visible
Definition qquickitem.h:80
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void setMnemonicVisible(bool visible)
QQuickMnemonicLabel(QQuickItem *parent=nullptr)
void setText(const QString &text)
static QQuickTextPrivate * get(QQuickText *t)
void setText(const QString &)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void truncate(qsizetype pos)
Truncates the string at the given position index.
Definition qstring.cpp:6319
qsizetype size() const noexcept
Returns the number of characters in this string.
Definition qstring.h:186
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
QString text
EGLint EGLint * formats
Combined button and popup list for selecting options.
GLenum GLuint GLenum GLsizei length
GLsizei range
GLuint start
GLfloat n
GLenum GLsizei len
static QTextLayout::FormatRange underlineRange(int start, int length=1)
\inmodule QtCore \reentrant
Definition qchar.h:18