feat: remember volume

This commit is contained in:
Gary Wang 2024-10-21 00:40:34 +08:00
parent cf90e2d70c
commit a3bc60c977
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
3 changed files with 51 additions and 2 deletions

View File

@ -32,6 +32,7 @@
#include <QAudioDevice> #include <QAudioDevice>
#include <QMessageBox> #include <QMessageBox>
#include <QStringBuilder> #include <QStringBuilder>
#include <QSettings>
constexpr QSize miniSize(490, 160); constexpr QSize miniSize(490, 160);
constexpr QSize fullSize(490, 420); constexpr QSize fullSize(490, 420);
@ -57,10 +58,13 @@ MainWindow::MainWindow(QWidget *parent)
ui->actionHelp->setShortcut(QKeySequence::HelpContents); ui->actionHelp->setShortcut(QKeySequence::HelpContents);
addAction(ui->actionHelp); addAction(ui->actionHelp);
ui->actionOpen->setShortcut(QKeySequence::Open);
addAction(ui->actionOpen);
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint);
setAttribute(Qt::WA_TranslucentBackground, true); setAttribute(Qt::WA_TranslucentBackground, true);
loadConfig();
loadSkinData(); loadSkinData();
initConnections(); initConnections();
initUiAndAnimation(); initUiAndAnimation();
@ -70,6 +74,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
saveConfig();
delete m_lrcbar; delete m_lrcbar;
delete ui; 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() 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); bool canOpen = file.open(QIODevice::ReadOnly);
if (!canOpen) return; if (!canOpen) return;
QDataStream stream(&file); QDataStream stream(&file);
@ -609,6 +632,10 @@ void MainWindow::on_lrcBtn_clicked()
} }
} }
void MainWindow::on_actionOpen_triggered()
{
loadFile();
}
void MainWindow::on_actionHelp_triggered() void MainWindow::on_actionHelp_triggered()
{ {

View File

@ -76,6 +76,7 @@ private slots:
void on_playListBtn_clicked(); void on_playListBtn_clicked();
void on_playlistView_activated(const QModelIndex &index); void on_playlistView_activated(const QModelIndex &index);
void on_lrcBtn_clicked(); void on_lrcBtn_clicked();
void on_actionOpen_triggered();
void on_actionHelp_triggered(); void on_actionHelp_triggered();
signals: signals:
@ -101,6 +102,8 @@ private:
void initUiAndAnimation(); void initUiAndAnimation();
void initConnections(); void initConnections();
void loadConfig();
void saveConfig();
void loadSkinData(); void loadSkinData();
void saveSkinData(); void saveSkinData();

View File

@ -72,6 +72,7 @@ QSlider::add-page:vertical {
/****** PushButton ******/ /****** PushButton ******/
QPushButton { QPushButton {
color: white;
border: 0px solid grey; border: 0px solid grey;
background-color: transparent; background-color: transparent;
} }
@ -106,6 +107,7 @@ QLabel#coverLabel {
/****** ListView ******/ /****** ListView ******/
QListView { QListView {
color: white;
background: rgba(0, 0, 0, 50); background: rgba(0, 0, 0, 50);
}</string> }</string>
</property> </property>
@ -659,7 +661,10 @@ QListView {
</widget> </widget>
<action name="actionHelp"> <action name="actionHelp">
<property name="text"> <property name="text">
<string>help</string> <string>Help</string>
</property>
<property name="toolTip">
<string>Help</string>
</property> </property>
<property name="shortcut"> <property name="shortcut">
<string>F1</string> <string>F1</string>
@ -668,6 +673,20 @@ QListView {
<enum>QAction::MenuRole::NoRole</enum> <enum>QAction::MenuRole::NoRole</enum>
</property> </property>
</action> </action>
<action name="actionOpen">
<property name="icon">
<iconset theme="document-open"/>
</property>
<property name="text">
<string>Open</string>
</property>
<property name="shortcut">
<string>Ctrl+O</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>