1010#include " ConfigWidget.h"
1111#include " FloatingPointWidget.h"
1212
13+ // #include <iostream>
14+ // using std::cout;
15+ // using std::endl;
16+
1317namespace PokemonAutomation {
1418
1519
1620
1721ConfigWidget* FloatingPointCell::make_QtWidget (QWidget& parent){
18- return new FloatingPointCellWidget (parent, *this );
22+ return new FloatingPointCellWidget (parent, *this , true );
1923}
2024ConfigWidget* FloatingPointOption::make_QtWidget (QWidget& parent){
2125 return new FloatingPointOptionWidget (parent, *this );
@@ -27,7 +31,7 @@ ConfigWidget* FloatingPointOption::make_QtWidget(QWidget& parent){
2731FloatingPointCellWidget::~FloatingPointCellWidget (){
2832 m_value.remove_listener (*this );
2933}
30- FloatingPointCellWidget::FloatingPointCellWidget (QWidget& parent, FloatingPointCell& value)
34+ FloatingPointCellWidget::FloatingPointCellWidget (QWidget& parent, FloatingPointCell& value, bool sanitize )
3135 : QLineEdit(QString::number(value, ' f' ), &parent)
3236 , ConfigWidget(value, *this )
3337 , m_value(value)
@@ -48,17 +52,23 @@ FloatingPointCellWidget::FloatingPointCellWidget(QWidget& parent, FloatingPointC
4852 );
4953 connect (
5054 this , &QLineEdit::editingFinished,
51- this , [this ](){
55+ this , [this , sanitize ](){
5256 bool ok;
5357 double current = this ->text ().toDouble (&ok);
5458 QPalette palette;
55- if (ok && m_value.check_validity (current).empty ()){
56- palette.setColor (QPalette::Text, Qt::black);
59+ palette.setColor (QPalette::Text, Qt::black);
60+ if (sanitize){
61+ m_value.set_and_sanitize (current);
5762 }else {
58- palette.setColor (QPalette::Text, Qt::red);
63+ if (!ok || !m_value.check_validity (current).empty ()){
64+ palette.setColor (QPalette::Text, Qt::red);
65+ }
66+ m_value.set (current);
5967 }
6068 this ->setPalette (palette);
61- m_value.set (current);
69+
70+ // Always update the UI.
71+ on_config_value_changed (this );
6272 }
6373 );
6474 value.add_listener (*this );
@@ -91,7 +101,7 @@ FloatingPointOptionWidget::FloatingPointOptionWidget(QWidget& parent, FloatingPo
91101 text->setTextInteractionFlags (Qt::TextBrowserInteraction);
92102 text->setOpenExternalLinks (true );
93103 layout->addWidget (text, 1 );
94- m_cell = new FloatingPointCellWidget (*this , value);
104+ m_cell = new FloatingPointCellWidget (*this , value, false );
95105 layout->addWidget (m_cell, 1 );
96106 value.add_listener (*this );
97107}
0 commit comments