Ignore scrolling for connection map combo boxes

This commit is contained in:
GriffinR 2024-08-13 21:43:23 -04:00
parent 7c73161ad0
commit 63b77a1fdc
4 changed files with 14 additions and 2 deletions

View file

@ -16,9 +16,12 @@ public:
void setClearButtonEnabled(bool enabled); void setClearButtonEnabled(bool enabled);
void setEditable(bool editable); void setEditable(bool editable);
void setLineEdit(QLineEdit *edit); void setLineEdit(QLineEdit *edit);
void setFocusedScrollingEnabled(bool enabled);
private: private:
void setItem(int index, const QString &text); void setItem(int index, const QString &text);
bool focusedScrollingEnabled = true;
}; };
#endif // NOSCROLLCOMBOBOX_H #endif // NOSCROLLCOMBOBOX_H

View file

@ -1059,9 +1059,11 @@ bool MainWindow::setProjectUI() {
ui->comboBox_DiveMap->clear(); ui->comboBox_DiveMap->clear();
ui->comboBox_DiveMap->addItems(project->mapNames); ui->comboBox_DiveMap->addItems(project->mapNames);
ui->comboBox_DiveMap->setClearButtonEnabled(true); ui->comboBox_DiveMap->setClearButtonEnabled(true);
ui->comboBox_DiveMap->setFocusedScrollingEnabled(false);
ui->comboBox_EmergeMap->clear(); ui->comboBox_EmergeMap->clear();
ui->comboBox_EmergeMap->addItems(project->mapNames); ui->comboBox_EmergeMap->addItems(project->mapNames);
ui->comboBox_EmergeMap->setClearButtonEnabled(true); ui->comboBox_EmergeMap->setClearButtonEnabled(true);
ui->comboBox_EmergeMap->setFocusedScrollingEnabled(false);
sortMapList(); sortMapList();

View file

@ -17,6 +17,7 @@ ConnectionsListItem::ConnectionsListItem(QWidget *parent, MapConnection * connec
ui->comboBox_Map->setMinimumContentsLength(6); ui->comboBox_Map->setMinimumContentsLength(6);
ui->comboBox_Map->addItems(mapNames); 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->setMinimum(INT_MIN);
ui->spinBox_Offset->setMaximum(INT_MAX); ui->spinBox_Offset->setMaximum(INT_MAX);

View file

@ -37,11 +37,17 @@ void NoScrollComboBox::setLineEdit(QLineEdit *edit) {
void NoScrollComboBox::wheelEvent(QWheelEvent *event) void NoScrollComboBox::wheelEvent(QWheelEvent *event)
{ {
// Only allow scrolling to modify contents when it explicitly has focus. // By default NoScrollComboBoxes will allow scrolling to modify its contents only when it explicitly has focus.
if (hasFocus()) // If focusedScrollingEnabled is false it won't allow scrolling even with focus.
if (this->focusedScrollingEnabled && hasFocus())
QComboBox::wheelEvent(event); QComboBox::wheelEvent(event);
} }
void NoScrollComboBox::setFocusedScrollingEnabled(bool enabled)
{
this->focusedScrollingEnabled = enabled;
}
void NoScrollComboBox::setItem(int index, const QString &text) void NoScrollComboBox::setItem(int index, const QString &text)
{ {
if (index >= 0) { if (index >= 0) {