/* $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
*/
#include <msp/gltk/button.h>
+#include <msp/gltk/label.h>
#include <msp/strings/formatter.h>
#include <msp/strings/lexicalcast.h>
#include "engineer.h"
using namespace Msp;
using namespace Marklin;
-TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t):
+TrainProperties::TrainProperties(Engineer &e, const GLtk::Resources &r, Train *t):
Widget(r),
- Panel(r),
+ Dialog(r),
engineer(e),
train(t)
{
- set_size(200, 95);
+ set_size(200, 120);
+
+ GLtk::Label *label;
+ add(*(label=new GLtk::Label(res, "Train properties")));
+ label->set_geometry(GLtk::Geometry(10, geom.h-25, geom.w-20, 20));
add(*(ent_addr=new GLtk::Entry(res)));
- ent_addr->set_geometry(GLtk::Geometry(10, geom.h-30, 40, 20));
+ ent_addr->set_geometry(GLtk::Geometry(10, geom.h-50, 40, 20));
add(*(drp_type=new GLtk::Dropdown(res)));
- drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
+ drp_type->set_geometry(GLtk::Geometry(60, geom.h-50, geom.w-70, 20));
const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
- for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
+ unsigned n = 0;
+ for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i, ++n)
+ {
drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
+ if(train && i->second==&train->get_locomotive().get_type())
+ drp_type->set_selected_index(n);
+ }
- add(*(ent_name=new GLtk::Entry(res, "Train")));
- ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20));
-
- GLtk::Button *btn;
-
- add(*(btn=new GLtk::Button(res, "OK")));
- btn->set_style("green");
- btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
- btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked));
+ add(*(ent_name=new GLtk::Entry(res)));
+ ent_name->set_geometry(GLtk::Geometry(10, geom.h-75, geom.w-20, 20));
- add(*(btn=new GLtk::Button(res, "Cncl")));
- btn->set_style("red");
- btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
- btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked));
+ if(train)
+ {
+ ent_addr->set_text(lexical_cast(train->get_locomotive().get_address()));
+ ent_name->set_text(train->get_name());
+ }
+ else
+ ent_name->set_text(format("Train %d", engineer.get_traffic_manager().get_trains().size()+1));
}
-void TrainProperties::ok_clicked()
+void TrainProperties::on_ok_clicked()
{
if(!train)
{
const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
map<unsigned, LocoType *>::const_iterator i = locos.begin();
advance(i, drp_type->get_selected_index());
- train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
+
+ unsigned addr = lexical_cast<unsigned>(ent_addr->get_text());
+ Locomotive *loco = new Locomotive(*i->second, engineer.get_control(), addr);
+ train = new Train(engineer.get_traffic_manager(), *loco);
}
train->set_name(ent_name->get_text());
- signal_ok.emit();
-}
-
-void TrainProperties::cancel_clicked()
-{
- signal_cancel.emit();
}