Use QDialog instead of QWidget for Settings
authorDaniel Klaffenbach <danielklaffenbach@gmail.com>
Sun, 31 Oct 2010 15:18:21 +0000 (16:18 +0100)
committerDaniel Klaffenbach <danielklaffenbach@gmail.com>
Sun, 31 Oct 2010 15:18:21 +0000 (16:18 +0100)
src/mainwindow.cpp
src/mainwindow.h
src/settings.cpp [new file with mode: 0644]
src/settings.h [new file with mode: 0644]
src/settings.ui [new file with mode: 0644]
src/settingswidget.cpp [deleted file]
src/settingswidget.h [deleted file]
src/settingswidget.ui [deleted file]
src/src.pro

index 55e9c0b..8149779 100644 (file)
@@ -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
index 8be058e..c8866a8 100644 (file)
@@ -26,7 +26,7 @@
 #include <QStringList>
 
 #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 (file)
index 0000000..36b3e19
--- /dev/null
@@ -0,0 +1,90 @@
+#include "settings.h"
+#include "ui_settings.h"
+
+#include <QMessageBox>
+#if defined(Q_WS_MAEMO_5)
+    #include <QMaemo5InformationBox>
+#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 (file)
index 0000000..dcb29ca
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <QDialog>
+#include <QSettings>
+
+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 (file)
index 0000000..946f5f0
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Settings</class>
+ <widget class="QDialog" name="Settings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>308</width>
+    <height>134</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <property name="locale">
+   <locale language="English" country="UnitedStates"/>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QCheckBox" name="checkBox_oc">
+       <property name="text">
+        <string>Enable Overclocking</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="checkBox_rotate">
+       <property name="text">
+        <string>Enable Auto-rotate</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QCheckBox" name="checkBox_temperature">
+       <property name="text">
+        <string>Display more accurate temperature</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QDialogButtonBox" name="buttonBox">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="standardButtons">
+        <set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>Settings</receiver>
+   <slot>hide()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>153</x>
+     <y>107</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>153</x>
+     <y>66</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/src/settingswidget.cpp b/src/settingswidget.cpp
deleted file mode 100644 (file)
index 96f4b10..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * QCPUFreq - a simple cpufreq GUI
- * Copyright (C) 2010 Daniel Klaffenbach <danielklaffenbach@gmail.com>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-
-#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 (file)
index a55c02d..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * QCPUFreq - a simple cpufreq GUI
- * Copyright (C) 2010 Daniel Klaffenbach <danielklaffenbach@gmail.com>
- *
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-#ifndef SETTINGSWIDGET_H
-#define SETTINGSWIDGET_H
-
-#include <QWidget>
-#include <QSettings>
-
-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 (file)
index cbc74c6..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>SettingsWidget</class>
- <widget class="QWidget" name="SettingsWidget">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>355</width>
-    <height>130</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string>Form</string>
-  </property>
-  <property name="locale">
-   <locale language="English" country="UnitedStates"/>
-  </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0">
-    <layout class="QVBoxLayout" name="verticalLayout">
-     <item>
-      <widget class="QCheckBox" name="checkBox_oc">
-       <property name="text">
-        <string>Enable Overclocking</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QCheckBox" name="checkBox_rotate">
-       <property name="text">
-        <string>Enable Auto-rotate</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <widget class="QCheckBox" name="checkBox_temperature">
-       <property name="text">
-        <string>Display more accurate temperature</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-   <item row="0" column="1">
-    <layout class="QVBoxLayout" name="verticalLayout_2">
-     <item>
-      <widget class="QPushButton" name="btn_save">
-       <property name="text">
-        <string>Save</string>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer name="verticalSpacer">
-       <property name="orientation">
-        <enum>Qt::Vertical</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>20</width>
-         <height>40</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="btn_cancel">
-       <property name="text">
-        <string>Cancel</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-  </layout>
- </widget>
- <resources/>
- <connections>
-  <connection>
-   <sender>btn_cancel</sender>
-   <signal>clicked()</signal>
-   <receiver>SettingsWidget</receiver>
-   <slot>close()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>304</x>
-     <y>106</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>177</x>
-     <y>64</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
-</ui>
index 42eb06b..46d77b3 100644 (file)
@@ -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