Merge branch 'test/route'
authorToni Jussila <toni.jussila@fudeco.com>
Mon, 26 Apr 2010 07:34:20 +0000 (10:34 +0300)
committerToni Jussila <toni.jussila@fudeco.com>
Mon, 26 Apr 2010 07:34:20 +0000 (10:34 +0300)
Client/accelerometer.cpp
Client/accrealtimedialog.cpp
Client/accrealtimedialog.h
Client/custombutton.cpp [new file with mode: 0644]
Client/custombutton.h [new file with mode: 0644]
Client/mainwindow.cpp
Client/mainwindow.h
Client/resultdialog.cpp
Server/application/models/database_sample_data.sql

index c2f0bab..9bfd904 100644 (file)
@@ -15,7 +15,7 @@
 #include <QDBusPendingReply>
 
 #define kFilteringFactor 0.2
-#define kIterations      1024
+#define kIterations      100
 
 /**
  * Default constructor for Accelerometer class
index bf34104..fd5100f 100644 (file)
@@ -143,19 +143,22 @@ void AccRealTimeDialog::readAccelerometerData()
         if(!resultDialog)
         {
             resultDialog = new ResultDialog(this);
+            connect(resultDialog, SIGNAL(rejected()), this, SLOT(killResultDialog()));
+            connect(resultDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double)));
         }
-        connect(resultDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double)));
-        resultDialog->setEnd(stopMeasureSpeed);
-
-        //Put all times from all speeds
-        QMap<int,double> tempMap = calculate->getValuesMap();
-
-        for( int i = 1 ; i <= tempMap.count() ; i++ )
+        if(resultDialog)
         {
-            resultDialog->setValue(i*10,tempMap[i*10]);
+            resultDialog->setEnd(stopMeasureSpeed);
+            //Put all times from all speeds
+            QMap<int,double> tempMap = calculate->getValuesMap();
+
+            for( int i = 1 ; i <= tempMap.count() ; i++ )
+            {
+                resultDialog->setValue(i*10,tempMap[i*10]);
+            }
+            resultDialog->show();
+            this->hide();
         }
-        resultDialog->show();
-        this->hide();
     }
 }
 
@@ -210,3 +213,16 @@ void AccRealTimeDialog::sendResult(double result)
 {
     emit sendresult(result);
 }
+
+/**
+  *This slot function kills resultDialog.
+  *
+  **/
+void AccRealTimeDialog::killResultDialog()
+{
+    if(resultDialog)
+    {
+        delete resultDialog;
+        resultDialog = NULL;
+    }
+}
index c4dff1f..cc59593 100644 (file)
@@ -61,6 +61,7 @@ private slots:
     void on_buttonAbort_clicked();
     void readAccelerometerData();
     void sendResult(double);
+    void killResultDialog();
 
 signals:
     void sendresult(double);
diff --git a/Client/custombutton.cpp b/Client/custombutton.cpp
new file mode 100644 (file)
index 0000000..af023ad
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Custom button class for customized button.
+ *
+ * @author      Jukka Kurttila <jktla@suomi24.fi>
+ * @copyright   (c) 2010 Speed Freak team
+ * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
+ */
+
+#include "custombutton.h"
+
+#include <QPainter>
+#include <QIcon>
+
+/**
+  *Constructor of this class.
+  */
+CustomButton::CustomButton(QWidget *parent, QIcon *icon) : QWidget(parent)
+{
+    bPressed = false;
+    if( icon )
+    {
+        pict1 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::On));
+        pict2 = new QPixmap(icon->pixmap(125,125,QIcon::Normal,QIcon::Off));
+    }
+}
+/**
+  *Destructor of this class.
+  */
+CustomButton::~CustomButton()
+{
+    if(!pict1)
+        delete pict1;
+    if(!pict2)
+        delete pict2;
+}
+
+void CustomButton::paintEvent(QPaintEvent *)
+{
+    QPainter painter(this);
+
+    if(!bPressed)
+        painter.drawPixmap(0,0,*pict2);
+    else
+        painter.drawPixmap(0,0,*pict1);
+
+    //Debug print
+    //painter.drawText(50,50,"y: "+QString::number(mY));
+}
+void CustomButton::mousePressEvent(QMouseEvent* me)
+{
+    bPressed = true;
+    repaint();
+}
+void CustomButton::mouseReleaseEvent(QMouseEvent* me)
+{
+    mX = me->x();
+    mY = me->y();
+    //Emit open dialog signal if mouse is still over button
+    if( mY < this->height() && mY > 0 && mX < this->width() && mX > 0 )
+        emit OpenDialog();
+
+    bPressed = false;
+    repaint();
+}
+void CustomButton::mouseMoveEvent(QMouseEvent* me)
+{
+    mX = me->x();
+    mY = me->y();
+    //Is mouse moved outside button?
+    if( mY > this->height() || mY < 0 || mX > this->width() || mX < 0 )
+        bPressed = false;
+    else
+        bPressed = true;
+    repaint();
+}
diff --git a/Client/custombutton.h b/Client/custombutton.h
new file mode 100644 (file)
index 0000000..cad74ec
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Custom button class for customized button.
+ *
+ * @author      Jukka Kurttila <jktla@suomi24.fi>
+ * @copyright   (c) 2010 Speed Freak team
+ * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
+ */
+
+#ifndef CUSTOMBUTTON_H
+#define CUSTOMBUTTON_H
+
+#include <QPushButton>
+#include <QPixmap>
+#include <QMouseEvent>
+
+class CustomButton : public QWidget
+{
+    Q_OBJECT
+public:
+    CustomButton(QWidget *parent = 0, QIcon* iconParam = 0);
+    ~CustomButton();
+
+signals:
+    void OpenDialog();
+
+protected:
+    void paintEvent(QPaintEvent *);
+    void mousePressEvent(QMouseEvent* me);
+    void mouseReleaseEvent(QMouseEvent* me);
+    void mouseMoveEvent(QMouseEvent* me);
+
+private:
+    QPixmap* pict1;
+    QPixmap* pict2;
+    bool bPressed;
+    int mX,mY;
+};
+
+#endif // CUSTOMBUTTON_H
index 05fd9a7..bc32c76 100644 (file)
@@ -58,6 +58,20 @@ MainWindow::MainWindow(QWidget *parent) :
     ui->pushButtonWWW->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     ui->pushButtonCredits->setAutoFillBackground(true);
     ui->pushButtonCredits->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
