7#include <QtQuick/private/qquicktext_p_p.h>
11QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent)
16QString QQuickMnemonicLabel::text()
const
21void QQuickMnemonicLabel::setText(
const QString &text)
23 if (m_fullText == text)
30bool QQuickMnemonicLabel::isMnemonicVisible()
const
32 return m_mnemonicVisible;
35void QQuickMnemonicLabel::setMnemonicVisible(
bool visible)
37 if (m_mnemonicVisible == visible)
40 m_mnemonicVisible = visible;
43 if (isComponentComplete())
49 QTextLayout::FormatRange range;
51 range.length = length;
52 range.format.setFontUnderline(
true);
57void QQuickMnemonicLabel::updateMnemonic()
59 QString text(m_fullText.size(), QChar::Null);
62 int len = m_fullText.size();
63 QList<QTextLayout::FormatRange> formats;
65 if (m_fullText.at(pos) == QLatin1Char(
'&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char(
'&'))) {
66 if (m_mnemonicVisible && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char(
'&')))
67 formats += underlineRange(pos);
72 }
else if (m_fullText.at(pos) == QLatin1Char(
'(') && len >= 4 &&
73 m_fullText.at(pos + 1) == QLatin1Char(
'&') &&
74 m_fullText.at(pos + 2) != QLatin1Char(
'&') &&
75 m_fullText.at(pos + 3) == QLatin1Char(
')')) {
77 if (m_mnemonicVisible) {
78 formats += underlineRange(pos + 1);
81 while (idx > n && text.at(idx - n - 1).isSpace())
89 text[idx] = m_fullText.at(pos);
96 QQuickTextPrivate::get(
this)->layout.setFormats(formats);
97 QQuickText::setText(text);
102#include "moc_qquickmnemoniclabel_p.cpp"
static QTextLayout::FormatRange underlineRange(int start, int length=1)