Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/preferences enums #12798

Merged
merged 5 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/preferences/colorpalettesettings.cpp
src/preferences/colorpalettesettings.cpp
src/preferences/configobject.cpp
src/preferences/constants.cpp
src/preferences/dialog/dlgprefautodj.cpp
src/preferences/dialog/dlgprefautodjdlg.ui
src/preferences/dialog/dlgprefbeats.cpp
Expand Down
19 changes: 10 additions & 9 deletions src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "dialog/dlgdevelopertools.h"
#include "dialog/dlgkeywheel.h"
#include "moc_mixxxmainwindow.cpp"
#include "preferences/constants.h"
#include "preferences/dialog/dlgpreferences.h"
#ifdef __BROADCAST__
#include "broadcast/broadcastmanager.h"
Expand Down Expand Up @@ -100,7 +99,7 @@ MixxxMainWindow::MixxxMainWindow(std::shared_ptr<mixxx::CoreServices> pCoreServi
#endif
m_pDeveloperToolsDlg(nullptr),
m_pPrefDlg(nullptr),
m_toolTipsCfg(mixxx::TooltipsPreference::TOOLTIPS_ON) {
m_toolTipsCfg(mixxx::preferences::Tooltips::On) {
DEBUG_ASSERT(pCoreServices);
// These depend on the settings
#ifdef __LINUX__
Expand Down Expand Up @@ -176,9 +175,10 @@ void MixxxMainWindow::initialize() {
// Set the visibility of tooltips, default "1" = ON
m_toolTipsCfg = pConfig->getValue(
ConfigKey("[Controls]", "Tooltips"),
mixxx::TooltipsPreference::TOOLTIPS_ON);
mixxx::preferences::Tooltips::On);
#ifdef MIXXX_USE_QOPENGL
ToolTipQOpenGL::singleton().setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON);
ToolTipQOpenGL::singleton().setActive(
m_toolTipsCfg == mixxx::preferences::Tooltips::On);
#endif

#ifdef __ENGINEPRIME__
Expand Down Expand Up @@ -1153,10 +1153,11 @@ void MixxxMainWindow::slotShowKeywheel(bool toggle) {
}
}

void MixxxMainWindow::slotTooltipModeChanged(mixxx::TooltipsPreference tt) {
void MixxxMainWindow::slotTooltipModeChanged(mixxx::preferences::Tooltips tt) {
m_toolTipsCfg = tt;
#ifdef MIXXX_USE_QOPENGL
ToolTipQOpenGL::singleton().setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON);
ToolTipQOpenGL::singleton().setActive(
m_toolTipsCfg == mixxx::preferences::Tooltips::On);
#endif
}

Expand Down Expand Up @@ -1259,14 +1260,14 @@ bool MixxxMainWindow::eventFilter(QObject* obj, QEvent* event) {
"DlgPreferences") {
// return true for no tool tips
switch (m_toolTipsCfg) {
case mixxx::TooltipsPreference::TOOLTIPS_ONLY_IN_LIBRARY:
case mixxx::preferences::Tooltips::OnlyInLibrary:
if (dynamic_cast<WBaseWidget*>(obj) != nullptr) {
return true;
}
break;
case mixxx::TooltipsPreference::TOOLTIPS_ON:
case mixxx::preferences::Tooltips::On:
break;
case mixxx::TooltipsPreference::TOOLTIPS_OFF:
case mixxx::preferences::Tooltips::Off:
return true;
default:
DEBUG_ASSERT(!"m_toolTipsCfg value unknown");
Expand Down
10 changes: 5 additions & 5 deletions src/mixxxmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class MixxxMainWindow : public QMainWindow {
/// creates the menu_bar and inserts the file Menu
void createMenuBar();
void connectMenuBar();
void setInhibitScreensaver(mixxx::ScreenSaverPreference inhibit);
mixxx::ScreenSaverPreference getInhibitScreensaver();
void setInhibitScreensaver(mixxx::preferences::ScreenSaver inhibit);
mixxx::preferences::ScreenSaver getInhibitScreensaver();

inline GuiTick* getGuiTick() { return m_pGuiTick; };

Expand Down Expand Up @@ -87,7 +87,7 @@ class MixxxMainWindow : public QMainWindow {
void initializationProgressUpdate(int progress, const QString& serviceName);

private slots:
void slotTooltipModeChanged(mixxx::TooltipsPreference tt);
void slotTooltipModeChanged(mixxx::preferences::Tooltips tt);

signals:
void skinLoaded();
Expand Down Expand Up @@ -148,9 +148,9 @@ class MixxxMainWindow : public QMainWindow {
std::unique_ptr<mixxx::LibraryExporter> m_pLibraryExporter;
#endif

mixxx::TooltipsPreference m_toolTipsCfg;
mixxx::preferences::Tooltips m_toolTipsCfg;

mixxx::ScreenSaverPreference m_inhibitScreensaver;
mixxx::preferences::ScreenSaver m_inhibitScreensaver;

QSet<ControlObject*> m_skinCreatedControls;
};
4 changes: 4 additions & 0 deletions src/preferences/constants.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// just a stub so the MOC file can be included somewhere
#include "constants.h"

#include "moc_constants.cpp"
42 changes: 33 additions & 9 deletions src/preferences/constants.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,44 @@
#pragma once

// required for Qt-Macros
#include <qobjectdefs.h>

namespace mixxx {

namespace preferences {

inline namespace constants {
Q_NAMESPACE

// In order for this Q_NAMESPACE to work, all members of the namespace must
// be declared here. see QTBUG-68611

// Don't change these constants since they are stored in user configuration
// files.
enum class TooltipsPreference {
TOOLTIPS_OFF = 0,
TOOLTIPS_ON = 1,
TOOLTIPS_ONLY_IN_LIBRARY = 2,
enum class Tooltips {
Off = 0,
On = 1,
OnlyInLibrary = 2,
};
Q_ENUM_NS(Tooltips);

// Settings to enable or disable the prevention to run the screensaver.
enum class ScreenSaverPreference {
PREVENT_OFF = 0,
PREVENT_ON = 1,
PREVENT_ON_PLAY = 2
enum class ScreenSaver {
Off = 0,
On = 1,
OnPlay = 2
};
Q_ENUM_NS(ScreenSaver);

enum class MultiSamplingMode {
Disabled = 0,
Two = 2,
Four = 4,
Eight = 8,
Sixteen = 16
};
Q_ENUM_NS(MultiSamplingMode);

} // namespace mixxx
} // namespace constants
} // namespace preferences
} // namespace mixxx
2 changes: 1 addition & 1 deletion src/preferences/dialog/dlgpreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class DlgPreferences : public QDialog, public Ui::DlgPreferencesDlg {
void resetToDefaults();

void reloadUserInterface();
void tooltipModeChanged(mixxx::TooltipsPreference tooltipMode);
void tooltipModeChanged(mixxx::preferences::Tooltips tooltipMode);
void menuBarAutoHideChanged();

protected:
Expand Down
98 changes: 55 additions & 43 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include <QList>
#include <QLocale>
#include <QScreen>
#include <QVariant>
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved
#include <QtGlobal>

#include "control/controlobject.h"
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "moc_dlgprefinterface.cpp"
#include "preferences/constants.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be moved to preferences/dialog/dlgpreferencepage.h to include it only once

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and be removed from src/mixxxmainwindow.cpp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure about dlgpreferencepage.h? its not used in there anywhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the baseclass of all pref pages, would it increase the include 'load' including it there?
If so, just leave as it is.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, but its bad practice as well. It also wouldn't make any difference in terms of compilation time. In general its best to include what you use at the point of usage and nowhere else...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. it's already included in the header

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, so the cppcoreguidelines don't say much about that. If you insist, I'll remove the header from the .cpp.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please remove it. It'd be removed anyway with the next include cleanup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, this got a little mixed up, I was referring to the include in src/mixxxmainwindow.cpp.
Anyway, clean this up as much you like, I don't mind too much, just noticed it when looking for places where constants.h is included.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup sorry. I don't think anymore cleanup is needed now.

#include "preferences/usersettings.h"
#include "skin/legacy/legacyskinparser.h"
#include "skin/skin.h"
Expand Down Expand Up @@ -177,38 +179,47 @@ DlgPrefInterface::DlgPrefInterface(
// Screensaver mode
comboBoxScreensaver->clear();
comboBoxScreensaver->addItem(tr("Allow screensaver to run"),
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_OFF));
QVariant::fromValue(mixxx::preferences::ScreenSaver::Off));
comboBoxScreensaver->addItem(tr("Prevent screensaver from running"),
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON));
QVariant::fromValue((mixxx::preferences::ScreenSaver::On)));
comboBoxScreensaver->addItem(tr("Prevent screensaver while playing"),
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON_PLAY));
QVariant::fromValue(mixxx::preferences::ScreenSaver::OnPlay));

int inhibitsettings = static_cast<int>(m_pScreensaverManager->status());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
QVariant::fromValue(m_pScreensaverManager->status())));

