3 This file is part of R²C²
4 Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/strings/formatter.h>
9 #include "libr2c2/zone.h"
17 Zonebar::Zonebar(Designer &d):
21 pnl_content->add(*(drp_groups = new GLtk::Dropdown));
22 drp_groups->set_geometry(GLtk::Geometry(0, 10, 195, 20));
23 drp_groups->set_tooltip("Select zone group to edit");
24 drp_groups->signal_item_selected.connect(sigc::mem_fun(this, &Zonebar::group_selected));
26 pnl_content->add(*(drp_numbers = new GLtk::Dropdown));
27 drp_numbers->set_geometry(GLtk::Geometry(200, 10, 100, 20));
28 drp_groups->set_tooltip("Select zone to edit");
29 drp_numbers->signal_item_selected.connect(sigc::mem_fun(this, &Zonebar::number_selected));
33 pnl_content->add(*(btn = new GLtk::Button("Del")));
34 btn->set_geometry(GLtk::Geometry(300, 10, 40, 24));
35 btn->set_style("red");
36 btn->set_tooltip("Delete selected zone");
37 btn->signal_clicked.connect(sigc::mem_fun(this, &Zonebar::delete_zone_clicked));
39 pnl_content->add(*(btn = new GLtk::Button("Prop")));
40 btn->set_geometry(GLtk::Geometry(340, 10, 40, 24));
41 btn->set_tooltip("Change properties of the selected zone");
42 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::zone_properties));
44 pnl_content->add(*(btn = new GLtk::Button("AddT")));
45 btn->set_geometry(GLtk::Geometry(380, 10, 40, 24));
46 btn->set_tooltip("Add selected tracks to zone");
47 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_zone));
49 Layout &rlayout = designer.get_layout();
50 rlayout.signal_zone_added.connect(sigc::mem_fun(this, &Zonebar::zone_added));
51 rlayout.signal_zone_removed.connect(sigc::hide(sigc::mem_fun(this, &Zonebar::update_groups)));
53 const Layout::ZoneSet &zones = rlayout.get_zones();
54 for(Layout::ZoneSet::const_iterator i=zones.begin(); i!=zones.end(); ++i)
55 (*i)->signal_name_changed.connect(sigc::mem_fun(this, &Zonebar::zone_renamed));
60 void Zonebar::zone_added(Zone &zone)
62 zone.signal_name_changed.connect(sigc::mem_fun(this, &Zonebar::zone_renamed));
66 void Zonebar::zone_renamed(const string &, const string &, unsigned)
71 void Zonebar::group_selected(unsigned index, const string &group)
73 if(index==drp_groups->get_n_items()-1)
75 Zone *zone = new Zone(designer.get_layout());
76 zone->set_name("New zone", "track", 1);
77 designer.edit_zone(zone);
82 Zone *cur = designer.get_current_zone();
83 if(cur && group==cur->get_group())
86 designer.edit_zone(0);
87 update_numbers(group);
91 void Zonebar::number_selected(unsigned index, const string &)
93 if(drp_groups->get_selected_index()<0)
96 string group = drp_groups->get_selected();
97 Layout::ZoneArray zones = designer.get_layout().get_zones(group);
98 if(index==drp_numbers->get_n_items()-1)
100 Zone *cur = designer.get_current_zone();
101 string qualifier = (cur ? cur->get_qualifier() : "track");
103 Zone *zone = new Zone(designer.get_layout());
104 zone->set_name(group, qualifier, zones.size()+1);
105 designer.edit_zone(zone);
107 update_numbers(group);
111 else if(index<zones.size())
112 designer.edit_zone(zones[index]);
115 void Zonebar::delete_zone_clicked()
117 Zone *cur = designer.get_current_zone();
118 designer.edit_zone(0);
122 void Zonebar::update_groups()
124 const Layout::ZoneSet &zones = designer.get_layout().get_zones();
126 for(Layout::ZoneSet::const_iterator i=zones.begin(); i!=zones.end(); ++i)
127 groups.insert((*i)->get_group());
129 Zone *cur = designer.get_current_zone();
134 for(set<string>::iterator i=groups.begin(); i!=groups.end(); ++i, ++n)
136 drp_groups->append(*i);
137 if(cur && *i==cur->get_group())
140 drp_groups->append("(new)");
141 drp_groups->set_selected_index(selected);
144 update_numbers(cur->get_group());
146 drp_numbers->clear();
149 void Zonebar::update_numbers(const string &group)
151 Layout::ZoneArray zones = designer.get_layout().get_zones(group);
152 Zone *cur = designer.get_current_zone();
154 drp_numbers->clear();
157 for(Layout::ZoneArray::iterator i=zones.begin(); i!=zones.end(); ++i, ++n)
159 drp_numbers->append(format("%s %d", (*i)->get_qualifier(), (*i)->get_number()));
163 drp_numbers->append("(new)");
164 drp_numbers->set_selected_index(selected);