3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include "libmarklin/driver.h"
11 #include "mainpanel.h"
12 #include "trainproperties.h"
17 MainPanel::MainPanel(Engineer &e, GLtk::Resources &r):
26 add(*(btn=new GLtk::Button(res, "Off")));
27 btn->set_geometry(GLtk::Geometry(10, 70, 40, 25));
28 btn->set_style("red");
29 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_off));
31 add(*(ind_off=new GLtk::Indicator(res)));
32 ind_off->set_geometry(GLtk::Geometry(10, 95, 40, 12));
33 ind_off->set_style("red");
35 add(*(btn=new GLtk::Button(res, "On")));
36 btn->set_geometry(GLtk::Geometry(50, 70, 40, 25));
37 btn->set_style("green");
38 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_on));
40 add(*(ind_on=new GLtk::Indicator(res)));
41 ind_on->set_geometry(GLtk::Geometry(50, 95, 40, 12));
42 ind_on->set_style("green");
44 add(*(btn=new GLtk::Button(res, "Halt")));
45 btn->set_geometry(GLtk::Geometry(90, 70, 40, 25));
46 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::toggle_halt));
48 add(*(ind_halt=new GLtk::Indicator(res)));
49 ind_halt->set_geometry(GLtk::Geometry(90, 95, 40, 12));
51 add(*(btn=new GLtk::Button(res, "Quit")));
52 btn->set_geometry(GLtk::Geometry(150, 70, 40, 25));
53 btn->set_style("red");
54 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::quit));
56 add(*(btn=new GLtk::Button(res, "+Loc")));
57 btn->set_geometry(GLtk::Geometry(10, 40, 40, 25));
58 btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::new_loc));
60 add(*(lbl_status=new GLtk::Label(res)));
61 lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 20));
62 lbl_status->set_style("digital");
64 Marklin::Driver &driver = engineer.get_layout().get_driver();
65 if(driver.get_power())
66 ind_on->set_active(true);
68 ind_off->set_active(true);
70 driver.signal_power.connect(sigc::mem_fun(this, &MainPanel::power_event));
71 driver.signal_halt.connect(sigc::mem_fun(this, &MainPanel::halt_event));
74 void MainPanel::set_status_text(const string &txt)
76 lbl_status->set_text(txt);
79 void MainPanel::power_on()
81 engineer.get_layout().get_driver().set_power(true);
84 void MainPanel::power_off()
86 engineer.get_layout().get_driver().set_power(false);
89 void MainPanel::toggle_halt()
91 Marklin::Driver &driver = engineer.get_layout().get_driver();
92 driver.halt(!driver.is_halted());
95 void MainPanel::new_loc()
97 TrainProperties *dialog = new TrainProperties(engineer, res, 0);
98 engineer.get_root().add(*dialog);
99 dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h);
100 dialog->set_visible(true);
103 void MainPanel::quit()
108 void MainPanel::power_event(bool p)
110 ind_on->set_active(p);
111 ind_off->set_active(!p);
114 void MainPanel::halt_event(bool h)
116 ind_halt->set_active(h);