Skip to content

Commit

Permalink
fix: add multi-sampling settings for QML
Browse files Browse the repository at this point in the history
  • Loading branch information
acolombier committed Jan 11, 2024
1 parent 66f3f89 commit d204e9a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
5 changes: 3 additions & 2 deletions res/qml/Mixxx/Controls/Knob.qml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ Item {
// by enabling multisampling, so we use 4xMSAA here.
//
// See https://www.qt.io/blog/2017/07/07/let-there-be-shapes for details.
layer.enabled: true
layer.samples: 4
property int multiSamplingLevel: Mixxx.Config.getMultiSamplingLevel()
layer.enabled: multiSamplingLevel != 0
layer.samples: multiSamplingLevel

ShapePath {
id: arcPath
Expand Down
38 changes: 36 additions & 2 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ namespace {

const QString kConfigGroup = QStringLiteral("[Config]");
const QString kControlsGroup = QStringLiteral("[Controls]");
const QString kPreferencesGroup = QStringLiteral("[Preferences]");
const QString kScaleFactorKey = QStringLiteral("ScaleFactor");
const QString kStartInFullscreenKey = QStringLiteral("StartInFullscreen");
const QString kSchemeKey = QStringLiteral("Scheme");
const QString kResizableSkinKey = QStringLiteral("ResizableSkin");
const QString kLocaleKey = QStringLiteral("Locale");
const QString kTooltipsKey = QStringLiteral("Tooltips");
const QString kMultiSamplingKey = QStringLiteral("multi_sampling");

} // namespace

Expand Down Expand Up @@ -181,6 +183,31 @@ DlgPrefInterface::DlgPrefInterface(
int inhibitsettings = static_cast<int>(m_pScreensaverManager->status());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));

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

m_multiSampling = m_pConfig->getValue(ConfigKey(kPreferencesGroup, kMultiSamplingKey), 0);
int mulitSamplingIndex = mulitSamplingComboBox->findData(m_multiSampling);
if (mulitSamplingIndex != -1) {
mulitSamplingComboBox->setCurrentIndex(mulitSamplingIndex);
} else {
mulitSamplingComboBox->setCurrentIndex(0);
m_pConfig->set(ConfigKey(kPreferencesGroup, kMultiSamplingKey), ConfigValue(0));
}
} else
#endif
{
mulitSamplingLabel->hide();
mulitSamplingComboBox->hide();
}

// Tooltip configuration
connect(buttonGroupTooltips,
QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked),
Expand Down Expand Up @@ -319,7 +346,7 @@ void DlgPrefInterface::notifyRebootNecessary() {
// make the fact that you have to restart mixxx more obvious
QMessageBox::information(this,
tr("Information"),
tr("Mixxx must be restarted before the new locale or scaling "
tr("Mixxx must be restarted before the new locale, scaling or multi-sampling "
"settings will take effect."));
}

Expand Down Expand Up @@ -418,11 +445,18 @@ void DlgPrefInterface::slotApply() {
static_cast<mixxx::ScreenSaverPreference>(screensaverComboBoxState));
}

if (locale != m_localeOnUpdate || scaleFactor != m_dScaleFactor) {
int multiSampling = mulitSamplingComboBox->itemData(
mulitSamplingComboBox->currentIndex())
.toInt();
m_pConfig->set(ConfigKey(kPreferencesGroup, kMultiSamplingKey), ConfigValue(multiSampling));

if (locale != m_localeOnUpdate || scaleFactor != m_dScaleFactor ||
multiSampling != m_multiSampling) {
notifyRebootNecessary();
// hack to prevent showing the notification when pressing "Okay" after "Apply"
m_localeOnUpdate = locale;
m_dScaleFactor = scaleFactor;
m_multiSampling = multiSampling;
}

// load skin/scheme if necessary
Expand Down
1 change: 1 addition & 0 deletions src/preferences/dialog/dlgprefinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class DlgPrefInterface : public DlgPreferencePage, public Ui::DlgPrefControlsDlg
QString m_colorScheme;
QString m_colorSchemeOnUpdate;
QString m_localeOnUpdate;
int m_multiSampling;
mixxx::TooltipsPreference m_tooltipMode;
double m_dScaleFactor;
double m_minScaleFactor;
Expand Down
11 changes: 10 additions & 1 deletion src/preferences/dialog/dlgprefinterfacedlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,16 @@
<item row="4" column="1" colspan="2">
<widget class="QComboBox" name="comboBoxScreensaver"/>
</item>

<item row="5" column="0">
<widget class="QLabel" name="mulitSamplingLabel">
<property name="text">
<string>Multi-Sampling</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2">
<widget class="QComboBox" name="mulitSamplingComboBox"/>
</item>
</layout>
</widget>
</item>
Expand Down
9 changes: 9 additions & 0 deletions src/qml/qmlconfigproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ QVariantList paletteToQColorList(const ColorPalette& palette) {
}
return colors;
}

const QString kPreferencesGroup = QStringLiteral("[Preferences]");
const QString kMultiSamplingKey = QStringLiteral("multi_sampling");

} // namespace

namespace mixxx {
Expand All @@ -31,6 +35,11 @@ QVariantList QmlConfigProxy::getTrackColorPalette() {
return paletteToQColorList(colorPaletteSettings.getTrackColorPalette());
}

int QmlConfigProxy::getMultiSamplingLevel() {
ColorPaletteSettings colorPaletteSettings(m_pConfig);
return m_pConfig->getValue(ConfigKey(kPreferencesGroup, kMultiSamplingKey), 0);
}

// static
QmlConfigProxy* QmlConfigProxy::create(QQmlEngine* pQmlEngine, QJSEngine* pJsEngine) {
// The implementation of this method is mostly taken from the code example
Expand Down
3 changes: 3 additions & 0 deletions src/qml/qmlconfigproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ class QmlConfigProxy : public QObject {
UserSettingsPointer pConfig,
QObject* parent = nullptr);

// We use method here instead of properties as there is no way to achieve property binding
// with UserSettings, since there is no synchronisation upon mutations.
Q_INVOKABLE QVariantList getHotcueColorPalette();
Q_INVOKABLE QVariantList getTrackColorPalette();
Q_INVOKABLE int getMultiSamplingLevel();

static QmlConfigProxy* create(QQmlEngine* pQmlEngine, QJSEngine* pJsEngine);
static inline void registerUserSettings(UserSettingsPointer pConfig) {
Expand Down

0 comments on commit d204e9a

Please sign in to comment.