-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathlegacyskinparser.cpp
2498 lines (2158 loc) · 93.1 KB
/
legacyskinparser.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 "skin/legacy/legacyskinparser.h"
#include <QDir>
#include <QGridLayout>
#include <QLabel>
#include <QSplitter>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QtDebug>
#include <QtGlobal>
#include "control/controlobject.h"
#include "controllers/controllerlearningeventfilter.h"
#include "controllers/controllermanager.h"
#include "controllers/keyboard/keyboardeventfilter.h"
#include "library/basetracktablemodel.h"
#include "library/library.h"
#include "library/library_prefs.h"
#include "mixer/basetrackplayer.h"
#include "mixer/playermanager.h"
#include "moc_legacyskinparser.cpp"
#include "skin/legacy/colorschemeparser.h"
#include "skin/legacy/launchimage.h"
#include "skin/legacy/skincontext.h"
#include "track/track.h"
#include "util/cmdlineargs.h"
#include "util/timer.h"
#include "util/valuetransformer.h"
#include "util/xml.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "waveform/vsyncthread.h"
#endif
#include "waveform/waveformwidgetfactory.h"
#include "widget/controlwidgetconnection.h"
#include "widget/wbasewidget.h"
#include "widget/wbattery.h"
#include "widget/wbeatspinbox.h"
#include "widget/wcombobox.h"
#include "widget/wcoverart.h"
#include "widget/wdisplay.h"
#include "widget/weffectbuttonparametername.h"
#include "widget/weffectchain.h"
#include "widget/weffectchainpresetbutton.h"
#include "widget/weffectchainpresetselector.h"
#include "widget/weffectknobparametername.h"
#include "widget/weffectname.h"
#include "widget/weffectparameterknob.h"
#include "widget/weffectparameterknobcomposed.h"
#include "widget/weffectpushbutton.h"
#include "widget/weffectselector.h"
#include "widget/whotcuebutton.h"
#include "widget/wkey.h"
#include "widget/wknob.h"
#include "widget/wknobcomposed.h"
#include "widget/wlabel.h"
#include "widget/wlibrary.h"
#include "widget/wlibrarysidebar.h"
#include "widget/wnumber.h"
#include "widget/wnumberdb.h"
#include "widget/wnumberpos.h"
#include "widget/wnumberrate.h"
#include "widget/woverviewhsv.h"
#include "widget/woverviewlmh.h"
#include "widget/woverviewrgb.h"
#include "widget/wpixmapstore.h"
#include "widget/wpushbutton.h"
#include "widget/wraterange.h"
#include "widget/wrecordingduration.h"
#include "widget/wscrollable.h"
#include "widget/wsearchlineedit.h"
#include "widget/wsingletoncontainer.h"
#include "widget/wsizeawarestack.h"
#include "widget/wskincolor.h"
#include "widget/wslidercomposed.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "widget/wspinny.h"
#include "widget/wspinnyglsl.h"
#endif
#include "widget/wsplitter.h"
#include "widget/wstarrating.h"
#include "widget/wstatuslight.h"
#include "widget/wtime.h"
#include "widget/wtrackproperty.h"
#include "widget/wtrackwidgetgroup.h"
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include "widget/wvumeter.h"
#include "widget/wvumeterglsl.h"
#include "widget/wvumeterlegacy.h"
#endif
#include "widget/wwaveformviewer.h"
#include "widget/wwidget.h"
#include "widget/wwidgetgroup.h"
#include "widget/wwidgetstack.h"
using mixxx::skin::SkinManifest;
/// This QSet allows to make use of the implicit sharing
/// of QString instead of every widget keeping its own copy.
QSet<QString> LegacySkinParser::s_sharedGroupStrings;
static bool sDebug = false;
ControlObject* LegacySkinParser::controlFromConfigKey(
const ConfigKey& key, bool bPersist, bool* pCreated) {
if (!key.isValid()) {
return nullptr;
}
// Don't warn if the control doesn't exist. Skins use this to create
// controls.
ControlObject* pControl = ControlObject::getControl(key, ControlFlag::NoWarnIfMissing);
if (pControl) {
if (pCreated) {
*pCreated = false;
}
return pControl;
}
// TODO(rryan): Make this configurable by the skin.
if (CmdlineArgs::Instance().getDeveloper()) {
qInfo() << "Creating skin control object:"
<< QString("%1,%2").arg(key.group, key.item);
}
// Since the usual behavior here is to create a skin-defined push
// button, actually make it a push button and set it to toggle.
ControlPushButton* controlButton = new ControlPushButton(key, bPersist);
controlButton->setButtonMode(ControlPushButton::TOGGLE);
if (pCreated) {
*pCreated = true;
}
// If we created this control, add it to the set of skin-created
// controls, so that it can be deleted when the MixxxMainWindow is
// destroyed.
VERIFY_OR_DEBUG_ASSERT(m_pSkinCreatedControls) {
qWarning() << "Can't add skin-created control" << key << "to set, control will be leaked!";
return controlButton;
}
DEBUG_ASSERT(!m_pSkinCreatedControls->contains(controlButton));
m_pSkinCreatedControls->insert(controlButton);
return controlButton;
}
ControlObject* LegacySkinParser::controlFromConfigNode(const QDomElement& element,
const QString& nodeName,
bool* pCreated) {
QDomElement keyElement = m_pContext->selectElement(element, nodeName);
if (keyElement.isNull()) {
return nullptr;
}
QString name = m_pContext->nodeToString(keyElement);
ConfigKey key = ConfigKey::parseCommaSeparated(name);
bool bPersist = m_pContext->selectAttributeBool(keyElement, "persist", false);
return controlFromConfigKey(key, bPersist, pCreated);
}
LegacySkinParser::LegacySkinParser(UserSettingsPointer pConfig)
: m_pConfig(pConfig),
m_pSkinCreatedControls(nullptr),
m_pKeyboard(nullptr),
m_pPlayerManager(nullptr),
m_pControllerManager(nullptr),
m_pLibrary(nullptr),
m_pVCManager(nullptr),
m_pEffectsManager(nullptr),
m_pRecordingManager(nullptr),
m_pParent(nullptr) {
}
LegacySkinParser::LegacySkinParser(UserSettingsPointer pConfig,
QSet<ControlObject*>* pSkinCreatedControls,
KeyboardEventFilter* pKeyboard,
PlayerManager* pPlayerManager,
ControllerManager* pControllerManager,
Library* pLibrary,
VinylControlManager* pVCMan,
EffectsManager* pEffectsManager,
RecordingManager* pRecordingManager)
: m_pConfig(pConfig),
m_pSkinCreatedControls(pSkinCreatedControls),
m_pKeyboard(pKeyboard),
m_pPlayerManager(pPlayerManager),
m_pControllerManager(pControllerManager),
m_pLibrary(pLibrary),
m_pVCManager(pVCMan),
m_pEffectsManager(pEffectsManager),
m_pRecordingManager(pRecordingManager),
m_pParent(nullptr) {
DEBUG_ASSERT(m_pSkinCreatedControls);
}
LegacySkinParser::~LegacySkinParser() {
}
bool LegacySkinParser::canParse(const QString& skinPath) {
QDir skinDir(skinPath);
if (!skinDir.exists()) {
return false;
}
if (!skinDir.exists("skin.xml")) {
return false;
}
// TODO check skin.xml for compliance
return true;
}
// static
QDomElement LegacySkinParser::openSkin(const QString& skinPath) {
QDir skinDir(skinPath);
if (!skinDir.exists()) {
qDebug() << "LegacySkinParser::openSkin - skin dir do not exist:" << skinPath;
return QDomElement();
}
QString skinXmlPath = skinDir.filePath("skin.xml");
QFile skinXmlFile(skinXmlPath);
if (!skinXmlFile.open(QIODevice::ReadOnly)) {
qDebug() << "LegacySkinParser::openSkin - can't open file:" << skinXmlPath
<< "in directory:" << skinDir.path();
return QDomElement();
}
QDomDocument skin("skin");
QString errorMessage;
int errorLine;
int errorColumn;
if (!skin.setContent(&skinXmlFile,&errorMessage,&errorLine,&errorColumn)) {
qDebug() << "LegacySkinParser::openSkin - setContent failed see"
<< "line:" << errorLine << "column:" << errorColumn;
qDebug() << "LegacySkinParser::openSkin - message:" << errorMessage;
return QDomElement();
}
skinXmlFile.close();
return skin.documentElement();
}
// static
QList<QString> LegacySkinParser::getSchemeList(const QString& qSkinPath) {
QDomElement docElem = openSkin(qSkinPath);
QList<QString> schemeList;
QDomNode colScheme = docElem.namedItem("Schemes");
if (!colScheme.isNull() && colScheme.isElement()) {
QDomNode scheme = colScheme.firstChild();
while (!scheme.isNull()) {
if (scheme.isElement()) {
QString schemeName = XmlParse::selectNodeQString(scheme, "Name");
schemeList.append(schemeName);
}
scheme = scheme.nextSibling();
}
}
return schemeList;
}
// static
void LegacySkinParser::clearSharedGroupStrings() {
// This frees up the memory allocated by the QString objects
s_sharedGroupStrings.clear();
}
SkinManifest LegacySkinParser::getSkinManifest(const QDomElement& skinDocument) {
QDomNode manifest_node = skinDocument.namedItem("manifest");
SkinManifest manifest;
if (manifest_node.isNull() || !manifest_node.isElement()) {
return manifest;
}
manifest.set_title(XmlParse::selectNodeQString(manifest_node, "title").toStdString());
manifest.set_author(XmlParse::selectNodeQString(manifest_node, "author").toStdString());
manifest.set_version(XmlParse::selectNodeQString(manifest_node, "version").toStdString());
manifest.set_language(XmlParse::selectNodeQString(manifest_node, "language").toStdString());
manifest.set_description(XmlParse::selectNodeQString(manifest_node, "description").toStdString());
manifest.set_license(XmlParse::selectNodeQString(manifest_node, "license").toStdString());
QDomNode attributes_node = manifest_node.namedItem("attributes");
if (!attributes_node.isNull() && attributes_node.isElement()) {
QDomNodeList attribute_nodes = attributes_node.toElement().elementsByTagName("attribute");
for (int i = 0; i < attribute_nodes.count(); ++i) {
QDomNode attribute_node = attribute_nodes.item(i);
if (attribute_node.isElement()) {
QDomElement attribute_element = attribute_node.toElement();
QString configKey = attribute_element.attribute("config_key");
QString persist = attribute_element.attribute("persist");
QString value = attribute_element.text();
SkinManifest::Attribute* attr = manifest.add_attribute();
attr->set_config_key(configKey.toStdString());
attr->set_persist(persist.toLower() == "true");
attr->set_value(value.toStdString());
}
}
}
return manifest;
}
// static
Qt::MouseButton LegacySkinParser::parseButtonState(const QDomNode& node,
const SkinContext& context) {
QString buttonState;
if (context.hasNodeSelectString(node, "ButtonState", &buttonState)) {
if (buttonState.contains("LeftButton", Qt::CaseInsensitive)) {
return Qt::LeftButton;
} else if (buttonState.contains("RightButton", Qt::CaseInsensitive)) {
return Qt::RightButton;
}
}
return Qt::NoButton;
}
QWidget* LegacySkinParser::parseSkin(const QString& skinPath, QWidget* pParent) {
ScopedTimer timer("SkinLoader::parseSkin");
qDebug() << "LegacySkinParser loading skin:" << skinPath;
m_pContext = std::make_unique<SkinContext>(m_pConfig, skinPath + "/skin.xml");
m_pContext->setSkinBasePath(skinPath);
if (m_pParent) {
qDebug() << "ERROR: Somehow a parent already exists -- you are probably re-using a LegacySkinParser which is not advisable!";
}
QDomElement skinDocument = openSkin(skinPath);
if (skinDocument.isNull()) {
qDebug() << "LegacySkinParser::parseSkin - failed for skin:" << skinPath;
return nullptr;
}
SkinManifest manifest = getSkinManifest(skinDocument);
// Apply SkinManifest attributes by looping through the proto.
for (int i = 0; i < manifest.attribute_size(); ++i) {
const SkinManifest::Attribute& attribute = manifest.attribute(i);
if (!attribute.has_config_key()) {
continue;
}
bool ok = false;
double value = QString::fromStdString(attribute.value()).toDouble(&ok);
if (!ok) {
SKIN_WARNING(skinDocument,
*m_pContext,
QStringLiteral("Failed reading double value from skin attribute: %1")
.arg(QString::fromStdString(attribute.value())));
continue;
}
ConfigKey configKey = ConfigKey::parseCommaSeparated(
QString::fromStdString(attribute.config_key()));
// Set the specified attribute, possibly creating the control
// object in the process.
bool created = false;
// If there is no existing value for this CO in the skin,
// update the config with the specified value. If the attribute
// is set to persist, the value will be read when the control is created.
// TODO: This is a hack, but right now it's the cleanest way to
// get a CO with a specified initial value. We should have a better
// mechanism to provide initial default values for COs.
if (attribute.persist() &&
m_pConfig->getValueString(configKey).isEmpty()) {
m_pConfig->set(configKey, ConfigValue(QString::number(value)));
}
ControlObject* pControl = controlFromConfigKey(configKey,
attribute.persist(),
&created);
if (pControl == nullptr) {
continue;
}
if (created) {
if (!attribute.persist()) {
// Only set the value if the control wasn't set up through
// the persist logic. Skin attributes are always
// set on skin load.
pControl->set(value);
}
} else {
if (!attribute.persist()) {
// Set the value using the static function, so the
// value changes signal is transmitted to the owner.
ControlObject::set(configKey, value);
}
}
}
// This enables file paths like 'skins:Deere/some_template.xml',
// in addition to relative paths like 'skins:Deere/some_template.xml'
// Note: Here we assume this path exists. If it doesn't SkinLoader::getSkinSearchPaths()
// would have already triggered an error message.
// Note: we may also add the user skins path, in case there are custom skins
// that use the same template inheritance scheme like official skins, but we
// don't because unfortunately there is no reliable way to apply equivalent
// path replacement in stylesheetAbsIconPaths().
QString systemSkinsPath(m_pConfig->getResourcePath() + "skins/");
QDir::setSearchPaths("skins", QStringList{systemSkinsPath});
ColorSchemeParser::setupLegacyColorSchemes(skinDocument, m_pConfig, &m_style, m_pContext.get());
// don't parent till here so the first opengl waveform doesn't screw
// up --bkgood
// I'm disregarding this return value because I want to return the
// created parent so MixxxMainWindow can use it for various purposes
// (fullscreen mostly) --bkgood
m_pParent = pParent;
QList<QWidget*> widgets = parseNode(skinDocument);
if (widgets.empty()) {
SKIN_WARNING(skinDocument, *m_pContext, QStringLiteral("Skin produced no widgets!"));
return nullptr;
} else if (widgets.size() > 1) {
SKIN_WARNING(skinDocument,
*m_pContext,
QStringLiteral("Skin produced more than 1 widget!"));
}
return widgets[0];
}
LaunchImage* LegacySkinParser::parseLaunchImage(const QString& skinPath, QWidget* pParent) {
m_pContext = std::make_unique<SkinContext>(m_pConfig, skinPath + "/skin.xml");
m_pContext->setSkinBasePath(skinPath);
QDomElement skinDocument = openSkin(skinPath);
if (skinDocument.isNull()) {
return nullptr;
}
QString nodeName = skinDocument.nodeName();
if (nodeName != "skin") {
return nullptr;
}
// This allows image urls like
// url(skin:/style/mixxx-icon-logo-symbolic.svg);
QStringList skinPaths(skinPath);
QDir::setSearchPaths("skin", skinPaths);
QString styleSheet = parseLaunchImageStyle(skinDocument);
// Transform relative 'skin:' urls into absolute paths.
// See stylesheetAbsIconPaths() for details.
LaunchImage* pLaunchImage = new LaunchImage(pParent, stylesheetAbsIconPaths(styleSheet));
setupSize(skinDocument, pLaunchImage);
return pLaunchImage;
}
QList<QWidget*> wrapWidget(QWidget* pWidget) {
QList<QWidget*> result;
if (pWidget != nullptr) {
result.append(pWidget);
}
return result;
}
QList<QWidget*> LegacySkinParser::parseNode(const QDomElement& node) {
QList<QWidget*> result;
QString nodeName = node.nodeName();
//qDebug() << "parseNode" << node.nodeName();
// TODO(rryan) replace with a map to function pointers?
if (sDebug) {
qDebug() << "BEGIN PARSE NODE" << nodeName;
}
// Root of the document
if (nodeName == "skin") {
// Parent all the skin widgets to an inner QWidget (this was MixxxView
// in <=1.8, MixxxView was a subclass of QWidget), and then wrap it in
// an outer widget. The Background parser parents the background image
// to the inner widget but then sets the fill color of the outer widget
// so that fullscreen will expand with the right color to fill in the
// non-background areas. We put the inner widget in a layout inside the
// outer widget so that it stays centered in fullscreen mode.
// If the root widget has a layout we are loading a "new style" skin.
QString layout = m_pContext->selectString(node, "Layout");
bool newStyle = !layout.isEmpty();
qDebug() << "Skin is a" << (newStyle ? ">=1.12.0" : "<1.12.0") << "style skin.";
if (newStyle) {
// New style skins are just a WidgetGroup at the root.
result.append(parseWidgetGroup(node));
} else {
// From here on is loading for legacy skins only.
QWidget* pOuterWidget = new QWidget(m_pParent);
QWidget* pInnerWidget = new QWidget(pOuterWidget);
// <Background> is only valid for old-style skins.
QDomElement background = m_pContext->selectElement(node, "Background");
if (!background.isNull()) {
parseBackground(background, pOuterWidget, pInnerWidget);
}
// Interpret <Size>, <SizePolicy>, <Style>, etc. tags for the root node.
setupWidget(node, pInnerWidget, false);
m_pParent = pInnerWidget;
// Legacy skins do not use a <Children> block.
QDomNodeList children = node.childNodes();
for (int i = 0; i < children.count(); ++i) {
QDomNode node = children.at(i);
if (node.isElement()) {
parseNode(node.toElement());
}
}
// Keep innerWidget centered (for fullscreen).
pOuterWidget->setLayout(new QHBoxLayout(pOuterWidget));
pOuterWidget->layout()->setContentsMargins(0, 0, 0, 0);
pOuterWidget->layout()->addWidget(pInnerWidget);
result.append(pOuterWidget);
}
} else if (nodeName == "SliderComposed") {
result = wrapWidget(parseStandardWidget<WSliderComposed>(node));
} else if (nodeName == "PushButton") {
result = wrapWidget(parseStandardWidget<WPushButton>(node));
} else if (nodeName == "EffectPushButton") {
result = wrapWidget(parseEffectPushButton(node));
} else if (nodeName == "HotcueButton") {
result = wrapWidget(parseHotcueButton(node));
} else if (nodeName == "ComboBox") {
result = wrapWidget(parseStandardWidget<WComboBox>(node));
} else if (nodeName == "Overview") {
result = wrapWidget(parseOverview(node));
} else if (nodeName == "Visual") {
result = wrapWidget(parseVisual(node));
} else if (nodeName == "Text") {
result = wrapWidget(parseText(node));
} else if (nodeName == "TrackProperty") {
result = wrapWidget(parseTrackProperty(node));
} else if (nodeName == "StarRating") {
result = wrapWidget(parseStarRating(node));
} else if (nodeName == "VuMeter") {
result = wrapWidget(parseVuMeter(node));
} else if (nodeName == "StatusLight") {
result = wrapWidget(parseStandardWidget<WStatusLight>(node));
} else if (nodeName == "Display") {
result = wrapWidget(parseStandardWidget<WDisplay>(node));
} else if (nodeName == "BeatSpinBox") {
result = wrapWidget(parseBeatSpinBox(node));
} else if (nodeName == "NumberRate") {
result = wrapWidget(parseNumberRate(node));
} else if (nodeName == "RateRange") {
result = wrapWidget(parseRateRange(node));
} else if (nodeName == "NumberPos") {
result = wrapWidget(parseNumberPos(node));
} else if (nodeName == "Number" || nodeName == "NumberBpm") {
// NumberBpm is deprecated, and is now the same as a Number
result = wrapWidget(parseLabelWidget<WNumber>(node));
} else if (nodeName == "NumberDb") {
result = wrapWidget(parseLabelWidget<WNumberDb>(node));
} else if (nodeName == "Label") {
result = wrapWidget(parseLabelWidget<WLabel>(node));
} else if (nodeName == "Knob") {
result = wrapWidget(parseStandardWidget<WKnob>(node));
} else if (nodeName == "KnobComposed") {
result = wrapWidget(parseStandardWidget<WKnobComposed>(node));
} else if (nodeName == "TableView") {
result = wrapWidget(parseTableView(node));
} else if (nodeName == "CoverArt") {
result = wrapWidget(parseCoverArt(node));
} else if (nodeName == "SearchBox") {
result = wrapWidget(parseSearchBox(node));
} else if (nodeName == "WidgetGroup") {
result = wrapWidget(parseWidgetGroup(node));
} else if (nodeName == "TrackWidgetGroup") {
result = wrapWidget(parseTrackWidgetGroup(node));
} else if (nodeName == "WidgetStack") {
result = wrapWidget(parseWidgetStack(node));
} else if (nodeName == "SizeAwareStack") {
result = wrapWidget(parseSizeAwareStack(node));
} else if (nodeName == "EffectChainName") {
result = wrapWidget(parseEffectChainName(node));
} else if (nodeName == "EffectChainPresetButton") {
result = wrapWidget(parseEffectChainPresetButton(node));
} else if (nodeName == "EffectChainPresetSelector") {
result = wrapWidget(parseEffectChainPresetSelector(node));
} else if (nodeName == "EffectName") {
result = wrapWidget(parseEffectName(node));
} else if (nodeName == "EffectSelector") {
result = wrapWidget(parseEffectSelector(node));
} else if (nodeName == "EffectParameterKnob") {
result = wrapWidget(parseEffectParameterKnob(node));
} else if (nodeName == "EffectParameterKnobComposed") {
result = wrapWidget(parseEffectParameterKnobComposed(node));
} else if (nodeName == "EffectParameterName") {
result = wrapWidget(parseEffectParameterName(node));
} else if (nodeName == "EffectButtonParameterName") {
result = wrapWidget(parseEffectButtonParameterName(node));
} else if (nodeName == "Spinny") {
result = wrapWidget(parseSpinny(node));
} else if (nodeName == "Time") {
result = wrapWidget(parseLabelWidget<WTime>(node));
} else if (nodeName == "RecordingDuration") {
result = wrapWidget(parseRecordingDuration(node));
} else if (nodeName == "Splitter") {
result = wrapWidget(parseSplitter(node));
} else if (nodeName == "LibrarySidebar") {
result = wrapWidget(parseLibrarySidebar(node));
} else if (nodeName == "Library") {
result = wrapWidget(parseLibrary(node));
} else if (nodeName == "Key") {
result = wrapWidget(parseEngineKey(node));
} else if (nodeName == "Battery") {
result = wrapWidget(parseBattery(node));
} else if (nodeName == "SetVariable") {
m_pContext->updateVariable(node);
} else if (nodeName == "Scrollable") {
result = wrapWidget(parseScrollable(node));
} else if (nodeName == "Template") {
result = parseTemplate(node);
} else if (nodeName == "SingletonDefinition") {
parseSingletonDefinition(node);
} else if (nodeName == "SingletonContainer") {
result = wrapWidget(parseStandardWidget<WSingletonContainer>(node));
} else {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral("Invalid node name in skin: %1")
.arg(nodeName));
}
if (sDebug) {
qDebug() << "END PARSE NODE" << nodeName;
}
return result;
}
QWidget* LegacySkinParser::parseSplitter(const QDomElement& node) {
WSplitter* pSplitter = new WSplitter(m_pParent, m_pConfig);
commonWidgetSetup(node, pSplitter);
QDomNode childrenNode = m_pContext->selectNode(node, "Children");
QWidget* pOldParent = m_pParent;
m_pParent = pSplitter;
if (!childrenNode.isNull()) {
// Descend children
QDomNodeList children = childrenNode.childNodes();
for (int i = 0; i < children.count(); ++i) {
QDomNode node = children.at(i);
if (node.isElement()) {
QList<QWidget*> children = parseNode(node.toElement());
foreach (QWidget* pChild, children) {
if (pChild == nullptr) {
continue;
}
pSplitter->addWidget(pChild);
}
}
}
}
pSplitter->setup(node, *m_pContext);
pSplitter->Init();
m_pParent = pOldParent;
return pSplitter;
}
QWidget* LegacySkinParser::parseScrollable(const QDomElement& node) {
WScrollable* pScrollable = new WScrollable(m_pParent);
commonWidgetSetup(node, pScrollable);
QDomNode childrenNode = m_pContext->selectNode(node, "Children");
QWidget* pOldParent = m_pParent;
m_pParent = pScrollable;
if (!childrenNode.isNull()) {
QDomNodeList childNodes = childrenNode.childNodes();
if (childNodes.count() != 1) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral("Scrollables must have exactly one child"));
}
QDomNode childnode = childNodes.at(0);
if (childnode.isElement()) {
QList<QWidget*> children = parseNode(childnode.toElement());
if (children.count() != 1) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral(
"Scrollables must have exactly one child"));
} else if (children.at(0) != nullptr) {
pScrollable->setWidget(children.at(0));
}
}
}
pScrollable->setup(node, *m_pContext);
pScrollable->Init();
m_pParent = pOldParent;
return pScrollable;
}
void LegacySkinParser::parseChildren(
const QDomElement& node,
WWidgetGroup* pGroup) {
QDomNode childrenNode = m_pContext->selectNode(node, "Children");
QWidget* pOldParent = m_pParent;
m_pParent = pGroup;
if (!childrenNode.isNull()) {
// Descend children
QDomNodeList children = childrenNode.childNodes();
for (int i = 0; i < children.count(); ++i) {
QDomNode node = children.at(i);
if (node.isElement()) {
QList<QWidget*> children = parseNode(node.toElement());
foreach (QWidget* pChild, children) {
if (pChild == nullptr) {
continue;
}
pGroup->addWidget(pChild);
}
}
}
}
m_pParent = pOldParent;
}
QWidget* LegacySkinParser::parseWidgetGroup(const QDomElement& node) {
WWidgetGroup* pGroup = new WWidgetGroup(m_pParent);
setupBaseWidget(node, pGroup);
setupWidget(node, pGroup->toQWidget());
pGroup->setup(node, *m_pContext);
// Note: if we call setupConnections earlier and it sets the visible property
// to true, the style is not applied correctly
setupConnections(node, pGroup);
pGroup->Init();
parseChildren(node, pGroup);
return pGroup;
}
QWidget* LegacySkinParser::parseWidgetStack(const QDomElement& node) {
ControlObject* pNextControl = controlFromConfigNode(node.toElement(), "NextControl");
ConfigKey nextConfigKey;
if (pNextControl != nullptr) {
nextConfigKey = pNextControl->getKey();
}
ControlObject* pPrevControl = controlFromConfigNode(node.toElement(), "PrevControl");
ConfigKey prevConfigKey;
if (pPrevControl != nullptr) {
prevConfigKey = pPrevControl->getKey();
}
ControlObject* pCurrentPageControl = nullptr;
ConfigKey currentPageConfigKey;
QString currentpage_co = node.attribute("currentpage");
if (currentpage_co.length() > 0) {
ConfigKey configKey = ConfigKey::parseCommaSeparated(currentpage_co);
bool persist = m_pContext->selectAttributeBool(node, "persist", false);
pCurrentPageControl = controlFromConfigKey(configKey, persist);
if (pCurrentPageControl != nullptr) {
currentPageConfigKey = pCurrentPageControl->getKey();
}
}
WWidgetStack* pStack = new WWidgetStack(m_pParent, nextConfigKey,
prevConfigKey, currentPageConfigKey);
pStack->setObjectName("WidgetStack");
pStack->setContentsMargins(0, 0, 0, 0);
commonWidgetSetup(node, pStack);
QWidget* pOldParent = m_pParent;
m_pParent = pStack;
QDomNode childrenNode = m_pContext->selectNode(node, "Children");
if (!childrenNode.isNull()) {
// Descend children
QDomNodeList children = childrenNode.childNodes();
for (int i = 0; i < children.count(); ++i) {
QDomNode node = children.at(i);
if (!node.isElement()) {
continue;
}
QDomElement element = node.toElement();
QList<QWidget*> child_widgets = parseNode(element);
if (child_widgets.empty()) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral(
"WidgetStack child produced no widget."));
continue;
}
if (child_widgets.size() > 1) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral(
"WidgetStack child produced multiple widgets. "
"All but the first are ignored."));
}
QWidget* pChild = child_widgets[0];
if (pChild == nullptr) {
continue;
}
ControlObject* pControl = nullptr;
QString trigger_configkey = element.attribute("trigger");
if (trigger_configkey.length() > 0) {
ConfigKey configKey = ConfigKey::parseCommaSeparated(trigger_configkey);
pControl = controlFromConfigKey(configKey, false);
}
int on_hide_select = -1;
QString on_hide_attr = element.attribute("on_hide_select");
if (on_hide_attr.length() > 0) {
bool ok = false;
on_hide_select = on_hide_attr.toInt(&ok);
if (!ok) {
on_hide_select = -1;
}
}
pStack->addWidgetWithControl(pChild, pControl, on_hide_select);
}
}
// Init the widget last now that all the children have been created,
// so if the current page was saved we can switch to the correct page.
pStack->Init();
m_pParent = pOldParent;
return pStack;
}
QWidget* LegacySkinParser::parseSizeAwareStack(const QDomElement& node) {
WSizeAwareStack* pStack = new WSizeAwareStack(m_pParent);
pStack->setObjectName("SizeAwareStack");
pStack->setContentsMargins(0, 0, 0, 0);
commonWidgetSetup(node, pStack);
QWidget* pOldParent = m_pParent;
m_pParent = pStack;
QDomNode childrenNode = m_pContext->selectNode(node, "Children");
if (!childrenNode.isNull()) {
// Descend children
QDomNodeList children = childrenNode.childNodes();
for (int i = 0; i < children.count(); ++i) {
QDomNode node = children.at(i);
if (!node.isElement()) {
continue;
}
QDomElement element = node.toElement();
QList<QWidget*> children = parseNode(element);
if (children.empty()) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral(
"SizeAwareStack child produced no widget."));
continue;
}
if (children.size() > 1) {
SKIN_WARNING(node,
*m_pContext,
QStringLiteral(
"SizeAwareStack child produced multiple "
"widgets. All but the first are ignored."));
}
QWidget* pChild = children[0];
if (pChild == nullptr) {
continue;
}
pStack->addWidget(pChild);
}
}
m_pParent = pOldParent;
return pStack;
}
QWidget* LegacySkinParser::parseBackground(const QDomElement& node,
QWidget* pOuterWidget,
QWidget* pInnerWidget) {
QLabel* bg = new QLabel(pInnerWidget);
QString filename = m_pContext->selectString(node, "Path");
QPixmap* background = WPixmapStore::getPixmapNoCache(
m_pContext->makeSkinPath(filename), m_pContext->getScaleFactor());
bg->move(0, 0);
if (background != nullptr && !background->isNull()) {
bg->setPixmap(*background);
}
bg->lower();
pInnerWidget->move(0,0);
if (background != nullptr && !background->isNull()) {
pInnerWidget->setFixedSize(background->width(), background->height());
pOuterWidget->setMinimumSize(background->width(), background->height());
}
// Default background color is now black, if people want to do <invert/>
// filters they'll have to figure something out for this.
QColor c(0,0,0);
QString cStr;
if (m_pContext->hasNodeSelectString(node, "BgColor", &cStr)) {
c = QColor(cStr);
}
QPalette palette;
palette.setBrush(QPalette::Window, WSkinColor::getCorrectColor(c));
pOuterWidget->setBackgroundRole(QPalette::Window);
pOuterWidget->setPalette(palette);
pOuterWidget->setAutoFillBackground(true);
// WPixmapStore::getPixmapNoCache() allocated background and gave us
// ownership. QLabel::setPixmap makes a copy, so we have to delete this.
delete background;
return bg;
}
template<class T>
T* LegacySkinParser::parseStandardWidget(const QDomElement& element) {
T* pWidget = new T(m_pParent);
commonWidgetSetup(element, pWidget);
pWidget->setup(element, *m_pContext);
pWidget->installEventFilter(m_pKeyboard);
pWidget->installEventFilter(
m_pControllerManager->getControllerLearningEventFilter());
pWidget->Init();
return pWidget;
}
template <class T>
QWidget* LegacySkinParser::parseLabelWidget(const QDomElement& element) {
T* pLabel = new T(m_pParent);
setupLabelWidget(element, pLabel);
return pLabel;
}
void LegacySkinParser::setupLabelWidget(const QDomElement& element, WLabel* pLabel) {
// NOTE(rryan): To support color schemes, the WWidget::setup() call must
// come first. This is because WLabel derivatives change the palette based
// on the node and setupWidget() will set the widget style. If the style is
// set before the palette is set then the custom palette will not take
// effect which breaks color scheme support.
pLabel->setup(element, *m_pContext);
commonWidgetSetup(element, pLabel);
pLabel->installEventFilter(m_pKeyboard);
pLabel->installEventFilter(
m_pControllerManager->getControllerLearningEventFilter());
pLabel->Init();
}
QWidget* LegacySkinParser::parseOverview(const QDomElement& node) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
Q_UNUSED(node);
return nullptr;
#else
QString group = lookupNodeGroup(node);
BaseTrackPlayer* pPlayer = m_pPlayerManager->getPlayer(group);
if (!pPlayer) {
SKIN_WARNING(node, *m_pContext, QStringLiteral("No player found for group: %1").arg(group));
return nullptr;
}
WOverview* overviewWidget = nullptr;
// "RGB" = "2", "HSV" = "1" or "Filtered" = "0" (LMH) waveform overview type
int type = m_pConfig->getValue(ConfigKey("[Waveform]","WaveformOverviewType"), 2);
if (type == 0) {
overviewWidget = new WOverviewLMH(group, m_pPlayerManager, m_pConfig, m_pParent);
} else if (type == 1) {
overviewWidget = new WOverviewHSV(group, m_pPlayerManager, m_pConfig, m_pParent);
} else {
overviewWidget = new WOverviewRGB(group, m_pPlayerManager, m_pConfig, m_pParent);
}