Prepared SmartReflex support, UI improvements
authorDaniel Klaffenbach <danielklaffenbach@gmail.com>
Tue, 22 Jun 2010 13:34:56 +0000 (15:34 +0200)
committerDaniel Klaffenbach <danielklaffenbach@gmail.com>
Tue, 22 Jun 2010 13:34:56 +0000 (15:34 +0200)
src/data/128x128/chip.png [new file with mode: 0644]
src/data/256x256/chip.png [new file with mode: 0644]
src/data/scripts/set_scalingmaxfreq
src/data/scripts/set_sr [new file with mode: 0755]
src/data/sudoers/qcpufreq.sudoers
src/mainwindow.cpp
src/mainwindow.h
src/mainwindow.ui
src/resources.qrc [new file with mode: 0644]
src/src.pro

diff --git a/src/data/128x128/chip.png b/src/data/128x128/chip.png
new file mode 100644 (file)
index 0000000..6eec603
Binary files /dev/null and b/src/data/128x128/chip.png differ
diff --git a/src/data/256x256/chip.png b/src/data/256x256/chip.png
new file mode 100644 (file)
index 0000000..061278f
Binary files /dev/null and b/src/data/256x256/chip.png differ
index 7f441ae..3bd645b 100755 (executable)
@@ -1,4 +1,8 @@
 #!/bin/sh
+#
+# This script is part of QCPUFreq
+# (c)2010 Daniel Klaffenbach
+
 if [ -z $1 ]; then
        echo "Usage: $0 maxfreq"
        exit
diff --git a/src/data/scripts/set_sr b/src/data/scripts/set_sr
new file mode 100755 (executable)
index 0000000..55e9b7e
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# This script is part of QCPUFreq
+# (c)2010 Daniel Klaffenbach
+
+if [ -z $1 ]; then
+       echo "Usage: $0 on|off"
+       exit
+fi
+
+if [ $1 == 'on' ]; then
+       echo 1 > /sys/power/sr_vdd1_autocomp
+       echo 1 > /sys/power/sr_vdd2_autocomp
+else
+       echo 0 > /sys/power/sr_vdd1_autocomp
+       echo 0 > /sys/power/sr_vdd2_autocomp
+fi
index 98d9239..cd047d6 100755 (executable)
@@ -1 +1,2 @@
 user ALL = NOPASSWD: /opt/usr/bin/set_scalingmaxfreq
+user ALL = NOPASSWD: /opt/usr/bin/set_sr
index e62fac5..e33d4d5 100755 (executable)
@@ -23,6 +23,7 @@
 #include <QMessageBox>
 #include <QTextStream>
 #include <QProcess>
+#include <QDesktopWidget>
 
 
 #define APPNAME "QCPUFreq"
@@ -35,17 +36,24 @@ MainWindow::MainWindow(QWidget *parent) :
     ui->setupUi(this);
     refresh();
 
-       // enable auto rotation
-       setAutoRotaion();
+    // enable auto rotation
+    setAutoRotaion();
+
+    //create a QGraphicsScene for the little chip icon
+    scene = new QGraphicsScene();
+    orientationChanged();
 
     //connect signals and slots
     connect( ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()) );
     connect( ui->freq_adjust, SIGNAL(valueChanged(int)), this, SLOT(adjustFreq()) );
+    connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(orientationChanged()));
+
 }
 
 MainWindow::~MainWindow()
 {
     delete ui;
+    delete scene;
 }
 
 /**
@@ -169,6 +177,10 @@ QString MainWindow::readScalingFile(QString scaling_file)
     return txt;
 }
 
+
+/**
+  * Refreshes all of the values to display
+  */
 void MainWindow::refresh()
 {
     //get the current frequency and calculate the MHz value
@@ -195,10 +207,55 @@ void MainWindow::refresh()
     ui->freq_adjust->setSliderPosition( getScalingStep(getMaxFreq()) );
 }
 
