From bf47d5bbecdbc098126fc5ca34481f44414cbd9f Mon Sep 17 00:00:00 2001 From: Daniel Klaffenbach Date: Sun, 31 Oct 2010 15:12:31 +0100 Subject: [PATCH] Add support for reading/saving config file --- src/mainwindow.cpp | 4 +++- src/settingswidget.cpp | 41 ++++++++++++++++++++++++++++++++++++++--- src/settingswidget.h | 7 ++++++- src/settingswidget.ui | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 996f106..55e9c0b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -73,6 +73,8 @@ MainWindow::MainWindow(QWidget *parent) : #endif helpWindow.setWindowFlags( windowFlags() | Qt::Window ); + //Settings widget + settings.setWindowFlags(Qt::Popup); settings.hide(); //connect signals and slots @@ -510,7 +512,7 @@ void MainWindow::showHelp() */ void MainWindow::showSettings() { - settings.setWindowFlags(Qt::Popup); + settings.reset(); settings.show(); } diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp index 0ac30d8..96f4b10 100644 --- a/src/settingswidget.cpp +++ b/src/settingswidget.cpp @@ -1,6 +1,6 @@ /* * QCPUFreq - a simple cpufreq GUI - * Copyright (C) 2010 Daniel Klaffenbach + * Copyright (C) 2010 Daniel Klaffenbach * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,19 +23,54 @@ SettingsWidget::SettingsWidget(QWidget *parent) : QWidget(parent), + settings("qcpufreq"), ui(new Ui::SettingsWidget) { ui->setupUi(this); - settings = new QSettings("qcpufreq"); + + //read values from config file + autoRotate = settings.value("main/autorotate", true).toBool(); + overclocking = settings.value("main/overclocking", false).toBool(); + advancedTemperature = settings.value("main/advanced_temperature", true).toBool(); + + //reset GUI + reset(); + + connect(ui->btn_save, SIGNAL(clicked()), this, SLOT(save())); } SettingsWidget::~SettingsWidget() { delete ui; - delete settings; } +/** + * Resets the UI to the values stored by QSettings. + */ void SettingsWidget::reset() { + ui->checkBox_rotate->setChecked(autoRotate); + ui->checkBox_oc->setChecked(overclocking); + ui->checkBox_temperature->setChecked(advancedTemperature); +} + + +/** + * Saves the changes and hides the SettingsWidget. + */ +void SettingsWidget::save() +{ + autoRotate = ui->checkBox_rotate->isChecked(); + overclocking = ui->checkBox_oc->isChecked(); + advancedTemperature = ui->checkBox_temperature->isChecked(); + + settings.setValue("main/autorotate", autoRotate); + settings.setValue("main/overclocking", overclocking); + settings.setValue("main/advanced_temperature", advancedTemperature); + + //save settings to file + settings.sync(); + + hide(); } diff --git a/src/settingswidget.h b/src/settingswidget.h index 80d1181..a55c02d 100644 --- a/src/settingswidget.h +++ b/src/settingswidget.h @@ -36,10 +36,15 @@ public: public slots: void reset(); + void save(); + void showOverclockingWarning(); private: + bool advancedTemperature; + bool autoRotate; + bool overclocking; + QSettings settings; Ui::SettingsWidget *ui; - QSettings *settings; }; #endif // SETTINGSWIDGET_H diff --git a/src/settingswidget.ui b/src/settingswidget.ui index afcd723..cbc74c6 100644 --- a/src/settingswidget.ui +++ b/src/settingswidget.ui @@ -29,7 +29,7 @@ - Enable Auto-rotation + Enable Auto-rotate -- 1.7.9.5