diff options
author | Louie S <louie@example.com> | 2024-03-10 14:55:13 -0400 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-03-10 14:55:13 -0400 |
commit | 7a4c88bfc137f57293919473c9230d9a9eeebb45 (patch) | |
tree | 5b84a03eae581e6464ed527c4fc1e7701be06b13 /src | |
parent | ddee95158867554825092b9c29d8278320b93c61 (diff) |
Implemented preferencesDialog
Diffstat (limited to 'src')
-rw-r--r-- | src/assignmentList.cpp | 5 | ||||
-rw-r--r-- | src/preferencesDialog.cpp | 59 | ||||
-rw-r--r-- | src/preferencesDialog.h | 28 | ||||
-rw-r--r-- | src/preferencesDialog.ui | 4 |
4 files changed, 93 insertions, 3 deletions
diff --git a/src/assignmentList.cpp b/src/assignmentList.cpp index 0912031..75f524e 100644 --- a/src/assignmentList.cpp +++ b/src/assignmentList.cpp @@ -17,6 +17,7 @@ #include "backend/db_sqlite.h" #include "entryLayout.h" #include "groupLayout.h" +#include "preferencesDialog.h" #include "settings.h" AssignmentList::AssignmentList() { @@ -117,7 +118,9 @@ void AssignmentList::addGroup() { } void AssignmentList::preferences() { - qDebug() << "WIP"; + PreferencesDialog preferences_dialog; + if(preferences_dialog.exec() == QDialog::Accepted) + this->displayWidgets(); } void AssignmentList::reload() { diff --git a/src/preferencesDialog.cpp b/src/preferencesDialog.cpp new file mode 100644 index 0000000..d3b3dff --- /dev/null +++ b/src/preferencesDialog.cpp @@ -0,0 +1,59 @@ +#include <QFileDialog> +#include <QSettings> + +#include "preferencesDialog.h" + +PreferencesDialog::PreferencesDialog() { + // load uic + ui.setupUi(this); + + // display widgets + // TODO make this a scollable window + // FIXME could use some work on sizing + this->setupPathsTab(); + + // create button connections + QObject::connect(ui.close_button, &QPushButton::released, this, &PreferencesDialog::close); + QObject::connect(ui.apply_button, &QPushButton::released, this, &PreferencesDialog::apply); + QObject::connect(ui.reload_button, &QPushButton::released, this, &PreferencesDialog::reload); +} + +void PreferencesDialog::setupPathsTab() { + QSettings settings; + settings.beginGroup("paths"); + + ui.db_path_edit->setText(settings.value("db_path").toString()); + QObject::connect(ui.db_path_button, &QPushButton::released, this, &PreferencesDialog::dbPathDialog); +} + +void PreferencesDialog::dbPathDialog() { + QFileDialog file_dialog; + // TODO create filter to only allow selecting .db files + QString new_path = file_dialog.getOpenFileName(this, "Open File"); + + if(!new_path.isEmpty()) + ui.db_path_edit->setText(new_path); +} + +// close the dialog, returning our ret_value +void PreferencesDialog::close() { + this->done(ret_value); +} + +// update the configuration in the config file +void PreferencesDialog::apply() { + QSettings settings; + + // save paths + settings.beginGroup("paths"); + settings.setValue("db_path", ui.db_path_edit->text()); + + // set the return value to accepted + this->ret_value = QDialog::Accepted; +} + +// update, reload, and close the window +void PreferencesDialog::reload() { + this->apply(); + this->accept(); +} diff --git a/src/preferencesDialog.h b/src/preferencesDialog.h new file mode 100644 index 0000000..ac9b88e --- /dev/null +++ b/src/preferencesDialog.h @@ -0,0 +1,28 @@ +#ifndef PREFERENCESDIALOG_H +#define PREFERENCESDIALOG_H + +#include <QDialog> + +#include "ui_preferencesDialog.h" + +// set configuration options in the program +class PreferencesDialog : public QDialog { + Q_OBJECT + + public: + PreferencesDialog(); + + private: + Ui::preferencesDialog ui; + QDialog::DialogCode ret_value = QDialog::Rejected; + + void setupPathsTab(); + + private slots: + void dbPathDialog(); + void close(); + void apply(); + void reload(); +}; + +#endif diff --git a/src/preferencesDialog.ui b/src/preferencesDialog.ui index 244eb26..343ba33 100644 --- a/src/preferencesDialog.ui +++ b/src/preferencesDialog.ui @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> - <class>Dialog</class> - <widget class="QDialog" name="Dialog"> + <class>preferencesDialog</class> + <widget class="QDialog" name="preferencesDialog"> <property name="geometry"> <rect> <x>0</x> |