From 63b77a1fdc66fb58ab22db4eb325261e5f893985 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Tue, 13 Aug 2024 21:43:23 -0400 Subject: [PATCH] Ignore scrolling for connection map combo boxes --- include/ui/noscrollcombobox.h | 3 +++ src/mainwindow.cpp | 2 ++ src/ui/connectionslistitem.cpp | 1 + src/ui/noscrollcombobox.cpp | 10 ++++++++-- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/ui/noscrollcombobox.h b/include/ui/noscrollcombobox.h index 7b6f7522..32966b3a 100644 --- a/include/ui/noscrollcombobox.h +++ b/include/ui/noscrollcombobox.h @@ -16,9 +16,12 @@ public: void setClearButtonEnabled(bool enabled); void setEditable(bool editable); void setLineEdit(QLineEdit *edit); + void setFocusedScrollingEnabled(bool enabled); private: void setItem(int index, const QString &text); + + bool focusedScrollingEnabled = true; }; #endif // NOSCROLLCOMBOBOX_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 48dc6564..c6b8c3c0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1059,9 +1059,11 @@ bool MainWindow::setProjectUI() { ui->comboBox_DiveMap->clear(); ui->comboBox_DiveMap->addItems(project->mapNames); ui->comboBox_DiveMap->setClearButtonEnabled(true); + ui->comboBox_DiveMap->setFocusedScrollingEnabled(false); ui->comboBox_EmergeMap->clear(); ui->comboBox_EmergeMap->addItems(project->mapNames); ui->comboBox_EmergeMap->setClearButtonEnabled(true); + ui->comboBox_EmergeMap->setFocusedScrollingEnabled(false); sortMapList(); diff --git a/src/ui/connectionslistitem.cpp b/src/ui/connectionslistitem.cpp index 2501d2d4..049bb17d 100644 --- a/src/ui/connectionslistitem.cpp +++ b/src/ui/connectionslistitem.cpp @@ -17,6 +17,7 @@ ConnectionsListItem::ConnectionsListItem(QWidget *parent, MapConnection * connec ui->comboBox_Map->setMinimumContentsLength(6); ui->comboBox_Map->addItems(mapNames); + ui->comboBox_Map->setFocusedScrollingEnabled(false); // Scrolling could cause rapid changes to many different maps ui->spinBox_Offset->setMinimum(INT_MIN); ui->spinBox_Offset->setMaximum(INT_MAX); diff --git a/src/ui/noscrollcombobox.cpp b/src/ui/noscrollcombobox.cpp index 5288ad97..3db2a956 100644 --- a/src/ui/noscrollcombobox.cpp +++ b/src/ui/noscrollcombobox.cpp @@ -37,11 +37,17 @@ void NoScrollComboBox::setLineEdit(QLineEdit *edit) { void NoScrollComboBox::wheelEvent(QWheelEvent *event) { - // Only allow scrolling to modify contents when it explicitly has focus. - if (hasFocus()) + // By default NoScrollComboBoxes will allow scrolling to modify its contents only when it explicitly has focus. + // If focusedScrollingEnabled is false it won't allow scrolling even with focus. + if (this->focusedScrollingEnabled && hasFocus()) QComboBox::wheelEvent(event); } +void NoScrollComboBox::setFocusedScrollingEnabled(bool enabled) +{ + this->focusedScrollingEnabled = enabled; +} + void NoScrollComboBox::setItem(int index, const QString &text) { if (index >= 0) {