+    /*
+    QIcon* icon = new QIcon();
+    icon->addFile(QString(":/new/prefix1/Graphics/Speedometer.png"), QSize(125,125), QIcon::Normal, QIcon::Off);
+    icon->addFile(QString(":/new/prefix1/Graphics/Speedometer2.png"), QSize(125,125), QIcon::Normal, QIcon::On);
+
+    customButtonAccelerate = new CustomButton(this,icon);
+    delete icon;
+
+    int buttons_x = 50,buttons_y = 165;
+    customButtonAccelerate->setGeometry(buttons_x,buttons_y,130,130);
+    connect(customButtonAccelerate, SIGNAL(OpenDialog()), this, SLOT(OpenAccStartDialog()));
+
+    customButtonAccelerate->show();
+    */
 }
 
 MainWindow::~MainWindow()
@@ -84,6 +98,10 @@ MainWindow::~MainWindow()
 
     if(helpDialog)
         delete helpDialog;
+/*
+    if(customButtonAccelerate)
+        delete customButtonAccelerate;
+*/
 }
 
 void MainWindow::changeEvent(QEvent *e)
@@ -114,6 +132,7 @@ void MainWindow::on_pushButtonCredits_clicked()
     if(!helpDialog)
         helpDialog = new HelpDialog;
 
+    connect(helpDialog, SIGNAL(rejected()), this, SLOT(killDialog()));
     helpDialog->show();
 }
 
@@ -323,3 +342,14 @@ void MainWindow::setUsernameToMainPanel()
         this->setWindowTitle("SpeedFreak - Not logged");
     }
 }
+/**
+  * This slot function opens acceleration start dialog.
+  */
+void MainWindow::OpenAccStartDialog()
+{
+    if(!accstart)
+        accstart = new accelerationstart(this);
+    connect(accstart, SIGNAL(sendresult(QString, double)), this, SLOT(clientSendResult(QString, double)));
+    connect(accstart, SIGNAL(rejected()), this, SLOT(killDialog()));
+    accstart->show();
+}
index 4a99582..3c1ae06 100644 (file)
@@ -26,6 +26,7 @@
 #include "routedialog.h"
 #include "resultdialog.h"
 #include "helpdialog.h"
+#include "custombutton.h"
 
 
 namespace Ui {
@@ -55,6 +56,8 @@ private:
     Ui::MainWindow *ui;
     void setListViewTopList(QString category, int size);
 
+    CustomButton* customButtonAccelerate;
+
 private slots:
     void on_pushButtonResults_clicked();
     void on_pushButtonAccelerate_clicked();
@@ -72,6 +75,7 @@ private slots:
     void showTop10();
     void killDialog();
     void setUsernameToMainPanel();
+    void OpenAccStartDialog();
 
 };
 
index 88171ab..37cf348 100644 (file)
@@ -315,6 +315,7 @@ void ResultDialog::on_pushButtonNew_clicked()
     }
     resultString = "";
     this->close();
+    emit rejected();
 }
 
 /**
index 4774b12..75f3775 100644 (file)
@@ -23,9 +23,9 @@ LOCK TABLES `categories` WRITE;
 /*!40000 ALTER TABLE `categories` DISABLE KEYS */;
 INSERT INTO `categories` (`id`,`slug`,`description`,`unit`)
 VALUES
-       (1,'acceleration-0-10','Acceleration from 0km/h to 100km/h','km/h'),
-       (2,'acceleration-0-40','Acceleration from 0km/h to 100km/h','km/h'),
-       (3,'acceleration-0-100','Acceleration from 0km/h to 100km/h','km/h');
+    (1,'acceleration-0-10','Acceleration from 0km/h to 10km/h','km/h'),
+    (2,'acceleration-0-40','Acceleration from 0km/h to 40km/h','km/h'),
+    (3,'acceleration-0-100','Acceleration from 0km/h to 100km/h','km/h');
 
 /*!40000 ALTER TABLE `categories` ENABLE KEYS */;
 UNLOCK TABLES;