211 lines
6.9 KiB
C++
211 lines
6.9 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "JFJochViewerMenu.h"
|
|
|
|
#include <QMessageBox>
|
|
#include <QApplication>
|
|
#include <QFileDialog>
|
|
#include <QString>
|
|
#include <QGridLayout>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QSpinBox>
|
|
#include <QDialogButtonBox>
|
|
|
|
#include "../common/GitInfo.h"
|
|
|
|
JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) {
|
|
// Create "File" menu
|
|
QMenu *fileMenu = addMenu("File");
|
|
|
|
const QAction *openAction = fileMenu->addAction("&Open");
|
|
connect(openAction, &QAction::triggered, this, &JFJochViewerMenu::openSelected);
|
|
|
|
const QAction *openHttpAction = fileMenu->addAction("Open &HTTP");
|
|
connect(openHttpAction, &QAction::triggered, this, &JFJochViewerMenu::openHttpSelected);
|
|
|
|
const QAction *closeAction = fileMenu->addAction("&Close");
|
|
connect(closeAction, &QAction::triggered, this, &JFJochViewerMenu::closeSelected);
|
|
|
|
// Add seperator
|
|
fileMenu->addSeparator();
|
|
|
|
// Add "Quit" action
|
|
const QAction *quitAction = fileMenu->addAction("&Quit");
|
|
connect(quitAction, &QAction::triggered, this, &JFJochViewerMenu::quitSelected);
|
|
|
|
QMenu *windowMenu = addMenu("Window");
|
|
toggleImageWindowAction = windowMenu->addAction("Image list");
|
|
toggleImageWindowAction->setCheckable(true);
|
|
toggleImageWindowAction->setChecked(false);
|
|
connect(toggleImageWindowAction, &QAction::toggled,
|
|
this, &JFJochViewerMenu::imageListWindowToggled);
|
|
|
|
toggleMetadataWindowAction = windowMenu->addAction("Metadata");
|
|
toggleMetadataWindowAction->setCheckable(true);
|
|
toggleMetadataWindowAction->setChecked(false);
|
|
connect(toggleMetadataWindowAction, &QAction::toggled,
|
|
this, &JFJochViewerMenu::metadataWindowToggled);
|
|
|
|
toggleSpotWindowAction = windowMenu->addAction("Spot list");
|
|
toggleSpotWindowAction->setCheckable(true);
|
|
toggleSpotWindowAction->setChecked(false);
|
|
connect(toggleSpotWindowAction, &QAction::toggled,
|
|
this, &JFJochViewerMenu::spotListWindowToggled);
|
|
|
|
toggleReflectionWindowAction = windowMenu->addAction("Reflection list");
|
|
toggleReflectionWindowAction->setCheckable(true);
|
|
toggleReflectionWindowAction->setChecked(false);
|
|
connect(toggleReflectionWindowAction, &QAction::toggled,
|
|
this, &JFJochViewerMenu::reflectionListWindowToggled);
|
|
|
|
toggleProcessingWindowAction = windowMenu->addAction("Processing");
|
|
toggleProcessingWindowAction->setCheckable(true);
|
|
toggleProcessingWindowAction->setChecked(false);
|
|
connect(toggleProcessingWindowAction, &QAction::toggled,
|
|
this, &JFJochViewerMenu::processingWindowToggled);
|
|
|
|
QMenu *helpMenu = addMenu("Help");
|
|
// Add "About" action
|
|
const QAction *aboutAction = helpMenu->addAction("About");
|
|
connect(aboutAction, &QAction::triggered, this, &JFJochViewerMenu::aboutSelected);
|
|
}
|
|
|
|
void JFJochViewerMenu::aboutSelected() {
|
|
QString version(QString::fromStdString(jfjoch_version()));
|
|
// Create QMessageBox
|
|
QMessageBox aboutBox(this);
|
|
aboutBox.setWindowTitle("About Jungfraujoch Image Viewer");
|
|
|
|
// Set detailed text with proper spacing and structure
|
|
aboutBox.setText(
|
|
"<h3>Jungfraujoch Image Viewer</h3>" // Use HTML for improved style
|
|
"<p><b>Version:</b> " + version + "</p>"
|
|
"<p><b>Copyright:</b> 2019-2025 Paul Scherrer Institute</p>"
|
|
"<p><b>Author:</b> Filip Leonarski <filip.leonarski@psi.ch></p>"
|
|
);
|
|
|
|
// Optional: Add a larger informative text, if needed
|
|
aboutBox.setInformativeText(
|
|
"This program comes with ABSOLUTELY NO WARRANTY. "
|
|
"This is free software, and you are welcome to redistribute it "
|
|
"under certain conditions (GPLv3).\n\n"
|
|
"Development supported by Innovation Project (101.535.1 IP-ENG) from Innosuisse."
|
|
);
|
|
|
|
// Set an icon
|
|
aboutBox.setIcon(QMessageBox::Information);
|
|
|
|
// Execute the dialog
|
|
aboutBox.exec();
|
|
}
|
|
|
|
void JFJochViewerMenu::openSelected() {
|
|
QString fileName = QFileDialog::getOpenFileName(
|
|
this,
|
|
"Open File", // Dialog title
|
|
"", // Default folder
|
|
"HDF5 Master Files (*_master.h5);; HDF5 Files (*.h5);;All Files (*)" // Filter for .h5 files
|
|
);
|
|
|
|
if (!fileName.isEmpty())
|
|
emit fileOpenSelected(fileName, 0, 1);
|
|
}
|
|
|
|
void JFJochViewerMenu::closeSelected() {
|
|
emit fileCloseSelected();
|
|
}
|
|
|
|
void JFJochViewerMenu::quitSelected() {
|
|
QApplication::quit();
|
|
}
|
|
|
|
void JFJochViewerMenu::imageListWindowToggled(bool checked) {
|
|
if (checked)
|
|
emit openImageListWindow();
|
|
else
|
|
emit closeImageListWindow();
|
|
}
|
|
|
|
void JFJochViewerMenu::metadataWindowToggled(bool checked) {
|
|
if (checked)
|
|
emit openMetadataWindow();
|
|
else
|
|
emit closeMetadataWindow();
|
|
}
|
|
|
|
void JFJochViewerMenu::imageListWindowClosing() {
|
|
toggleImageWindowAction->setChecked(false);
|
|
}
|
|
|
|
void JFJochViewerMenu::metadataWindowClosing() {
|
|
toggleMetadataWindowAction->setChecked(false);
|
|
}
|
|
|
|
void JFJochViewerMenu::spotListWindowToggled(bool checked) {
|
|
if (checked)
|
|
emit openSpotListWindow();
|
|
else
|
|
emit closeSpotListWindow();
|
|
}
|
|
|
|
void JFJochViewerMenu::spotListWindowClosing() {
|
|
toggleSpotWindowAction->setChecked(false);
|
|
}
|
|
|
|
void JFJochViewerMenu::reflectionListWindowToggled(bool checked) {
|
|
if (checked)
|
|
emit openReflectionListWindow();
|
|
else
|
|
emit closeReflectionListWindow();
|
|
}
|
|
|
|
void JFJochViewerMenu::reflectionListWindowClosing() {
|
|
toggleReflectionWindowAction->setChecked(false);
|
|
}
|
|
|
|
void JFJochViewerMenu::processingWindowToggled(bool checked) {
|
|
if (checked)
|
|
emit openProcessingWindow();
|
|
else
|
|
emit closeProcessingWindow();
|
|
}
|
|
void JFJochViewerMenu::processingWindowClosing() {
|
|
toggleProcessingWindowAction->setChecked(false);
|
|
}
|
|
|
|
void JFJochViewerMenu::openHttpSelected() {
|
|
QDialog dialog(this);
|
|
dialog.setWindowTitle("Open HTTP Connection");
|
|
dialog.setMinimumWidth(400);
|
|
|
|
QGridLayout *layout = new QGridLayout(&dialog);
|
|
layout->addWidget(new QLabel("http://"), 0, 0);
|
|
layout->addWidget(new QLabel(":"), 0, 2);
|
|
|
|
QLineEdit *hostEdit = new QLineEdit(&dialog);
|
|
hostEdit->setText("localhost");
|
|
layout->addWidget(hostEdit, 0, 1);
|
|
|
|
QSpinBox *portSpinBox = new QSpinBox(&dialog);
|
|
portSpinBox->setRange(1, 65535);
|
|
portSpinBox->setValue(5232);
|
|
layout->addWidget(portSpinBox, 0, 3);
|
|
|
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
connect(buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
|
|
connect(buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
|
|
layout->addWidget(buttonBox, 1, 0, 1, 4);
|
|
|
|
dialog.setLayout(layout);
|
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
QString url = QString("http://%1:%2")
|
|
.arg(hostEdit->text())
|
|
.arg(portSpinBox->value());
|
|
|
|
emit fileOpenSelected(url, -1, 1);
|
|
}
|
|
}
|