10#include <QtGui/qicon.h>
11#if QT_CONFIG(shortcut)
12#include <QtGui/qkeysequence.h>
14#include <QtGui/qpa/qplatformtheme.h>
15#include <QtGui/private/qguiapplication_p.h>
16#include <QtQuickTemplates2/private/qquickshortcutcontext_p_p.h>
18#include "widgets/qwidgetplatform_p.h"
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
61
62
63
64
67
68
69
70
80 m_role(QPlatformMenuItem::TextHeuristicRole),
84 m_iconLoader(
nullptr),
92 m_menu->removeItem(
this);
94 m_group->removeItem(
this);
97 m_iconLoader =
nullptr;
109 if (!m_handle && m_menu && m_menu
->handle()) {
110 m_handle = m_menu
->handle()->createMenuItem();
114 m_handle = QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
120 connect(m_handle, &QPlatformMenuItem::activated,
this, &QQuickLabsPlatformMenuItem::activate);
134 m_handle->setIsSeparator(m_separator);
135 m_handle->setCheckable(m_checkable);
136 m_handle->setChecked(m_checked);
137 m_handle->setRole(m_role);
138 m_handle->setText(m_text);
139 m_handle->setFont(m_font);
143 m_handle->setIcon(m_iconLoader->toQIcon());
153#if QT_CONFIG(shortcut)
154 QKeySequence sequence;
155 if (m_shortcut.metaType().id() == QMetaType::Int)
156 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
157 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
158 sequence = m_shortcut.value<QKeySequence>();
160 sequence = QKeySequence::fromString(m_shortcut.toString());
161 m_handle->setShortcut(sequence.toString());
169
170
171
172
173
174
190
191
192
193
194
195
203 if (m_subMenu == menu)
208 emit subMenuChanged();
212
213
214
215
216
224 if (m_group == group)
231 group->addItem(
this);
238 emit enabledChanged();
240 emit visibleChanged();
244
245
246
247
248
249
250
251
252
253
261 if (m_enabled == enabled)
275 emit enabledChanged();
279
280
281
282
290 if (m_visible == visible)
297 emit visibleChanged();
301
302
303
304
305
306
307
315 if (m_separator == separator)
318 m_separator = separator;
320 emit separatorChanged();
324
325
326
327
328
329
330
331
332
333
334
335
343 if (m_checkable == checkable)
346 m_checkable = checkable;
348 emit checkableChanged();
352
353
354
355
356
357
358
366 if (m_checked == checked)
369 if (checked && !m_checkable)
374 emit checkedChanged();
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
416
417
418
419
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
461#if QT_CONFIG(shortcut)
462 if (e->type() == QEvent::Shortcut) {
463 QShortcutEvent *se =
static_cast<QShortcutEvent *>(e);
464 if (se->shortcutId() == m_shortcutId) {
470 return QObject::event(e);
475 if (m_shortcut == shortcut)
479 m_shortcut = shortcut;
482 emit shortcutChanged();
486
487
488
489
490
491
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
543
544
545
546
569 static int slot = staticMetaObject.indexOfSlot(
"updateIcon()");
570 m_iconLoader =
new QQuickLabsPlatformIconLoader(slot, that);
589#if QT_CONFIG(shortcut)
590 QKeySequence sequence;
591 if (m_shortcut.metaType().id() == QMetaType::Int)
592 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
593 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
594 sequence = m_shortcut.value<QKeySequence>();
596 sequence = QKeySequence::fromString(m_shortcut.toString());
597 if (!sequence.isEmpty() && m_enabled) {
598 m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(
this, sequence,
599 Qt::WindowShortcut, QQuickShortcutContext::matcher);
608#if QT_CONFIG(shortcut)
609 if (m_shortcutId == -1)
612 QKeySequence sequence;
613 if (m_shortcut.metaType().id() == QMetaType::Int)
614 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
615 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
616 sequence = m_shortcut.value<QKeySequence>();
618 sequence = QKeySequence::fromString(m_shortcut.toString());
619 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId,
this, sequence);
625#include "moc_qquicklabsplatformmenuitem_p.cpp"
Combined button and popup list for selecting options.