Skip to content

Commit 7c87579

Browse files
author
Milkii Brewster
committed
add checkbox to hide unenabled controllers in preferences
adds a checkbox in preferences > controllers to hide controllers that are not enabled, making it easier for users with many controllers to find the ones they actually use. the checkbox state is persisted in the config and the controller list visibility is updated efficiently using setHidden() to avoid expensive widget rebuilding. implementation: - added checkbox ui element "hide controllers that are not enabled" - persists state in [controller]/hide_unenabled_controllers config key - uses lightweight updatecontrollervisibility() method to toggle tree item visibility instead of destroying/rebuilding all widgets - matches controllers correctly using controller pages in sync with tree items - updates visibility automatically when controller enabled state changes - added controller() getter to dlgprefcontroller for proper matching fixes #14275
1 parent 604b32c commit 7c87579

File tree

5 files changed

+84
-0
lines changed

5 files changed

+84
-0
lines changed

src/controllers/defs_controllers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ const auto kMidiThroughPortPrefix = QLatin1String("MIDI Through Port");
3232
const ConfigKey kMidiThroughCfgKey =
3333
ConfigKey(QStringLiteral("[Controller]"), QStringLiteral("midi_through_enabled"));
3434
#endif
35+
36+
const ConfigKey kHideUnenabledControllersCfgKey =
37+
ConfigKey(QStringLiteral("[Controller]"), QStringLiteral("hide_unenabled_controllers"));

src/controllers/dlgprefcontroller.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class DlgPrefController : public DlgPreferencePage {
3838
QUrl helpUrl() const override;
3939
void keyPressEvent(QKeyEvent* pEvent) override;
4040

41+
Controller* controller() const {
42+
return m_pController;
43+
}
44+
4145
public slots:
4246
/// Called when the preference dialog (not this page) is shown to the user.
4347
void slotUpdate() override;

src/controllers/dlgprefcontrollers.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ DlgPrefControllers::DlgPrefControllers(DlgPreferences* pPreferences,
4444
this,
4545
&DlgPrefControllers::rescanControllers);
4646

47+
// Hide unenabled controllers checkbox
48+
checkBox_hideUnenabled->setChecked(
49+
m_pConfig->getValue(kHideUnenabledControllersCfgKey, false));
50+
connect(checkBox_hideUnenabled,
51+
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
52+
&QCheckBox::checkStateChanged,
53+
#else
54+
&QCheckBox::stateChanged,
55+
#endif
56+
this,
57+
&DlgPrefControllers::slotHideUnenabledChanged);
58+
4759
#ifdef __PORTMIDI__
4860
checkBox_midithrough->setChecked(m_pConfig->getValue(kMidiThroughCfgKey, false));
4961
connect(checkBox_midithrough,
@@ -256,6 +268,32 @@ void DlgPrefControllers::setupControllerWidgets() {
256268
temp.setBold(pController->isOpen());
257269
pControllerTreeItem->setFont(0, temp);
258270
}
271+
272+
// Update visibility based on checkbox state
273+
updateControllerVisibility();
274+
}
275+
276+
void DlgPrefControllers::updateControllerVisibility() {
277+
bool hideUnenabled = m_pConfig->getValue(kHideUnenabledControllersCfgKey, false);
278+
279+
// Use the controller pages to match tree items with controllers
280+
// since they are built together and always in sync
281+
for (int i = 0; i < m_controllerTreeItems.size() && i < m_controllerPages.size(); ++i) {
282+
QTreeWidgetItem* pTreeItem = m_controllerTreeItems.at(i);
283+
DlgPrefController* pControllerDlg = m_controllerPages.at(i);
284+
285+
if (pTreeItem && pControllerDlg && pControllerDlg->controller()) {
286+
Controller* pController = pControllerDlg->controller();
287+
288+
if (!hideUnenabled) {
289+
// Show all controllers
290+
pTreeItem->setHidden(false);
291+
} else {
292+
// Hide if controller is not open/enabled
293+
pTreeItem->setHidden(!pController->isOpen());
294+
}
295+
}
296+
}
259297
}
260298

261299
void DlgPrefControllers::slotHighlightDevice(DlgPrefController* pControllerDlg, bool enabled) {
@@ -273,8 +311,26 @@ void DlgPrefControllers::slotHighlightDevice(DlgPrefController* pControllerDlg,
273311
QFont temp = pControllerTreeItem->font(0);
274312
temp.setBold(enabled);
275313
pControllerTreeItem->setFont(0, temp);
314+
315+
// Update visibility in case the checkbox is checked and this controller's state changed
316+
bool hideUnenabled = m_pConfig->getValue(kHideUnenabledControllersCfgKey, false);
317+
if (hideUnenabled) {
318+
pControllerTreeItem->setHidden(!enabled);
319+
}
276320
}
277321

322+
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
323+
void DlgPrefControllers::slotHideUnenabledChanged(Qt::CheckState state) {
324+
m_pConfig->setValue(kHideUnenabledControllersCfgKey, state != Qt::Unchecked);
325+
updateControllerVisibility();
326+
}
327+
#else
328+
void DlgPrefControllers::slotHideUnenabledChanged(bool checked) {
329+
m_pConfig->setValue(kHideUnenabledControllersCfgKey, checked);
330+
updateControllerVisibility();
331+
}
332+
#endif
333+
278334
#ifdef __PORTMIDI__
279335
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
280336
void DlgPrefControllers::slotMidiThroughChanged(Qt::CheckState state) {

src/controllers/dlgprefcontrollers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ class DlgPrefControllers : public DlgPreferencePage, public Ui::DlgPrefControlle
4141

4242
private slots:
4343
void rescanControllers();
44+
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
45+
void slotHideUnenabledChanged(Qt::CheckState state);
46+
#else
47+
void slotHideUnenabledChanged(bool checked);
48+
#endif
4449
#ifdef __PORTMIDI__
4550
#if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
4651
void slotMidiThroughChanged(Qt::CheckState state);
@@ -53,6 +58,7 @@ class DlgPrefControllers : public DlgPreferencePage, public Ui::DlgPrefControlle
5358
private:
5459
void destroyControllerWidgets();
5560
void setupControllerWidgets();
61+
void updateControllerVisibility();
5662
void openLocalFile(const QString& file);
5763

5864
DlgPreferences* m_pDlgPreferences;

src/controllers/dlgprefcontrollersdlg.ui

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@
7070
</widget>
7171
</item>
7272

73+
<item>
74+
<widget class="QCheckBox" name="checkBox_hideUnenabled">
75+
<property name="sizePolicy">
76+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
77+
<horstretch>0</horstretch>
78+
<verstretch>0</verstretch>
79+
</sizepolicy>
80+
</property>
81+
<property name="text">
82+
<string>Hide controllers that are not enabled</string>
83+
</property>
84+
</widget>
85+
</item>
86+
7387
<item>
7488
<widget class="Line" name="line_midithrough">
7589
<property name="orientation">
@@ -224,6 +238,7 @@
224238
</layout>
225239
</widget>
226240
<tabstops>
241+
checkBox_hideUnenabled
227242
checkBox_midithrough
228243
btnOpenUserMappings
229244
</tabstops>

0 commit comments

Comments
 (0)