Settings dialog started. It is empty so far.
authorMax Lapan <max.lapan@gmail.com>
Thu, 11 Mar 2010 16:39:02 +0000 (19:39 +0300)
committerMax Lapan <max.lapan@gmail.com>
Thu, 11 Mar 2010 16:39:02 +0000 (19:39 +0300)
main.cpp
mainwidget.cpp
mainwidget.hpp
settingsDialog.cpp [new file with mode: 0644]
settingsDialog.hpp [new file with mode: 0644]
yandex-traffic-gui.pri

index c3e31ae..3c26806 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,3 +1,4 @@
+#include <QtCore>
 #include "qmaemo5homescreenadaptor.h"
 #include "mainwidget.hpp"
 
@@ -9,6 +10,8 @@ int main(int argc, char *argv[])
     MainWidget w;
     QMaemo5HomescreenAdaptor *adaptor = new QMaemo5HomescreenAdaptor (&w);
 
+    w.connect (adaptor, SIGNAL (settingsRequested ()), SLOT (settingsDialog ()));
+
     adaptor->setSettingsAvailable (true);
 
     w.show ();
index 160a8c0..20e5d58 100644 (file)
@@ -1,7 +1,7 @@
 #include <QtGui>
 
 #include "mainwidget.hpp"
-
+#include "settingsDialog.hpp"
 
 
 // --------------------------------------------------
@@ -17,46 +17,57 @@ MainWidget::MainWidget ()
     _light = new TrafficLight (this);
     _label = new QLabel (this);
 
+    _traffic = new Traffic;
+    _regions = new RegionsTable;
+    _settings = new Settings;
+
     QHBoxLayout *layout = new QHBoxLayout;
     layout->addWidget (_light);
     layout->addWidget (_label);
     setLayout (layout);
 
-    connect (&_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
+    connect (_traffic, SIGNAL (updated ()), SLOT (trafficUpdated ()));
 
     // every 5 minutes (TODO, make option)
     startTimer (5*60*1000);
 
-    // perform update just after creation
-    _traffic.update ();
+    updateData ();
 }
 
 
+MainWidget::~MainWidget ()
+{
+    delete _traffic;
+    delete _regions;
+    delete _settings;
+
+    delete _light;
+    delete _label;
+}
+
 
 void MainWidget::paintEvent(QPaintEvent *event)
 {
     QPainter p(this);
-    p.setBrush(QColor(0, 0, 0, 128));
-    p.setPen(Qt::NoPen);
-    p.drawRoundedRect(rect(), 10, 10);
-    p.end();
+    p.setBrush (QColor(0, 0, 0, 128));
+    p.setPen (Qt::NoPen);
+    p.drawRoundedRect (rect(), 10, 10);
+    p.end ();
 
-    QWidget::paintEvent(event);
+    QWidget::paintEvent (event);
 }
 
 
 void MainWidget::timerEvent (QTimerEvent *)
 {
-    // Perform traffic information refresh
-    // TODO: only if internet connection is available
-    _traffic.update ();
+    updateData ();
 }
 
 
 
 void MainWidget::trafficUpdated ()
 {
-    ExtendedTrafficInfo info = _traffic.lookup_ext ("1");
+    ExtendedTrafficInfo info = _traffic->lookup_ext ("1");
 
     if (info.valid ()) {
         _light->setColor (info.color ());
@@ -68,3 +79,18 @@ void MainWidget::trafficUpdated ()
     else
         _light->setColor (ExtendedTrafficInfo::Unknown);
 }
+
+
+void MainWidget::updateData ()
+{
+    // Here we need to check for internet connection
+    _traffic->update ();
+}
+
+
+void MainWidget::settingsDialog ()
+{
+    SettingsDialog dlg (this, _settings);
+
+    dlg.exec ();
+}
index 59aa5f2..fe41022 100644 (file)
@@ -13,21 +13,27 @@ class MainWidget : public QWidget
 {
     Q_OBJECT
 private:
-    Traffic _traffic;
-    RegionsTable _regions;
-    Settings _settings;
+    Traffic* _traffic;
+    RegionsTable* _regions;
+    Settings* _settings;
 
     // Widgets
-    TrafficLight *_light;
-    QLabel *_label;
+    TrafficLight* _light;
+    QLabel* _label;
 
 public:
     MainWidget ();
+    virtual ~MainWidget ();
+
+public slots:
+    void settingsDialog ();
 
 protected:
     void paintEvent (QPaintEvent *event);
     void timerEvent (QTimerEvent *event);
 
+    void updateData ();
+
 protected slots:
     void trafficUpdated ();
 };
diff --git a/settingsDialog.cpp b/settingsDialog.cpp
new file mode 100644 (file)
index 0000000..a64dd59
--- /dev/null
@@ -0,0 +1,12 @@
+#include <QtGui>
+#include "settingsDialog.hpp"
+
+
+// --------------------------------------------------
+// SettingsDialog
+// --------------------------------------------------
+SettingsDialog::SettingsDialog (QWidget *parent, Settings *settings)
+    : QDialog (parent)
+{
+    setWindowTitle (tr ("Settings"));
+}
diff --git a/settingsDialog.hpp b/settingsDialog.hpp
new file mode 100644 (file)
index 0000000..8bee870
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef __SETTINGSDIALOG_H__
+#define __SETTINGSDIALOG_H__
+
+#include <QtGui>
+
+#include "settings.hpp"
+
+
+class SettingsDialog : public QDialog
+{
+    Q_OBJECT
+public:
+    SettingsDialog (QWidget *parent, Settings *settings);
+};
+
+
+#endif // __SETTINGSDIALOG_H__
index 347ffa2..7973229 100644 (file)
@@ -1,5 +1,5 @@
-HEADERS += $$PWD/mainwidget.hpp $$PWD/light.hpp
-SOURCES += $$PWD/mainwidget.cpp $$PWD/light.cpp
+HEADERS += $$PWD/mainwidget.hpp $$PWD/light.hpp $$PWD/settingsDialog.hpp
+SOURCES += $$PWD/mainwidget.cpp $$PWD/light.cpp $$PWD/settingsDialog.cpp
 
 QT += network xml