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
60
61
62
63
66
67
68
69
79 m_role(QPlatformMenuItem::TextHeuristicRole),
83 m_iconLoader(
nullptr),
91 m_menu->removeItem(
this);
93 m_group->removeItem(
this);
96 m_iconLoader =
nullptr;
108 if (!m_handle && m_menu && m_menu
->handle()) {
109 m_handle = m_menu
->handle()->createMenuItem();
113 m_handle = QGuiApplicationPrivate::platformTheme()->createPlatformMenuItem();
119 connect(m_handle, &QPlatformMenuItem::activated,
this, &QQuickLabsPlatformMenuItem::activate);
120 connect(m_handle, &QPlatformMenuItem::hovered,
this, &QQuickLabsPlatformMenuItem::hovered);
133 m_handle->setIsSeparator(m_separator);
134 m_handle->setCheckable(m_checkable);
135 m_handle->setChecked(m_checked);
136 m_handle->setRole(m_role);
137 m_handle->setText(m_text);
138 m_handle->setFont(m_font);
142 m_handle->setIcon(m_iconLoader->toQIcon());
152#if QT_CONFIG(shortcut)
153 QKeySequence sequence;
154 if (m_shortcut.metaType().id() == QMetaType::Int)
155 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
156 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
157 sequence = m_shortcut.value<QKeySequence>();
159 sequence = QKeySequence::fromString(m_shortcut.toString());
160 m_handle->setShortcut(sequence.toString());
168
169
170
171
172
173
189
190
191
192
193
194
202 if (m_subMenu == menu)
207 emit subMenuChanged();
211
212
213
214
215
223 if (m_group == group)
230 group->addItem(
this);
237 emit enabledChanged();
239 emit visibleChanged();
243
244
245
246
247
248
249
250
251
252
260 if (m_enabled == enabled)
274 emit enabledChanged();
278
279
280
281
289 if (m_visible == visible)
296 emit visibleChanged();
300
301
302
303
304
305
306
314 if (m_separator == separator)
317 m_separator = separator;
319 emit separatorChanged();
323
324
325
326
327
328
329
330
331
332
333
334
342 if (m_checkable == checkable)
345 m_checkable = checkable;
347 emit checkableChanged();
351
352
353
354
355
356
357
365 if (m_checked == checked)
368 if (checked && !m_checkable)
373 emit checkedChanged();
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
415
416
417
418
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
460#if QT_CONFIG(shortcut)
461 if (e->type() == QEvent::Shortcut) {
462 QShortcutEvent *se =
static_cast<QShortcutEvent *>(e);
463 if (se->shortcutId() == m_shortcutId) {
469 return QObject::event(e);
474 if (m_shortcut == shortcut)
478 m_shortcut = shortcut;
481 emit shortcutChanged();
485
486
487
488
489
490
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
542
543
544
545
568 static int slot = staticMetaObject.indexOfSlot(
"updateIcon()");
569 m_iconLoader =
new QQuickLabsPlatformIconLoader(slot, that);
588#if QT_CONFIG(shortcut)
589 QKeySequence sequence;
590 if (m_shortcut.metaType().id() == QMetaType::Int)
591 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
592 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
593 sequence = m_shortcut.value<QKeySequence>();
595 sequence = QKeySequence::fromString(m_shortcut.toString());
596 if (!sequence.isEmpty() && m_enabled) {
597 m_shortcutId = QGuiApplicationPrivate::instance()->shortcutMap.addShortcut(
this, sequence,
598 Qt::WindowShortcut, QQuickShortcutContext::matcher);
607#if QT_CONFIG(shortcut)
608 if (m_shortcutId == -1)
611 QKeySequence sequence;
612 if (m_shortcut.metaType().id() == QMetaType::Int)
613 sequence = QKeySequence(
static_cast<QKeySequence::StandardKey>(m_shortcut.toInt()));
614 else if (m_shortcut.metaType().id() == QMetaType::QKeySequence)
615 sequence = m_shortcut.value<QKeySequence>();
617 sequence = QKeySequence::fromString(m_shortcut.toString());
618 QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(m_shortcutId,
this, sequence);
624#include "moc_qquicklabsplatformmenuitem_p.cpp"
Combined button and popup list for selecting options.