9#include <QtGui/qicon.h>
10#if QT_CONFIG(shortcut)
11#include <QtGui/qkeysequence.h>
13#include <QtGui/qpa/qplatformtheme.h>
14#include <QtGui/private/qguiapplication_p.h>
15#include <QtQuickTemplates2/private/qquickshortcutcontext_p_p.h>
17#include "widgets/qwidgetplatform_p.h"
22
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
59
60
61
62
65
66
67
68
78 m_role(QPlatformMenuItem::TextHeuristicRole),
82 m_iconLoader(
nullptr),
90 m_menu->removeItem(
this);
92 m_group->removeItem(
this);
95 m_iconLoader =
nullptr;
107 if (!m_handle && m_menu && m_menu
->handle()) {
108 m_handle = m_menu
->handle()->createMenuItem();
112 m_handle = QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
118 connect(m_handle, &QPlatformMenuItem::activated,
this, &QQuickLabsPlatformMenuItem::activate);
119 connect(m_handle, &QPlatformMenuItem::hovered,
this, &QQuickLabsPlatformMenuItem::hovered);
132 m_handle->setIsSeparator(m_separator);
133 m_handle->setCheckable(m_checkable);
134 m_handle->setChecked(m_checked);
135 m_handle->setRole(m_role);
136 m_handle->setText(m_text);
137 m_handle->setFont(m_font);
141 m_handle->setIcon(m_iconLoader->toQIcon());
151#if QT_CONFIG(shortcut)
152 QKeySequence sequence;
153 if (m_shortcut.metaType().id() == QMetaType::Int)
154 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
155 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
156 sequence = m_shortcut.value<QKeySequence>();
158 sequence = QKeySequence::fromString(m_shortcut.toString());
159 m_handle->setShortcut(sequence.toString());
167
168
169
170
171
172
188
189
190
191
192
193
201 if (m_subMenu == menu)
206 emit subMenuChanged();
210
211
212
213
214
222 if (m_group == group)
229 group->addItem(
this);
236 emit enabledChanged();
238 emit visibleChanged();
242
243
244
245
246
247
248
249
250
251
259 if (m_enabled == enabled)
273 emit enabledChanged();
277
278
279
280
288 if (m_visible == visible)
295 emit visibleChanged();
299
300
301
302
303
304
305
313 if (m_separator == separator)
316 m_separator = separator;
318 emit separatorChanged();
322
323
324
325
326
327
328
329
330
331
332
333
341 if (m_checkable == checkable)
344 m_checkable = checkable;
346 emit checkableChanged();
350
351
352
353
354
355
356
364 if (m_checked == checked)
367 if (checked && !m_checkable)
372 emit checkedChanged();
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
414
415
416
417
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
459#if QT_CONFIG(shortcut)
460 if (e->type() == QEvent::Shortcut) {
461 QShortcutEvent *se =
static_cast<QShortcutEvent *>(e);
462 if (se->shortcutId() == m_shortcutId) {
468 return QObject::event(e);
473 if (m_shortcut == shortcut)
477 m_shortcut = shortcut;
480 emit shortcutChanged();
484
485
486
487
488
489
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
541
542
543
544
567 static int slot = staticMetaObject.indexOfSlot(
"updateIcon()");
568 m_iconLoader =
new QQuickLabsPlatformIconLoader(slot, that);
587#if QT_CONFIG(shortcut)
588 QKeySequence sequence;
589 if (m_shortcut.metaType().id() == QMetaType::Int)
590 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
591 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
592 sequence = m_shortcut.value<QKeySequence>();
594 sequence = QKeySequence::fromString(m_shortcut.toString());
595 if (!sequence.isEmpty() && m_enabled) {
596 m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(
this, sequence,
597 Qt::WindowShortcut, QQuickShortcutContext::matcher);
606#if QT_CONFIG(shortcut)
607 if (m_shortcutId == -1)
610 QKeySequence sequence;
611 if (m_shortcut.metaType().id() == QMetaType::Int)
612 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
613 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
614 sequence = m_shortcut.value<QKeySequence>();
616 sequence = QKeySequence::fromString(m_shortcut.toString());
617 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId,
this, sequence);
623#include "moc_qquicklabsplatformmenuitem_p.cpp"
Combined button and popup list for selecting options.