Add LED pattern button class, display pattern duration as secondary text
[led-pattern-ed] / src / led-pattern-button.vala
1 /* This file is part of LED Pattern Editor.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
5  * LED Pattern Editor is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * LED Pattern Editor is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 class LedPatternButton : Gtk.Button {
20         LedPatternRX51 pattern;
21         Gtk.Label value_label;
22
23         public LedPatternButton (LedPatternRX51 _pattern) {
24                 pattern = _pattern;
25
26                 var hbox = new Gtk.HBox (false, Hildon.MARGIN_DOUBLE);
27
28                 var lpv = new LedPatternView (pattern);
29                 lpv.set_size_request (200, -1);
30                 hbox.pack_start (lpv, false, false, 0);
31
32                 var label_box = new Gtk.VBox (false, 0);
33
34                 var title = new Gtk.Label (pattern.name.has_prefix ("Pattern") ?
35                                            pattern.name.offset (7) : pattern.name);
36                 title.set_alignment (0.0f, 0.5f);
37                 label_box.pack_start (title, false, false, 0);
38
39                 value_label = new Gtk.Label ("%.2f s".printf (pattern.duration / 1000.0));
40                 value_label.set_alignment (0.0f, 0.5f);
41                 Hildon.helper_set_logical_color (value_label, Gtk.RcFlags.FG, Gtk.StateType.NORMAL, "SecondaryTextColor");
42                 Hildon.helper_set_logical_color (value_label, Gtk.RcFlags.FG, Gtk.StateType.PRELIGHT, "SecondaryTextColor");
43                 Hildon.helper_set_logical_font (value_label, "SmallSystemFont");
44                 label_box.pack_start (value_label, true, true, 0);
45
46                 hbox.pack_start (label_box, true, true, 0);
47
48                 add (hbox);
49
50                 pattern.changed.connect (on_pattern_changed);
51         }
52
53         private void on_pattern_changed () {
54                 value_label.set_text ("%.2f s".printf (pattern.duration / 1000.0));
55         }
56 }