// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #include #include #include #include "ResolutionRingWidget.h" ResolutionRingWidget::ResolutionRingWidget(QWidget *parent) : QWidget(parent) { res_rings_edit = new QLineEdit(this); res_rings_edit->setPlaceholderText("Ring positions, e.g., 1.0,2.5,3.7"); res_rings_edit->setEnabled(false); // Initially disabled as "Auto Res Rings" is checked by default none_button = new QRadioButton("None", this); auto_button = new QRadioButton("Auto", this); manual_button = new QRadioButton("Manual", this); est_button = new QRadioButton("Resolution estimation from processing", this); est_button->setChecked(true); button_group = new QButtonGroup(this); button_group->addButton(none_button, 0); button_group->addButton(auto_button, 1); button_group->addButton(manual_button, 2); button_group->addButton(est_button, 3); QVBoxLayout *layout = new QVBoxLayout(this); layout->addWidget(none_button); layout->addWidget(auto_button); QHBoxLayout *manual_layout = new QHBoxLayout(); manual_layout->addWidget(manual_button); manual_layout->addWidget(res_rings_edit); layout->addLayout(manual_layout); layout->addWidget(est_button); connect(res_rings_edit, &QLineEdit::editingFinished, this, &ResolutionRingWidget::editingFinished); connect(auto_button, &QRadioButton::clicked, this, &ResolutionRingWidget::autoButtonClicked); connect(manual_button, &QRadioButton::clicked, this, &ResolutionRingWidget::manualButtonClicked); connect(est_button, &QRadioButton::clicked, this, &ResolutionRingWidget::estButtonClicked); connect(none_button, &QRadioButton::clicked, this, &ResolutionRingWidget::noneButtonClicked); } void ResolutionRingWidget::setRings(const QVector &v) { QString txt; for (float i : v) { txt += QString::number(i, 'f', 4) + ","; } res_rings_edit->setText(txt); res_rings_edit->setEnabled(true); manual_button->setChecked(true); editingFinished(); } void ResolutionRingWidget::autoButtonClicked() { res_rings_edit->setEnabled(false); emit ringModeSet(JFJochDiffractionImage::RingMode::Auto); } void ResolutionRingWidget::estButtonClicked() { res_rings_edit->setEnabled(false); emit ringModeSet(JFJochDiffractionImage::RingMode::Estimation); } void ResolutionRingWidget::noneButtonClicked() { res_rings_edit->setEnabled(false); emit ringModeSet(JFJochDiffractionImage::RingMode::None); } void ResolutionRingWidget::manualButtonClicked() { res_rings_edit->setEnabled(true); editingFinished(); } void ResolutionRingWidget::editingFinished() { QString text = res_rings_edit->text(); QStringList stringList = text.split(',', Qt::SkipEmptyParts); QVector manualResRings; bool validInput = true; for (const QString &str: stringList) { bool ok; float value = str.toFloat(&ok); if (ok && value >= 0) { manualResRings.append(value); } else { validInput = false; break; } } if (!validInput) { res_rings_edit->setStyleSheet("border: 1px solid red;"); // Highlight error } else { res_rings_edit->setStyleSheet(""); // Reset to default style emit resRingsSet(manualResRings); // Update resolution ring vector } } void ResolutionRingWidget::setRingMode(JFJochDiffractionImage::RingMode mode) { /* */ }