+
+/**
+  * Repaints part of the GUI after the device was rotated
+  */
+void MainWindow::orientationChanged()
+{
+    QPixmap image;
+
+    //check whether we are using portrait or landscape mode
+    if ( usePortrait() ) {
+       //in portrait mode we want to display the large image
+       image.load( ":/img/chip256" );
+       this->scene->clear();
+       this->scene->addPixmap(  image  );
+
+       ui->graphicsPortrait->setScene( this->scene );
+       ui->graphicsPortrait->setMaximumSize( 256, 256 );
+       ui->graphicsLandscape->setMaximumSize( 0, 0 );
+    } else {
+       image.load( ":/img/chip128" );
+       this->scene->clear();
+       this->scene->addPixmap(  image  );
+
+       ui->graphicsLandscape->setScene( this->scene );
+       ui->graphicsLandscape->setMaximumSize( 128, 128 );
+       ui->graphicsPortrait->setMaximumSize( 0, 0 );
+    }
+}
+
+
+/**
+  * Enables the auto-rotation feature of Maemo5 devices
+  */
 void MainWindow::setAutoRotaion()
 {
 #if defined(Q_WS_MAEMO_5)
     setAttribute(Qt::WA_Maemo5AutoOrientation, true);
-    //setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
 #endif
 }
+
+
+/**
+  * Returns true when the device is in portrait mode
+  */
+bool MainWindow::usePortrait()
+{
+    QRect screenGeometry = QApplication::desktop()->screenGeometry();
+    if (screenGeometry.width() > screenGeometry.height())
+       return false;
+    else
+       return true;
+}
index 392066c..c15ab45 100755 (executable)
@@ -20,6 +20,7 @@
 #define MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QGraphicsScene>
 
 namespace Ui {
     class MainWindow;
@@ -36,12 +37,14 @@ public:
 public slots:
     void about();
     void adjustFreq();
+    void orientationChanged();
     void setAutoRotaion();
     void refresh();
 
 
 private:
     Ui::MainWindow *ui;
+    QGraphicsScene *scene;
     QString readScalingFile( QString scaling_file );
     int getCurFreq();
     int getMaxFreq();
@@ -50,6 +53,7 @@ private:
     QString getScalingGovernor();
     int getScalingSteps();
     int getScalingStep( int freq );
+    bool usePortrait();
 };
 
 #endif // MAINWINDOW_H
index e6f8dbf..65a4fd8 100755 (executable)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>616</width>
-    <height>469</height>
+    <width>699</width>
+    <height>619</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -19,7 +19,7 @@
   <widget class="QWidget" name="centralWidget">
    <layout class="QGridLayout" name="gridLayout_2">
     <item row="0" column="0">
-     <layout class="QVBoxLayout" name="verticalLayout_2">
+     <layout class="QVBoxLayout" name="verticalLayout_3">
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
             </property>
            </widget>
           </item>
+          <item row="3" column="0">
+           <widget class="QLabel" name="label_5">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="text">
+             <string>SmartReflex™:</string>
+            </property>
+           </widget>
+          </item>
+          <item row="3" column="1">
+           <widget class="QPushButton" name="sr_btn">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="text">
+             <string>Disabled</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <layout class="QVBoxLayout" name="verticalLayout_2">
+          <item>
+           <spacer name="verticalSpacer_3">
+            <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="QGraphicsView" name="graphicsLandscape">
+            <property name="sizePolicy">
+             <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+              <horstretch>0</horstretch>
+              <verstretch>0</verstretch>
+             </sizepolicy>
+            </property>
+            <property name="minimumSize">
+             <size>
+              <width>0</width>
+              <height>0</height>
+             </size>
+            </property>
+            <property name="maximumSize">
+             <size>
+              <width>128</width>
+              <height>128</height>
+             </size>
+            </property>
+            <property name="baseSize">
+             <size>
+              <width>0</width>
+              <height>0</height>
+             </size>
+            </property>
+            <property name="autoFillBackground">
+             <bool>false</bool>
+            </property>
+            <property name="styleSheet">
+             <string notr="true">background: transparent;</string>
+            </property>
+            <property name="frameShape">
+             <enum>QFrame::NoFrame</enum>
+            </property>
+            <property name="lineWidth">
+             <number>0</number>
+            </property>
+            <property name="verticalScrollBarPolicy">
+             <enum>Qt::ScrollBarAlwaysOff</enum>
+            </property>
+            <property name="horizontalScrollBarPolicy">
+             <enum>Qt::ScrollBarAlwaysOff</enum>
+            </property>
+            <property name="interactive">
+             <bool>true</bool>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <spacer name="verticalSpacer_2">
+            <property name="orientation">
+             <enum>Qt::Vertical</enum>
+            </property>
+            <property name="sizeHint" stdset="0">
+             <size>
+              <width>20</width>
+              <height>18</height>
+             </size>
+            </property>
+           </spacer>
+          </item>
          </layout>
         </item>
