[1442] | 1 | #include <map_win.h> |
---|
| 2 | #include <set> |
---|
| 3 | |
---|
[1446] | 4 | bool MapWin::close_if_escape_is_pressed(GdkEventKey* e) |
---|
[1442] | 5 | { |
---|
[1446] | 6 | if(e->keyval==GDK_Escape) |
---|
| 7 | { |
---|
| 8 | hide(); |
---|
| 9 | } |
---|
| 10 | return true; |
---|
| 11 | } |
---|
[1442] | 12 | |
---|
[1446] | 13 | MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst),table(PROPERTY_NUM, 2, false) |
---|
| 14 | { |
---|
| 15 | set_title(title); |
---|
| 16 | set_default_size(200, 50); |
---|
[1442] | 17 | |
---|
[1446] | 18 | signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::close_if_escape_is_pressed)); |
---|
[1442] | 19 | |
---|
[1446] | 20 | combo_array=new Gtk::Combo [PROPERTY_NUM]; |
---|
| 21 | |
---|
[1442] | 22 | for(int i=0;i<PROPERTY_NUM;i++) |
---|
| 23 | { |
---|
| 24 | |
---|
| 25 | std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps(); |
---|
| 26 | std::set<int> props; |
---|
| 27 | |
---|
| 28 | int actprop; |
---|
[1446] | 29 | |
---|
| 30 | //here we find out, which map is the default in MapStorage for this property, which are not |
---|
[1442] | 31 | for(int j=0;j<ms.numOfEdgeMaps();j++) |
---|
| 32 | { |
---|
[1446] | 33 | //this is the default value for this property |
---|
[1442] | 34 | if(emsi->second==&(ms.default_edgemaps[i])) |
---|
| 35 | { |
---|
| 36 | actprop=j; |
---|
| 37 | } |
---|
[1446] | 38 | //this is the other maps to show for this property |
---|
[1442] | 39 | for(int k=0;k<PROPERTY_NUM;k++) |
---|
| 40 | { |
---|
| 41 | if(emsi->second==&(ms.default_edgemaps[k])) |
---|
| 42 | { |
---|
| 43 | props.insert(j); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | emsi++; |
---|
| 47 | } |
---|
| 48 | |
---|
[1446] | 49 | //combo_array[i].set_group(group); |
---|
[1442] | 50 | |
---|
[1446] | 51 | //filling in combo box with choices |
---|
| 52 | std::list<Glib::ustring> listStrings; |
---|
| 53 | |
---|
| 54 | listStrings.push_back("Default"); |
---|
[1442] | 55 | |
---|
| 56 | emsi=ms.beginOfEdgeMaps(); |
---|
[1446] | 57 | |
---|
[1442] | 58 | for(int j=0;j<ms.numOfEdgeMaps();j++) |
---|
| 59 | { |
---|
| 60 | if( ( props.find(j) )==( props.end() ) ) |
---|
| 61 | { |
---|
[1446] | 62 | listStrings.push_back(emsi->first); |
---|
[1442] | 63 | } |
---|
| 64 | emsi++; |
---|
| 65 | } |
---|
[1446] | 66 | |
---|
| 67 | combo_array[i].set_popdown_strings(listStrings); |
---|
| 68 | |
---|
| 69 | //Restrict it to these choices only: |
---|
| 70 | combo_array[i].set_value_in_list(); |
---|
| 71 | |
---|
| 72 | //binding signal to thew actual entry |
---|
| 73 | combo_array[i].get_entry()->signal_changed().connect |
---|
| 74 | ( |
---|
| 75 | sigc::bind |
---|
| 76 | ( |
---|
| 77 | sigc::mem_fun(*this, &MapWin::combo_changed), |
---|
| 78 | i |
---|
| 79 | ) |
---|
| 80 | ); |
---|
| 81 | |
---|
| 82 | //placing actual entry in the right place |
---|
| 83 | |
---|
| 84 | label=new Gtk::Label; |
---|
| 85 | label->set_text(property_strings[i]); |
---|
| 86 | |
---|
| 87 | // labelpluscombo=new Gtk::HBox; |
---|
| 88 | // labelpluscombo->pack_start(*label); |
---|
| 89 | // labelpluscombo->pack_start(combo_array[i]); |
---|
| 90 | |
---|
| 91 | table.attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
---|
| 92 | table.attach(combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3); |
---|
| 93 | |
---|
| 94 | /* |
---|
| 95 | if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2) |
---|
| 96 | { |
---|
| 97 | vbox_r1.pack_start(*labelpluscombo); |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | vbox_r2.pack_start(*labelpluscombo); |
---|
| 102 | } |
---|
| 103 | actpos++; |
---|
| 104 | //*/ |
---|
| 105 | |
---|
[1442] | 106 | } |
---|
| 107 | |
---|
[1446] | 108 | combos.pack_start(vbox_r1); |
---|
| 109 | combos.pack_start(vbox_r2); |
---|
| 110 | |
---|
| 111 | //add(combos); |
---|
| 112 | add(table); |
---|
[1442] | 113 | |
---|
| 114 | show_all_children(); |
---|
| 115 | |
---|
| 116 | } |
---|
| 117 | |
---|
[1446] | 118 | void MapWin::combo_changed(int prop) |
---|
[1442] | 119 | { |
---|
| 120 | |
---|
| 121 | //most nem kommentezem fel, mert ugyis valtozik |
---|
[1446] | 122 | Gtk::Entry* entry = combo_array[prop].get_entry(); |
---|
[1442] | 123 | |
---|
[1446] | 124 | if(entry) |
---|
[1442] | 125 | { |
---|
[1446] | 126 | Glib::ustring mapname = entry->get_text(); |
---|
| 127 | if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty. |
---|
| 128 | { |
---|
| 129 | if(mapname=="Default") |
---|
| 130 | { |
---|
| 131 | mapname=property_strings[prop]; |
---|
| 132 | } |
---|
[1442] | 133 | |
---|
[1446] | 134 | if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) |
---|
| 135 | { |
---|
| 136 | switch(prop) |
---|
| 137 | { |
---|
| 138 | case WIDTH: |
---|
| 139 | gdc.changeLineWidth(mapname); |
---|
| 140 | break; |
---|
| 141 | case COLOR: |
---|
| 142 | gdc.changeColor(mapname); |
---|
| 143 | break; |
---|
| 144 | case TEXT: |
---|
| 145 | gdc.changeText(mapname); |
---|
| 146 | break; |
---|
| 147 | default: |
---|
| 148 | std::cout<<"Error\n"; |
---|
| 149 | } |
---|
| 150 | } |
---|
[1442] | 151 | } |
---|
| 152 | } |
---|
| 153 | }; |
---|