From a3bc60c9771d552eb0d505716a5b77b6344f94c0 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Mon, 21 Oct 2024 00:40:34 +0800 Subject: [PATCH] feat: remember volume --- mainwindow.cpp | 29 ++++++++++++++++++++++++++++- mainwindow.h | 3 +++ mainwindow.ui | 21 ++++++++++++++++++++- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 28c4262..90bb15c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -32,6 +32,7 @@ #include #include #include +#include constexpr QSize miniSize(490, 160); constexpr QSize fullSize(490, 420); @@ -57,10 +58,13 @@ MainWindow::MainWindow(QWidget *parent) ui->actionHelp->setShortcut(QKeySequence::HelpContents); addAction(ui->actionHelp); + ui->actionOpen->setShortcut(QKeySequence::Open); + addAction(ui->actionOpen); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); setAttribute(Qt::WA_TranslucentBackground, true); + loadConfig(); loadSkinData(); initConnections(); initUiAndAnimation(); @@ -70,6 +74,7 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { + saveConfig(); delete m_lrcbar; delete ui; } @@ -531,9 +536,27 @@ void MainWindow::initConnections() }); } +void MainWindow::loadConfig() +{ + QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + QSettings settings(configDir.filePath("settings.ini"), QSettings::IniFormat); + ui->volumeSlider->setValue(settings.value("volume", 100).toInt()); +} + +void MainWindow::saveConfig() +{ + QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + if (!configDir.exists()) { + configDir.mkpath("."); + } + QSettings settings(configDir.filePath("settings.ini"), QSettings::IniFormat); + settings.setValue("volume", ui->volumeSlider->value()); +} + void MainWindow::loadSkinData() { - QFile file(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/skin.dat"); + QDir configDir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + QFile file(configDir.filePath("skin.dat")); bool canOpen = file.open(QIODevice::ReadOnly); if (!canOpen) return; QDataStream stream(&file); @@ -609,6 +632,10 @@ void MainWindow::on_lrcBtn_clicked() } } +void MainWindow::on_actionOpen_triggered() +{ + loadFile(); +} void MainWindow::on_actionHelp_triggered() { diff --git a/mainwindow.h b/mainwindow.h index 86e68fe..479a608 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -76,6 +76,7 @@ private slots: void on_playListBtn_clicked(); void on_playlistView_activated(const QModelIndex &index); void on_lrcBtn_clicked(); + void on_actionOpen_triggered(); void on_actionHelp_triggered(); signals: @@ -101,6 +102,8 @@ private: void initUiAndAnimation(); void initConnections(); + void loadConfig(); + void saveConfig(); void loadSkinData(); void saveSkinData(); diff --git a/mainwindow.ui b/mainwindow.ui index 159905a..e869eaf 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -72,6 +72,7 @@ QSlider::add-page:vertical { /****** PushButton ******/ QPushButton { + color: white; border: 0px solid grey; background-color: transparent; } @@ -106,6 +107,7 @@ QLabel#coverLabel { /****** ListView ******/ QListView { + color: white; background: rgba(0, 0, 0, 50); } @@ -659,7 +661,10 @@ QListView { - help + Help + + + Help F1 @@ -668,6 +673,20 @@ QListView { QAction::MenuRole::NoRole + + + + + + Open + + + Ctrl+O + + + QAction::MenuRole::NoRole + +