// Multi-Sampling
#ifdef MIXXX_USE_QML
if (CmdlineArgs::Instance().isQml()) {
multiSamplingComboBox->clear();
multiSamplingComboBox->addItem(tr("Disabled"), 0);
multiSamplingComboBox->addItem(tr("2x MSAA"), 2);
multiSamplingComboBox->addItem(tr("4x MSAA"), 4);
multiSamplingComboBox->addItem(tr("8x MSAA"), 8);
multiSamplingComboBox->addItem(tr("16x MSAA"), 16);

m_multiSampling = m_pConfig->getValue(ConfigKey(kPreferencesGroup, kMultiSamplingKey), 4);
int multiSamplingIndex = multiSamplingComboBox->findData(m_multiSampling);
multiSamplingComboBox->addItem(tr("Disabled"),
QVariant::fromValue(mixxx::preferences::MultiSamplingMode::Disabled));
multiSamplingComboBox->addItem(tr("2x MSAA"),
QVariant::fromValue(mixxx::preferences::MultiSamplingMode::Two));
multiSamplingComboBox->addItem(tr("4x MSAA"),
QVariant::fromValue(mixxx::preferences::MultiSamplingMode::Four));
multiSamplingComboBox->addItem(tr("8x MSAA"),
QVariant::fromValue(mixxx::preferences::MultiSamplingMode::Eight));
multiSamplingComboBox->addItem(tr("16x MSAA"),
QVariant::fromValue(mixxx::preferences::MultiSamplingMode::Sixteen));

m_multiSampling = m_pConfig->getValue<mixxx::preferences::MultiSamplingMode>(
ConfigKey(kPreferencesGroup, kMultiSamplingKey),
mixxx::preferences::MultiSamplingMode::Four);
int multiSamplingIndex = multiSamplingComboBox->findData(
QVariant::fromValue((m_multiSampling)));
if (multiSamplingIndex != -1) {
multiSamplingComboBox->setCurrentIndex(multiSamplingIndex);
} else {
multiSamplingComboBox->setCurrentIndex(0);
m_pConfig->set(ConfigKey(kPreferencesGroup, kMultiSamplingKey), ConfigValue(0));
multiSamplingComboBox->setCurrentIndex(0); // Disabled
m_pConfig->setValue(ConfigKey(kPreferencesGroup, kMultiSamplingKey),
mixxx::preferences::MultiSamplingMode::Disabled);
}
} else
#endif
{
#ifdef MIXXX_USE_QML
m_multiSampling = 0;
m_multiSampling = mixxx::preferences::MultiSamplingMode::Disabled;
#endif
multiSamplingLabel->hide();
multiSamplingComboBox->hide();
Expand Down Expand Up @@ -313,8 +324,8 @@ void DlgPrefInterface::slotUpdate() {

loadTooltipPreferenceFromConfig();

int inhibitsettings = static_cast<int>(m_pScreensaverManager->status());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
QVariant::fromValue(m_pScreensaverManager->status())));
}

