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

add WCollapsibleGroupBox, use for controller mapping info boxes and settings #14324

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -1535,6 +1535,7 @@ add_library(
src/widget/wbasewidget.cpp
src/widget/wbattery.cpp
src/widget/wbeatspinbox.cpp
src/widget/wcollapsiblegroupbox.cpp
src/widget/wcolorpicker.cpp
src/widget/wcolorpickeraction.cpp
src/widget/wcombobox.cpp
Expand Down
47 changes: 44 additions & 3 deletions src/controllers/dlgprefcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "util/desktophelper.h"
#include "util/parented_ptr.h"
#include "util/string.h"
#include "widget/wcollapsiblegroupbox.h"

namespace {
const QString kMappingExt(".midi.xml");
Expand Down Expand Up @@ -766,6 +767,7 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
if (m_pControllerManager->getConfiguredMappingFileForDevice(
m_pController->getName()) != mappingFilePath) {
setDirty(true);
m_settingsCollapsedStates.clear();
} else if (m_pMapping && m_pMapping->isDirty()) {
// We have pending changes, don't reload the mapping from file!
// This is called by show()/slotUpdate() after MIDI learning ended
Expand Down Expand Up @@ -807,6 +809,9 @@ void DlgPrefController::slotMappingSelected(int chosenIndex) {
!mappingFilePath.isEmpty();
m_ui.controllerTabs->setTabVisible(m_inputMappingsTabIndex, showMidiTabs);
m_ui.controllerTabs->setTabVisible(m_outputMappingsTabIndex, showMidiTabs);
// Also disable accordingly so hidden tabs can not get keyboard focus
m_ui.controllerTabs->setTabEnabled(m_inputMappingsTabIndex, showMidiTabs);
m_ui.controllerTabs->setTabEnabled(m_outputMappingsTabIndex, showMidiTabs);

// Hide the entire QTabWidget if all tabs are removed
m_ui.controllerTabs->setVisible(getNumberOfVisibleTabs() > 0);
Expand Down Expand Up @@ -1073,7 +1078,40 @@ void DlgPrefController::slotShowMapping(std::shared_ptr<LegacyControllerMapping>
}

if (pLayout != nullptr && !settings.isEmpty()) {
m_ui.settingsTab->layout()->addWidget(pLayout->build(m_ui.settingsTab));
QWidget* pSettingsWidget = pLayout->build(m_ui.settingsTab);
m_ui.settingsTab->layout()->addWidget(pSettingsWidget);

// Add an expanding spacer so that when we collapse all groups,
// they are pushed to the top.
m_ui.settingsTab->layout()->addItem(new QSpacerItem(
1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding));

// Make all top-level groupboxes checkable so we get the
// collapse/expand functionality. Qt::FindDirectChildrenOnly
// ensures we only iterate over the top-level groupboxes.
const QList<WCollapsibleGroupBox*> boxes =
pSettingsWidget->findChildren<WCollapsibleGroupBox*>(
QString() /* match any ObjectName */,
Qt::FindDirectChildrenOnly);
for (auto* pBox : std::as_const(boxes)) {
const QString title = pBox->title();
pBox->setCheckable(true);
// The collapsed state is saved/restored via the groupbox' title.
// Note: If multiple top-levle groups happen to have the same title
// (which should not normally happen in well-behaved controller mappings,
// but is not strictly prohibited), the last one to be expanded/
// collapsed determines the state that will be restored.
if (m_settingsCollapsedStates.contains(title)) {
pBox->setChecked(m_settingsCollapsedStates.value(title));
}

connect(pBox,
&WCollapsibleGroupBox::toggled,
this,
[this, title](bool checked) {
m_settingsCollapsedStates.insert(title, checked);
});
}

for (const auto& setting : std::as_const(settings)) {
connect(setting.get(),
Expand All @@ -1085,8 +1123,9 @@ void DlgPrefController::slotShowMapping(std::shared_ptr<LegacyControllerMapping>
}

// Show or hide the settings tab based on the presence of settings
m_ui.controllerTabs->setTabVisible(
m_settingsTabIndex, pMapping && !pMapping->getSettings().isEmpty());
bool showSettings = pMapping && !pMapping->getSettings().isEmpty();
m_ui.controllerTabs->setTabVisible(m_settingsTabIndex, showSettings);
m_ui.controllerTabs->setTabEnabled(m_settingsTabIndex, showSettings);

// If there is still settings that may be saved and no new mapping selected
// (e.g restored default), we keep the the dirty mapping live so it can be
Expand All @@ -1105,11 +1144,13 @@ void DlgPrefController::slotShowMapping(std::shared_ptr<LegacyControllerMapping>
auto screens = pMapping->getInfoScreens();
bool hasScreens = !screens.isEmpty();
m_ui.controllerTabs->setTabVisible(m_screensTabIndex, hasScreens);
m_ui.controllerTabs->setTabEnabled(m_screensTabIndex, hasScreens);
if (hasScreens) {
slotShowPreviewScreens(m_pController->getScriptEngine().get());
}
} else {
m_ui.controllerTabs->setTabVisible(m_screensTabIndex, false);
m_ui.controllerTabs->setTabEnabled(m_screensTabIndex, false);
}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/controllers/dlgprefcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,5 @@ class DlgPrefController : public DlgPreferencePage {
int m_outputMappingsTabIndex; // Index of the output mappings tab
int m_settingsTabIndex; // Index of the settings tab
int m_screensTabIndex; // Index of the screens tab
QHash<QString, bool> m_settingsCollapsedStates;
};
Loading
Loading