| 32 | static const int MIN_FIELD_WIDTH = 80; |
| 33 | |
| 34 | WidgetSettingFloat::WidgetSettingFloat(QTreeWidget* tree, QTreeWidgetItem* item, const SettingMetaFloat& meta, |
| 35 | SettingDataSet& data_set) |
| 36 | : WidgetSettingBase(tree, item), |
| 37 | meta(meta), |
| 38 | data_set(data_set), |
| 39 | field(new QLineEdit(this)), |
| 40 | timer_error(new QTimer(this)), |
| 41 | timer_valid(new QTimer(this)) { |
| 42 | const std::string unit = meta.unit.empty() ? "" : format(" (%s)", meta.unit.c_str()); |
| 43 | const std::string status = meta.status == STATUS_STABLE ? "" : std::string(" (") + GetToken(this->meta.status) + ")"; |
| 44 | |
| 45 | this->field->setFont(tree->font()); |
| 46 | this->field->setAlignment(Qt::AlignRight); |
| 47 | this->field->show(); |
| 48 | this->default_palette = this->field->palette(); |
| 49 | |
| 50 | this->connect(this->field, SIGNAL(textEdited(const QString&)), this, SLOT(OnTextEdited(const QString&))); |
| 51 | this->connect(this->timer_error, &QTimer::timeout, this, &WidgetSettingFloat::OnErrorValue); |
| 52 | this->connect(this->timer_valid, &QTimer::timeout, this, &WidgetSettingFloat::OnValidValue); |
| 53 | |
| 54 | std::string tooltip = meta.description; |
| 55 | if (meta.HasRange()) { |
| 56 | tooltip += format(" [%f, %f]", meta.min_value, meta.max_value); |
| 57 | } |
| 58 | |
| 59 | this->item->setText(0, (this->meta.label + unit + status).c_str()); |
| 60 | this->item->setFont(0, this->tree->font()); |
| 61 | this->item->setToolTip(0, tooltip.c_str()); |
| 62 | this->item->setSizeHint(0, QSize(0, ITEM_HEIGHT)); |
| 63 | this->tree->setItemWidget(this->item, 0, this); |
| 64 | |
| 65 | this->Refresh(REFRESH_ENABLE_AND_STATE); |
| 66 | } |
| 67 | |
| 68 | WidgetSettingFloat::~WidgetSettingFloat() { |
| 69 | this->timer_error->stop(); |