1 #include <msp/gltk/button.h>
2 #include <msp/gltk/stack.h>
3 #include "libr2c2/layout.h"
4 #include "clockdialog.h"
5 #include "clockwidget.h"
12 ClockDialog::ClockDialog(Engineer &engineer):
13 DynamicDialog(engineer.get_user_interface()),
14 clock(engineer.get_layout().get_clock())
16 Loader::WidgetMap widgets;
17 DataFile::load(*this, "data/clockdialog.ui", widgets);
19 GLtk::Button *button = dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_rate"));
20 button->signal_clicked.connect(sigc::mem_fun(this, &ClockDialog::set_rate));
21 ent_rate = dynamic_cast<GLtk::Entry *>(get_item(widgets, "ent_rate"));
22 ent_rate->set_text(lexical_cast<string>(clock.get_rate()));
24 button = dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_stop"));
25 button->signal_clicked.connect(sigc::mem_fun(this, &ClockDialog::stop_clicked));
26 ind_stopped = dynamic_cast<GLtk::Indicator *>(get_item(widgets, "ind_stopped"));
27 ind_stopped->set_active(clock.is_stopped());
29 button = dynamic_cast<GLtk::Button *>(get_item(widgets, "btn_time"));
30 button->signal_clicked.connect(sigc::mem_fun(this, &ClockDialog::set_time));
31 ent_hour = dynamic_cast<GLtk::Entry *>(get_item(widgets, "ent_hour"));
32 ent_minute = dynamic_cast<GLtk::Entry *>(get_item(widgets, "ent_minute"));
34 GLtk::Stack stack(*layout);
35 stack.arrange(*get_item(widgets, "placeholder"));
36 add(*(new ClockWidget(clock)));
38 clock.signal_minute.connect(sigc::mem_fun(this, &ClockDialog::update_time));
39 clock.signal_discontinuity.connect(sigc::mem_fun(this, &ClockDialog::update_time));
43 void ClockDialog::update_time()
45 Time::TimeDelta time = clock.get_current_time();
46 unsigned hour = time/Time::hour;
47 unsigned minute = static_cast<unsigned>(time/Time::min)%60;
48 ent_hour->set_text(lexical_cast<string>(hour));
49 ent_minute->set_text(lexical_cast<string>(minute));
52 void ClockDialog::set_rate()
56 float rate = lexical_cast<float>(ent_rate->get_text());
59 catch(const lexical_error &e)
64 void ClockDialog::stop_clicked()
66 clock.stop(!clock.is_stopped());
67 ind_stopped->set_active(clock.is_stopped());
70 void ClockDialog::set_time()
74 unsigned hour = lexical_cast<unsigned>(ent_hour->get_text());
75 unsigned minute = lexical_cast<unsigned>(ent_minute->get_text());
76 clock.set_current_time(hour*Time::hour+minute*Time::min);
78 catch(const lexical_error &e)
83 bool ClockDialog::save_state(DataFile::Statement &st) const
85 st.keyword = "clockdialog";
86 save_position(st.sub);