From daa0fac096029bf0d71ca3ff59ba8d44726ced6c Mon Sep 17 00:00:00 2001 From: Kenichi Kamiya Date: Tue, 8 Apr 2025 00:57:13 +0900 Subject: [PATCH] Added CLI support for file path input - Enabled passing a file path via CLI arguments. - Automatically set the default filter (PSF or MIF) based on the file extension. Intentionally ignored unsupported extensions like psfu, consistent with current behaviors. --- include/mainwindow.h | 2 +- src/main.cpp | 7 ++++++- src/mainwindow.cpp | 23 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 47c32d4..f0d9ffa 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -18,7 +18,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); + explicit MainWindow(QWidget *parent = nullptr, const QString &filePath = ""); ~MainWindow(); private slots: diff --git a/src/main.cpp b/src/main.cpp index cf46f05..676226a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,12 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); - MainWindow w; + QString filePath; + QStringList arguments = QCoreApplication::arguments(); + if (arguments.size() > 1) { + filePath = arguments.at(1); + } + MainWindow w(nullptr, filePath); a.setStyle("fusion"); w.show(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4e6ab02..5212832 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11,7 +11,7 @@ #include "dlgsymbinfo.h" #include "psfutil.h" -MainWindow::MainWindow(QWidget *parent) : +MainWindow::MainWindow(QWidget *parent, const QString &filePath) : QMainWindow(parent), selectedFilter(""), ui(new Ui::MainWindow) @@ -20,6 +20,27 @@ MainWindow::MainWindow(QWidget *parent) : ui->listFontGlyphs->setItemDelegate(new QGlyphListWidgetItemDelegate); fileModified = false; connect(ui->widgetGlyphEditor, &QFontGlyphEditor::glyphChanged, this, &MainWindow::on_glyphChanged); + + if (!filePath.isEmpty()) { + QFileInfo fi(filePath); + if (fi.exists()) { + currentFile.setFileName(filePath); + + QString extension = fi.suffix().toLower(); + if (extension == "psf") { + selectedFilter = "PSF file (*.psf)"; + } else if (extension == "mif") { + selectedFilter = "Verilog MIF (*.mif)"; + } else { + QMessageBox::warning(this, "Error", "Unsupported file type: " + extension); + return; + } + + on_actionOpenFontFile_triggered(); + } else { + QMessageBox::warning(this, "Error", "File does not exist: " + filePath); + } + } } MainWindow::~MainWindow() {