]> git.tdb.fi Git - r2c2.git/blob - source/designer/toolbar.cpp
950cfc5aaa8edf0706a1e8f6bc89d78a776c8118
[r2c2.git] / source / designer / toolbar.cpp
1 #include "toolbar.h"
2
3 using namespace std;
4 using namespace Msp;
5
6 Toolbar::Toolbar(const string &name, unsigned w):
7         content_width(w),
8         expanded(true)
9 {
10         set_focusable(false);
11
12         add(*(lbl_title = new GLtk::Label(name)));
13
14         add(*(btn_expand = new GLtk::Button));
15         btn_expand->set_size(15, 20);
16         btn_expand->set_style("arrow_left");
17         btn_expand->set_tooltip("Collapse toolbar");
18         btn_expand->signal_clicked.connect(sigc::mem_fun(this, &Toolbar::expand_clicked));
19
20         add(*(pnl_content = new GLtk::Panel));
21         pnl_content->set_size(content_width, 40);
22         pnl_content->set_style("group");
23 }
24
25 void Toolbar::expand(bool e)
26 {
27         expanded = e;
28         btn_expand->set_style(expanded ? "arrow_left" : "arrow_right");
29         btn_expand->set_tooltip(expanded ? "Collapse toolbar" : "Expand toolbar");
30         pnl_content->set_visible(expanded);
31
32         unsigned w = lbl_title->get_geometry().w+40;
33         if(expanded)
34                 w += content_width+5;
35         set_size(w, 40);
36
37         signal_expanded.emit(expanded);
38 }
39
40 void Toolbar::expand_clicked()
41 {
42         expand(!expanded);
43 }
44
45 void Toolbar::on_style_change()
46 {
47         lbl_title->autosize();
48         const GLtk::Geometry &lbl_geom = lbl_title->get_geometry();
49         unsigned w = lbl_geom.w+40;
50         if(expanded)
51                 w += content_width+5;
52         set_size(w, 40);
53
54         lbl_title->set_position(10, (geom.h-lbl_geom.h)/2);
55         btn_expand->set_position(lbl_geom.w+15, 10);
56         pnl_content->set_position(lbl_geom.w+35, 0);
57 }