hegyi@1882
|
1 |
#include "mapselector.h"
|
hegyi@1882
|
2 |
|
hegyi@1882
|
3 |
MapSelector::MapSelector(std::vector<std::string> ml, std::string act, int identifier, bool edge):id(identifier),itisedge(edge),set_new_map(false)
|
hegyi@1882
|
4 |
{
|
hegyi@1882
|
5 |
update_list(ml);
|
hegyi@1882
|
6 |
|
hegyi@1882
|
7 |
if(act=="")
|
hegyi@1882
|
8 |
{
|
hegyi@1882
|
9 |
cbt.set_active(0);
|
hegyi@1882
|
10 |
default_state=true;
|
hegyi@1882
|
11 |
}
|
hegyi@1882
|
12 |
else
|
hegyi@1882
|
13 |
{
|
hegyi@1882
|
14 |
cbt.set_active_text((Glib::ustring)act);
|
hegyi@1882
|
15 |
default_state=false;
|
hegyi@1882
|
16 |
}
|
hegyi@1882
|
17 |
|
hegyi@1882
|
18 |
//binding signal to the actual entry
|
hegyi@1882
|
19 |
cbt.signal_changed().connect
|
hegyi@1882
|
20 |
(
|
hegyi@1882
|
21 |
sigc::mem_fun((*this), &MapSelector::comboChanged),
|
hegyi@1882
|
22 |
false
|
hegyi@1882
|
23 |
);
|
hegyi@1882
|
24 |
|
hegyi@1882
|
25 |
if(itisedge)
|
hegyi@1882
|
26 |
{
|
hegyi@1882
|
27 |
label=new Gtk::Label(edge_property_strings[id]);
|
hegyi@1882
|
28 |
}
|
hegyi@1882
|
29 |
else
|
hegyi@1882
|
30 |
{
|
hegyi@1882
|
31 |
label=new Gtk::Label(node_property_strings[id]);
|
hegyi@1882
|
32 |
}
|
hegyi@1882
|
33 |
|
hegyi@1882
|
34 |
label->set_width_chars(longest_property_string_length);
|
hegyi@1882
|
35 |
|
hegyi@1882
|
36 |
defbut=new Gtk::Button();
|
hegyi@1882
|
37 |
defbut->set_label("Reset");
|
hegyi@1882
|
38 |
|
hegyi@1882
|
39 |
defbut->signal_pressed().connect
|
hegyi@1882
|
40 |
(
|
hegyi@1882
|
41 |
sigc::mem_fun(*this, &MapSelector::reset)
|
hegyi@1882
|
42 |
);
|
hegyi@1882
|
43 |
|
hegyi@1882
|
44 |
newbut=new Gtk::Button(Gtk::Stock::NEW);
|
hegyi@1882
|
45 |
|
hegyi@1882
|
46 |
newbut->signal_pressed().connect
|
hegyi@1882
|
47 |
(
|
hegyi@1882
|
48 |
sigc::mem_fun(*this, &MapSelector::new_but_pressed)
|
hegyi@1882
|
49 |
);
|
hegyi@1882
|
50 |
|
hegyi@1882
|
51 |
add(*label);
|
hegyi@1882
|
52 |
|
hegyi@1882
|
53 |
add(cbt);
|
hegyi@1882
|
54 |
|
hegyi@1882
|
55 |
add(*defbut);
|
hegyi@1882
|
56 |
add(*newbut);
|
hegyi@1882
|
57 |
}
|
hegyi@1882
|
58 |
|
hegyi@1882
|
59 |
void MapSelector::new_but_pressed()
|
hegyi@1882
|
60 |
{
|
hegyi@1882
|
61 |
set_new_map=true;
|
hegyi@1882
|
62 |
signal_newmapwin.emit(itisedge);
|
hegyi@1882
|
63 |
}
|
hegyi@1882
|
64 |
|
hegyi@1882
|
65 |
void MapSelector::update_list( std::vector< std::string > ml )
|
hegyi@1882
|
66 |
{
|
hegyi@1882
|
67 |
int prev_act=cbt.get_active_row_number();
|
hegyi@1882
|
68 |
cbt.clear();
|
hegyi@1882
|
69 |
std::vector< std::string >::iterator emsi=ml.begin();
|
hegyi@1882
|
70 |
for(;emsi!=ml.end();emsi++)
|
hegyi@1882
|
71 |
{
|
hegyi@1882
|
72 |
cbt.append_text(*emsi);
|
hegyi@1882
|
73 |
}
|
hegyi@1882
|
74 |
cbt.prepend_text("Default values");
|
hegyi@1882
|
75 |
if(prev_act!=-1)
|
hegyi@1882
|
76 |
{
|
hegyi@1882
|
77 |
cbt.set_active(prev_act);
|
hegyi@1882
|
78 |
}
|
hegyi@1882
|
79 |
}
|
hegyi@1882
|
80 |
|
hegyi@1882
|
81 |
void MapSelector::comboChanged()
|
hegyi@1882
|
82 |
{
|
hegyi@1882
|
83 |
if(cbt.get_active_row_number()!=0)
|
hegyi@1882
|
84 |
{
|
hegyi@1882
|
85 |
default_state=false;
|
hegyi@1882
|
86 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@1882
|
87 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@1882
|
88 |
{
|
hegyi@1882
|
89 |
signal_cbt.emit(mapname);
|
hegyi@1882
|
90 |
}
|
hegyi@1882
|
91 |
}
|
hegyi@1882
|
92 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@1882
|
93 |
{
|
hegyi@1882
|
94 |
reset();
|
hegyi@1882
|
95 |
}
|
hegyi@1882
|
96 |
}
|
hegyi@1882
|
97 |
|
hegyi@1882
|
98 |
void MapSelector::reset()
|
hegyi@1882
|
99 |
{
|
hegyi@1882
|
100 |
default_state=true;
|
hegyi@1882
|
101 |
|
hegyi@1882
|
102 |
cbt.set_active(0);
|
hegyi@1882
|
103 |
|
hegyi@1882
|
104 |
signal_cbt.emit("");
|
hegyi@1882
|
105 |
}
|
hegyi@1882
|
106 |
|
hegyi@1882
|
107 |
|
hegyi@1882
|
108 |
Glib::ustring MapSelector::get_active_text()
|
hegyi@1882
|
109 |
{
|
hegyi@1882
|
110 |
return cbt.get_active_text();
|
hegyi@1882
|
111 |
}
|
hegyi@1882
|
112 |
|
hegyi@1882
|
113 |
void MapSelector::set_active_text(Glib::ustring text)
|
hegyi@1882
|
114 |
{
|
hegyi@1882
|
115 |
cbt.set_active_text(text);
|
hegyi@1882
|
116 |
}
|
hegyi@1882
|
117 |
|
hegyi@1882
|
118 |
void MapSelector::append_text(Glib::ustring text)
|
hegyi@1882
|
119 |
{
|
hegyi@1882
|
120 |
cbt.append_text(text);
|
hegyi@1882
|
121 |
if(set_new_map)
|
hegyi@1882
|
122 |
{
|
hegyi@1882
|
123 |
set_active_text(text);
|
hegyi@1882
|
124 |
set_new_map=false;
|
hegyi@1882
|
125 |
}
|
hegyi@1882
|
126 |
}
|
hegyi@1882
|
127 |
|
hegyi@1882
|
128 |
sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
|
hegyi@1882
|
129 |
{
|
hegyi@1882
|
130 |
return signal_cbt;
|
hegyi@1882
|
131 |
}
|
hegyi@1882
|
132 |
|
hegyi@1882
|
133 |
sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
|
hegyi@1882
|
134 |
{
|
hegyi@1882
|
135 |
return signal_newmapwin;
|
hegyi@1882
|
136 |
}
|