]> git.tdb.fi Git - r2c2.git/blob - source/designer/zoneproperties.cpp
Arrange widgets in Designer with GLtk::Layout
[r2c2.git] / source / designer / zoneproperties.cpp
1 #include <msp/gltk/button.h>
2 #include <msp/gltk/label.h>
3 #include <msp/gltk/mixedrows.h>
4 #include "zoneproperties.h"
5
6 using namespace std;
7 using namespace Msp;
8 using namespace R2C2;
9
10 ZoneProperties::ZoneProperties(Zone &z):
11         zone(z)
12 {
13         GLtk::MixedRows *rows = new GLtk::MixedRows;
14         set_layout(rows);
15
16         GLtk::Label *lbl1, *lbl2;
17
18         add(*(lbl1 = new GLtk::Label("Zone properties")));
19         layout->set_expand(*lbl1, true, false);
20         lbl1->set_style("title");
21
22         rows->start_row();
23         add(*(lbl1 = new GLtk::Label("Group")));
24         add(*(ent_group = new GLtk::Entry(zone.get_group())));
25         ent_group->set_edit_size(30, 1);
26
27         rows->start_row();
28         add(*(lbl2 = new GLtk::Label("Qualifier")));
29         rows->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
30
31         add(*(drp_qualifier = new GLtk::Dropdown));
32         const char *qualifiers[] = { "track", "platform", "siding", 0 };
33         for(unsigned i=0; qualifiers[i]; ++i)
34         {
35                 drp_qualifier->append(qualifiers[i]);
36                 if(zone.get_qualifier()==qualifiers[i])
37                         drp_qualifier->set_selected_index(i);
38         }
39
40         rows->start_row();
41         add(*(lbl1 = new GLtk::Label("Number")));
42         rows->add_constraint(*lbl1, GLtk::Layout::COPY_WIDTH, *lbl2);
43         add(*(ent_number = new GLtk::Entry(lexical_cast<string>(zone.get_number()))));
44         ent_number->set_edit_size(4, 1);
45
46         GLtk::Button *btn;
47
48         rows->start_row();
49         rows->split_columns();
50         add_button(*(btn = new GLtk::Button("Cncl")), 0);
51         btn->set_style("red");
52
53         add_button(*(btn = new GLtk::Button("OK")), 1);
54         btn->set_style("green");
55 }
56
57 void ZoneProperties::on_response(int code)
58 {
59         if(code==1)
60         {
61                 string qualifier;
62                 if(drp_qualifier->get_selected_index()>=0)
63                         qualifier = drp_qualifier->get_selected();
64                 unsigned number = lexical_cast<unsigned>(ent_number->get_text());
65                 zone.set_name(ent_group->get_text(), qualifier, number);
66         }
67 }