~lubuntu-software-center-team/lubuntu-software-center/vala-port

« back to all changes in this revision

Viewing changes to src/Widgets/Pages/CategoriesView.vala

  • Committer: Stephen Smally
  • Date: 2012-03-04 12:59:13 UTC
  • Revision ID: eco.stefi@fastwebnet.it-20120304125913-bk1iutifwoeoyo0i
Worked a lot!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using Gtk;
 
3
 
 
4
namespace Lsc.Widgets {
 
5
    public class CategoryButton : Button {
 
6
        public CategoryButton (string icon, string name, bool fill = false) {
 
7
            get_style_context ().add_provider (CategoriesView.style_provider, -1);
 
8
            can_focus = false;
 
9
            sensitive = ! fill;
 
10
            if (icon != "" && ! fill) {
 
11
                Box container = new Box(Orientation.HORIZONTAL, 3);
 
12
                Box label_box = new Box(Orientation.VERTICAL, 0);
 
13
                label_box.valign = Align.CENTER;
 
14
                Image image_widget = new Image.from_icon_name(icon, IconSize.LARGE_TOOLBAR);
 
15
                
 
16
                Label title = new Label("<b>"+name+"</b>");
 
17
                title.ellipsize = Pango.EllipsizeMode.END;
 
18
                title.halign = Align.START;
 
19
                title.valign = Align.END;
 
20
                title.use_markup = true;
 
21
                
 
22
                Label description = new Label("<i>Comment</i>");
 
23
                description.ellipsize = Pango.EllipsizeMode.END;
 
24
                description.halign = Align.START;
 
25
                description.valign = Align.START;
 
26
                description.use_markup = true;
 
27
                
 
28
                label_box.pack_start(title, false, false, 0);
 
29
                label_box.pack_start(description, false, false, 0);
 
30
                
 
31
                container.pack_start(image_widget, false, false, 0);
 
32
                container.pack_start(label_box, false, false, 0);
 
33
                add(container);
 
34
            }
 
35
        }
 
36
    }
 
37
    
 
38
    public class CategoriesView : Box {
 
39
        // Css Provider
 
40
        private string CSS_STYLE = """
 
41
        .CategoriesView *:first-child .button:first-child {
 
42
            border-width: 1 0 0 1;
 
43
            border-radius: 4 0 0 0;
 
44
            -unico-outer-stroke-width: 1 0 0 1;
 
45
        }
 
46
        
 
47
        .CategoriesView *:first-child .button {
 
48
            border-width: 1 0 0 1;
 
49
            border-radius: 0 0 0 0;
 
50
            -unico-outer-stroke-width: 1 0 0 0;
 
51
        }
 
52
        
 
53
        .CategoriesView *:first-child .button:last-child {
 
54
            border-width: 1 1 0 1;
 
55
            border-radius: 0 4 0 0;
 
56
            -unico-outer-stroke-width: 1 1 0 0;
 
57
        }
 
58
        
 
59
        .CategoriesView *.button:first-child {
 
60
            padding: 0;
 
61
            margin: 0;
 
62
            border-width: 1 0 0 1;
 
63
            border-radius: 0 0 0 0;
 
64
            -unico-outer-stroke-width: 0 0 0 1;
 
65
        }
 
66
        
 
67
        .CategoriesView *.button {
 
68
            padding: 0;
 
69
            margin: 0;
 
70
            border-width: 1 0 0 1;
 
71
            border-radius: 0 0 0 0;
 
72
            -unico-outer-stroke-width: 0 0 0 0;
 
73
        }
 
74
        
 
75
        .CategoriesView *.button:last-child {
 
76
            padding: 0;
 
77
            margin: 0;
 
78
            border-width: 1 1 0 1;
 
79
            border-radius: 0 0 0 0;
 
80
            -unico-outer-stroke-width: 0 1 0 0;
 
81
        }
 
82
        
 
83
        .CategoriesView *:last-child .button:first-child {
 
84
            border-width: 1 0 1 1;
 
85
            border-radius: 0 0 0 4;
 
86
            -unico-outer-stroke-width: 0 0 1 1;
 
87
        }
 
88
        
 
89
        .CategoriesView *:last-child .button {
 
90
            border-width: 1 0 1 1;
 
91
            border-radius: 0 0 0 0;
 
92
            -unico-outer-stroke-width: 0 0 1 0;
 
93
        }
 
94
        
 
95
        .CategoriesView *:last-child .button:last-child {
 
96
            border-width: 1 1 1 1;
 
97
            border-radius: 0 0 4 0;
 
98
            -unico-outer-stroke-width: 0 1 1 0;
 
99
        }
 
100
        """;
 
101
        internal static CssProvider style_provider;
 
102
        
 
103
        public signal void category_choosed ();
 
104
        
 
105
        // Vars
 
106
        public Box box_child;
 
107
        private CategoryButton button_child;
 
108
        private int columns;
 
109
        private int actual_col;
 
110
        
 
111
        public void add_category (string image, string name) {
 
112
            if (actual_col == columns) {
 
113
                box_child = new Box(Orientation.HORIZONTAL, 0);
 
114
                box_child.homogeneous = true;
 
115
                box_child.show();
 
116
                pack_start(box_child, true, true, 0);
 
117
                actual_col = 0;
 
118
            }
 
119
            
 
120
            button_child = new CategoryButton(image, name);
 
121
            button_child.clicked.connect(() => { category_choosed(); });
 
122
            button_child.show_all();
 
123
            
 
124
            box_child.pack_start(button_child, true, true, 0);
 
125
            actual_col++;
 
126
        }
 
127
        
 
128
        public void fill_space () {
 
129
            while (actual_col != columns) {
 
130
                button_child = new CategoryButton("", "", true);
 
131
                button_child.clicked.connect(() => { category_choosed(); });
 
132
                button_child.show_all();
 
133
                box_child.pack_start(button_child, true, true, 0);
 
134
                actual_col++;
 
135
            }
 
136
        }
 
137
        
 
138
        public CategoriesView (int cols) {
 
139
            columns = cols;
 
140
            actual_col = 0;
 
141
            
 
142
            if (style_provider == null) {
 
143
                style_provider = new CssProvider();
 
144
                try {
 
145
                    style_provider.load_from_data (CSS_STYLE, -1);
 
146
                } catch (Error e) {
 
147
                    warning ("CategoryView: %s. The widget will not look as intended", e.message);
 
148
                }
 
149
            }
 
150
            
 
151
            orientation = Orientation.VERTICAL;
 
152
            spacing = 0;
 
153
            get_style_context().add_class("CategoriesView");
 
154
            
 
155
            box_child = new Box(Orientation.HORIZONTAL, 0);
 
156
            box_child.homogeneous = true;
 
157
            pack_start(box_child, true, true, 0);
 
158
        }
 
159
    }
 
160
}