]> git.tdb.fi Git - r2c2.git/blob - source/engineer/trainproperties.cpp
Code reformatting: add spaces around assignment operators
[r2c2.git] / source / engineer / trainproperties.cpp
1 /* $Id$
2
3 This file is part of the MSP Märklin suite
4 Copyright © 2006-2008 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include <msp/gltk/button.h>
9 #include <msp/strings/formatter.h>
10 #include <msp/strings/lexicalcast.h>
11 #include "engineer.h"
12 #include "trainproperties.h"
13
14 using namespace std;
15 using namespace Msp;
16 using namespace Marklin;
17
18 TrainProperties::TrainProperties(Engineer &e, GLtk::Resources &r, Train *t):
19         Panel(r),
20         engineer(e),
21         train(t)
22 {
23         set_size(200, 95);
24
25         add(*(ent_addr=new GLtk::Entry(res)));
26         ent_addr->set_geometry(GLtk::Geometry(10, geom.h-30, 40, 20));
27
28         add(*(drp_type=new GLtk::Dropdown(res)));
29         drp_type->set_geometry(GLtk::Geometry(60, geom.h-30, geom.w-70, 20));
30
31         const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
32         for(map<unsigned, LocoType *>::const_iterator i=locos.begin(); i!=locos.end(); ++i)
33                 drp_type->append(format("%d %s", i->second->get_article_number(), i->second->get_name()));
34
35         add(*(ent_name=new GLtk::Entry(res, "Train")));
36         ent_name->set_geometry(GLtk::Geometry(10, geom.h-55, geom.w-20, 20));
37
38         GLtk::Button *btn;
39
40         add(*(btn=new GLtk::Button(res, "OK")));
41         btn->set_style("green");
42         btn->set_geometry(GLtk::Geometry(geom.w-40, 10, 30, 25));
43         btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::ok_clicked));
44
45         add(*(btn=new GLtk::Button(res, "Cncl")));
46         btn->set_style("red");
47         btn->set_geometry(GLtk::Geometry(geom.w-80, 10, 30, 25));
48         btn->signal_clicked.connect(sigc::mem_fun(this, &TrainProperties::cancel_clicked));
49 }
50
51 void TrainProperties::ok_clicked()
52 {
53         if(!train)
54         {
55                 const map<unsigned, LocoType *> &locos = engineer.get_catalogue().get_locomotives();
56                 map<unsigned, LocoType *>::const_iterator i = locos.begin();
57                 advance(i, drp_type->get_selected_index());
58                 train = engineer.add_train(*i->second, lexical_cast<unsigned>(ent_addr->get_text()));
59         }
60
61         train->set_name(ent_name->get_text());
62         signal_ok.emit();
63 }
64
65 void TrainProperties::cancel_clicked()
66 {
67 }