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() {