Skip to content

Commit

Permalink
WIP expose preferences window to QML
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Sep 28, 2021
1 parent ca16b93 commit 4900acf
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 64 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/qml/qmlapplication.cpp
src/qml/qmlcontrolproxy.cpp
src/qml/qmlconfigproxy.cpp
src/qml/qmldlgpreferencesproxy.cpp
src/qml/qmleffectmanifestparametersmodel.cpp
src/qml/qmleffectsmanagerproxy.cpp
src/qml/qmleffectslotproxy.cpp
Expand Down Expand Up @@ -1235,6 +1236,8 @@ endif()

# The mixxx executable
add_executable(mixxx WIN32 src/main.cpp)
# FIXME: ugly hack to get #include "preferences/dialog/dlgpreferencs.h" in src/qmlapplication.h to work.
target_include_directories(mixxx PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/mixxx-lib_autogen/include")
set_target_properties(mixxx-lib PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY}")
target_link_libraries(mixxx PRIVATE mixxx-lib mixxx-gitinfostore)

Expand Down
12 changes: 12 additions & 0 deletions res/qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "." as Skin
import Mixxx 0.1 as Mixxx
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.11
Expand Down Expand Up @@ -64,6 +65,17 @@ ApplicationWindow {
checkable: true
}

Skin.Button {
id: showPreferencesButton

text: "Prefs"
activeColor: Theme.white
checkable: true
onClicked: {
Mixxx.PreferencesDialog.show();
}
}

}

}
Expand Down
25 changes: 14 additions & 11 deletions src/preferences/dialog/dlgpreferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,20 @@ DlgPreferences::DlgPreferences(
tr("Interface"),
"ic_preferences_interface.svg");

DlgPrefWaveform* pWaveformPage = new DlgPrefWaveform(this, m_pConfig, pLibrary);
addPageWidget(PreferencesPage(
pWaveformPage,
new QTreeWidgetItem(contentsTreeWidget, QTreeWidgetItem::Type)),
tr("Waveforms"),
"ic_preferences_waveforms.svg");
connect(pWaveformPage,
&DlgPrefWaveform::reloadUserInterface,
this,
&DlgPreferences::reloadUserInterface,
Qt::DirectConnection);
// ugly proxy for determining whether this is being instatiated for QML or legacy QWidgets GUI
if (pSkinLoader) {
DlgPrefWaveform* pWaveformPage = new DlgPrefWaveform(this, m_pConfig, pLibrary);
addPageWidget(PreferencesPage(
pWaveformPage,
new QTreeWidgetItem(contentsTreeWidget, QTreeWidgetItem::Type)),
tr("Waveforms"),
"ic_preferences_waveforms.svg");
connect(pWaveformPage,
&DlgPrefWaveform::reloadUserInterface,
this,
&DlgPreferences::reloadUserInterface,
Qt::DirectConnection);
}

