From 3f50c821de14b8deab2374810bf974908e6681e8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 19 Mar 2014 18:46:42 +0200 Subject: [PATCH] Display the current time in the main window --- data/mainwindow.ui | 5 +++++ source/engineer/mainwindow.cpp | 14 ++++++++++++++ source/engineer/mainwindow.h | 2 ++ source/libr2c2/clock.cpp | 6 ++++++ source/libr2c2/clock.h | 4 ++++ source/libr2c2/layout.h | 2 +- 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/data/mainwindow.ui b/data/mainwindow.ui index e796913..30971f5 100644 --- a/data/mainwindow.ui +++ b/data/mainwindow.ui @@ -78,4 +78,9 @@ column { style "digital"; }; + + label "lbl_clock" + { + style "digital"; + }; }; diff --git a/source/engineer/mainwindow.cpp b/source/engineer/mainwindow.cpp index 5fdda1d..22c65d1 100644 --- a/source/engineer/mainwindow.cpp +++ b/source/engineer/mainwindow.cpp @@ -1,4 +1,6 @@ #include +#include +#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(get_item(widgets, "ind_off")); ind_halt = dynamic_cast(get_item(widgets, "ind_halt")); lbl_status = dynamic_cast(get_item(widgets, "lbl_status")); + lbl_clock = dynamic_cast(get_item(widgets, "lbl_clock")); dynamic_cast(get_item(widgets, "btn_on"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::on_clicked)); dynamic_cast(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)); +} diff --git a/source/engineer/mainwindow.h b/source/engineer/mainwindow.h index fcdb803..ec20795 100644 --- a/source/engineer/mainwindow.h +++ b/source/engineer/mainwindow.h @@ -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 diff --git a/source/libr2c2/clock.cpp b/source/libr2c2/clock.cpp index 5f87c44..890b2b2 100644 --- a/source/libr2c2/clock.cpp +++ b/source/libr2c2/clock.cpp @@ -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 diff --git a/source/libr2c2/clock.h b/source/libr2c2/clock.h index 0fa5f59..1c00158 100644 --- a/source/libr2c2/clock.h +++ b/source/libr2c2/clock.h @@ -1,12 +1,16 @@ #ifndef LIBR2C2_CLOCK_H_ #define LIBR2C2_CLOCK_H_ +#include #include namespace R2C2 { class Clock { +public: + sigc::signal signal_minute; + private: Msp::Time::TimeDelta current_time; float rate; diff --git a/source/libr2c2/layout.h b/source/libr2c2/layout.h index 498a45a..af06d4b 100644 --- a/source/libr2c2/layout.h +++ b/source/libr2c2/layout.h @@ -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 &); -- 2.43.0