From: Daniel Klaffenbach Date: Sun, 31 Oct 2010 15:18:21 +0000 (+0100) Subject: Use QDialog instead of QWidget for Settings X-Git-Tag: v0.4.0~21 X-Git-Url: https://vcs.maemo.org/git/?p=qcpufreq;a=commitdiff_plain;h=ec1dcd3a4bc61d75bedeff148be3b17b2f5a5f4f Use QDialog instead of QWidget for Settings --- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 55e9c0b..8149779 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -74,7 +74,7 @@ MainWindow::MainWindow(QWidget *parent) : helpWindow.setWindowFlags( windowFlags() | Qt::Window ); //Settings widget - settings.setWindowFlags(Qt::Popup); + //settings.setWindowFlags(Qt::Popup); settings.hide(); //connect signals and slots diff --git a/src/mainwindow.h b/src/mainwindow.h index 8be058e..c8866a8 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -26,7 +26,7 @@ #include #include "helpwindow.h" -#include "settingswidget.h" +#include "settings.h" namespace Ui { class MainWindow; @@ -83,7 +83,7 @@ private: //! the QGraphicsScene will contain the large chip icon displayed in the UI QGraphicsScene scene; bool showSudoError; - SettingsWidget settings; + Settings settings; bool usePortrait(); }; diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..36b3e19 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,90 @@ +#include "settings.h" +#include "ui_settings.h" + +#include +#if defined(Q_WS_MAEMO_5) + #include +#endif + + +Settings::Settings(QWidget *parent) : + QDialog(parent), + settings("qcpufreq"), + ui(new Ui::Settings) +{ + ui->setupUi(this); + + //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->buttonBox, SIGNAL(accepted()), this, SLOT(save())); + connect(ui->checkBox_oc, SIGNAL(clicked()), this, SLOT(showOverclockingWarning())); +} + +Settings::~Settings() +{ + delete ui; +} + +/** + * Returns true if we are on a Maemo 5 OS. + */ +bool Settings::platformMaemo() +{ + #if defined(Q_WS_MAEMO_5) + return true; + #else + return false; + #endif +} + + +/** + * Resets the UI to the values stored by QSettings. + */ +void Settings::reset() +{ + ui->checkBox_rotate->setChecked(autoRotate); + ui->checkBox_oc->setChecked(overclocking); + ui->checkBox_temperature->setChecked(advancedTemperature); +} + + +/** + * Saves the changes and hides the SettingsWidget. + */ +void Settings::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(); +} + + +/** + * Displays a warning when overclocking is being enabled. + */ +void Settings::showOverclockingWarning() +{ + +#if defined(Q_WS_MAEMO_5) + QMaemo5InformationBox::information(this, tr( "Please note that overclocking voids your warranty and may break your device! Be careful!"), 0); +#else + QMessageBox::warning(this, tr("Warning"), tr("Please note that overclocking voids your warranty and may break your device! Be careful!")); +#endif + +} diff --git a/src/settings.h b/src/settings.h new file mode 100644 index 0000000..dcb29ca --- /dev/null +++ b/src/settings.h @@ -0,0 +1,33 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include +#include + +namespace Ui { + class Settings; +} + +class Settings : public QDialog +{ + Q_OBJECT + +public: + explicit Settings(QWidget *parent = 0); + ~Settings(); + bool platformMaemo(); + +public slots: + void reset(); + void save(); + void showOverclockingWarning(); + +private: + bool advancedTemperature; + bool autoRotate; + bool overclocking; + QSettings settings; + Ui::Settings *ui; +}; + +#endif // SETTINGS_H diff --git a/src/settings.ui b/src/settings.ui new file mode 100644 index 0000000..946f5f0 --- /dev/null +++ b/src/settings.ui @@ -0,0 +1,76 @@ + + + Settings + + + + 0 + 0 + 308 + 134 + + + + Dialog + + + + + + + + + + + Enable Overclocking + + + + + + + Enable Auto-rotate + + + + + + + Display more accurate temperature + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Save + + + + + + + + + + + buttonBox + rejected() + Settings + hide() + + + 153 + 107 + + + 153 + 66 + + + + + diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp deleted file mode 100644 index 96f4b10..0000000 --- a/src/settingswidget.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * QCPUFreq - a simple cpufreq GUI - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - - -#include "settingswidget.h" -#include "ui_settingswidget.h" - - -SettingsWidget::SettingsWidget(QWidget *parent) : - QWidget(parent), - settings("qcpufreq"), - ui(new Ui::SettingsWidget) -{ - ui->setupUi(this); - - //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; -} - - -/** - * 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 deleted file mode 100644 index a55c02d..0000000 --- a/src/settingswidget.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * QCPUFreq - a simple cpufreq GUI - * 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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef SETTINGSWIDGET_H -#define SETTINGSWIDGET_H - -#include -#include - -namespace Ui { - class SettingsWidget; -} - -class SettingsWidget : public QWidget -{ - Q_OBJECT - -public: - explicit SettingsWidget(QWidget *parent = 0); - ~SettingsWidget(); - -public slots: - void reset(); - void save(); - void showOverclockingWarning(); - -private: - bool advancedTemperature; - bool autoRotate; - bool overclocking; - QSettings settings; - Ui::SettingsWidget *ui; -}; - -#endif // SETTINGSWIDGET_H diff --git a/src/settingswidget.ui b/src/settingswidget.ui deleted file mode 100644 index cbc74c6..0000000 --- a/src/settingswidget.ui +++ /dev/null @@ -1,97 +0,0 @@ - - - SettingsWidget - - - - 0 - 0 - 355 - 130 - - - - Form - - - - - - - - - - - Enable Overclocking - - - - - - - Enable Auto-rotate - - - - - - - Display more accurate temperature - - - - - - - - - - - Save - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - Cancel - - - - - - - - - - - btn_cancel - clicked() - SettingsWidget - close() - - - 304 - 106 - - - 177 - 64 - - - - - diff --git a/src/src.pro b/src/src.pro index 42eb06b..46d77b3 100644 --- a/src/src.pro +++ b/src/src.pro @@ -13,15 +13,15 @@ TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ helpwindow.cpp \ - settingswidget.cpp + settings.cpp HEADERS += mainwindow.h \ helpwindow.h \ - settingswidget.h + settings.h FORMS += mainwindow.ui \ helpwindow.ui \ - settingswidget.ui + settings.ui TRANSLATIONS = de.ts zh.ts