X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=339f4eca669f7e9d4337dd25ab674c4937a260c7;hb=dcfa1e9503b7e97b61396d7458f0b2e5896779cd;hp=7c3ba71a5c8e1cf83cebe85d9b64f8c400cc5a4a;hpb=f9254f57b736927a57a2fd793ee18f6c9766dd43;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index 7c3ba71..339f4ec 100644 --- a/source/engineer/trainpanel.cpp +++ b/source/engineer/trainpanel.cpp @@ -1,7 +1,7 @@ /* $Id$ This file is part of the MSP Märklin suite -Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa +Copyright © 2006-2009 Mikkosoft Productions, Mikko Rasa Distributed under the GPL */ @@ -9,18 +9,21 @@ Distributed under the GPL #include #include "libmarklin/locomotive.h" #include "engineer.h" +#include "routeselect.h" #include "trainpanel.h" +#include "trainproperties.h" using namespace std; using namespace Msp; using namespace Marklin; TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): + Widget(r), Panel(r), engineer(e), train(t) { - set_size(200, 145); + set_size(200, 170); add(*(lbl_addr=new GLtk::Label(res, format("%2d", train.get_locomotive().get_address())))); lbl_addr->set_style("digital"); @@ -34,7 +37,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(lbl_speed=new GLtk::Label(res, format("%2d", train.get_locomotive().get_speed())))); lbl_speed->set_style("digital"); lbl_speed->set_geometry(GLtk::Geometry(10, geom.h-58, 35, 24)); - train.get_locomotive().signal_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::loco_speed_changed)); + train.signal_target_speed_changed.connect(sigc::mem_fun(this, &TrainPanel::train_speed_changed)); add(*(sld_speed=new GLtk::HSlider(res))); sld_speed->set_geometry(GLtk::Geometry(50, geom.h-51, geom.w-80, 10)); @@ -47,6 +50,13 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): tgl_forward->set_geometry(GLtk::Geometry(geom.w-30, geom.h-59, 20, 27)); tgl_forward->set_value(!train.get_locomotive().get_reverse()); tgl_forward->signal_toggled.connect(sigc::mem_fun(this, &TrainPanel::forward_toggled)); + train.get_locomotive().signal_reverse_changed.connect(sigc::mem_fun(this, &TrainPanel::train_reverse_changed)); + + const Route *route = train.get_route(); + add(*(lbl_route=new GLtk::Label(res, (route ? route->get_name() : "Free run")))); + lbl_route->set_style("digital"); + lbl_route->set_geometry(GLtk::Geometry(10, 58, geom.w-20, 24)); + train.signal_route_changed.connect(sigc::mem_fun(this, &TrainPanel::train_route_changed)); add(*(lbl_status=new GLtk::Label(res, train.get_status()))); lbl_status->set_style("digital"); @@ -55,14 +65,14 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): const map &funcs = train.get_locomotive().get_type().get_functions(); unsigned x = 10; - for(map::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=35) + for(map::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, x+=36) { string fname = i->second; fname[0] = toupper(fname[0]); GLtk::Toggle *tgl; add(*(tgl=new GLtk::Toggle(res))); tgl->set_text(fname); - tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 35, 27)); + tgl->set_geometry(GLtk::Geometry(x, geom.h-85, 36, 27)); tgl->set_value(train.get_locomotive().get_function(i->first)); tgl->signal_toggled.connect(sigc::bind(sigc::mem_fun(this, &TrainPanel::func_toggled), i->first)); @@ -74,6 +84,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(btn=new GLtk::Button(res, "Edit"))); btn->set_geometry(GLtk::Geometry(geom.w-50, 10, 40, 24)); + btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::edit_clicked)); add(*(btn=new GLtk::Button(res, "Place"))); btn->set_geometry(GLtk::Geometry(geom.w-90, 10, 40, 24)); @@ -81,6 +92,10 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): add(*(btn=new GLtk::Button(res, "GoTo"))); btn->set_geometry(GLtk::Geometry(geom.w-130, 10, 40, 24)); + + add(*(btn=new GLtk::Button(res, "Route"))); + btn->set_geometry(GLtk::Geometry(geom.w-170, 10, 40, 24)); + btn->signal_clicked.connect(sigc::mem_fun(this, &TrainPanel::route_clicked)); } void TrainPanel::speed_slider_changed(double v) @@ -88,9 +103,15 @@ void TrainPanel::speed_slider_changed(double v) train.set_speed(static_cast(v)); } -void TrainPanel::loco_speed_changed(unsigned speed) +void TrainPanel::train_speed_changed(unsigned speed) { lbl_speed->set_text(format("%2d", speed)); + sld_speed->set_value(speed); +} + +void TrainPanel::train_reverse_changed(bool reverse) +{ + tgl_forward->set_value(!reverse); } void TrainPanel::loco_function_changed(unsigned func, bool value) @@ -100,6 +121,14 @@ void TrainPanel::loco_function_changed(unsigned func, bool value) i->second->set_value(value); } +void TrainPanel::train_route_changed(const Route *r) +{ + if(r) + lbl_route->set_text(r->get_name()); + else + lbl_route->set_text("Free run"); +} + void TrainPanel::train_status_changed(const string &s) { lbl_status->set_text(s); @@ -110,6 +139,22 @@ void TrainPanel::place_clicked() engineer.place_train(train); } +void TrainPanel::edit_clicked() +{ + TrainProperties *dialog = new TrainProperties(engineer, res, &train); + 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 TrainPanel::route_clicked() +{ + RouteSelect *dialog = new RouteSelect(engineer, res, train); + 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 TrainPanel::forward_toggled(bool value) { train.set_reverse(!value);