Skip to content

Commit

Permalink
Preferences: update link color when stylesheet is applied
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 20, 2024
1 parent 2d3d230 commit 6834aa0
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 119 deletions.
15 changes: 12 additions & 3 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,18 @@ QString DlgPrefController::mappingFileLinks(
return linkList.join("<br/>");
}

void DlgPrefController::enumerateMappings() {
enumerateMappings(m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()));
void DlgPrefController::updateMappingIconsAndColoredLinkTexts() {
// re-enumerating mappings is the easiest way to update the list icons
enumerateMappings(mappingFilePathFromIndex(m_ui.comboBoxMapping->currentIndex()));

// Update the colored links
createLinkColor();
// Note: this will show the links of the LOADED mapping, so when applying
// a stylesheet while the selected mapping hasn't been loaded, yet, the
// links will be wrong.
std::shared_ptr<LegacyControllerMapping> pMapping = m_pController->cloneMapping();
m_ui.labelLoadedMappingSupportLinks->setText(mappingSupportLinks(pMapping));
m_ui.labelLoadedMappingScriptFileLinks->setText(mappingFileLinks(pMapping));
}

void DlgPrefController::enumerateMappings(const QString& selectedMappingPath) {
Expand Down
6 changes: 1 addition & 5 deletions src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ class DlgPrefController : public DlgPreferencePage {
QUrl helpUrl() const override;
void keyPressEvent(QKeyEvent* pEvent) override;

/// Reload the mappings in the dropdown dialog.
/// Convenience method to be called by DlgPrefControllers.
/// Used to rebuild the mappings list with dark/light icons
/// matching the current color palette.
void enumerateMappings();
void enumerateMappings(const QString& selectedMappingPath);
void updateMappingIconsAndColoredLinkTexts();

public slots:
/// Called when the preference dialog (not this page) is shown to the user.
Expand Down
85 changes: 46 additions & 39 deletions src/controllers/dlgprefcontrollers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
m_pNumSamplers(make_parented<ControlProxy>(
kAppGroup, QStringLiteral("num_samplers"), this)) {
setupUi(this);
// Create text color for the cue mode link "?" to the manual
createLinkColor();

setupControllerWidgets();

connect(btnOpenUserMappings, &QPushButton::clicked, this, [this]() {
Expand All @@ -44,41 +43,7 @@ DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
this,
&DlgPrefControllers::rescanControllers);

// Setting the description text here instead of in the ui file allows to paste
// a formatted link (text color is a more readable blend of text color and original link color).
txtMappingsOverview->setText(tr(
"Mixxx uses \"mappings\" to connect messages from your controller to "
"controls in Mixxx. If you do not see a mapping for your controller "
"in the \"Load Mapping\" menu when you click on your controller on the "
"left sidebar, you may be able to download one online from the %1. "
"Place the XML (.xml) and Javascript (.js) file(s) in the \"User Mapping "
"Folder\" then restart Mixxx. If you download a mapping in a ZIP file, "
"extract the XML and Javascript file(s) from the ZIP file to your "
"\"User Mapping Folder\" then restart Mixxx.")
.arg(coloredLinkString(
m_pLinkColor,
QStringLiteral("Mixxx Controller Forums"),
MIXXX_CONTROLLER_FORUMS_URL)));

txtHardwareCompatibility->setText(coloredLinkString(
m_pLinkColor,
tr("Mixxx DJ Hardware Guide"),
MIXXX_WIKI_HARDWARE_COMPATIBILITY_URL));

txtControllerForums->setText(coloredLinkString(
m_pLinkColor,
QStringLiteral("Mixxx Controller Forums"),
MIXXX_CONTROLLER_FORUMS_URL));

txtControllerMappingFormat->setText(coloredLinkString(
m_pLinkColor,
tr("MIDI Mapping File Format"),
MIXXX_WIKI_CONTROLLER_MAPPING_FORMAT_URL));

txtControllerScripting->setText(coloredLinkString(
m_pLinkColor,
tr("MIDI Scripting with Javascript"),
MIXXX_WIKI_MIDI_SCRIPTING_URL));
updateColoredLinkTexts();
}

DlgPrefControllers::~DlgPrefControllers() {
Expand Down Expand Up @@ -219,12 +184,54 @@ void DlgPrefControllers::setupControllerWidgets() {
}
}

void DlgPrefControllers::updateMappingIconsInControllerPages() {
void DlgPrefControllers::updateMappingIconsAndColoredLinkTexts() {
updateColoredLinkTexts();

for (auto page : std::as_const(m_controllerPages)) {
page->enumerateMappings();
page->updateMappingIconsAndColoredLinkTexts();
}
}

void DlgPrefControllers::updateColoredLinkTexts() {
// Setting the description text here instead of in the ui file allows to paste
// a formatted link (text color is a more readable blend of text color and original link color).

createLinkColor();
txtMappingsOverview->setText(tr(
"Mixxx uses \"mappings\" to connect messages from your controller to "
"controls in Mixxx. If you do not see a mapping for your controller "
"in the \"Load Mapping\" menu when you click on your controller on the "
"left sidebar, you may be able to download one online from the %1. "
"Place the XML (.xml) and Javascript (.js) file(s) in the \"User Mapping "
"Folder\" then restart Mixxx. If you download a mapping in a ZIP file, "
"extract the XML and Javascript file(s) from the ZIP file to your "
"\"User Mapping Folder\" then restart Mixxx.")
.arg(coloredLinkString(
m_pLinkColor,
QStringLiteral("Mixxx Controller Forums"),
MIXXX_CONTROLLER_FORUMS_URL)));

txtHardwareCompatibility->setText(coloredLinkString(
m_pLinkColor,
tr("Mixxx DJ Hardware Guide"),
MIXXX_WIKI_HARDWARE_COMPATIBILITY_URL));

txtControllerForums->setText(coloredLinkString(
m_pLinkColor,
QStringLiteral("Mixxx Controller Forums"),
MIXXX_CONTROLLER_FORUMS_URL));

txtControllerMappingFormat->setText(coloredLinkString(
m_pLinkColor,
tr("MIDI Mapping File Format"),
MIXXX_WIKI_CONTROLLER_MAPPING_FORMAT_URL));

txtControllerScripting->setText(coloredLinkString(
m_pLinkColor,
tr("MIDI Scripting with Javascript"),
MIXXX_WIKI_MIDI_SCRIPTING_URL));
}

void DlgPrefControllers::slotHighlightDevice(DlgPrefController* pControllerDlg, bool enabled) {
int controllerPageIndex = m_controllerPages.indexOf(pControllerDlg);
if (controllerPageIndex < 0) {
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/dlgprefcontrollers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class DlgPrefControllers : public DlgPreferencePage, public Ui::DlgPrefControlle
bool handleTreeItemClick(QTreeWidgetItem* clickedItem);
QUrl helpUrl() const override;

/// Calls slotUpdate() of each controller page to update the mapping icons
void updateMappingIconsInControllerPages();
void updateMappingIconsAndColoredLinkTexts();
void updateColoredLinkTexts() override;

public slots:
/// Called when the preference dialog (not this page) is shown to the user.
Expand Down
42 changes: 25 additions & 17 deletions src/preferences/dialog/dlgprefdeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ DlgPrefDeck::DlgPrefDeck(QWidget* parent, UserSettingsPointer pConfig)
m_iNumConfiguredDecks(0),
m_iNumConfiguredSamplers(0) {
setupUi(this);
// Create text color for the cue mode link "?" to the manual
createLinkColor();

m_pNumDecks->connectValueChanged(this, [=, this](double value) { slotNumDecksChanged(value); });
slotNumDecksChanged(m_pNumDecks->get(), true);
Expand Down Expand Up @@ -291,21 +289,11 @@ DlgPrefDeck::DlgPrefDeck(QWidget* parent, UserSettingsPointer pConfig)
pControl->set(static_cast<int>(m_keyunlockMode));
}

// Cue Mode
// Add "(?)" with a manual link to the label
labelCueMode->setText(labelCueMode->text() + QChar(' ') +
coloredLinkString(
m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_CUE_MODES_URL));

// Sync Mode
// Add "(?)" with a manual link to the label
labelSyncMode->setText(labelSyncMode->text() + QChar(' ') +
coloredLinkString(
m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_SYNC_MODES_URL));
// Store translated label texts
labelCueMode->setProperty(kOriginalText, labelCueMode->text());
labelSyncMode->setProperty(kOriginalText, labelSyncMode->text());
// Create text color manual links
updateColoredLinkTexts();

// Speed / Pitch reset configuration
// Update "reset speed" and "reset pitch" check boxes
Expand Down Expand Up @@ -506,6 +494,26 @@ void DlgPrefDeck::slotUpdate() {
spinBoxPermanentRateFine->setValue(RateControl::getPermanentRateChangeFineAmount());
}

void DlgPrefDeck::updateColoredLinkTexts() {
createLinkColor();
// Cue Mode
// Add "(?)" with a manual link to the label
labelCueMode->setText(
labelCueMode->property(kOriginalText).toString() + QChar(' ') +
coloredLinkString(
m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_CUE_MODES_URL));
// Sync Mode
// Add "(?)" with a manual link to the label
labelSyncMode->setText(
labelSyncMode->property(kOriginalText).toString() + QChar(' ') +
coloredLinkString(
m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_SYNC_MODES_URL));
}

void DlgPrefDeck::slotResetToDefaults() {
// Track time display mode
radioButtonRemaining->setChecked(true);
Expand Down
2 changes: 2 additions & 0 deletions src/preferences/dialog/dlgprefdeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class DlgPrefDeck : public DlgPreferencePage, public Ui::DlgPrefDeckDlg {
void slotUpdateSpeedAutoReset(bool);
void slotUpdatePitchAutoReset(bool);

void updateColoredLinkTexts() override;

private:
// Because the CueDefault list is out of order, we have to set the combo
// box using the user data, not the index. Returns the index of the item
Expand Down
6 changes: 6 additions & 0 deletions src/preferences/dialog/dlgpreferencepage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QDebug>
#include <QString>
#include <QUrl>
#include <QWidget>
Expand Down Expand Up @@ -38,6 +39,8 @@ class DlgPreferencePage : public QWidget {

QColor m_pLinkColor;

const char* kOriginalText = "originalText";

public slots:
/// Called when the preference dialog is shown to the user (not necessarily
/// when this PreferencePage is shown to the user). At this point, the
Expand Down Expand Up @@ -81,4 +84,7 @@ class DlgPreferencePage : public QWidget {
palette().text().color())
.name();
}

virtual void updateColoredLinkTexts() {
}
};
7 changes: 4 additions & 3 deletions src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ bool DlgPreferences::eventFilter(QObject* o, QEvent* e) {
if (e->type() == QEvent::StyleChange) {
// The stylesheet has been changed or reloaded,
// update the tree icons to match the new palette.
updateTreeIcons();
updateTreeIconsAndColoredLinks();
}

// Standard event processing
Expand Down Expand Up @@ -482,13 +482,14 @@ void DlgPreferences::addPageWidget(const PreferencesPage& page) {
page.pDlg->sizeHint() + QSize(iframe, iframe));
}

void DlgPreferences::updateTreeIcons() {
void DlgPreferences::updateTreeIconsAndColoredLinks() {
selectIconsPath();
for (const auto& page : std::as_const(m_allPages)) {
page.pTreeItem->setIcon(0, QIcon(m_iconsPath.filePath(page.iconFileName)));
page.pDlg->updateColoredLinkTexts();
}
// Update icons in controller mapping list
m_pControllersDlg->updateMappingIconsInControllerPages();
m_pControllersDlg->updateMappingIconsAndColoredLinkTexts();
}

void DlgPreferences::selectIconsPath() {
Expand Down
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class DlgPreferences : public QDialog, public Ui::DlgPreferencesDlg {
QList<PreferencesPage> m_allPages;
void onShow();
void onHide();
void updateTreeIcons();
void updateTreeIconsAndColoredLinks();
void selectIconsPath();
QRect getDefaultGeometry();

Expand Down
35 changes: 22 additions & 13 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,19 @@ DlgPrefLibrary::DlgPrefLibrary(
#endif
builtInFormats->setText(builtInFormatsStr);

// Store translated label texts
label_settingsManualLink->setProperty(kOriginalText, tr("See the manual for details"));
label_searchBpmFuzzyRangeInfo->setProperty(
kOriginalText, label_searchBpmFuzzyRangeInfo->text());
// Create text color manual links
createLinkColor();
// Add link to the manual where configuration files are explained in detail
label_settingsManualLink->setText(coloredLinkString(
m_pLinkColor,
tr("See the manual for details"),
MIXXX_MANUAL_SETTINGS_DIRECTORY_URL));
updateColoredLinkTexts();

// TODO It seems this isnot required anymore with Qt 6.2.3
connect(label_settingsManualLink,
&QLabel::linkActivated,
[](const QString& url) {
mixxx::DesktopHelper::openUrl(url);
});

// Add link to the track search documentation
label_searchBpmFuzzyRangeInfo->setText(
label_searchBpmFuzzyRangeInfo->text() + QStringLiteral(" ") +
coloredLinkString(m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_SETTINGS_DIRECTORY_URL));
connect(label_searchBpmFuzzyRangeInfo,
&QLabel::linkActivated,
[](const QString& url) {
Expand Down Expand Up @@ -388,6 +381,22 @@ void DlgPrefLibrary::slotUpdate() {
checkbox_played_track_color->setChecked(applyPlayedTrackColor);
}

void DlgPrefLibrary::updateColoredLinkTexts() {
createLinkColor();
// Add link to the manual where configuration files are explained in detail
label_settingsManualLink->setText(coloredLinkString(
m_pLinkColor,
label_settingsManualLink->property(kOriginalText).toString(),
MIXXX_MANUAL_SETTINGS_DIRECTORY_URL));
// Add link to the track search documentation
label_searchBpmFuzzyRangeInfo->setText(
label_searchBpmFuzzyRangeInfo->property(kOriginalText).toString() +
QStringLiteral(" ") +
coloredLinkString(m_pLinkColor,
QStringLiteral("(?)"),
MIXXX_MANUAL_SETTINGS_DIRECTORY_URL));
}

void DlgPrefLibrary::slotCancel() {
// Undo any changes in the library font or row height.
m_pLibrary->setFont(m_originalTrackTableFont);
Expand Down
2 changes: 2 additions & 0 deletions src/preferences/dialog/dlgpreflibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class DlgPrefLibrary : public DlgPreferencePage, public Ui::DlgPrefLibraryDlg {

QUrl helpUrl() const override;

void updateColoredLinkTexts() override;

public slots:
// Common preference page slots.
void slotUpdate() override;
Expand Down
22 changes: 13 additions & 9 deletions src/preferences/dialog/dlgprefmodplug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ DlgPrefModplug::DlgPrefModplug(QWidget *parent,
m_pUi(new Ui::DlgPrefModplug),
m_pConfig(_config) {
m_pUi->setupUi(this);
// Create text color for the OpenMTP manual link
createLinkColor();
m_pUi->advancedSettings->setVisible(m_pUi->showAdvanced->isChecked());

connect(m_pUi->memoryLimit,
Expand All @@ -31,13 +29,7 @@ DlgPrefModplug::DlgPrefModplug(QWidget *parent,
m_pUi->advancedSettings,
&QWidget::setVisible);

m_pUi->modplugSettingsHint->setText(
tr("All settings take effect on next track load. Currently loaded tracks "
"are not affected. For an explanation of these settings, see the %1")
.arg(coloredLinkString(
m_pLinkColor,
"OpenMPT manual",
"http://wiki.openmpt.org/Manual:_Setup/Player")));
updateColoredLinkTexts();

setScrollSafeGuardForAllInputWidgets(this);
}
Expand Down Expand Up @@ -211,3 +203,15 @@ void DlgPrefModplug::applySettings() {
// apply modplug settings
mixxx::SoundSourceModPlug::configure(bufferSizeLimit, settings);
}

void DlgPrefModplug::updateColoredLinkTexts() {
createLinkColor();

m_pUi->modplugSettingsHint->setText(
tr("All settings take effect on next track load. Currently loaded tracks "
"are not affected. For an explanation of these settings, see the %1")
.arg(coloredLinkString(
m_pLinkColor,
"OpenMPT manual",
"http://wiki.openmpt.org/Manual:_Setup/Player")));
}
Loading

0 comments on commit 6834aa0

Please sign in to comment.