]> git.tdb.fi Git - r2c2.git/blob - source/designer/toolbar.cpp
Split the single large toolbar into a few smaller collapsible ones
[r2c2.git] / source / designer / toolbar.cpp
1 /* $Id$
2
3 This file is part of R²C²
4 Copyright © 2010 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
6 */
7
8 #include "toolbar.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 Toolbar::Toolbar(const string &name, unsigned w):
14         content_width(w),
15         expanded(true)
16 {
17         set_focusable(false);
18
19         add(*(lbl_title = new GLtk::Label(name)));
20
21         add(*(btn_expand = new GLtk::Button));
22         btn_expand->set_size(15, 20);
23         btn_expand->set_style("arrow_left");
24         btn_expand->set_tooltip("Collapse toolbar");
25         btn_expand->signal_clicked.connect(sigc::mem_fun(this, &Toolbar::expand_clicked));
26
27         add(*(pnl_content = new GLtk::Panel));
28         pnl_content->set_size(content_width, 40);
29         pnl_content->set_style("group");
30 }
31
32 void Toolbar::expand(bool e)
33 {
34         expanded = e;
35         btn_expand->set_style(expanded ? "arrow_left" : "arrow_right");
36         btn_expand->set_tooltip(expanded ? "Collapse toolbar" : "Expand toolbar");
37         pnl_content->set_visible(expanded);
38
39         unsigned w = lbl_title->get_geometry().w+40;
40         if(expanded)
41                 w += content_width+5;
42         set_size(w, 40);
43
44         signal_expanded.emit(expanded);
45 }
46
47 void Toolbar::expand_clicked()
48 {
49         expand(!expanded);
50 }
51
52 void Toolbar::on_style_change()
53 {
54         lbl_title->autosize();
55         const GLtk::Geometry &lbl_geom = lbl_title->get_geometry();
56         unsigned w = lbl_geom.w+40;
57         if(expanded)
58                 w += content_width+5;
59         set_size(w, 40);
60
61         lbl_title->set_position(10, (geom.h-lbl_geom.h)/2);
62         btn_expand->set_position(lbl_geom.w+15, 10);
63         pnl_content->set_position(lbl_geom.w+35, 0);
64 }