Merge lp:~victored/granite/welcome-screen into lp:~elementary-pantheon/granite/granite
- welcome-screen
- Merge into granite
Proposed by
Victor Martinez
Status: | Merged |
---|---|
Merged at revision: | 153 |
Proposed branch: | lp:~victored/granite/welcome-screen |
Merge into: | lp:~elementary-pantheon/granite/granite |
Diff against target: |
487 lines (+226/-121) 2 files modified
demo/main.vala (+68/-51) lib/Widgets/Welcome.vala (+158/-70) |
To merge this branch: | bzr merge lp:~victored/granite/welcome-screen |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
xapantu | Pending | ||
Review via email: mp+87219@code.launchpad.net |
Commit message
Description of the change
Welcome Screen:
- Style changes (white background, etc.)
- New functions:
append_with_image (Gtk.Image? icon, string option, string description);
append_
This fixes lp:909067
To post a comment you must log in.
- 151. By Victor Martinez
-
- More logical function names
- Code cleanup
- Finished basic button styling - 152. By Victor Martinez
-
Small tweaks
- 153. By Victor Martinez
-
* Font and spacing adjustments
* Smarter case correction - 154. By Victor Martinez
-
- Added Daniel's CSS theme
- Minor code Fixes - 155. By Victor Martinez
-
Removed style provider
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'demo/main.vala' |
2 | --- demo/main.vala 2012-01-06 20:47:23 +0000 |
3 | +++ demo/main.vala 2012-01-11 19:46:23 +0000 |
4 | @@ -25,35 +25,35 @@ |
5 | { |
6 | construct |
7 | { |
8 | - application_id = "demo.granite.org"; |
9 | - program_name = "Granite Demo"; |
10 | - app_years = "2011"; |
11 | - |
12 | - build_version = "1.0"; |
13 | - app_icon = "text-editor"; |
14 | - main_url = "https://launchpad.net/granite"; |
15 | - bug_url = "https://bugs.launchpad.net/granite"; |
16 | - help_url = "https://answers.launchpad.net/granite"; |
17 | - translate_url = "https://translations.launchpad.net/granite"; |
18 | - about_authors = {"Kekun", |
19 | - null |
20 | - }; |
21 | - about_documenters = {"Valadoc", |
22 | - null |
23 | - }; |
24 | - about_artists = {"Daniel P. Fore", |
25 | - null |
26 | - }; |
27 | - |
28 | - about_authors = {"Maxwell Barvian <mbarvian@gmail.com>", |
29 | - "Daniel Foré <bunny@go-docky.com>", |
30 | - "Avi Romanoff <aviromanoff@gmail.com>", |
31 | - null |
32 | - }; |
33 | - |
34 | - about_comments = "A demo of the Granite toolkit"; |
35 | - about_translators = "Launchpad Translators"; |
36 | - about_license_type = Gtk.License.GPL_3_0; |
37 | + application_id = "demo.granite.org"; |
38 | + program_name = "Granite Demo"; |
39 | + app_years = "2011"; |
40 | + |
41 | + build_version = "1.0"; |
42 | + app_icon = "text-editor"; |
43 | + main_url = "https://launchpad.net/granite"; |
44 | + bug_url = "https://bugs.launchpad.net/granite"; |
45 | + help_url = "https://answers.launchpad.net/granite"; |
46 | + translate_url = "https://translations.launchpad.net/granite"; |
47 | + about_authors = {"Kekun", |
48 | + null |
49 | + }; |
50 | + about_documenters = {"Valadoc", |
51 | + null |
52 | + }; |
53 | + about_artists = {"Daniel P. Fore", |
54 | + null |
55 | + }; |
56 | + |
57 | + about_authors = {"Maxwell Barvian <mbarvian@gmail.com>", |
58 | + "Daniel Foré <bunny@go-docky.com>", |
59 | + "Avi Romanoff <aviromanoff@gmail.com>", |
60 | + null |
61 | + }; |
62 | + |
63 | + about_comments = "A demo of the Granite toolkit"; |
64 | + about_translators = "Launchpad Translators"; |
65 | + about_license_type = Gtk.License.GPL_3_0; |
66 | } |
67 | public Demo() |
68 | { |
69 | @@ -62,16 +62,33 @@ |
70 | public override void activate() { |
71 | var win = new Gtk.Window(); |
72 | win.delete_event.connect( () => { Gtk.main_quit(); return false; }); |
73 | - |
74 | + |
75 | var notebook = new Gtk.Notebook(); |
76 | win.add(notebook); |
77 | - |
78 | + |
79 | /* welcome */ |
80 | - var welcome = new Welcome("Granite", "Let's try..."); |
81 | + |
82 | + // These strings will be automatically corrected by the widget |
83 | + var welcome = new Welcome("welcome widget", "description text"); |
84 | notebook.append_page(welcome, new Gtk.Label("Welcome")); |
85 | - welcome.append("gtk-open", "Open", "Open a file"); |
86 | - welcome.append("gtk-save", "Save", "Save with a much longer description"); |
87 | - |
88 | + |
89 | + Gdk.Pixbuf? pixbuf = null; |
90 | + |
91 | + try { |
92 | + pixbuf = Gtk.IconTheme.get_default().load_icon ("document-new", 48, Gtk.IconLookupFlags.GENERIC_FALLBACK); |
93 | + } |
94 | + catch(Error e) { |
95 | + warning("Could not load icon, %s", e.message); |
96 | + } |
97 | + |
98 | + Gtk.Image? image = new Gtk.Image.from_icon_name("document-open", Gtk.IconSize.DIALOG); |
99 | + |
100 | + // Adding elements. Use the most convenient function to add an icon |
101 | + welcome.append_with_pixbuf(pixbuf, "create", "write a new document"); |
102 | + welcome.append_with_image(image, "open", "select a file"); |
103 | + welcome.append("document-save", "save", "with a much longer description"); |
104 | + welcome.append("help-info", "Discover", "Learn more about this app"); |
105 | + |
106 | /* modebutton */ |
107 | var mode_button = new ModeButton(); |
108 | mode_button.valign = Gtk.Align.CENTER; |
109 | @@ -80,8 +97,8 @@ |
110 | mode_button.append(new Gtk.Label("Input")); |
111 | mode_button.append(new Gtk.Label("Output")); |
112 | mode_button.append(new Gtk.Label("Quite long")); |
113 | - mode_button.append(new Gtk.Label("Veruy very long \n with a line break")); |
114 | - |
115 | + mode_button.append(new Gtk.Label("Very very long \n with a line break")); |
116 | + |
117 | var vbox = new Gtk.VBox(false, 0); |
118 | var toolbar = new Gtk.Toolbar(); |
119 | toolbar.get_style_context().add_class("primary-toolbar"); |
120 | @@ -105,7 +122,7 @@ |
121 | toolbutton.add(tool_mode); |
122 | toolbar.insert(toolbutton, -1); |
123 | vbox.pack_start(toolbar, false, false); |
124 | - |
125 | + |
126 | vbox.pack_start(mode_button); |
127 | |
128 | mode_button = new ModeButton(); |
129 | @@ -115,26 +132,26 @@ |
130 | mode_button.append(new Gtk.Label("a")); |
131 | vbox.pack_start(mode_button); |
132 | notebook.append_page(vbox, new Gtk.Label("ModeButton")); |
133 | - |
134 | + |
135 | /* static notebook */ |
136 | var staticbox = new Gtk.VBox (false, 5); |
137 | var staticnotebook = new StaticNotebook (); |
138 | - |
139 | + |
140 | var pageone = new Gtk.Label("Page 1"); |
141 | - |
142 | + |
143 | staticnotebook.append_page (new Gtk.Label("Page 1"), pageone); |
144 | staticnotebook.append_page (new Gtk.Label("Page 2"), new Gtk.Label("Page 2")); |
145 | staticnotebook.append_page (new Gtk.Label("Page 3"), new Gtk.Label("Page 3")); |
146 | - |
147 | + |
148 | staticnotebook.page_changed.connect(() => pageone.set_text("Page changed")); |
149 | - |
150 | + |
151 | staticbox.add (staticnotebook); |
152 | - |
153 | + |
154 | notebook.append_page (staticbox, new Gtk.Label ("Static Notebook")); |
155 | var button_about = new Gtk.Button.with_label("show_about"); |
156 | notebook.append_page (button_about, new Gtk.Label ("About Dialog")); |
157 | button_about.clicked.connect(() => { show_about(win); } ); |
158 | - |
159 | + |
160 | var popover_buttons = new Gtk.VBox(false, 0); |
161 | var hbox3 = new Gtk.HBox(false, 0); |
162 | hbox3.halign = Gtk.Align.END; |
163 | @@ -145,7 +162,7 @@ |
164 | var pop = new PopOver(); |
165 | var pop_hbox = (Gtk.Box)pop.get_content_area(); |
166 | pop_hbox.add(new HintedEntry("This is an HIntedEntry")); |
167 | - pop_hbox.add(new Gtk.Label("Another label")); |
168 | + pop_hbox.add(new Gtk.Label("Another label")); |
169 | var mode_pop = new ModeButton(); |
170 | mode_pop.append(new Gtk.Label("ele")); |
171 | mode_pop.append(new Gtk.Label("ment")); |
172 | @@ -160,13 +177,13 @@ |
173 | popover_buttons.pack_start(new Gtk.Label("Let's try the PopOvers!"), false, false); |
174 | popover_buttons.pack_start(hbox3, false, false); |
175 | notebook.append_page (popover_buttons, new Gtk.Label ("PopOvers")); |
176 | - |
177 | + |
178 | var calendar_button = new Gtk.HBox(false, 0); |
179 | var date_button = new Granite.Widgets.DatePicker.with_format("%d-%m-%y"); |
180 | date_button.valign = date_button.halign = Gtk.Align.CENTER; |
181 | calendar_button.add(date_button); |
182 | notebook.append_page (calendar_button, new Gtk.Label ("Calendar")); |
183 | - |
184 | + |
185 | /* Contractor */ |
186 | var contractor_tab = new Gtk.VBox (false, 0); |
187 | notebook.append_page (contractor_tab, new Gtk.Label ("Contractor")); |
188 | @@ -174,7 +191,7 @@ |
189 | GLib.HashTable<string, string>[] hash_ = Contractor.get_contract("/.zip", "application/zip"); |
190 | foreach(var hash in hash_) |
191 | { |
192 | - text_view.buffer.text += hash.lookup("Name") + ": " + hash.lookup("Description") + " icon: " + hash.lookup("Exec") + "\n"; |
193 | + text_view.buffer.text += hash.lookup("Name") + ": " + hash.lookup("Description") + " icon: " + hash.lookup("Exec") + "\n"; |
194 | } |
195 | contractor_tab.add(text_view); |
196 | contractor_tab.add(new ContractorView("file:///home/user/file.txt", "text/plain")); |
197 | @@ -187,9 +204,9 @@ |
198 | public static int main(string[] args) |
199 | { |
200 | new Granite.Demo().run(args); |
201 | - |
202 | + |
203 | Gtk.main(); |
204 | - |
205 | + |
206 | return 0; |
207 | } |
208 | } |
209 | |
210 | === modified file 'lib/Widgets/Welcome.vala' |
211 | --- lib/Widgets/Welcome.vala 2011-08-04 12:44:27 +0000 |
212 | +++ lib/Widgets/Welcome.vala 2012-01-11 19:46:23 +0000 |
213 | @@ -1,116 +1,204 @@ |
214 | -// |
215 | +// |
216 | // Copyright (C) 2011 Maxwell Barvian |
217 | -// |
218 | +// |
219 | // This program is free software: you can redistribute it and/or modify |
220 | // it under the terms of the GNU General Public License as published by |
221 | // the Free Software Foundation, either version 3 of the License, or |
222 | // (at your option) any later version. |
223 | -// |
224 | +// |
225 | // This program is distributed in the hope that it will be useful, |
226 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
227 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
228 | // GNU General Public License for more details. |
229 | -// |
230 | +// |
231 | // You should have received a copy of the GNU General Public License |
232 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
233 | // |
234 | |
235 | using Gtk; |
236 | |
237 | -public class Granite.Widgets.Welcome : VBox { |
238 | +public class Granite.Widgets.Welcome : Gtk.EventBox { |
239 | |
240 | // Signals |
241 | public signal void activated (int index); |
242 | |
243 | - protected new List<Button> children; |
244 | - protected VBox options; |
245 | + protected new GLib.List<Gtk.Button> children = new GLib.List<Gtk.Button> (); |
246 | + protected Gtk.Box options; |
247 | + |
248 | + private enum CaseConversionMode { |
249 | + TITLE, |
250 | + SENTENCE |
251 | + } |
252 | |
253 | public Welcome (string title_text, string subtitle_text) { |
254 | - |
255 | - children = new List<Button> (); |
256 | - options = new Gtk.VBox (false, 6); |
257 | - |
258 | - // VBox properties |
259 | - spacing = 5; |
260 | - homogeneous = false; |
261 | + string _title_text = modify_text_case (title_text, CaseConversionMode.TITLE); |
262 | + string _subtitle_text = modify_text_case (subtitle_text, CaseConversionMode.SENTENCE); |
263 | + |
264 | + Gtk.Box content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); |
265 | + |
266 | + // Set theming |
267 | + this.get_style_context().add_class ("GraniteWelcomeScreen"); |
268 | + |
269 | + // Box properties |
270 | + content.homogeneous = false; |
271 | |
272 | // Top spacer |
273 | - pack_start (new Gtk.VBox (false, 0), true, true, 0); |
274 | + content.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); |
275 | |
276 | // Labels |
277 | - var title = new Label ("<span weight='heavy' size='15000'>" + title_text + "</span>"); |
278 | + var title = new Gtk.Label ("<span weight='medium' size='14700'>" + _title_text + "</span>"); |
279 | + |
280 | + title.get_style_context().add_class ("title"); |
281 | + |
282 | title.use_markup = true; |
283 | - title.set_justify (Justification.CENTER); |
284 | - pack_start (title, false, true, 0); |
285 | + title.set_justify (Gtk.Justification.CENTER); |
286 | + content.pack_start (title, false, true, 0); |
287 | |
288 | - var subtitle = new Label (subtitle_text); |
289 | + var subtitle = new Gtk.Label ("<span weight='medium' size='11500'>" + _subtitle_text + "</span>"); |
290 | + subtitle.use_markup = true; |
291 | subtitle.sensitive = false; |
292 | - subtitle.set_justify (Justification.CENTER); |
293 | - pack_start (subtitle, false, true, 6); |
294 | + subtitle.set_justify (Gtk.Justification.CENTER); |
295 | + content.pack_start (subtitle, false, true, 2); |
296 | + |
297 | + subtitle.get_style_context().add_class("subtitle"); |
298 | |
299 | // Options wrapper |
300 | - |
301 | - var options_wrapper = new HBox (false, 0); |
302 | - |
303 | - options_wrapper.pack_start (new Gtk.VBox (false, 0), true, true, 0); // left padding |
304 | - options_wrapper.pack_start (options, false, false, 0); // actual options |
305 | - options_wrapper.pack_end (new Gtk.VBox (false, 0), true, true, 0); // right padding |
306 | - |
307 | - pack_start (options_wrapper, false, false, 0); |
308 | + this.options = new Gtk.Box (Gtk.Orientation.VERTICAL, 8); |
309 | + var options_wrapper = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); |
310 | + |
311 | + options_wrapper.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // left padding |
312 | + options_wrapper.pack_start (this.options, false, false, 0); // actual options |
313 | + options_wrapper.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // right padding |
314 | + |
315 | + content.pack_start (options_wrapper, false, false, 20); |
316 | |
317 | // Bottom spacer |
318 | - pack_end (new Gtk.VBox (false, 0), true, true, 0); |
319 | - } |
320 | - |
321 | - public void append (string icon_name, string label_text, string description_text) { |
322 | - |
323 | - // Button |
324 | - var button = new Button (); |
325 | - button.set_relief (ReliefStyle.NONE); |
326 | - |
327 | - // HBox wrapper |
328 | - var hbox = new HBox (false, 6); |
329 | - |
330 | - // Add left image |
331 | - var icon = new Image.from_icon_name (icon_name, IconSize.DIALOG); |
332 | - hbox.pack_start (icon, false, true, 6); |
333 | - |
334 | - // Add right vbox |
335 | - var vbox = new VBox (false, 0); |
336 | - |
337 | - vbox.pack_start (new HBox (false, 0), true, true, 0); // top spacing |
338 | + content.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); |
339 | + |
340 | + add (content); |
341 | + } |
342 | + |
343 | + public void set_sensitivity (uint index, bool val) { |
344 | + if(index < children.length () && children.nth_data (index) is Gtk.Widget) |
345 | + children.nth_data (index).set_sensitive (val); |
346 | + } |
347 | + |
348 | + public void append (string icon_name, string option_text, string description_text) { |
349 | + Gtk.Image? image = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG); |
350 | + append_with_image (image, option_text, description_text); |
351 | + } |
352 | + |
353 | + public void append_with_pixbuf (Gdk.Pixbuf? pixbuf, string option_text, string description_text) { |
354 | + var image = new Gtk.Image.from_pixbuf (pixbuf); |
355 | + append_with_image (image, option_text, description_text); |
356 | + } |
357 | + |
358 | + public void append_with_image (Gtk.Image? image, string option_text, string description_text) { |
359 | + string _option_text = modify_text_case (option_text, CaseConversionMode.TITLE); |
360 | + string _description_text = modify_text_case (description_text, CaseConversionMode.SENTENCE); |
361 | |
362 | // Option label |
363 | - var label = new Label ("<span weight='medium' size='12500'>" + label_text + "</span>"); |
364 | + var label = new Gtk.Label ("<span weight='medium' size='11700'>" + _option_text + "</span>"); |
365 | label.use_markup = true; |
366 | - label.set_alignment(0.0f, 0.5f); |
367 | - vbox.pack_start (label, false, false, 0); |
368 | + label.halign = Gtk.Align.START; |
369 | + label.valign = Gtk.Align.CENTER; |
370 | + label.get_style_context().add_class ("option-title"); |
371 | |
372 | // Description label |
373 | - var description = new Label (description_text); |
374 | + var description = new Gtk.Label ("<span weight='medium' size='11400'>" + _description_text + "</span>"); |
375 | + description.use_markup = true; |
376 | + description.halign = Gtk.Align.START; |
377 | + description.valign = Gtk.Align.CENTER; |
378 | description.sensitive = false; |
379 | - description.set_alignment(0.0f, 0.5f); |
380 | - vbox.pack_start (description, false, false, 0); |
381 | - |
382 | - vbox.pack_end (new Gtk.VBox (false, 0), true, true, 0); // bottom spacing |
383 | - |
384 | - hbox.pack_start (vbox, false, true, 6); |
385 | - |
386 | - button.add (hbox); |
387 | + description.get_style_context().add_class ("option-description"); |
388 | + |
389 | + // Button |
390 | + var button = new Gtk.Button (); |
391 | + button.set_relief (Gtk.ReliefStyle.NONE); |
392 | + |
393 | + // Button contents wrapper |
394 | + var button_contents = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 7); |
395 | + |
396 | + // Add left image |
397 | + if (image != null) { |
398 | + image.set_pixel_size (48); |
399 | + button_contents.pack_start (image, false, true, 8); |
400 | + } |
401 | + |
402 | + // Add right text wrapper |
403 | + var text_wrapper = new Gtk.Box (Gtk.Orientation.VERTICAL, 3); |
404 | + // top spacing |
405 | + text_wrapper.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); |
406 | + text_wrapper.pack_start (label, false, false, 0); |
407 | + text_wrapper.pack_start (description, false, false, 0); |
408 | + // bottom spacing |
409 | + text_wrapper.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); |
410 | + |
411 | + button_contents.pack_start (text_wrapper, false, true, 8); |
412 | + |
413 | + button.add (button_contents); |
414 | children.append (button); |
415 | options.pack_start (button, false, false, 0); |
416 | |
417 | button.button_release_event.connect ( () => { |
418 | - int index = children.index (button); |
419 | + int index = this.children.index (button); |
420 | activated (index); // send signal |
421 | - |
422 | return false; |
423 | } ); |
424 | - |
425 | - } |
426 | - |
427 | - public new void set_sensitive (int index, bool sensitivity) { |
428 | - children.nth_data (index).sensitive = sensitivity; |
429 | - } |
430 | - |
431 | + } |
432 | + |
433 | + private string modify_text_case (string text, CaseConversionMode mode) { |
434 | + |
435 | + /** |
436 | + * This function will not modify the text if any the following conditions are met: |
437 | + * - @text ends with a dot. |
438 | + * - @text contains at least one character outside the English alphabet. |
439 | + */ |
440 | + |
441 | + var fixed_text = new StringBuilder (); |
442 | + unichar c; |
443 | + |
444 | + // Disabling this feature for other languages |
445 | + for (int i = 0; text.get_next_char (ref i, out c);) { |
446 | + if (c.isgraph () && !('a' <= c.tolower () && c.tolower () <= 'z')) |
447 | + return text; |
448 | + } |
449 | + // Checking if @text ends with a dot. |
450 | + if (c == '.') |
451 | + return text; |
452 | + |
453 | + switch (mode) { |
454 | + case CaseConversionMode.TITLE: |
455 | + unichar last_char = ' '; |
456 | + for (int i = 0; text.get_next_char (ref i, out c);) { |
457 | + if (last_char.isspace () && c.islower ()) |
458 | + fixed_text.append_unichar (c.totitle ()); |
459 | + else |
460 | + fixed_text.append_unichar (c); |
461 | + |
462 | + last_char = c; |
463 | + } |
464 | + break; |
465 | + case CaseConversionMode.SENTENCE: |
466 | + bool fixed = false; |
467 | + unichar last_char = ' '; |
468 | + for (int i = 0; text.get_next_char (ref i, out c);) { |
469 | + if (!fixed && last_char.isspace ()) { |
470 | + if (c.islower ()) |
471 | + fixed_text.append_unichar (c.totitle ()); |
472 | + else |
473 | + fixed_text.append_unichar (c); |
474 | + fixed = true; |
475 | + } |
476 | + else { |
477 | + fixed_text.append_unichar (c); |
478 | + } |
479 | + } |
480 | + fixed_text.append_unichar ('.'); |
481 | + break; |
482 | + } |
483 | + |
484 | + return fixed_text.str; |
485 | + } |
486 | } |
487 | + |