-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
librarycontrol.cpp
1013 lines (905 loc) · 34.8 KB
/
librarycontrol.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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "library/librarycontrol.h"
#include <QApplication>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <QModelIndexList>
#include <QWindow>
#include <QtDebug>
#include "control/controlobject.h"
#include "control/controlpushbutton.h"
#include "library/library.h"
#include "library/libraryview.h"
#include "mixer/playermanager.h"
#include "moc_librarycontrol.cpp"
#include "util/cmdlineargs.h"
#include "widget/wlibrary.h"
#include "widget/wlibrarysidebar.h"
#include "widget/wsearchlineedit.h"
#include "widget/wtracktableview.h"
LoadToGroupController::LoadToGroupController(LibraryControl* pParent, const QString& group)
: QObject(pParent),
m_group(group) {
m_pLoadControl = std::make_unique<ControlPushButton>(ConfigKey(group, "LoadSelectedTrack"));
connect(m_pLoadControl.get(),
&ControlObject::valueChanged,
this,
&LoadToGroupController::slotLoadToGroup);
m_pLoadAndPlayControl = std::make_unique<ControlPushButton>(ConfigKey(group, "LoadSelectedTrackAndPlay"));
connect(m_pLoadAndPlayControl.get(),
&ControlObject::valueChanged,
this,
&LoadToGroupController::slotLoadToGroupAndPlay);
connect(this,
&LoadToGroupController::loadToGroup,
pParent,
&LibraryControl::slotLoadSelectedTrackToGroup);
}
LoadToGroupController::~LoadToGroupController() = default;
void LoadToGroupController::slotLoadToGroup(double v) {
if (v > 0) {
emit loadToGroup(m_group, false);
}
}
void LoadToGroupController::slotLoadToGroupAndPlay(double v) {
if (v > 0) {
emit loadToGroup(m_group, true);
}
}
LibraryControl::LibraryControl(Library* pLibrary)
: QObject(pLibrary),
m_pLibrary(pLibrary),
m_pFocusedWidget(FocusWidget::None),
m_pLibraryWidget(nullptr),
m_pSidebarWidget(nullptr),
m_pSearchbox(nullptr),
m_numDecks("[Master]", "num_decks", this),
m_numSamplers("[Master]", "num_samplers", this),
m_numPreviewDecks("[Master]", "num_preview_decks", this) {
qRegisterMetaType<FocusWidget>("FocusWidget");
slotNumDecksChanged(m_numDecks.get());
slotNumSamplersChanged(m_numSamplers.get());
slotNumPreviewDecksChanged(m_numPreviewDecks.get());
m_numDecks.connectValueChanged(this, &LibraryControl::slotNumDecksChanged);
m_numSamplers.connectValueChanged(this, &LibraryControl::slotNumSamplersChanged);
m_numPreviewDecks.connectValueChanged(this, &LibraryControl::slotNumPreviewDecksChanged);
// Controls to navigate vertically within currently focused widget (up/down buttons)
m_pMoveUp = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveUp"));
m_pMoveDown = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveDown"));
m_pMoveVertical = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "MoveVertical"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pMoveUp.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveUp);
connect(m_pMoveDown.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveDown);
connect(m_pMoveVertical.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotMoveVertical);
#endif
// Controls to navigate vertically within currently focused widget (up/down buttons)
m_pScrollUp = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "ScrollUp"));
m_pScrollDown = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "ScrollDown"));
m_pScrollVertical = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "ScrollVertical"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pScrollUp.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotScrollUp);
connect(m_pScrollDown.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotScrollDown);
connect(m_pScrollVertical.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotScrollVertical);
#endif
// Controls to navigate horizontally within currently selected item (left/right buttons)
m_pMoveLeft = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveLeft"));
m_pMoveRight = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveRight"));
m_pMoveHorizontal = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "MoveHorizontal"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pMoveLeft.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveLeft);
connect(m_pMoveRight.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveRight);
connect(m_pMoveHorizontal.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotMoveHorizontal);
#endif
// Controls to navigate between widgets
// Relative focus controls (emulate Tab/Shift+Tab button press)
m_pMoveFocusForward = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveFocusForward"));
m_pMoveFocusBackward = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveFocusBackward"));
m_pMoveFocus = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "MoveFocus"), false);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pMoveFocusForward.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveFocusForward);
connect(m_pMoveFocusBackward.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveFocusBackward);
connect(m_pMoveFocus.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotMoveFocus);
#endif
// Direct focus control, read/write
m_pFocusedWidgetCO = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "focused_widget"));
m_pFocusedWidgetCO->setStates(static_cast<int>(FocusWidget::Count));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_pFocusedWidgetCO->connectValueChangeRequest(
this,
[this](double value) {
// Focus can not be removed from a widget just moved to another one.
// Thus, to keep the CO and QApplication::focusWidget() in sync we
// have to prevent scripts or GUI buttons setting the CO to 'None'.
// It's only set to 'None' internally when one of the library widgets
// receives a FocusOutEvent(), e.g. when the focus is moved to another
// widget, or when the main window loses focus.
const int valueInt = static_cast<int>(value);
if (valueInt != static_cast<int>(FocusWidget::None) &&
valueInt < static_cast<int>(FocusWidget::Count)) {
setLibraryFocus(static_cast<FocusWidget>(valueInt));
}
});
#endif
// Control to "goto" the currently selected item in focused widget (context dependent)
m_pGoToItem = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "GoToItem"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pGoToItem.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotGoToItem);
#endif
// Auto DJ controls
m_pAutoDjAddTop = std::make_unique<ControlPushButton>(ConfigKey("[Library]","AutoDjAddTop"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pAutoDjAddTop.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotAutoDjAddTop);
#endif
m_pAutoDjAddBottom = std::make_unique<ControlPushButton>(ConfigKey("[Library]","AutoDjAddBottom"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pAutoDjAddBottom.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotAutoDjAddBottom);
#endif
m_pAutoDjAddReplace = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "AutoDjAddReplace"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pAutoDjAddReplace.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotAutoDjAddReplace);
#endif
// Sort controls
m_pSortColumn = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "sort_column"));
m_pSortOrder = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "sort_order"));
m_pSortOrder->setButtonMode(ControlPushButton::TOGGLE);
m_pSortColumnToggle = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "sort_column_toggle"), false);
m_pSortFocusedColumn = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "sort_focused_column"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
connect(m_pSortColumn.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotSortColumn);
connect(m_pSortColumnToggle.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotSortColumnToggle);
connect(m_pSortFocusedColumn.get(),
&ControlObject::valueChanged,
this,
[this](double value) {
if (value > 0.0) {
slotSortColumnToggle(static_cast<int>(TrackModel::SortColumnId::CurrentIndex));
}
});
// Font sizes
m_pFontSizeKnob = std::make_unique<ControlObject>(
ConfigKey("[Library]", "font_size_knob"), false);
connect(m_pFontSizeKnob.get(),
&ControlObject::valueChanged,
this,
&LibraryControl::slotFontSize);
m_pFontSizeDecrement = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "font_size_decrement"));
connect(m_pFontSizeDecrement.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotDecrementFontSize);
m_pFontSizeIncrement = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "font_size_increment"));
connect(m_pFontSizeIncrement.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotIncrementFontSize);
#endif
// Track Color controls
m_pTrackColorPrev = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "track_color_prev"));
m_pTrackColorNext = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "track_color_next"));
connect(m_pTrackColorPrev.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorPrev);
connect(m_pTrackColorNext.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotTrackColorNext);
// Controls to select saved searchbox queries and to clear the searchbox
m_pSelectHistoryNext = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "search_history_next"));
connect(m_pSelectHistoryNext.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value > 0.0) {
m_pSearchbox->slotMoveSelectedHistory(1);
}
});
m_pSelectHistoryPrev = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "search_history_prev"));
connect(m_pSelectHistoryPrev.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value > 0.0) {
m_pSearchbox->slotMoveSelectedHistory(-1);
}
});
m_pSelectHistorySelect = std::make_unique<ControlEncoder>(
ConfigKey("[Library]", "search_history_selector"), false);
connect(m_pSelectHistorySelect.get(),
&ControlEncoder::valueChanged,
this,
[this](double steps) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
int iSteps = static_cast<int>(steps);
if (iSteps) {
m_pSearchbox->slotMoveSelectedHistory(static_cast<int>(steps));
}
});
m_pClearSearch = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "clear_search"));
connect(m_pClearSearch.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value > 0.0) {
m_pSearchbox->slotClearSearch();
}
});
m_pDeleteSearchQuery = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "delete_search_query"));
connect(m_pDeleteSearchQuery.get(),
&ControlPushButton::valueChanged,
this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
if (value > 0.0) {
m_pSearchbox->slotDeleteCurrentItem();
}
});
// Show the track context menu for selected tracks, or hide it
// if it is the current active window
// The control is updated in slotUpdateTrackMenuControl with the actual state
// sent from WTrackMenu via WTrackTableView
m_pShowTrackMenu = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "show_track_menu"));
m_pShowTrackMenu->setStates(2);
m_pShowTrackMenu->connectValueChangeRequest(this,
[this](double value) {
VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) {
return;
}
bool show = static_cast<bool>(value);
emit showHideTrackMenu(show);
});
// Deprecated controls
m_pSelectNextTrack = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextTrack"));
connect(m_pSelectNextTrack.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotSelectNextTrack);
m_pSelectPrevTrack = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectPrevTrack"));
connect(m_pSelectPrevTrack.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotSelectPrevTrack);
// Ignoring no-ops is important since this is for +/- tickers.
m_pSelectTrack = std::make_unique<ControlObject>(ConfigKey("[Playlist]","SelectTrackKnob"), false);
connect(m_pSelectTrack.get(),
&ControlObject::valueChanged,
this,
&LibraryControl::slotSelectTrack);
m_pSelectNextSidebarItem = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectNextPlaylist"));
connect(m_pSelectNextSidebarItem.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotSelectNextSidebarItem);
m_pSelectPrevSidebarItem = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "SelectPrevPlaylist"));
connect(m_pSelectPrevSidebarItem.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotSelectPrevSidebarItem);
// Ignoring no-ops is important since this is for +/- tickers.
m_pSelectSidebarItem = std::make_unique<ControlObject>(ConfigKey("[Playlist]", "SelectPlaylist"), false);
connect(m_pSelectSidebarItem.get(),
&ControlObject::valueChanged,
this,
&LibraryControl::slotSelectSidebarItem);
m_pToggleSidebarItem = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]", "ToggleSelectedSidebarItem"));
connect(m_pToggleSidebarItem.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotToggleSelectedSidebarItem);
m_pLoadSelectedIntoFirstStopped = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]","LoadSelectedIntoFirstStopped"));
connect(m_pLoadSelectedIntoFirstStopped.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotLoadSelectedIntoFirstStopped);
ControlDoublePrivate::insertAlias(ConfigKey("[Playlist]", "AutoDjAddTop"), ConfigKey("[Library]", "AutoDjAddTop"));
ControlDoublePrivate::insertAlias(ConfigKey("[Playlist]", "AutoDjAddBottom"), ConfigKey("[Library]", "AutoDjAddBottom"));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QApplication* app = qApp;
// Update controls if any widget in any Mixxx window gets or loses focus
connect(app,
&QApplication::focusChanged,
this,
&LibraryControl::updateFocusedWidgetControls);
// Also update controls if the window focus changed.
// Even though any new menu window has focus and will receive keypress events
// it does NOT have a focused widget before the first click or keypress.
// Thus a QMenu popping up is not reported by focusChanged(oldWidget, newWidget).
// QApplication::focusWidget() is still that in the previously focused
// window (MixxxMainWindow for example).
connect(app,
&QGuiApplication::focusWindowChanged,
this,
&LibraryControl::updateFocusedWidgetControls);
#endif
}
LibraryControl::~LibraryControl() = default;
void LibraryControl::maybeCreateGroupController(const QString& group) {
if (m_loadToGroupControllers.find(group) == m_loadToGroupControllers.end()) {
m_loadToGroupControllers.emplace(group, std::make_unique<LoadToGroupController>(this, group));
}
}
void LibraryControl::slotNumDecksChanged(double v) {
int iNumDecks = static_cast<int>(v);
if (iNumDecks < 0) {
return;
}
for (int i = 0; i < iNumDecks; ++i) {
maybeCreateGroupController(PlayerManager::groupForDeck(i));
}
}
void LibraryControl::slotNumSamplersChanged(double v) {
int iNumSamplers = static_cast<int>(v);
if (iNumSamplers < 0) {
return;
}
for (int i = 0; i < iNumSamplers; ++i) {
maybeCreateGroupController(PlayerManager::groupForSampler(i));
}
}
void LibraryControl::slotNumPreviewDecksChanged(double v) {
int iNumPreviewDecks = static_cast<int>(v);
if (iNumPreviewDecks < 0) {
return;
}
for (int i = 0; i < iNumPreviewDecks; ++i) {
maybeCreateGroupController(PlayerManager::groupForPreviewDeck(i));
}
}
void LibraryControl::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
if (m_pSidebarWidget) {
disconnect(m_pSidebarWidget, nullptr, this, nullptr);
}
m_pSidebarWidget = pSidebarWidget;
connect(m_pSidebarWidget,
&WLibrarySidebar::destroyed,
this,
&LibraryControl::sidebarWidgetDeleted);
}
void LibraryControl::bindLibraryWidget(WLibrary* pLibraryWidget, KeyboardEventFilter* pKeyboard) {
Q_UNUSED(pKeyboard);
if (m_pLibraryWidget) {
disconnect(m_pLibraryWidget, nullptr, this, nullptr);
}
m_pLibraryWidget = pLibraryWidget;
connect(m_pLibraryWidget,
&WLibrary::destroyed,
this,
&LibraryControl::libraryWidgetDeleted);
}
void LibraryControl::bindSearchboxWidget(WSearchLineEdit* pSearchbox) {
if (m_pSearchbox) {
disconnect(m_pSearchbox, nullptr, this, nullptr);
}
m_pSearchbox = pSearchbox;
connect(m_pSearchbox,
&WSearchLineEdit::destroyed,
this,
&LibraryControl::searchboxWidgetDeleted);
}
void LibraryControl::libraryWidgetDeleted() {
m_pLibraryWidget = nullptr;
}
void LibraryControl::sidebarWidgetDeleted() {
m_pSidebarWidget = nullptr;
}
void LibraryControl::searchboxWidgetDeleted() {
m_pSearchbox = nullptr;
}
void LibraryControl::slotUpdateTrackMenuControl(bool visible) {
m_pShowTrackMenu->setAndConfirm(visible ? 1.0 : 0.0);
}
void LibraryControl::slotLoadSelectedTrackToGroup(const QString& group, bool play) {
if (!m_pLibraryWidget) {
return;
}
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->loadSelectedTrackToGroup(group, play);
}
void LibraryControl::slotLoadSelectedIntoFirstStopped(double v) {
if (!m_pLibraryWidget) {
return;
}
if (v > 0) {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->activateSelectedTrack();
}
}
void LibraryControl::slotAutoDjAddTop(double v) {
if (!m_pLibraryWidget) {
return;
}
if (v > 0) {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->slotAddToAutoDJTop();
}
}
void LibraryControl::slotAutoDjAddBottom(double v) {
if (!m_pLibraryWidget) {
return;
}
if (v > 0) {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->slotAddToAutoDJBottom();
}
}
void LibraryControl::slotAutoDjAddReplace(double v) {
if (!m_pLibraryWidget) {
return;
}
if (v > 0) {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->slotAddToAutoDJReplace();
}
}
void LibraryControl::slotSelectNextTrack(double v) {
if (v > 0) {
slotSelectTrack(1);
}
}
void LibraryControl::slotSelectPrevTrack(double v) {
if (v > 0) {
slotSelectTrack(-1);
}
}
void LibraryControl::slotSelectTrack(double v) {
if (!m_pLibraryWidget) {
return;
}
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
int i = (int)v;
pActiveView->moveSelection(i);
}
void LibraryControl::slotMoveUp(double v) {
if (v > 0) {
slotMoveVertical(1);
}
}
void LibraryControl::slotMoveDown(double v) {
if (v > 0) {
slotMoveVertical(-1);
}
}
void LibraryControl::slotMoveVertical(double v) {
if (v == 0) {
return;
}
switch (m_pFocusedWidget) {
case FocusWidget::Sidebar: {
int i = static_cast<int>(v);
slotSelectSidebarItem(i);
return;
}
case FocusWidget::TracksTable: {
// This wraps around at top/bottom. Doesn't match Up/Down key behaviour
// and may not be desired.
//int i = static_cast<int>(v);
//slotSelectTrack(i);
//return;
break;
}
case FocusWidget::Dialog: {
// For navigating dialogs map up/down to Tab/BackTab
// Don't use Shift + Tab! (see moveFocus())
const auto key = (v > 0) ? Qt::Key_Tab : Qt::Key_Backtab;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
return;
}
case FocusWidget::ContextMenu: {
// To navigate menus (and activate menus that were just opened) send the
// keyEvent to focusWindow() (not focusWidget() like emitKeyEvent() does)
const auto key = (v < 0) ? Qt::Key_Up : Qt::Key_Down;
const auto times = static_cast<unsigned short>(std::abs(v));
QKeyEvent event = QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times};
QApplication::sendEvent(QApplication::focusWindow(), &event);
return;
}
case FocusWidget::Searchbar:
// There's also m_pSearchbox->slotMoveSelectedHistory but that wraps around
// at top/bottom. Doesn't match Up/Down key behaviour and may not be desired.
// Proceed and let emitkeyEvent deal with it.
break;
case FocusWidget::None:
case FocusWidget::Unknown:
default:
// 'Unknown' uncategorized widget like a QComboBox. Return to not alter
// any WBeatSpinBox or WEffectSelector
setLibraryFocus(FocusWidget::TracksTable);
return;
}
const auto key = (v < 0) ? Qt::Key_Up : Qt::Key_Down;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
void LibraryControl::slotScrollUp(double v) {
if (v > 0) {
slotScrollVertical(-1);
}
}
void LibraryControl::slotScrollDown(double v) {
if (v > 0) {
slotScrollVertical(1);
}
}
void LibraryControl::slotScrollVertical(double v) {
const auto key = (v < 0) ? Qt::Key_PageUp: Qt::Key_PageDown;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
void LibraryControl::slotMoveLeft(double v) {
if (v > 0) {
slotMoveHorizontal(-1);
}
}
void LibraryControl::slotMoveRight(double v) {
if (v > 0) {
slotMoveHorizontal(1);
}
}
void LibraryControl::slotMoveHorizontal(double v) {
const auto key = (v < 0) ? Qt::Key_Left: Qt::Key_Right;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
void LibraryControl::slotMoveFocusForward(double v) {
if (v > 0) {
slotMoveFocus(1);
}
}
void LibraryControl::slotMoveFocusBackward(double v) {
if (v > 0) {
slotMoveFocus(-1);
}
}
void LibraryControl::slotMoveFocus(double v) {
// Don't use Key_Tab + ShiftModifier for moving focus backwards!
// This would indeed move the focus, though it has a significant side-effect
// compared to pressing Shift + Tab on a real keyboard:
// Shift would remain 'pressed' in the previously focused widget until it
// receives any keyEvent with Qt::NoModifier.
const auto key = (v > 0) ? Qt::Key_Tab : Qt::Key_Backtab;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
void LibraryControl::emitKeyEvent(QKeyEvent&& event) {
if (!QApplication::focusWindow()) {
qInfo() << "No Mixxx window, popup or menu has focus."
<< "Don't send key events.";
return;
}
switch (m_pFocusedWidget) {
case FocusWidget::None:
return setLibraryFocus(FocusWidget::TracksTable);
default:
break;
}
// Send the event pointer to the currently focused widget
auto* focusWidget = QApplication::focusWidget();
if (focusWidget) {
for (auto i = 0; i < event.count(); ++i) {
QApplication::sendEvent(focusWidget, &event);
}
}
}
FocusWidget LibraryControl::getFocusedWidget() {
auto* focusWindow = QApplication::focusWindow();
if (!focusWindow) {
return FocusWidget::None;
}
// Any QMenu is focusWindow() but NOT focusWidget() before any menu item
// is highlighted, though it can already receive keypress events.
// Thus, test for focus window type first to catch open popups.
if (focusWindow->type() == Qt::Popup) {
// WMainMenuBar
// WTrackMenuClassWindow = WTrackMenu + submenus
// QMenuClassWindow = e.g. sidebar context menu
// qt_edit_menuWindow = QLineEdit/QCombobox context menu
// QComboBoxListView of WEffectSelector, WSearchLineEdit, ...
return FocusWidget::ContextMenu;
} else if (focusWindow->type() == Qt::Dialog) {
// DlgPreferencesDlgWindow
// DlgDeveloperToolsWindow
// DlgAboutDlgWindow
// DlgKeywheelWindow
// QInputDialogClassWindow (file dialogs, rename/create dialogs)
// error messages and Close Mixxx confirmation dialog
// ToDo(ronso0) handle CoverArt:
// - refocus tracks view?
// DlgCoverArtFullSizeWindow
return FocusWidget::Dialog;
}
// Now we assume MixxxMainWindow is focused
if (!QApplication::focusWidget()) {
return FocusWidget::None;
}
if (m_pSearchbox && m_pSearchbox->hasFocus()) {
return FocusWidget::Searchbar;
} else if (m_pSidebarWidget && m_pSidebarWidget->hasFocus()) {
return FocusWidget::Sidebar;
} else if (m_pLibraryWidget && m_pLibraryWidget->getActiveView()->hasFocus()) {
return FocusWidget::TracksTable;
} else {
// Unknown widget, for example Clear button in WSearcLineEdit,
// some drop-down view, WBeatSpinBox or QLineEdit in WtrackTableView
return FocusWidget::Unknown;
}
}
void LibraryControl::setLibraryFocus(FocusWidget newFocusWidget) {
if (!QApplication::focusWindow()) {
qInfo() << "No Mixxx window, popup or menu has focus."
<< "Don't attempt to focus a specific widget.";
return;
}
// ignore no-op
if (newFocusWidget == m_pFocusedWidget) {
return;
}
switch (newFocusWidget) {
case FocusWidget::Searchbar:
VERIFY_OR_DEBUG_ASSERT(m_pSearchbox) {
return;
}
return m_pSearchbox->setFocus();
case FocusWidget::Sidebar:
VERIFY_OR_DEBUG_ASSERT(m_pSidebarWidget) {
return;
}
return m_pSidebarWidget->setFocus();
case FocusWidget::TracksTable:
VERIFY_OR_DEBUG_ASSERT(m_pLibraryWidget) {
return;
}
return m_pLibraryWidget->getActiveView()->setFocus();
case FocusWidget::None:
// What could be the goal, what are the consequences of manually
// removing focus from a widget?
default:
// Ignore invalid requests and don't allow focussing any other widget
// manually, like QDialog or QMenu.
return;
}
// Done. QApplication::focusChanged will invoke updateFocusControl()
// to update [Library],focused_widget
}
void LibraryControl::updateFocusedWidgetControls() {
m_pFocusedWidget = getFocusedWidget();
// Update "[Library], focused_widget" control
double newVal = static_cast<double>(m_pFocusedWidget);
m_pFocusedWidgetCO->setAndConfirm(newVal);
}
void LibraryControl::slotSelectSidebarItem(double v) {
if (!m_pSidebarWidget) {
return;
}
if (v == 0) {
return;
}
const auto key = (v < 0) ? Qt::Key_Up : Qt::Key_Down;
const auto times = static_cast<unsigned short>(std::abs(v));
QKeyEvent event = QKeyEvent{
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times};
QApplication::sendEvent(m_pSidebarWidget, &event);
}
void LibraryControl::slotSelectNextSidebarItem(double v) {
if (v > 0) {
slotSelectSidebarItem(1);
}
}
void LibraryControl::slotSelectPrevSidebarItem(double v) {
if (v > 0) {
slotSelectSidebarItem(-1);
}
}
void LibraryControl::slotToggleSelectedSidebarItem(double v) {
if (m_pSidebarWidget && v > 0) {
m_pSidebarWidget->toggleSelectedItem();
}
}
void LibraryControl::slotGoToItem(double v) {
if (v <= 0) {
return;
}
switch (m_pFocusedWidget) {
case FocusWidget::Sidebar:
// Focus the library if this is a leaf node in the tree
// Note that Tracks and AutoDJ always return 'false':
// expanding those root items via controllers is considered dispensable
// because the subfeatures' actions can't be accessed by controllers anyway.
if (m_pSidebarWidget->isLeafNodeSelected()) {
setLibraryFocus(FocusWidget::TracksTable);
} else {
// Otherwise toggle the sidebar item expanded state
m_pSidebarWidget->toggleSelectedItem();
}
return;
case FocusWidget::TracksTable:
return m_pLibraryWidget->getActiveView()->activateSelectedTrack();
case FocusWidget::Dialog: {
// press & release Space (QAbstractButton::clicked() is emitted on release)
QKeyEvent pressSpace = QKeyEvent{QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier};
QKeyEvent releaseSpace = QKeyEvent{QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier};
QApplication::sendEvent(QApplication::focusWindow(), &pressSpace);
QApplication::sendEvent(QApplication::focusWindow(), &releaseSpace);
return;
}
case FocusWidget::ContextMenu:
case FocusWidget::Unknown: {
// press Return to
// * expand submenus or select highlighted menu item
// * click Clear button in WSearcLineEdit (Note: even though this QToolButton
// inherits QAbstractButton, clicked is emitted on keypress if Return is used)
// * confirm and WBeatSpinBox and move focus to tracks table
// * ) and some more.
// If Unknown is some other 'untrained' or unresponsive widget
// GoToItem is inappropriate and we can't do much about that.
QKeyEvent event = QKeyEvent{QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier};
QApplication::sendEvent(QApplication::focusWindow(), &event);
return;
}
case FocusWidget::Searchbar:
case FocusWidget::None:
default:
return setLibraryFocus(FocusWidget::TracksTable);
}
}
void LibraryControl::slotSortColumn(double v) {
m_pSortColumnToggle->set(v);
}
void LibraryControl::slotSortColumnToggle(double v) {
int sortColumnId = static_cast<int>(v);
if (sortColumnId == static_cast<int>(TrackModel::SortColumnId::CurrentIndex)) {
if (!m_pLibraryWidget) {
return;
}
// Get the ID of the column with the cursor
sortColumnId =
static_cast<int>(m_pLibraryWidget->getActiveView()
->getColumnIdFromCurrentIndex());
}
if (static_cast<int>(m_pSortColumn->get()) == sortColumnId) {
m_pSortOrder->set((m_pSortOrder->get() == 0) ? 1.0 : 0.0);
} else {
m_pSortColumn->set(sortColumnId);
m_pSortOrder->set(0.0);
}
}
void LibraryControl::slotFontSize(double v) {
if (v == 0.0) {
return;
}
QFont font = m_pLibrary->getTrackTableFont();
font.setPointSizeF(font.pointSizeF() + v);
m_pLibrary->setFont(font);
}
void LibraryControl::slotIncrementFontSize(double v) {
if (v > 0.0) {
slotFontSize(1);
}
}
void LibraryControl::slotDecrementFontSize(double v) {
if (v > 0.0) {
slotFontSize(-1);
}
}
void LibraryControl::slotTrackColorPrev(double v) {
if (!m_pLibraryWidget) {
return;
}
if (v > 0) {
LibraryView* pActiveView = m_pLibraryWidget->getActiveView();
if (!pActiveView) {
return;
}
pActiveView->assignPreviousTrackColor();
}
}