1 #include <msp/gltk/button.h>
2 #include <msp/strings/format.h>
3 #include "libr2c2/clock.h"
4 #include "libr2c2/driver.h"
6 #include "mainwindow.h"
7 #include "trainlistdialog.h"
12 MainWindow::MainWindow(Engineer &e):
15 Loader::WidgetMap widgets;
16 DataFile::load(*this, "data/mainwindow.ui", widgets);
18 ind_on = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_on"));
19 ind_off = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_off"));
20 ind_halt = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_halt"));
21 lbl_status = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_status"));
22 lbl_clock = dynamic_cast<GLtk::Label *>(get_item(widgets, "lbl_clock"));
24 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_on"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::on_clicked));
25 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_off"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::off_clicked));
26 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_halt"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::halt_clicked));
27 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_trains"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::trains_clicked));
28 dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_quit"))->signal_clicked.connect(sigc::mem_fun(this, &MainWindow::quit_clicked));
30 R2C2::Driver &driver = engineer.get_layout().get_driver();
31 if(driver.get_power())
32 ind_on->set_active(true);
34 ind_off->set_active(true);
36 driver.signal_power.connect(sigc::mem_fun(this, &MainWindow::power_event));
37 driver.signal_halt.connect(sigc::mem_fun(this, &MainWindow::halt_event));
39 engineer.get_layout().get_clock().signal_minute.connect(sigc::mem_fun(this, &MainWindow::clock_minute));
42 void MainWindow::set_status_text(const string &txt)
44 lbl_status->set_text(txt);
47 void MainWindow::on_clicked()
49 engineer.get_layout().get_driver().set_power(true);
52 void MainWindow::off_clicked()
54 engineer.get_layout().get_driver().set_power(false);
57 void MainWindow::halt_clicked()
59 R2C2::Driver &driver = engineer.get_layout().get_driver();
60 driver.halt(!driver.is_halted());
63 void MainWindow::trains_clicked()
65 TrainListDialog *dlg = new TrainListDialog(engineer);
66 find_ancestor<GLtk::Root>()->add(*dlg);
69 void MainWindow::quit_clicked()
74 void MainWindow::power_event(bool p)
76 ind_on->set_active(p);
77 ind_off->set_active(!p);
80 void MainWindow::halt_event(bool h)
82 ind_halt->set_active(h);
85 void MainWindow::clock_minute()
87 const Time::TimeDelta &time = engineer.get_layout().get_clock().get_current_time();
88 unsigned minute = time/Time::min;
89 unsigned hour = minute/60;
91 lbl_clock->set_text(format("%02d:%02d", hour, minute));