void DlgPrefInterface::slotResetToDefaults() {
Expand All @@ -341,10 +352,12 @@ void DlgPrefInterface::slotResetToDefaults() {

// Inhibit the screensaver
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON)));
QVariant::fromValue(mixxx::preferences::ScreenSaver::On)));

#ifdef MIXXX_USE_QML
multiSamplingComboBox->setCurrentIndex(4); // 4x MSAA
multiSamplingComboBox->setCurrentIndex(
multiSamplingComboBox->findData(QVariant::fromValue(
mixxx::preferences::MultiSamplingMode::Four))); // 4x MSAA
#endif

#ifdef Q_OS_IOS
Expand All @@ -357,11 +370,11 @@ void DlgPrefInterface::slotResetToDefaults() {
}

void DlgPrefInterface::slotSetTooltips() {
m_tooltipMode = mixxx::TooltipsPreference::TOOLTIPS_ON;
m_tooltipMode = mixxx::preferences::Tooltips::On;
if (radioButtonTooltipsOff->isChecked()) {
m_tooltipMode = mixxx::TooltipsPreference::TOOLTIPS_OFF;
m_tooltipMode = mixxx::preferences::Tooltips::Off;
} else if (radioButtonTooltipsLibrary->isChecked()) {
m_tooltipMode = mixxx::TooltipsPreference::TOOLTIPS_ONLY_IN_LIBRARY;
m_tooltipMode = mixxx::preferences::Tooltips::OnlyInLibrary;
}
}

Expand Down Expand Up @@ -445,8 +458,7 @@ void DlgPrefInterface::slotApply() {
m_pConfig->set(ConfigKey(kConfigGroup, kSchemeKey), m_colorScheme);
}

QString locale = ComboBoxLocale->itemData(
ComboBoxLocale->currentIndex()).toString();
QString locale = ComboBoxLocale->currentData().toString();
m_pConfig->set(ConfigKey(kConfigGroup, kLocaleKey), locale);

