From: Max Lapan Date: Thu, 11 Mar 2010 16:39:02 +0000 (+0300) Subject: Settings dialog started. It is empty so far. X-Git-Tag: v0.1~45 X-Git-Url: http://vcs.maemo.org/git/?p=yandex-traffic;a=commitdiff_plain;h=ce812d6d505f1ec7367dd195acd3551ce1847691 Settings dialog started. It is empty so far. --- diff --git a/main.cpp b/main.cpp index c3e31ae..3c26806 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #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 (); diff --git a/mainwidget.cpp b/mainwidget.cpp index 160a8c0..20e5d58 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -1,7 +1,7 @@ #include #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 (); +} diff --git a/mainwidget.hpp b/mainwidget.hpp index 59aa5f2..fe41022 100644 --- a/mainwidget.hpp +++ b/mainwidget.hpp @@ -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 index 0000000..a64dd59 --- /dev/null +++ b/settingsDialog.cpp @@ -0,0 +1,12 @@ +#include +#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 index 0000000..8bee870 --- /dev/null +++ b/settingsDialog.hpp @@ -0,0 +1,17 @@ +#ifndef __SETTINGSDIALOG_H__ +#define __SETTINGSDIALOG_H__ + +#include + +#include "settings.hpp" + + +class SettingsDialog : public QDialog +{ + Q_OBJECT +public: + SettingsDialog (QWidget *parent, Settings *settings); +}; + + +#endif // __SETTINGSDIALOG_H__ diff --git a/yandex-traffic-gui.pri b/yandex-traffic-gui.pri index 347ffa2..7973229 100644 --- a/yandex-traffic-gui.pri +++ b/yandex-traffic-gui.pri @@ -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