/
wmainmenubar.cpp
749 lines (657 loc) · 32.2 KB
/
wmainmenubar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
#include "widget/wmainmenubar.h"
#include <QDesktopServices>
#include <QUrl>
#include "config.h"
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "mixer/playermanager.h"
#include "moc_wmainmenubar.cpp"
#include "util/cmdlineargs.h"
#include "util/experiment.h"
#include "vinylcontrol/defs_vinylcontrol.h"
namespace {
const int kMaxLoadToDeckActions = 4;
QString buildWhatsThis(const QString& title, const QString& text) {
QString preparedTitle = title;
return QString("%1\n\n%2").arg(preparedTitle.remove("&"), text);
}
#ifdef __VINYLCONTROL__
QString vinylControlDefaultKeyBinding(int deck) {
// More bindings need to be defined if you increment
// kMaximumVinylControlInputs.
DEBUG_ASSERT(deck < kMaximumVinylControlInputs);
switch (deck) {
case 0: return QObject::tr("Ctrl+t");
case 1: return QObject::tr("Ctrl+y");
case 2: return QObject::tr("Ctrl+u");
case 3: return QObject::tr("Ctrl+i");
default: return QString();
}
}
#endif // __VINYLCONTROL__
QString loadToDeckDefaultKeyBinding(int deck) {
switch (deck) {
case 0: return QObject::tr("Ctrl+o");
case 1: return QObject::tr("Ctrl+Shift+O");
default: return QString();
}
}
QString showPreferencesKeyBinding() {
#ifdef __APPLE__
return QObject::tr("Ctrl+,");
#else
return QObject::tr("Ctrl+P");
#endif
}
QUrl documentationUrl(
const QString& resourcePath, const QString& fileName, const QString& docUrl) {
QDir resourceDir(resourcePath);
// Documentation PDFs are included on Windows and Linux only,
// so on macOS this always returns the web URL.
#if defined(MIXXX_INSTALL_DOCDIR_RELATIVE_TO_DATADIR)
if (!resourceDir.exists(fileName)) {
resourceDir.cd(MIXXX_INSTALL_DOCDIR_RELATIVE_TO_DATADIR);
}
#endif
if (resourceDir.exists(fileName)) {
return QUrl::fromLocalFile(resourceDir.absoluteFilePath(fileName));
} else {
return QUrl(docUrl);
}
}
} // namespace
WMainMenuBar::WMainMenuBar(QWidget* pParent, UserSettingsPointer pConfig,
ConfigObject<ConfigValueKbd>* pKbdConfig)
: QMenuBar(pParent),
m_pConfig(pConfig),
m_pKbdConfig(pKbdConfig) {
setObjectName(QStringLiteral("MainMenu"));
initialize();
}
void WMainMenuBar::initialize() {
// FILE MENU
QMenu* pFileMenu = new QMenu(tr("&File"), this);
QString loadTrackText = tr("Load Track to Deck &%1");
QString loadTrackStatusText = tr("Loads a track in deck %1");
QString openText = tr("Open");
for (unsigned int deck = 0; deck < kMaxLoadToDeckActions; ++deck) {
QString playerLoadStatusText = loadTrackStatusText.arg(QString::number(deck + 1));
QAction* pFileLoadSongToPlayer = new QAction(
loadTrackText.arg(QString::number(deck + 1)), this);
QString binding = m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", QString("FileMenu_LoadDeck%1").arg(deck + 1)),
loadToDeckDefaultKeyBinding(deck));
if (!binding.isEmpty()) {
pFileLoadSongToPlayer->setShortcut(QKeySequence(binding));
pFileLoadSongToPlayer->setShortcutContext(Qt::ApplicationShortcut);
}
pFileLoadSongToPlayer->setStatusTip(playerLoadStatusText);
pFileLoadSongToPlayer->setWhatsThis(
buildWhatsThis(openText, playerLoadStatusText));
// Visibility of load to deck actions is set in
// WMainMenuBar::onNumberOfDecksChanged.
pFileLoadSongToPlayer->setVisible(false);
connect(pFileLoadSongToPlayer, &QAction::triggered,
this, [this, deck] { emit loadTrackToDeck(deck + 1); });
pFileMenu->addAction(pFileLoadSongToPlayer);
m_loadToDeckActions.push_back(pFileLoadSongToPlayer);
}
pFileMenu->addSeparator();
QString quitTitle = tr("&Exit");
QString quitText = tr("Quits Mixxx");
auto* pFileQuit = new QAction(quitTitle, this);
pFileQuit->setShortcut(
QKeySequence(m_pKbdConfig->getValue(ConfigKey("[KeyboardShortcuts]", "FileMenu_Quit"),
tr("Ctrl+q"))));
pFileQuit->setShortcutContext(Qt::ApplicationShortcut);
pFileQuit->setStatusTip(quitText);
pFileQuit->setWhatsThis(buildWhatsThis(quitTitle, quitText));
pFileQuit->setMenuRole(QAction::QuitRole);
connect(pFileQuit, &QAction::triggered, this, &WMainMenuBar::quit);
pFileMenu->addAction(pFileQuit);
addMenu(pFileMenu);
// LIBRARY MENU
QMenu* pLibraryMenu = new QMenu(tr("&Library"), this);
QString rescanTitle = tr("&Rescan Library");
QString rescanText = tr("Rescans library folders for changes to tracks.");
auto* pLibraryRescan = new QAction(rescanTitle, this);
pLibraryRescan->setStatusTip(rescanText);
pLibraryRescan->setWhatsThis(buildWhatsThis(rescanTitle, rescanText));
pLibraryRescan->setCheckable(false);
connect(pLibraryRescan, &QAction::triggered, this, &WMainMenuBar::rescanLibrary);
// Disable the action when a scan is active.
connect(this, &WMainMenuBar::internalLibraryScanActive, pLibraryRescan, &QAction::setDisabled);
pLibraryMenu->addAction(pLibraryRescan);
pLibraryMenu->addSeparator();
QString createPlaylistTitle = tr("Create &New Playlist");
QString createPlaylistText = tr("Create a new playlist");
auto* pLibraryCreatePlaylist = new QAction(createPlaylistTitle, this);
pLibraryCreatePlaylist->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "LibraryMenu_NewPlaylist"),
tr("Ctrl+n"))));
pLibraryCreatePlaylist->setShortcutContext(Qt::ApplicationShortcut);
pLibraryCreatePlaylist->setStatusTip(createPlaylistText);
pLibraryCreatePlaylist->setWhatsThis(buildWhatsThis(createPlaylistTitle, createPlaylistText));
connect(pLibraryCreatePlaylist, &QAction::triggered, this, &WMainMenuBar::createPlaylist);
pLibraryMenu->addAction(pLibraryCreatePlaylist);
QString createCrateTitle = tr("Create New &Crate");
QString createCrateText = tr("Create a new crate");
auto* pLibraryCreateCrate = new QAction(createCrateTitle, this);
pLibraryCreateCrate->setShortcut(
QKeySequence(m_pKbdConfig->getValue(ConfigKey("[KeyboardShortcuts]",
"LibraryMenu_NewCrate"),
tr("Ctrl+Shift+N"))));
pLibraryCreateCrate->setShortcutContext(Qt::ApplicationShortcut);
pLibraryCreateCrate->setStatusTip(createCrateText);
pLibraryCreateCrate->setWhatsThis(buildWhatsThis(createCrateTitle, createCrateText));
connect(pLibraryCreateCrate, &QAction::triggered, this, &WMainMenuBar::createCrate);
pLibraryMenu->addAction(pLibraryCreateCrate);
addMenu(pLibraryMenu);
#if defined(__APPLE__)
// Note: On macOS 10.11 ff. we have to deal with "automagic" menu items,
// when ever a menu "View" is present. QT (as of 5.12.3) does not handle this for us.
// Add an invisible suffix to the View item string so it doesn't string-equal "View" ,
// and the magic menu items won't get injected.
// https://bugs.launchpad.net/mixxx/+bug/1534292
QMenu* pViewMenu = new QMenu(tr("&View") + QStringLiteral("\u200C"), this);
#else
QMenu* pViewMenu = new QMenu(tr("&View"), this);
#endif
// Skin Settings Menu
QString mayNotBeSupported = tr("May not be supported on all skins.");
QString showSkinSettingsTitle = tr("Show Skin Settings Menu");
QString showSkinSettingsText = tr("Show the Skin Settings Menu of the currently selected Skin") +
" " + mayNotBeSupported;
auto* pViewShowSkinSettings = new QAction(showSkinSettingsTitle, this);
pViewShowSkinSettings->setCheckable(true);
pViewShowSkinSettings->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowSkinSettings"),
tr("Ctrl+1", "Menubar|View|Show Skin Settings"))));
pViewShowSkinSettings->setStatusTip(showSkinSettingsText);
pViewShowSkinSettings->setWhatsThis(buildWhatsThis(showSkinSettingsTitle, showSkinSettingsText));
createVisibilityControl(pViewShowSkinSettings, ConfigKey("[Master]", "skin_settings"));
pViewMenu->addAction(pViewShowSkinSettings);
// Microphone Section
QString showMicrophoneTitle = tr("Show Microphone Section");
QString showMicrophoneText = tr("Show the microphone section of the Mixxx interface.") +
" " + mayNotBeSupported;
auto* pViewShowMicrophone = new QAction(showMicrophoneTitle, this);
pViewShowMicrophone->setCheckable(true);
pViewShowMicrophone->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowMicrophone"),
tr("Ctrl+2", "Menubar|View|Show Microphone Section"))));
pViewShowMicrophone->setStatusTip(showMicrophoneText);
pViewShowMicrophone->setWhatsThis(buildWhatsThis(showMicrophoneTitle, showMicrophoneText));
createVisibilityControl(pViewShowMicrophone, ConfigKey("[Microphone]", "show_microphone"));
pViewMenu->addAction(pViewShowMicrophone);
#ifdef __VINYLCONTROL__
QString showVinylControlTitle = tr("Show Vinyl Control Section");
QString showVinylControlText = tr("Show the vinyl control section of the Mixxx interface.") +
" " + mayNotBeSupported;
auto* pViewVinylControl = new QAction(showVinylControlTitle, this);
pViewVinylControl->setCheckable(true);
pViewVinylControl->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowVinylControl"),
tr("Ctrl+3", "Menubar|View|Show Vinyl Control Section"))));
pViewVinylControl->setStatusTip(showVinylControlText);
pViewVinylControl->setWhatsThis(buildWhatsThis(showVinylControlTitle, showVinylControlText));
createVisibilityControl(pViewVinylControl, ConfigKey(VINYL_PREF_KEY, "show_vinylcontrol"));
pViewMenu->addAction(pViewVinylControl);
#endif
QString showPreviewDeckTitle = tr("Show Preview Deck");
QString showPreviewDeckText = tr("Show the preview deck in the Mixxx interface.") +
" " + mayNotBeSupported;
auto* pViewShowPreviewDeck = new QAction(showPreviewDeckTitle, this);
pViewShowPreviewDeck->setCheckable(true);
pViewShowPreviewDeck->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowPreviewDeck"),
tr("Ctrl+4", "Menubar|View|Show Preview Deck"))));
pViewShowPreviewDeck->setStatusTip(showPreviewDeckText);
pViewShowPreviewDeck->setWhatsThis(buildWhatsThis(showPreviewDeckTitle, showPreviewDeckText));
createVisibilityControl(pViewShowPreviewDeck, ConfigKey("[PreviewDeck]", "show_previewdeck"));
pViewMenu->addAction(pViewShowPreviewDeck);
QString showCoverArtTitle = tr("Show Cover Art");
QString showCoverArtText = tr("Show cover art in the Mixxx interface.") +
" " + mayNotBeSupported;
auto* pViewShowCoverArt = new QAction(showCoverArtTitle, this);
pViewShowCoverArt->setCheckable(true);
pViewShowCoverArt->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_ShowCoverArt"),
tr("Ctrl+6", "Menubar|View|Show Cover Art"))));
pViewShowCoverArt->setStatusTip(showCoverArtText);
pViewShowCoverArt->setWhatsThis(buildWhatsThis(showCoverArtTitle, showCoverArtText));
createVisibilityControl(pViewShowCoverArt, ConfigKey("[Library]", "show_coverart"));
pViewMenu->addAction(pViewShowCoverArt);
QString maximizeLibraryTitle = tr("Maximize Library");
QString maximizeLibraryText = tr("Maximize the track library to take up all the available screen space.") +
" " + mayNotBeSupported;
auto* pViewMaximizeLibrary = new QAction(maximizeLibraryTitle, this);
pViewMaximizeLibrary->setCheckable(true);
pViewMaximizeLibrary->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "ViewMenu_MaximizeLibrary"),
tr("Space", "Menubar|View|Maximize Library"))));
pViewMaximizeLibrary->setStatusTip(maximizeLibraryText);
pViewMaximizeLibrary->setWhatsThis(buildWhatsThis(maximizeLibraryTitle, maximizeLibraryText));
createVisibilityControl(pViewMaximizeLibrary, ConfigKey("[Master]", "maximize_library"));
pViewMenu->addAction(pViewMaximizeLibrary);
pViewMenu->addSeparator();
QString fullScreenTitle = tr("&Full Screen");
QString fullScreenText = tr("Display Mixxx using the full screen");
auto* pViewFullScreen = new QAction(fullScreenTitle, this);
QList<QKeySequence> shortcuts;
// We use F11 _AND_ the OS shortcut only on Linux and Windows because on
// newer macOS versions there might be issues with getting F11 working.
// https://github.com/mixxxdj/mixxx/pull/3011#issuecomment-678678328
#ifndef __APPLE__
shortcuts << QKeySequence("F11");
#endif
QKeySequence osShortcut = QKeySequence::FullScreen;
// Note(ronso0) Only add the OS shortcut if it's not empty and not F11.
// In some Linux distros the window managers doesn't pass the OS fullscreen
// key sequence to Mixxx for some reason.
// Both adding an empty key sequence or the same sequence twice can render
// the fullscreen shortcut nonfunctional.
// https://bugs.launchpad.net/mixxx/+bug/1882474 PR #3011
if (!osShortcut.isEmpty() && !shortcuts.contains(osShortcut)) {
shortcuts << osShortcut;
}
pViewFullScreen->setShortcuts(shortcuts);
pViewFullScreen->setShortcutContext(Qt::ApplicationShortcut);
pViewFullScreen->setCheckable(true);
pViewFullScreen->setChecked(false);
pViewFullScreen->setStatusTip(fullScreenText);
pViewFullScreen->setWhatsThis(buildWhatsThis(fullScreenTitle, fullScreenText));
connect(pViewFullScreen, &QAction::triggered, this, &WMainMenuBar::toggleFullScreen);
connect(this,
&WMainMenuBar::internalFullScreenStateChange,
pViewFullScreen,
&QAction::setChecked);
pViewMenu->addAction(pViewFullScreen);
addMenu(pViewMenu);
// OPTIONS MENU
QMenu* pOptionsMenu = new QMenu(tr("&Options"), this);
#ifdef __VINYLCONTROL__
QMenu* pVinylControlMenu = new QMenu(tr("&Vinyl Control"), this);
QString vinylControlText = tr(
"Use timecoded vinyls on external turntables to control Mixxx");
for (int i = 0; i < kMaximumVinylControlInputs; ++i) {
QString vinylControlTitle = tr("Enable Vinyl Control &%1").arg(i + 1);
auto* vc_checkbox = new QAction(vinylControlTitle, this);
m_vinylControlEnabledActions.push_back(vc_checkbox);
QString binding = m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]",
QString("OptionsMenu_EnableVinyl%1").arg(i + 1)),
vinylControlDefaultKeyBinding(i));
if (!binding.isEmpty()) {
vc_checkbox->setShortcut(QKeySequence(binding));
vc_checkbox->setShortcutContext(Qt::ApplicationShortcut);
}
// Either check or uncheck the vinyl control menu item depending on what
// it was saved as.
vc_checkbox->setCheckable(true);
vc_checkbox->setChecked(false);
// The visibility of these actions is set in
// WMainMenuBar::onNumberOfDecksChanged.
vc_checkbox->setVisible(false);
vc_checkbox->setStatusTip(vinylControlText);
vc_checkbox->setWhatsThis(buildWhatsThis(vinylControlTitle,
vinylControlText));
connect(vc_checkbox, &QAction::triggered,
this, [this, i] { emit toggleVinylControl(i); });
pVinylControlMenu->addAction(vc_checkbox);
}
pOptionsMenu->addMenu(pVinylControlMenu);
pOptionsMenu->addSeparator();
#endif
QString recordTitle = tr("&Record Mix");
QString recordText = tr("Record your mix to a file");
auto* pOptionsRecord = new QAction(recordTitle, this);
pOptionsRecord->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_RecordMix"),
tr("Ctrl+R"))));
pOptionsRecord->setShortcutContext(Qt::ApplicationShortcut);
pOptionsRecord->setCheckable(true);
pOptionsRecord->setStatusTip(recordText);
pOptionsRecord->setWhatsThis(buildWhatsThis(recordTitle, recordText));
connect(pOptionsRecord, &QAction::triggered, this, &WMainMenuBar::toggleRecording);
connect(this,
&WMainMenuBar::internalRecordingStateChange,
pOptionsRecord,
&QAction::setChecked);
pOptionsMenu->addAction(pOptionsRecord);
#ifdef __BROADCAST__
QString broadcastingTitle = tr("Enable Live &Broadcasting");
QString broadcastingText = tr("Stream your mixes to a shoutcast or icecast server");
auto* pOptionsBroadcasting = new QAction(broadcastingTitle, this);
pOptionsBroadcasting->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]",
"OptionsMenu_EnableLiveBroadcasting"),
tr("Ctrl+L"))));
pOptionsBroadcasting->setShortcutContext(Qt::ApplicationShortcut);
pOptionsBroadcasting->setCheckable(true);
pOptionsBroadcasting->setStatusTip(broadcastingText);
pOptionsBroadcasting->setWhatsThis(buildWhatsThis(broadcastingTitle, broadcastingText));
connect(pOptionsBroadcasting, &QAction::triggered, this, &WMainMenuBar::toggleBroadcasting);
connect(this,
&WMainMenuBar::internalBroadcastingStateChange,
pOptionsBroadcasting,
&QAction::setChecked);
pOptionsMenu->addAction(pOptionsBroadcasting);
#endif
pOptionsMenu->addSeparator();
QString keyboardShortcutTitle = tr("Enable &Keyboard Shortcuts");
QString keyboardShortcutText = tr("Toggles keyboard shortcuts on or off");
bool keyboardShortcutsEnabled = m_pConfig->getValueString(
ConfigKey("[Keyboard]", "Enabled")) == "1";
auto* pOptionsKeyboard = new QAction(keyboardShortcutTitle, this);
pOptionsKeyboard->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_EnableShortcuts"),
tr("Ctrl+`"))));
pOptionsKeyboard->setShortcutContext(Qt::ApplicationShortcut);
pOptionsKeyboard->setCheckable(true);
pOptionsKeyboard->setChecked(keyboardShortcutsEnabled);
pOptionsKeyboard->setStatusTip(keyboardShortcutText);
pOptionsKeyboard->setWhatsThis(buildWhatsThis(keyboardShortcutTitle, keyboardShortcutText));
connect(pOptionsKeyboard, &QAction::triggered, this, &WMainMenuBar::toggleKeyboardShortcuts);
pOptionsMenu->addAction(pOptionsKeyboard);
pOptionsMenu->addSeparator();
QString preferencesTitle = tr("&Preferences");
QString preferencesText = tr("Change Mixxx settings (e.g. playback, MIDI, controls)");
auto* pOptionsPreferences = new QAction(preferencesTitle, this);
pOptionsPreferences->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_Preferences"),
showPreferencesKeyBinding())));
pOptionsPreferences->setShortcutContext(Qt::ApplicationShortcut);
pOptionsPreferences->setStatusTip(preferencesText);
pOptionsPreferences->setWhatsThis(buildWhatsThis(preferencesTitle, preferencesText));
pOptionsPreferences->setMenuRole(QAction::PreferencesRole);
connect(pOptionsPreferences, &QAction::triggered, this, &WMainMenuBar::showPreferences);
pOptionsMenu->addAction(pOptionsPreferences);
addMenu(pOptionsMenu);
// DEVELOPER MENU
if (CmdlineArgs::Instance().getDeveloper()) {
QMenu* pDeveloperMenu = new QMenu(tr("&Developer"), this);
QString reloadSkinTitle = tr("&Reload Skin");
QString reloadSkinText = tr("Reload the skin");
auto* pDeveloperReloadSkin = new QAction(reloadSkinTitle, this);
pDeveloperReloadSkin->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_ReloadSkin"),
tr("Ctrl+Shift+R"))));
pDeveloperReloadSkin->setShortcutContext(Qt::ApplicationShortcut);
pDeveloperReloadSkin->setStatusTip(reloadSkinText);
pDeveloperReloadSkin->setWhatsThis(buildWhatsThis(reloadSkinTitle, reloadSkinText));
connect(pDeveloperReloadSkin, &QAction::triggered, this, &WMainMenuBar::reloadSkin);
pDeveloperMenu->addAction(pDeveloperReloadSkin);
QString developerToolsTitle = tr("Developer &Tools");
QString developerToolsText = tr("Opens the developer tools dialog");
auto* pDeveloperTools = new QAction(developerToolsTitle, this);
pDeveloperTools->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_DeveloperTools"),
tr("Ctrl+Shift+T"))));
pDeveloperTools->setShortcutContext(Qt::ApplicationShortcut);
pDeveloperTools->setCheckable(true);
pDeveloperTools->setChecked(false);
pDeveloperTools->setStatusTip(developerToolsText);
pDeveloperTools->setWhatsThis(buildWhatsThis(developerToolsTitle, developerToolsText));
connect(pDeveloperTools, &QAction::triggered, this, &WMainMenuBar::toggleDeveloperTools);
connect(this,
&WMainMenuBar::internalDeveloperToolsStateChange,
pDeveloperTools,
&QAction::setChecked);
pDeveloperMenu->addAction(pDeveloperTools);
QString enableExperimentTitle = tr("Stats: &Experiment Bucket");
QString enableExperimentToolsText = tr(
"Enables experiment mode. Collects stats in the EXPERIMENT tracking bucket.");
auto* pDeveloperStatsExperiment = new QAction(enableExperimentTitle, this);
pDeveloperStatsExperiment->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_DeveloperStatsExperiment"),
tr("Ctrl+Shift+E"))));
pDeveloperStatsExperiment->setShortcutContext(Qt::ApplicationShortcut);
pDeveloperStatsExperiment->setStatusTip(enableExperimentToolsText);
pDeveloperStatsExperiment->setWhatsThis(buildWhatsThis(
enableExperimentTitle, enableExperimentToolsText));
pDeveloperStatsExperiment->setCheckable(true);
pDeveloperStatsExperiment->setChecked(Experiment::isExperiment());
connect(pDeveloperStatsExperiment,
&QAction::triggered,
this,
&WMainMenuBar::slotDeveloperStatsExperiment);
pDeveloperMenu->addAction(pDeveloperStatsExperiment);
QString enableBaseTitle = tr("Stats: &Base Bucket");
QString enableBaseToolsText = tr(
"Enables base mode. Collects stats in the BASE tracking bucket.");
auto* pDeveloperStatsBase = new QAction(enableBaseTitle, this);
pDeveloperStatsBase->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "OptionsMenu_DeveloperStatsBase"),
tr("Ctrl+Shift+B"))));
pDeveloperStatsBase->setShortcutContext(Qt::ApplicationShortcut);
pDeveloperStatsBase->setStatusTip(enableBaseToolsText);
pDeveloperStatsBase->setWhatsThis(buildWhatsThis(
enableBaseTitle, enableBaseToolsText));
pDeveloperStatsBase->setCheckable(true);
pDeveloperStatsBase->setChecked(Experiment::isBase());
connect(pDeveloperStatsBase,
&QAction::triggered,
this,
&WMainMenuBar::slotDeveloperStatsBase);
pDeveloperMenu->addAction(pDeveloperStatsBase);
// "D" cannot be used with Alt here as it is already by the Developer menu
QString scriptDebuggerTitle = tr("Deb&ugger Enabled");
QString scriptDebuggerText = tr("Enables the debugger during skin parsing");
bool scriptDebuggerEnabled = m_pConfig->getValueString(
ConfigKey("[ScriptDebugger]", "Enabled")) == "1";
auto* pDeveloperDebugger = new QAction(scriptDebuggerTitle, this);
pDeveloperDebugger->setShortcut(
QKeySequence(m_pKbdConfig->getValue(
ConfigKey("[KeyboardShortcuts]", "DeveloperMenu_EnableDebugger"),
tr("Ctrl+Shift+D"))));
pDeveloperDebugger->setShortcutContext(Qt::ApplicationShortcut);
pDeveloperDebugger->setWhatsThis(buildWhatsThis(keyboardShortcutTitle, keyboardShortcutText));
pDeveloperDebugger->setCheckable(true);
pDeveloperDebugger->setStatusTip(scriptDebuggerText);
pDeveloperDebugger->setChecked(scriptDebuggerEnabled);
connect(pDeveloperDebugger,
&QAction::triggered,
this,
&WMainMenuBar::slotDeveloperDebugger);
pDeveloperMenu->addAction(pDeveloperDebugger);
addMenu(pDeveloperMenu);
}
addSeparator();
// HELP MENU
QMenu* pHelpMenu = new QMenu(tr("&Help"), this);
QString externalLinkSuffix;
#ifndef __APPLE__
// According to Apple's Human Interface Guidelines devs are encouraged
// to not use custom icons in menus.
// https://developer.apple.com/design/human-interface-guidelines/macos/menus/menu-anatomy/
externalLinkSuffix = QChar(' ') + QChar(0x2197); // north-east arrow
#endif
// Community Support
QString supportTitle = tr("&Community Support") + externalLinkSuffix;
QString supportText = tr("Get help with Mixxx");
auto* pHelpSupport = new QAction(supportTitle, this);
pHelpSupport->setStatusTip(supportText);
pHelpSupport->setWhatsThis(buildWhatsThis(supportTitle, supportText));
connect(pHelpSupport, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_SUPPORT_URL); });
pHelpMenu->addAction(pHelpSupport);
// User Manual
QUrl manualUrl = documentationUrl(m_pConfig->getResourcePath(),
MIXXX_MANUAL_FILENAME,
MIXXX_MANUAL_URL);
QString manualSuffix = manualUrl.isLocalFile() ? QString() : externalLinkSuffix;
QString manualTitle = tr("&User Manual") + manualSuffix;
QString manualText = tr("Read the Mixxx user manual.");
auto* pHelpManual = new QAction(manualTitle, this);
pHelpManual->setStatusTip(manualText);
pHelpManual->setWhatsThis(buildWhatsThis(manualTitle, manualText));
connect(pHelpManual, &QAction::triggered, this, [this, manualUrl] {
slotVisitUrl(manualUrl.toString());
});
pHelpMenu->addAction(pHelpManual);
// Keyboard Shortcuts
QUrl keyboardShortcutsUrl = documentationUrl(m_pConfig->getResourcePath(),
MIXXX_KBD_SHORTCUTS_FILENAME,
MIXXX_MANUAL_SHORTCUTS_URL);
QString keyboardShortcutsSuffix =
keyboardShortcutsUrl.isLocalFile() ? QString() : externalLinkSuffix;
QString shortcutsTitle = tr("&Keyboard Shortcuts") + keyboardShortcutsSuffix;
QString shortcutsText = tr("Speed up your workflow with keyboard shortcuts.");
auto* pHelpKbdShortcuts = new QAction(shortcutsTitle, this);
pHelpKbdShortcuts->setStatusTip(shortcutsText);
pHelpKbdShortcuts->setWhatsThis(buildWhatsThis(shortcutsTitle, shortcutsText));
connect(pHelpKbdShortcuts,
&QAction::triggered,
this,
[this, keyboardShortcutsUrl] {
slotVisitUrl(keyboardShortcutsUrl.toString());
});
pHelpMenu->addAction(pHelpKbdShortcuts);
// Translate This Application
QString translateTitle = tr("&Translate This Application") + externalLinkSuffix;
QString translateText = tr("Help translate this application into your language.");
auto* pHelpTranslation = new QAction(translateTitle, this);
pHelpTranslation->setStatusTip(translateText);
pHelpTranslation->setWhatsThis(buildWhatsThis(translateTitle, translateText));
connect(pHelpTranslation, &QAction::triggered,
this, [this] { slotVisitUrl(MIXXX_TRANSLATION_URL); });
pHelpMenu->addAction(pHelpTranslation);
pHelpMenu->addSeparator();
QString aboutTitle = tr("&About");
QString aboutText = tr("About the application");
auto* pHelpAboutApp = new QAction(aboutTitle, this);
pHelpAboutApp->setStatusTip(aboutText);
pHelpAboutApp->setWhatsThis(buildWhatsThis(aboutTitle, aboutText));
pHelpAboutApp->setMenuRole(QAction::AboutRole);
connect(pHelpAboutApp, &QAction::triggered, this, &WMainMenuBar::showAbout);
pHelpMenu->addAction(pHelpAboutApp);
addMenu(pHelpMenu);
}
void WMainMenuBar::onLibraryScanStarted() {
emit internalLibraryScanActive(true);
}
void WMainMenuBar::onLibraryScanFinished() {
emit internalLibraryScanActive(false);
}
void WMainMenuBar::onNewSkinLoaded() {
emit internalOnNewSkinLoaded();
}
void WMainMenuBar::onNewSkinAboutToLoad() {
emit internalOnNewSkinAboutToLoad();
}
void WMainMenuBar::onRecordingStateChange(bool recording) {
emit internalRecordingStateChange(recording);
}
void WMainMenuBar::onBroadcastingStateChange(bool broadcasting) {
emit internalBroadcastingStateChange(broadcasting);
}
void WMainMenuBar::onDeveloperToolsShown() {
emit internalDeveloperToolsStateChange(true);
}
void WMainMenuBar::onDeveloperToolsHidden() {
emit internalDeveloperToolsStateChange(false);
}
void WMainMenuBar::onFullScreenStateChange(bool fullscreen) {
emit internalFullScreenStateChange(fullscreen);
}
void WMainMenuBar::onVinylControlDeckEnabledStateChange(int deck, bool enabled) {
if (deck < 0 || deck >= m_vinylControlEnabledActions.size()) {
DEBUG_ASSERT(false);
return;
}
m_vinylControlEnabledActions.at(deck)->setChecked(enabled);
}
void WMainMenuBar::slotDeveloperStatsBase(bool enable) {
if (enable) {
Experiment::setBase();
} else {
Experiment::disable();
}
}
void WMainMenuBar::slotDeveloperStatsExperiment(bool enable) {
if (enable) {
Experiment::setExperiment();
} else {
Experiment::disable();
}
}
void WMainMenuBar::slotDeveloperDebugger(bool toggle) {
m_pConfig->set(ConfigKey("[ScriptDebugger]","Enabled"),
ConfigValue(toggle ? 1 : 0));
}
void WMainMenuBar::slotVisitUrl(const QString& url) {
QDesktopServices::openUrl(QUrl(url));
}
void WMainMenuBar::createVisibilityControl(QAction* pAction,
const ConfigKey& key) {
auto* pConnection = new VisibilityControlConnection(this, pAction, key);
connect(this,
&WMainMenuBar::internalOnNewSkinLoaded,
pConnection,
&VisibilityControlConnection::slotReconnectControl);
#ifdef __LINUX__
// reconnect when menu bar was recreated after toggling fullscreen
// so all hotkeys and menu actions continue to work
connect(this,
&WMainMenuBar::internalFullScreenStateChange,
pConnection,
&VisibilityControlConnection::slotReconnectControl);
#endif
connect(this,
&WMainMenuBar::internalOnNewSkinAboutToLoad,
pConnection,
&VisibilityControlConnection::slotClearControl);
}
void WMainMenuBar::onNumberOfDecksChanged(int decks) {
int deck = 0;
for (QAction* pVinylControlEnabled : qAsConst(m_vinylControlEnabledActions)) {
pVinylControlEnabled->setVisible(deck++ < decks);
}
deck = 0;
for (QAction* pLoadToDeck : qAsConst(m_loadToDeckActions)) {
pLoadToDeck->setVisible(deck++ < decks);
}
}
VisibilityControlConnection::VisibilityControlConnection(
QObject* pParent, QAction* pAction, const ConfigKey& key)
: QObject(pParent),
m_key(key),
m_pAction(pAction) {
connect(m_pAction, &QAction::triggered, this, &VisibilityControlConnection::slotActionToggled);
}
void VisibilityControlConnection::slotClearControl() {
m_pControl.reset();
m_pAction->setEnabled(false);
}
void VisibilityControlConnection::slotReconnectControl() {
m_pControl.reset(new ControlProxy(m_key, this, ControlFlag::NoAssertIfMissing));
m_pControl->connectValueChanged(this, &VisibilityControlConnection::slotControlChanged);
m_pAction->setEnabled(m_pControl->valid());
slotControlChanged();
}
void VisibilityControlConnection::slotControlChanged() {
if (m_pControl) {
m_pAction->setChecked(m_pControl->toBool());
}
}
void VisibilityControlConnection::slotActionToggled(bool toggle) {
if (m_pControl) {
m_pControl->set(toggle ? 1.0 : 0.0);
}
}