3 This file is part of the MSP Märklin suite
4 Copyright © 2009 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/gltk/button.h>
9 #include <msp/strings/formatter.h>
15 using namespace Marklin;
17 Toolbar::Toolbar(Designer &d):
18 GLtk::Widget(d.get_ui_resources()),
19 GLtk::Panel(d.get_ui_resources()),
27 add(*(btn=new GLtk::Button(res, "Load")));
28 btn->set_geometry(GLtk::Geometry(5, 10, 40, 24));
30 add(*(btn=new GLtk::Button(res, "Save")));
31 btn->set_geometry(GLtk::Geometry(45, 10, 40, 24));
32 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::save));
34 add(*(btn=new GLtk::Button(res, "Quit")));
35 btn->set_geometry(GLtk::Geometry(85, 10, 40, 24));
36 btn->set_style("red");
37 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::quit));
39 add(*(btn=new GLtk::Button(res, "Trnt")));
40 btn->set_geometry(GLtk::Geometry(135, 10, 40, 24));
42 add(*(btn=new GLtk::Button(res, "Sens")));
43 btn->set_geometry(GLtk::Geometry(175, 10, 40, 24));
45 add(*(lbl=new GLtk::Label(res, "Routes:")));
46 lbl->set_geometry(GLtk::Geometry(225, 22, 40, 13));
48 add(*(drp_routes=new GLtk::Dropdown(res)));
49 drp_routes->set_geometry(GLtk::Geometry(225, 5, 100, 17));
50 drp_routes->append("(new route)");
51 drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &Toolbar::route_selected));
53 add(*(btn=new GLtk::Button(res, "AddT")));
54 btn->set_geometry(GLtk::Geometry(325, 10, 40, 24));
55 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_route));
57 designer.get_layout()->signal_route_added.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes)));
58 designer.get_layout()->signal_route_removed.connect(sigc::hide(sigc::mem_fun(this, &Toolbar::update_routes)));
62 void Toolbar::route_selected(unsigned index, const string &)
64 if(index==drp_routes->get_n_items()-1)
66 Layout &layout = *designer.get_layout();
67 Route *route = new Route(layout, format("Route %d", layout.get_routes().size()+1));
68 designer.get_layout()->add_route(*route);
69 designer.edit_route(*route);
71 const set<Route *> &routes = designer.get_layout()->get_routes();
74 for(set<Route *>::const_iterator i=routes.begin(); (selected<0 && i!=routes.end()); ++i, ++n)
77 drp_routes->set_selected_index(selected);
81 const set<Route *> &routes = designer.get_layout()->get_routes();
82 set<Route *>::const_iterator i = routes.begin();
84 designer.edit_route(**i);
88 void Toolbar::update_routes()
91 const set<Route *> &routes = designer.get_layout()->get_routes();
94 for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n)
96 drp_routes->append((*i)->get_name());
97 if(*i==designer.get_current_route())
100 drp_routes->append("(new route)");
101 drp_routes->set_selected_index(selected);