double scaleFactor = spinBoxScaleFactor->value() / 100;
Expand All @@ -459,24 +471,24 @@ void DlgPrefInterface::slotApply() {
ConfigValue(checkBoxHideMenuBar->isChecked()));
emit menuBarAutoHideChanged();

m_pConfig->set(ConfigKey(kControlsGroup, kTooltipsKey),
ConfigValue(static_cast<int>(m_tooltipMode)));
m_pConfig->setValue(ConfigKey(kControlsGroup, kTooltipsKey),
m_tooltipMode);
emit tooltipModeChanged(m_tooltipMode);

// screensaver mode update
int screensaverComboBoxState = comboBoxScreensaver->itemData(
comboBoxScreensaver->currentIndex()).toInt();
int screensaverConfiguredState = static_cast<int>(m_pScreensaverManager->status());
const auto screensaverComboBoxState =
comboBoxScreensaver->currentData().value<mixxx::preferences::ScreenSaver>();
const auto screensaverConfiguredState = m_pScreensaverManager->status();
if (screensaverComboBoxState != screensaverConfiguredState) {
m_pScreensaverManager->setStatus(
static_cast<mixxx::ScreenSaverPreference>(screensaverComboBoxState));
m_pScreensaverManager->setStatus(screensaverComboBoxState);
}

#ifdef MIXXX_USE_QML
int multiSampling = multiSamplingComboBox->itemData(
multiSamplingComboBox->currentIndex())
.toInt();
m_pConfig->set(ConfigKey(kPreferencesGroup, kMultiSamplingKey), ConfigValue(multiSampling));
mixxx::preferences::MultiSamplingMode multiSampling =
multiSamplingComboBox->currentData()
.value<mixxx::preferences::MultiSamplingMode>();
m_pConfig->setValue<mixxx::preferences::MultiSamplingMode>(
ConfigKey(kPreferencesGroup, kMultiSamplingKey), multiSampling);
#endif

if (locale != m_localeOnUpdate || scaleFactor != m_dScaleFactor
Expand Down Expand Up @@ -505,21 +517,21 @@ void DlgPrefInterface::slotApply() {
}

void DlgPrefInterface::loadTooltipPreferenceFromConfig() {
const auto tooltipMode = static_cast<mixxx::TooltipsPreference>(
m_pConfig->getValue(ConfigKey(kControlsGroup, kTooltipsKey),
const auto tooltipMode = m_pConfig->getValue<mixxx::preferences::Tooltips>(
ConfigKey(kControlsGroup, kTooltipsKey),
#ifdef Q_OS_IOS
static_cast<int>(mixxx::TooltipsPreference::TOOLTIPS_OFF)));
mixxx::preferences::Tooltips::Off);
#else
static_cast<int>(mixxx::TooltipsPreference::TOOLTIPS_ON)));
mixxx::preferences::Tooltips::On);
#endif
switch (tooltipMode) {
case mixxx::TooltipsPreference::TOOLTIPS_OFF:
case mixxx::preferences::Tooltips::Off:
radioButtonTooltipsOff->setChecked(true);
break;
case mixxx::TooltipsPreference::TOOLTIPS_ONLY_IN_LIBRARY:
case mixxx::preferences::Tooltips::OnlyInLibrary:
radioButtonTooltipsLibrary->setChecked(true);
break;
case mixxx::TooltipsPreference::TOOLTIPS_ON:
case mixxx::preferences::Tooltips::On:
default:
radioButtonTooltipsLibraryAndSkin->setChecked(true);
break;
Expand Down
8 changes: 4 additions & 4 deletions src/preferences/dialog/dlgprefinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DlgPrefInterface : public DlgPreferencePage, public Ui::DlgPrefControlsDlg
signals:
void reloadUserInterface();
void menuBarAutoHideChanged();
void tooltipModeChanged(mixxx::TooltipsPreference tooltipMode);
void tooltipModeChanged(mixxx::preferences::Tooltips tooltipMode);

private:
void notifyRebootNecessary();
Expand All @@ -69,10 +69,10 @@ class DlgPrefInterface : public DlgPreferencePage, public Ui::DlgPrefControlsDlg
QString m_colorScheme;
QString m_colorSchemeOnUpdate;
QString m_localeOnUpdate;
int m_multiSampling;
mixxx::TooltipsPreference m_tooltipMode;
mixxx::preferences::MultiSamplingMode m_multiSampling;
mixxx::preferences::Tooltips m_tooltipMode;
double m_dScaleFactor;
double m_minScaleFactor;
double m_dDevicePixelRatio;
mixxx::ScreenSaverPreference m_screensaverMode;
mixxx::preferences::ScreenSaver m_screensaverMode;
};
Loading