X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Fmainpanel.cpp;h=2083e7c30940abaf225f58aafb38cf083791161a;hb=2029c5e4220e0809a39744a28ca9e2ff22e8ad28;hp=c89060a4416b77145337de2f2bffd743493cb6e3;hpb=aead7f2da831199fbb8f6950b067656b2965c2fa;p=r2c2.git diff --git a/source/engineer/mainpanel.cpp b/source/engineer/mainpanel.cpp index c89060a..2083e7c 100644 --- a/source/engineer/mainpanel.cpp +++ b/source/engineer/mainpanel.cpp @@ -1,53 +1,74 @@ +/* $Id$ + +This file is part of the MSP Märklin suite +Copyright © 2006-2010 Mikkosoft Productions, Mikko Rasa +Distributed under the GPL +*/ + #include +#include "libmarklin/driver.h" #include "engineer.h" #include "mainpanel.h" +#include "trainproperties.h" using namespace std; using namespace Msp; MainPanel::MainPanel(Engineer &e, GLtk::Resources &r): + Widget(r), Panel(r), engineer(e) { - set_size(200, 100); + set_size(200, 117); GLtk::Button *btn; add(*(btn=new GLtk::Button(res, "Off"))); - btn->set_geometry(GLtk::Geometry(10, 53, 40, 25)); + btn->set_geometry(GLtk::Geometry(10, 70, 40, 25)); btn->set_style("red"); btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_off)); add(*(ind_off=new GLtk::Indicator(res))); - ind_off->set_geometry(GLtk::Geometry(10, 78, 40, 12)); + ind_off->set_geometry(GLtk::Geometry(10, 95, 40, 12)); ind_off->set_style("red"); add(*(btn=new GLtk::Button(res, "On"))); - btn->set_geometry(GLtk::Geometry(50, 53, 40, 25)); + btn->set_geometry(GLtk::Geometry(50, 70, 40, 25)); btn->set_style("green"); btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::power_on)); add(*(ind_on=new GLtk::Indicator(res))); - ind_on->set_geometry(GLtk::Geometry(50, 78, 40, 12)); + ind_on->set_geometry(GLtk::Geometry(50, 95, 40, 12)); ind_on->set_style("green"); + add(*(btn=new GLtk::Button(res, "Halt"))); + btn->set_geometry(GLtk::Geometry(90, 70, 40, 25)); + btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::toggle_halt)); + + add(*(ind_halt=new GLtk::Indicator(res))); + ind_halt->set_geometry(GLtk::Geometry(90, 95, 40, 12)); + add(*(btn=new GLtk::Button(res, "Quit"))); - btn->set_geometry(GLtk::Geometry(150, 53, 40, 25)); + btn->set_geometry(GLtk::Geometry(150, 70, 40, 25)); btn->set_style("red"); btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::quit)); add(*(btn=new GLtk::Button(res, "+Loc"))); - btn->set_geometry(GLtk::Geometry(90, 53, 40, 25)); + btn->set_geometry(GLtk::Geometry(10, 40, 40, 25)); btn->signal_clicked.connect(sigc::mem_fun(this, &MainPanel::new_loc)); add(*(lbl_status=new GLtk::Label(res))); - lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 24)); + lbl_status->set_geometry(GLtk::Geometry(10, 10, 180, 20)); lbl_status->set_style("digital"); - if(engineer.get_control().get_power()) + Marklin::Driver &driver = engineer.get_layout().get_driver(); + if(driver.get_power()) ind_on->set_active(true); else ind_off->set_active(true); + + driver.signal_power.connect(sigc::mem_fun(this, &MainPanel::power_event)); + driver.signal_halt.connect(sigc::mem_fun(this, &MainPanel::halt_event)); } void MainPanel::set_status_text(const string &txt) @@ -57,24 +78,40 @@ void MainPanel::set_status_text(const string &txt) void MainPanel::power_on() { - engineer.get_control().set_power(true); - ind_on->set_active(true); - ind_off->set_active(false); + engineer.get_layout().get_driver().set_power(true); } void MainPanel::power_off() { - engineer.get_control().set_power(false); - ind_on->set_active(false); - ind_off->set_active(true); + engineer.get_layout().get_driver().set_power(false); +} + +void MainPanel::toggle_halt() +{ + Marklin::Driver &driver = engineer.get_layout().get_driver(); + driver.halt(!driver.is_halted()); } void MainPanel::new_loc() { - engineer.add_train(0); + TrainProperties *dialog = new TrainProperties(engineer, res, 0); + engineer.get_root().add(*dialog); + dialog->set_position(geom.x+geom.w, geom.y+geom.h-dialog->get_geometry().h); + dialog->set_visible(true); } void MainPanel::quit() { engineer.quit(); } + +void MainPanel::power_event(bool p) +{ + ind_on->set_active(p); + ind_off->set_active(!p); +} + +void MainPanel::halt_event(bool h) +{ + ind_halt->set_active(h); +}