From b53466d46a6459f74317c453657a0166c94e1fb1 Mon Sep 17 00:00:00 2001 From: Madison Webb Date: Mon, 24 Feb 2025 18:55:22 -0800 Subject: [PATCH] Added browseFiles button, also a .gitignore --- djsongmatch/fileDialogHelper.cpp | 13 +++++++++++++ djsongmatch/fileDialogHelper.h | 16 ++++++++++++++++ djsongmatch/mainwindow.cpp | 21 +++++++++++++++++++-- djsongmatch/mainwindow.h | 8 ++++++++ djsongmatch/mainwindow.ui | 27 +++++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 djsongmatch/fileDialogHelper.cpp create mode 100644 djsongmatch/fileDialogHelper.h diff --git a/djsongmatch/fileDialogHelper.cpp b/djsongmatch/fileDialogHelper.cpp new file mode 100644 index 0000000..b62ca95 --- /dev/null +++ b/djsongmatch/fileDialogHelper.cpp @@ -0,0 +1,13 @@ +#include "filedialoghelper.h" + +FileDialogHelper::FileDialogHelper(QObject *parent) + : QObject(parent) {} + +QString FileDialogHelper::openFileDialog(QWidget *parent) { + return QFileDialog::getOpenFileName( + parent, + "Select a File", + "", + "Audio Files (*.mp3 *.wav *.flac);;All Files (*)" + ); +} diff --git a/djsongmatch/fileDialogHelper.h b/djsongmatch/fileDialogHelper.h new file mode 100644 index 0000000..d14c51a --- /dev/null +++ b/djsongmatch/fileDialogHelper.h @@ -0,0 +1,16 @@ +#ifndef FILEDIALOGHELPER_H +#define FILEDIALOGHELPER_H + +#include +#include +#include + +class FileDialogHelper : public QObject { + Q_OBJECT + +public: + explicit FileDialogHelper(QObject *parent = nullptr); + QString openFileDialog(QWidget *parent = nullptr); // Function to open the file dialog +}; + +#endif // FILEDIALOGHELPER_H diff --git a/djsongmatch/mainwindow.cpp b/djsongmatch/mainwindow.cpp index 0d03e8c..746df67 100644 --- a/djsongmatch/mainwindow.cpp +++ b/djsongmatch/mainwindow.cpp @@ -1,15 +1,32 @@ #include "mainwindow.h" #include "./ui_mainwindow.h" +#include "fileDialogHelper.h" +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) + , fileDialogHelper(new FileDialogHelper(this)) // Initialize helper { ui->setupUi(this); + + // Automatically generated from Qt designer + connect(ui->browseFiles, &QPushButton::clicked, this, &MainWindow::on_browseButton_clicked); } -MainWindow::~MainWindow() -{ +MainWindow::~MainWindow() { delete ui; } +void MainWindow::on_browseButton_clicked() { + // Call the helper to open the file dialog + QString fileName = fileDialogHelper->openFileDialog(this); + + if (!fileName.isEmpty()) { + // Show a popup with the selected file path or update a label + QMessageBox::information(this, "File Selected", fileName); + + // Display file path on a label + // ui->filePathLabel->setText(fileName); + } +} diff --git a/djsongmatch/mainwindow.h b/djsongmatch/mainwindow.h index 934b0f3..4750a1f 100644 --- a/djsongmatch/mainwindow.h +++ b/djsongmatch/mainwindow.h @@ -2,6 +2,7 @@ #define MAINWINDOW_H #include +#include "filedialoghelper.h" QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } @@ -15,7 +16,14 @@ class MainWindow : public QMainWindow MainWindow(QWidget *parent = nullptr); ~MainWindow(); +private slots: + void on_browseButton_clicked(); // Slot to handle the Browse button click' + // Special Qt section indicating that functions are slots (can respond to signals) + // Functions cannot be connected to Qt signals unless marked as a slot. + private: Ui::MainWindow *ui; + FileDialogHelper *fileDialogHelper; // Helper for file dialog }; + #endif // MAINWINDOW_H diff --git a/djsongmatch/mainwindow.ui b/djsongmatch/mainwindow.ui index b742055..5f16890 100644 --- a/djsongmatch/mainwindow.ui +++ b/djsongmatch/mainwindow.ui @@ -13,8 +13,31 @@ MainWindow - - + + + + + 30 + 20 + 80 + 24 + + + + Browse Files + + + + + + + 0 + 0 + 800 + 21 + + +