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