addPageWidget(PreferencesPage(
new DlgPrefColors(this, m_pConfig, pLibrary),
Expand Down
116 changes: 67 additions & 49 deletions src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ DlgPrefInterface::DlgPrefInterface(
m_pConfig(pConfig),
m_pScreensaverManager(pScreensaverManager),
m_pSkinLoader(pSkinLoader),
m_pSkin(pSkinLoader->getConfiguredSkin()),
m_pSkin(pSkinLoader ? pSkinLoader->getConfiguredSkin() : nullptr),
m_dScaleFactor(1.0),
m_minScaleFactor(1.0),
m_dDevicePixelRatio(1.0),
Expand All @@ -67,11 +67,6 @@ DlgPrefInterface::DlgPrefInterface(
double unscaledDevicePixelRatio = m_dDevicePixelRatio / initialScaleFactor;
m_minScaleFactor = 1 / unscaledDevicePixelRatio;

VERIFY_OR_DEBUG_ASSERT(m_pSkin != nullptr) {
qWarning() << "Skipping creation of DlgPrefInterface because there is no skin available.";
return;
}

// Locale setting
// Iterate through the available locales and add them to the combobox
// Borrowed following snippet from http://qt-project.org/wiki/How_to_create_a_multi_language_application
Expand Down Expand Up @@ -126,50 +121,55 @@ DlgPrefInterface::DlgPrefInterface(
// ...and then insert entry for default system locale at the top
ComboBoxLocale->insertItem(0, QStringLiteral("System"), "");

// Skin configurations
QString sizeWarningString =
"<img src=\":/images/preferences/ic_preferences_warning.svg\") "
"width=16 height=16 /> " +
tr("The minimum size of the selected skin is bigger than your "
"screen resolution.");
warningLabel->setText(sizeWarningString);

ComboBoxSkinconf->clear();
// align left edge of preview image and skin description with comboboxes
skinPreviewLabel->setStyleSheet("QLabel { margin-left: 4px; }");
skinPreviewLabel->setText("");
skinDescriptionText->setStyleSheet("QLabel { margin-left: 2px; }");
skinDescriptionText->setText("");
skinDescriptionText->hide();

const QList<SkinPointer> skins = m_pSkinLoader->getSkins();
int index = 0;
for (const SkinPointer& pSkin : skins) {
ComboBoxSkinconf->insertItem(index, pSkin->name());
m_skins.insert(pSkin->name(), pSkin);
index++;
}
if (pSkinLoader) {
// Skin configurations
QString sizeWarningString =
"<img src=\":/images/preferences/ic_preferences_warning.svg\") "
"width=16 height=16 /> " +
tr("The minimum size of the selected skin is bigger than your "
"screen resolution.");
warningLabel->setText(sizeWarningString);

ComboBoxSkinconf->clear();
// align left edge of preview image and skin description with comboboxes
skinPreviewLabel->setStyleSheet("QLabel { margin-left: 4px; }");
skinPreviewLabel->setText("");
skinDescriptionText->setStyleSheet("QLabel { margin-left: 2px; }");
skinDescriptionText->setText("");
skinDescriptionText->hide();

ComboBoxSkinconf->setCurrentIndex(index);
// schemes must be updated here to populate the drop-down box and set m_colorScheme
slotUpdateSchemes();
slotSetSkinPreview();
const auto* const pScreen = getScreen();
if (m_pSkin->fitsScreenSize(*pScreen)) {
warningLabel->hide();
const QList<SkinPointer> skins = m_pSkinLoader->getSkins();
int index = 0;
for (const SkinPointer& pSkin : skins) {
ComboBoxSkinconf->insertItem(index, pSkin->name());
m_skins.insert(pSkin->name(), pSkin);
index++;
}

ComboBoxSkinconf->setCurrentIndex(index);
// schemes must be updated here to populate the drop-down box and set m_colorScheme
slotUpdateSchemes();
slotSetSkinPreview();
const auto* const pScreen = getScreen();
if (m_pSkin->fitsScreenSize(*pScreen)) {
warningLabel->hide();
} else {
warningLabel->show();
}
slotSetSkinDescription();

connect(ComboBoxSkinconf,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefInterface::slotSetSkin);
connect(ComboBoxSchemeconf,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefInterface::slotSetScheme);
} else {
warningLabel->show();
ComboBoxSkinconf->hide();
ComboBoxSchemeconf->hide();
}
slotSetSkinDescription();

connect(ComboBoxSkinconf,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefInterface::slotSetSkin);
connect(ComboBoxSchemeconf,
QOverload<int>::of(&QComboBox::currentIndexChanged),
this,
&DlgPrefInterface::slotSetScheme);

// Start in fullscreen mode
checkBoxStartFullScreen->setChecked(
Expand Down Expand Up @@ -215,6 +215,10 @@ QScreen* DlgPrefInterface::getScreen() const {
}

void DlgPrefInterface::slotUpdateSchemes() {
if (!m_pSkinLoader) {
return;
}

// Re-populates the scheme combobox and attempts to pick the color scheme from config file.
// Since this involves opening a file we won't do this as part of regular slotUpdate
const QList<QString> schlist = m_pSkin->colorschemes();
Expand Down Expand Up @@ -339,6 +343,10 @@ void DlgPrefInterface::slotSetScheme(int) {
}

void DlgPrefInterface::slotSetSkinDescription() {
if (!m_pSkinLoader) {
return;
}

const QString description = m_pSkin->description();
if (!description.isEmpty()) {
skinDescriptionText->show();
Expand All @@ -349,6 +357,10 @@ void DlgPrefInterface::slotSetSkinDescription() {
}

void DlgPrefInterface::slotSetSkinPreview() {
if (!m_pSkinLoader) {
return;
}

QPixmap preview = m_pSkin->preview(m_colorScheme);
preview.setDevicePixelRatio(m_dDevicePixelRatio);
skinPreviewLabel->setPixmap(preview.scaled(
Expand All @@ -358,6 +370,10 @@ void DlgPrefInterface::slotSetSkinPreview() {
}

void DlgPrefInterface::slotSetSkin(int) {
if (!m_pSkinLoader) {
return;
}

QString newSkinName = ComboBoxSkinconf->currentText();
if (newSkinName == m_pSkin->name()) {
return;
Expand All @@ -381,8 +397,10 @@ void DlgPrefInterface::slotSetSkin(int) {
}

void DlgPrefInterface::slotApply() {
m_pConfig->set(ConfigKey(kConfigGroup, kResizableSkinKey), m_pSkin->name());
m_pConfig->set(ConfigKey(kConfigGroup, kSchemeKey), m_colorScheme);
if (m_pSkinLoader) {
m_pConfig->set(ConfigKey(kConfigGroup, kResizableSkinKey), m_pSkin->name());
m_pConfig->set(ConfigKey(kConfigGroup, kSchemeKey), m_colorScheme);
}

QString locale = ComboBoxLocale->itemData(
ComboBoxLocale->currentIndex()).toString();
Expand Down
33 changes: 31 additions & 2 deletions src/qml/qmlapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "qml/asyncimageprovider.h"
#include "qml/qmlconfigproxy.h"
#include "qml/qmlcontrolproxy.h"
#include "qml/qmldlgpreferencesproxy.h"
#include "qml/qmleffectmanifestparametersmodel.h"
#include "qml/qmleffectslotproxy.h"
#include "qml/qmleffectsmanagerproxy.h"
Expand Down Expand Up @@ -46,8 +47,17 @@ QmlApplication::QmlApplication(
exit(result);
}

qmlRegisterType<QmlControlProxy>("Mixxx", 0, 1, "ControlProxy");
qmlRegisterType<QmlWaveformOverview>("Mixxx", 0, 1, "WaveformOverview");
m_pDlgPreferences = std::make_shared<DlgPreferences>(
m_pCoreServices->getScreensaverManager(),
nullptr,
m_pCoreServices->getSoundManager(),
m_pCoreServices->getPlayerManager(),
m_pCoreServices->getControllerManager(),
m_pCoreServices->getVinylControlManager(),
m_pCoreServices->getLV2Backend(),
m_pCoreServices->getEffectsManager(),
m_pCoreServices->getSettingsManager(),
m_pCoreServices->getLibrary());

// Any uncreateable non-singleton types registered here require arguments
// that we don't want to expose to QML directly. Instead, they can be
Expand All @@ -58,6 +68,25 @@ QmlApplication::QmlApplication(
// singletons to that they can be accessed by components instantiated by
// QML, which would also be suboptimal.

qmlRegisterSingletonType<QmlDlgPreferencesProxy>("Mixxx",
0,
1,
"PreferencesDialog",
lambda_to_singleton_type_factory_ptr(
[this](QQmlEngine* pEngine,
QJSEngine* pScriptEngine) -> QObject* {
Q_UNUSED(pScriptEngine);

QmlDlgPreferencesProxy* pDlgPreferencesProxy =
new QmlDlgPreferencesProxy(
m_pDlgPreferences,
pEngine);
return pDlgPreferencesProxy;
}));

qmlRegisterType<QmlControlProxy>("Mixxx", 0, 1, "ControlProxy");
qmlRegisterType<QmlWaveformOverview>("Mixxx", 0, 1, "WaveformOverview");

qmlRegisterSingletonType<QmlEffectsManagerProxy>("Mixxx",
0,
1,
Expand Down
7 changes: 5 additions & 2 deletions src/qml/qmlapplication.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#pragma once

#include <coreservices.h>

#include <QApplication>
#include <QFileSystemWatcher>
#include <QQmlApplicationEngine>

#include "coreservices.h"
#include "preferences/dialog/dlgpreferences.h"

namespace mixxx {
namespace qml {

Expand All @@ -27,6 +28,8 @@ class QmlApplication : public QObject {

std::unique_ptr<QQmlApplicationEngine> m_pAppEngine;
QFileSystemWatcher m_fileWatcher;

std::shared_ptr<DlgPreferences> m_pDlgPreferences;
};

} // namespace qml
Expand Down
17 changes: 17 additions & 0 deletions src/qml/qmldlgpreferencesproxy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "qmldlgpreferencesproxy.h"

namespace mixxx {
namespace qml {

QmlDlgPreferencesProxy::QmlDlgPreferencesProxy(
std::shared_ptr<DlgPreferences> pDlgPreferences, QObject* parent)
: QObject(parent),
m_pDlgPreferences(pDlgPreferences) {
}

void QmlDlgPreferencesProxy::show() {
m_pDlgPreferences->show();
}

} // namespace qml
} // namespace mixxx
23 changes: 23 additions & 0 deletions src/qml/qmldlgpreferencesproxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once
#include <QObject>

#include "preferences/dialog/dlgpreferences.h"

namespace mixxx {
namespace qml {

class QmlDlgPreferencesProxy : public QObject {
Q_OBJECT
public:
explicit QmlDlgPreferencesProxy(
std::shared_ptr<DlgPreferences> pDlgPreferences,
QObject* parent = nullptr);

Q_INVOKABLE void show();

private:
const std::shared_ptr<DlgPreferences> m_pDlgPreferences;
};

} // namespace qml
} // namespace mixxx

0 comments on commit 4900acf

Please sign in to comment.