X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fengineer%2Ftrainpanel.cpp;h=339f4eca669f7e9d4337dd25ab674c4937a260c7;hb=bc8ac89bbe774bb133b758416182aa18e5e0a5a5;hp=a8c0e90536580d3c7c40a27a32300d940446fb22;hpb=010d8321e982d1684fcbff5bf6fc2bdec7cb7bae;p=r2c2.git diff --git a/source/engineer/trainpanel.cpp b/source/engineer/trainpanel.cpp index a8c0e90..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,7 +9,9 @@ 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; @@ -21,7 +23,7 @@ TrainPanel::TrainPanel(Engineer &e, const GLtk::Resources &r, Train &t): 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"); @@ -48,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"); @@ -56,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)); @@ -75,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)); @@ -82,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) @@ -95,6 +109,11 @@ void TrainPanel::train_speed_changed(unsigned 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) { map::iterator i = tgl_funcs.find(func); @@ -102,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); @@ -112,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);