173 lines
6.0 KiB
C++
173 lines
6.0 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include <QCheckBox>
|
|
#include <QLabel>
|
|
#include <QVBoxLayout>
|
|
#include <QLineEdit>
|
|
#include <QPushButton>
|
|
#include <QColorDialog>
|
|
#include <QComboBox>
|
|
|
|
#include "JFJochViewerSidePanel.h"
|
|
#include "widgets/TitleLabel.h"
|
|
#include "JFJochViewerImageStatistics.h"
|
|
|
|
JFJochViewerSidePanel::JFJochViewerSidePanel(JFJochReader &in_reader, QWidget *parent)
|
|
: reader(in_reader), QWidget(parent) {
|
|
|
|
auto layout = new QVBoxLayout(this);
|
|
|
|
layout->addWidget(new TitleLabel("Image statistics", this));
|
|
|
|
auto stats = new JFJochViewerImageStatistics(reader, this);
|
|
layout->addWidget(stats);
|
|
connect(this, &JFJochViewerSidePanel::imageLoaded,
|
|
stats, &JFJochViewerImageStatistics::loadImage);
|
|
|
|
connect(this, &JFJochViewerSidePanel::imageCleared,
|
|
stats, &JFJochViewerImageStatistics::noImage);
|
|
|
|
layout->addWidget(new TitleLabel("Image features", this));
|
|
|
|
auto spotToggleCheckBox = new QCheckBox("Show spots", this);
|
|
spotToggleCheckBox->setCheckState(Qt::CheckState::Checked);
|
|
|
|
layout->addWidget(spotToggleCheckBox); // Add checkbox to the grid layout
|
|
|
|
connect(spotToggleCheckBox, &QCheckBox::toggled, this, &JFJochViewerSidePanel::spotsToggled);
|
|
|
|
resRingsCheckBox = new QCheckBox("Show resolution rings", this);
|
|
resRingsCheckBox->setCheckState(Qt::Checked);
|
|
layout->addWidget(resRingsCheckBox);
|
|
|
|
autoResRingsCheckBox = new QCheckBox("Resolution rings auto.", this);
|
|
res_rings_edit = new QLineEdit(this);
|
|
res_rings_edit->setPlaceholderText("Enter non-negative floats, e.g., 1.0,2.5,3.7");
|
|
res_rings_edit->setEnabled(false); // Initially disabled as "Auto Res Rings" is checked by default
|
|
|
|
layout->addWidget(autoResRingsCheckBox); // Add the checkbox to the grid layout
|
|
layout->addWidget(res_rings_edit); // Add the line edit to the grid layout
|
|
|
|
auto highestPixelsComboBox = new QComboBox(this);
|
|
highestPixelsComboBox->addItem("0 highest pixels", 0);
|
|
highestPixelsComboBox->addItem("1 highest pixel", 1);
|
|
highestPixelsComboBox->addItem("2 highest pixels", 2);
|
|
highestPixelsComboBox->addItem("3 highest pixels", 3);
|
|
highestPixelsComboBox->addItem("5 highest pixels", 5);
|
|
highestPixelsComboBox->addItem("10 highest pixels", 10);
|
|
highestPixelsComboBox->setCurrentIndex(0);
|
|
layout->addWidget(highestPixelsComboBox);
|
|
|
|
connect(highestPixelsComboBox, &QComboBox::currentIndexChanged, this, [this, highestPixelsComboBox](int index) {
|
|
int value = highestPixelsComboBox->itemData(index).toInt();
|
|
emit showHighestPixels(value);
|
|
});
|
|
|
|
auto saturatedPixelsCheckBox = new QCheckBox("Show saturated pixels", this);
|
|
layout->addWidget(saturatedPixelsCheckBox);
|
|
|
|
connect(saturatedPixelsCheckBox, &QCheckBox::toggled, this, &JFJochViewerSidePanel::saturatedPixelsToggled);
|
|
|
|
auto colorSelectButton = new QPushButton("Select feature color", this);
|
|
layout->addWidget(colorSelectButton);
|
|
|
|
connect(colorSelectButton, &QPushButton::clicked, this, [this]() {
|
|
QColor color = QColorDialog::getColor(Qt::magenta, this, "Select Feature Color");
|
|
if (color.isValid()) {
|
|
emit setFeatureColor(color);
|
|
}
|
|
});
|
|
|
|
auto spotColorSelectButton = new QPushButton("Select spot color", this);
|
|
layout->addWidget(spotColorSelectButton);
|
|
|
|
connect(spotColorSelectButton, &QPushButton::clicked, this, [this]() {
|
|
QColor color = QColorDialog::getColor(Qt::green, this, "Select Spot Color");
|
|
if (color.isValid()) {
|
|
emit setSpotColor(color);
|
|
}
|
|
});
|
|
|
|
connect(autoResRingsCheckBox, &QCheckBox::toggled, this, &JFJochViewerSidePanel::enableAutoResRings);
|
|
|
|
connect(res_rings_edit, &QLineEdit::editingFinished,
|
|
this, &JFJochViewerSidePanel::editingFinished);
|
|
|
|
connect(resRingsCheckBox, &QCheckBox::toggled,
|
|
this, &JFJochViewerSidePanel::enableResRings);
|
|
|
|
layout->addWidget(new TitleLabel("Azim. integration", this));
|
|
azint_plot = new JFJochSimpleChartView(this);
|
|
layout->addWidget(azint_plot);
|
|
|
|
layout->addStretch();
|
|
setLayout(layout); // Set the layout to the widget
|
|
}
|
|
|
|
void JFJochViewerSidePanel::enableAutoResRings(bool input) {
|
|
res_rings_edit->setEnabled(!input); // Enable line edit only if "Auto Res Rings" is unchecked
|
|
if (input) {
|
|
emit autoResRings();
|
|
} else {
|
|
editingFinished();
|
|
}
|
|
}
|
|
|
|
void JFJochViewerSidePanel::spotsToggled(bool input) {
|
|
emit showSpots(input);
|
|
}
|
|
|
|
void JFJochViewerSidePanel::editingFinished() {
|
|
QString text = res_rings_edit->text();
|
|
QStringList stringList = text.split(',', Qt::SkipEmptyParts);
|
|
QVector<float> 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 setResRings(manualResRings); // Update resolution ring vector
|
|
}
|
|
}
|
|
|
|
void JFJochViewerSidePanel::loadImage() {
|
|
auto image = reader.CopyImage();
|
|
if (image)
|
|
azint_plot->UpdateData(image->Dataset().az_int_bin_to_q, image->ImageData().az_int_profile);
|
|
emit imageLoaded();
|
|
|
|
}
|
|
|
|
void JFJochViewerSidePanel::noImage() {
|
|
azint_plot->ClearData();
|
|
emit imageCleared();
|
|
}
|
|
|
|
void JFJochViewerSidePanel::enableResRings(bool input) {
|
|
if (!input) {
|
|
autoResRingsCheckBox->setEnabled(false);
|
|
res_rings_edit->setEnabled(false);
|
|
emit setResRings({});
|
|
} else {
|
|
autoResRingsCheckBox->setEnabled(true);
|
|
enableAutoResRings(autoResRingsCheckBox->isChecked());
|
|
}
|
|
}
|
|
|
|
void JFJochViewerSidePanel::saturatedPixelsToggled(bool input) {
|
|
emit showSaturatedPixels(input);
|
|
}
|