+       </layout>
+      </item>
+      <item>
+       <spacer name="verticalSpacer_4">
+        <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>
+       <layout class="QHBoxLayout" name="horizontalLayout_2">
         <item>
          <spacer name="horizontalSpacer">
           <property name="orientation">
           </property>
          </spacer>
         </item>
+        <item>
+         <widget class="QGraphicsView" name="graphicsPortrait">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="minimumSize">
+           <size>
+            <width>0</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="maximumSize">
+           <size>
+            <width>128</width>
+            <height>128</height>
+           </size>
+          </property>
+          <property name="baseSize">
+           <size>
+            <width>0</width>
+            <height>0</height>
+           </size>
+          </property>
+          <property name="autoFillBackground">
+           <bool>false</bool>
+          </property>
+          <property name="styleSheet">
+           <string notr="true">background: transparent;</string>
+          </property>
+          <property name="frameShape">
+           <enum>QFrame::NoFrame</enum>
+          </property>
+          <property name="lineWidth">
+           <number>0</number>
+          </property>
+          <property name="verticalScrollBarPolicy">
+           <enum>Qt::ScrollBarAlwaysOff</enum>
+          </property>
+          <property name="horizontalScrollBarPolicy">
+           <enum>Qt::ScrollBarAlwaysOff</enum>
+          </property>
+          <property name="interactive">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="horizontalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>40</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
        </layout>
       </item>
       <item>
         <property name="sizeHint" stdset="0">
          <size>
           <width>20</width>
-          <height>40</height>
+          <height>68</height>
          </size>
         </property>
        </spacer>
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>616</width>
+     <width>699</width>
      <height>21</height>
     </rect>
    </property>
diff --git a/src/resources.qrc b/src/resources.qrc
new file mode 100644 (file)
index 0000000..2a61cb1
--- /dev/null
@@ -0,0 +1,6 @@
+<RCC>
+    <qresource prefix="/img">
+        <file alias="chip128">data/128x128/chip.png</file>
+        <file alias="chip256">data/256x256/chip.png</file>
+    </qresource>
+</RCC>
index 7acf4c0..6be15f4 100755 (executable)
@@ -39,7 +39,7 @@ unix {
 
        #MAKE INSTALL
 
-       INSTALLS += target helper sudoers desktop icon48 icon64
+       INSTALLS += target helper sudoers desktop icon48 icon64 helper_sr
        target.path =$$BINDIR
 
        desktop.path = /usr/share/applications/hildon
@@ -55,6 +55,13 @@ unix {
        helper.files += data/scripts/set_scalingmaxfreq
        helper.permissions = 755
 
+       helper_sr.path = $$BINDIR/
+       helper_sr.files += data/scripts/set_sr
+       helper_sr.permissions = 755
+
        sudoers.path = /etc/sudoers.d/
        sudoers.files += data/sudoers/qcpufreq.sudoers
 }
+
+RESOURCES += \
+    resources.qrc