]> git.tdb.fi Git - r2c2.git/commitdiff
Display the current time in the main window
authorMikko Rasa <tdb@tdb.fi>
Wed, 19 Mar 2014 16:46:42 +0000 (18:46 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 19 Mar 2014 20:21:03 +0000 (22:21 +0200)
data/mainwindow.ui
source/engineer/mainwindow.cpp
source/engineer/mainwindow.h
source/libr2c2/clock.cpp
source/libr2c2/clock.h
source/libr2c2/layout.h

index e7969131a05e71bd5a4c22effc53fbb328a81c89..30971f506e02659e09b8ab3c0b4c8d12ae9d54e2 100644 (file)
@@ -78,4 +78,9 @@ column
        {
                style "digital";
        };
+
+       label "lbl_clock"
+       {
+               style "digital";
+       };
 };
index 5fdda1d2a4d1c875a0281b44057bf07120be9451..22c65d11b2a53d000d1d0f7adb9029bf0a5306b8 100644 (file)
@@ -1,4 +1,6 @@
 #include <msp/gltk/button.h>
+#include <msp/strings/format.h>
+#include "libr2c2/clock.h"
 #include "libr2c2/driver.h"
 #include "engineer.h"
 #include "mainwindow.h"
@@ -17,6 +19,7 @@ MainWindow::MainWindow(Engineer &e):
        ind_off = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_off"));
        ind_halt = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_halt"));
        lbl_status = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_status"));
+       lbl_clock = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_clock"));
 
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_on"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::on_clicked));
        dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_off"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::off_clicked));
@@ -32,6 +35,8 @@ MainWindow::MainWindow(Engineer &e):
 
        driver.signal_power.connect(sigc::mem_fun(this, &MainWindow::power_event));
        driver.signal_halt.connect(sigc::mem_fun(this, &MainWindow::halt_event));
+
+       engineer.get_layout().get_clock().signal_minute.connect(sigc::mem_fun(this, &MainWindow::clock_minute));
 }
 
 void MainWindow::set_status_text(const string &txt)
@@ -76,3 +81,12 @@ void MainWindow::halt_event(bool h)
 {
        ind_halt->set_active(h);
 }
+
+void MainWindow::clock_minute()
+{
+       const Time::TimeDelta &time = engineer.get_layout().get_clock().get_current_time();
+       unsigned minute = time/Time::min;
+       unsigned hour = minute/60;
+       minute %= 60;
+       lbl_clock->set_text(format("%02d:%02d", hour, minute));
+}
index fcdb8034a7b592a60d22ff3cde60bb7af29b01d6..ec207958084a5d6c09aa0c438a897bfa781a8ed7 100644 (file)
@@ -16,6 +16,7 @@ private:
        Msp::GLtk::Indicator *ind_off;
        Msp::GLtk::Indicator *ind_halt;
        Msp::GLtk::Label *lbl_status;
+       Msp::GLtk::Label *lbl_clock;
 
 public:
        MainWindow(Engineer &);
@@ -29,6 +30,7 @@ private:
        void quit_clicked();
        void power_event(bool);
        void halt_event(bool);
+       void clock_minute();
 };
 
 #endif
index 5f87c44a90d6f38cc78c29e3377f91f2af798ce7..890b2b2cecb411bdd0b20728fadfe25951ed292a 100644 (file)
@@ -15,7 +15,13 @@ void Clock::set_rate(float s)
 
 void Clock::tick(const Time::TimeDelta &dt)
 {
+       unsigned prev_minute = current_time/Time::min;
        current_time += dt*rate;
+       if(current_time>=Time::day)
+               current_time -= Time::day;
+       unsigned minute = current_time/Time::min;
+       if(minute!=prev_minute)
+               signal_minute.emit();
 }
 
 } // namespace R2C2
index 0fa5f598f710b61ea7466d42f0cad50d093929f7..1c00158b5f4b65ea997cb195e06b05621d74ce19 100644 (file)
@@ -1,12 +1,16 @@
 #ifndef LIBR2C2_CLOCK_H_
 #define LIBR2C2_CLOCK_H_
 
+#include <sigc++/signal.h>
 #include <msp/time/timedelta.h>
 
 namespace R2C2 {
 
 class Clock
 {
+public:
+       sigc::signal<void> signal_minute;
+
 private:
        Msp::Time::TimeDelta current_time;
        float rate;
index 498a45a94f7552ba4c36ddf222e938765d919494..af06d4ba7eb017b81aaccd6343a8fd8206e01462 100644 (file)
@@ -98,7 +98,7 @@ public:
        Catalogue &get_catalogue() const { return catalogue; }
        bool has_driver() const { return driver; }
        Driver &get_driver() const;
-       const Clock &get_clock() const { return clock; }
+       Clock &get_clock() { return clock; }
        const std::string &get_base() const { return base; }
 
        void add(Object &);