7#include <QtGui/private/qguiapplication_p.h>
8#include <QtGui/qpa/qplatformtheme.h>
9#include <QtQuick/private/qquicktext_p_p.h>
13QQuickMnemonicLabel::QQuickMnemonicLabel(QQuickItem *parent)
18QString QQuickMnemonicLabel::text()
const
23void QQuickMnemonicLabel::setText(
const QString &text)
25 if (m_fullText == text)
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56bool QQuickMnemonicLabel::isMnemonicEnabled()
const
58 return m_mnemonicEnabled;
61void QQuickMnemonicLabel::setMnemonicEnabled(
bool enabled)
63 if (m_mnemonicEnabled == enabled)
66 m_mnemonicEnabled = enabled;
69 if (isComponentComplete())
75 QTextLayout::FormatRange range;
77 range.length = length;
78 range.format.setFontUnderline(
true);
83void QQuickMnemonicLabel::updateMnemonic()
85 if (!m_mnemonicEnabled) {
87 QQuickTextPrivate::get(
this)->layout.setFormats({});
88 QQuickText::setText(m_fullText);
92 const bool showUnderline = QGuiApplicationPrivate::platformTheme()->themeHint(
93 QPlatformTheme::UnderlineShortcut).toBool();
95 QString text(m_fullText.size(), QChar::Null);
98 int len = m_fullText.size();
99 QList<QTextLayout::FormatRange> formats;
101 if (m_fullText.at(pos) == QLatin1Char(
'&') && (len == 1 || m_fullText.at(pos + 1) != QLatin1Char(
'&'))) {
104 if (showUnderline && (pos == 0 || m_fullText.at(pos - 1) != QLatin1Char(
'&')))
105 formats += underlineRange(pos);
110 }
else if (m_fullText.at(pos) == QLatin1Char(
'(') && len >= 4 &&
111 m_fullText.at(pos + 1) == QLatin1Char(
'&') &&
112 m_fullText.at(pos + 2) != QLatin1Char(
'&') &&
113 m_fullText.at(pos + 3) == QLatin1Char(
')')) {
118 formats += underlineRange(pos + 1);
120 text[idx] = m_fullText.at(pos);
127 QQuickTextPrivate::get(
this)->layout.setFormats(formats);
128 QQuickText::setText(text);
133#include "moc_qquickmnemoniclabel_p.cpp"
Combined button and popup list for selecting options.
static QTextLayout::FormatRange underlineRange(int start, int length=1)