Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added browseFiles button, also a .gitignore #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions djsongmatch/fileDialogHelper.cpp
Original file line number Diff line number Diff line change
@@ -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 (*)"
);
}
16 changes: 16 additions & 0 deletions djsongmatch/fileDialogHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef FILEDIALOGHELPER_H
#define FILEDIALOGHELPER_H

#include <QObject>
#include <QString>
#include <QFileDialog>

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
21 changes: 19 additions & 2 deletions djsongmatch/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "fileDialogHelper.h"
#include <QMessageBox>

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);
}
}
8 changes: 8 additions & 0 deletions djsongmatch/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MAINWINDOW_H

#include <QMainWindow>
#include "filedialoghelper.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
Expand All @@ -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
27 changes: 25 additions & 2 deletions djsongmatch/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="browseFiles">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>80</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Browse Files</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
Expand Down