elementaryart team mailing list archive
-
elementaryart team
-
Mailing list archive
-
Message #01862
[Merge] lp:~victored/granite/welcome-screen into lp:granite
Victor Eduardo has proposed merging lp:~victored/granite/welcome-screen into lp:granite.
Requested reviews:
elementary Pantheon team (elementary-pantheon)
Related bugs:
Bug #909067 in Granite: "allow adding items to welcome widget with a pixbuf rather than icon name"
https://bugs.launchpad.net/granite/+bug/909067
For more details, see:
https://code.launchpad.net/~victored/granite/welcome-screen/+merge/87219
Welcome Screen:
- Style changes (white background, etc.)
- New functions:
append_from_image (Gtk.Image? icon, string option, string description);
append_from_pixbuf (Gdk.Pixbuf? icon, string option, string description);
This fixes lp:909067
--
https://code.launchpad.net/~victored/granite/welcome-screen/+merge/87219
Your team elementaryart (old) is subscribed to branch lp:granite.
=== added file 'data/style/WelcomeScreen.css'
--- data/style/WelcomeScreen.css 1970-01-01 00:00:00 +0000
+++ data/style/WelcomeScreen.css 2012-01-02 04:24:25 +0000
@@ -0,0 +1,60 @@
+.WelcomeScreen
+{
+ background-image: none;
+ background-color: #f9f9f9;
+ text-shadow: 0 1 alpha (shade (#dedede, 1.35), 0.5);
+}
+
+.WelcomeScreen .main-title,
+.WelcomeScreen .option-label
+{
+ color: #333333;
+}
+
+.WelcomeScreen .subtitle
+{
+ color: #8f8f8f;
+}
+
+/*
+TODO: Theme buttons
+
+.WelcomeScreen .button,
+.WelcomeScreen .button:active,
+.WelcomeScreen .button:hover,
+.WelcomeScreen .button:active:hover,
+.WelcomeScreen .button:insensitive
+{
+
+ -GtkButton-child-displacement-x: 0;
+ -GtkButton-child-displacement-y: 0;
+
+ background-image: -gtk-gradient (linear, left top, left bottom,
+ from (shade (#fff, 0.97)),
+ to (shade (#fff, 0.93)));
+
+ -unico-border-gradient: -gtk-gradient (linear,
+ left top, left bottom,
+ from (shade (#f9f9f9, 0.93)),
+ to (shade (#f9f9f9, 0.85)));
+}
+
+.WelcomeScreen .button:active,
+.WelcomeScreen .button:active:hover
+{
+ background-image: -gtk-gradient (linear, left top, left bottom,
+ from (shade (#f9f9f9, 0.90)),
+ to (shade (#f9f9f9, 0.96)));
+
+ -unico-border-gradient: -gtk-gradient (linear, left top, left bottom,
+ from (shade (#f9f9f9, 0.87)),
+ to (shade (#f9f9f9, 0.88)));
+}
+
+.WelcomeScreen .button:insensitive
+{
+ background-image: -gtk-gradient (linear, left top, left bottom,
+ from (shade (#fff, 0.98)),
+ to (shade (#fff, 0.99)));
+}
+*/
=== modified file 'demo/main.vala'
--- demo/main.vala 2011-11-04 18:54:58 +0000
+++ demo/main.vala 2012-01-02 04:24:25 +0000
@@ -67,10 +67,27 @@
win.add(notebook);
/* welcome */
- var welcome = new Welcome("Granite", "Let's try...");
+
+ // These strings will be corrected automatically by the widget
+ var welcome = new Welcome("do something", "description text.");
notebook.append_page(welcome, new Gtk.Label("Welcome"));
- welcome.append("gtk-open", "Open", "Open a file");
- welcome.append("gtk-save", "Save", "Save with a much longer description");
+
+ Gdk.Pixbuf? pixbuf = null;
+
+ try {
+ pixbuf = Gtk.IconTheme.get_default().load_icon ("document-new", 48, Gtk.IconLookupFlags.GENERIC_FALLBACK);
+ }
+ catch(Error e) {
+ warning("Could not load icon, %s", e.message);
+ }
+
+ Gtk.Image? image = new Gtk.Image.from_icon_name("document-open", Gtk.IconSize.DIALOG);
+
+ // Adding elements. Use the most convenient function to add an icon
+ welcome.append_from_pixbuf(pixbuf, "create", "write a new document.");
+ welcome.append_from_image(image, "open", "select a file.");
+ welcome.append("document-save", "save", "with a much longer description.");
+ welcome.append("help-info", "Learn", "Discover new features.");
/* modebutton */
var mode_button = new ModeButton();
=== modified file 'lib/Widgets/Welcome.vala'
--- lib/Widgets/Welcome.vala 2011-08-04 12:44:27 +0000
+++ lib/Widgets/Welcome.vala 2012-01-02 04:24:25 +0000
@@ -1,116 +1,244 @@
-//
+//
// Copyright (C) 2011 Maxwell Barvian
-//
+//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
-//
+//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
-//
+//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
using Gtk;
-public class Granite.Widgets.Welcome : VBox {
+public class Granite.Widgets.Welcome : Gtk.EventBox {
// Signals
public signal void activated (int index);
- protected new List<Button> children;
- protected VBox options;
+ protected new GLib.List<Gtk.Button> children = new GLib.List<Gtk.Button> ();
+ protected Gtk.Box options;
+
+ private enum CaseConversionMode {
+ UPPER_CASE,
+ LOWER_CASE,
+ TOGGLE_CASE,
+ TITLE,
+ SENTENCE
+ }
+
+ private CssProvider style_provider;
public Welcome (string title_text, string subtitle_text) {
- children = new List<Button> ();
- options = new Gtk.VBox (false, 6);
-
- // VBox properties
- spacing = 5;
- homogeneous = false;
+ string _title_text = fix_text (title_text, CaseConversionMode.TITLE);
+ string _subtitle_text = fix_text (subtitle_text, CaseConversionMode.SENTENCE);
+
+ Gtk.Box content = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
+
+ style_provider = new CssProvider ();
+
+ try {
+ style_provider.load_from_path (RESOURCES_DIR + "/style/WelcomeScreen.css");
+ } catch (Error e) {
+ warning ("Could not add CSS provider. Some widgets will not look as intended. %s", e.message);
+ }
+
+ var style_context = this.get_style_context();
+ style_context.add_class ("WelcomeScreen");
+ style_context.add_provider (style_provider, 1000);
+
+ // Box properties
+ content.homogeneous = false;
// Top spacer
- pack_start (new Gtk.VBox (false, 0), true, true, 0);
+ content.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0);
// Labels
- var title = new Label ("<span weight='heavy' size='15000'>" + title_text + "</span>");
+ var title = new Gtk.Label ("<span weight='medium' size='16000'>" + _title_text + "</span>");
+
+ var main_title_style = title.get_style_context();
+ main_title_style.add_class ("main-title");
+ main_title_style.add_provider (style_provider, 1000);
+
title.use_markup = true;
- title.set_justify (Justification.CENTER);
- pack_start (title, false, true, 0);
+ title.set_justify (Gtk.Justification.CENTER);
+ content.pack_start (title, false, true, 0);
- var subtitle = new Label (subtitle_text);
+ var subtitle = new Gtk.Label ("<span weight='medium' size='13000'>" + _subtitle_text + "</span>");
+ subtitle.use_markup = true;
subtitle.sensitive = false;
- subtitle.set_justify (Justification.CENTER);
- pack_start (subtitle, false, true, 6);
+ subtitle.set_justify (Gtk.Justification.CENTER);
+ content.pack_start (subtitle, false, true, 2);
+
+ var subtitle_style = subtitle.get_style_context();
+ subtitle_style.add_class("subtitle");
+ subtitle_style.add_provider (style_provider, 600);
// Options wrapper
-
- var options_wrapper = new HBox (false, 0);
-
- options_wrapper.pack_start (new Gtk.VBox (false, 0), true, true, 0); // left padding
- options_wrapper.pack_start (options, false, false, 0); // actual options
- options_wrapper.pack_end (new Gtk.VBox (false, 0), true, true, 0); // right padding
-
- pack_start (options_wrapper, false, false, 0);
+ this.options = new Gtk.Box (Gtk.Orientation.VERTICAL, 8);
+ var options_wrapper = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
+
+ options_wrapper.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // left padding
+ options_wrapper.pack_start (this.options, false, false, 0); // actual options
+ options_wrapper.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // right padding
+
+ content.pack_start (options_wrapper, false, false, 20);
// Bottom spacer
- pack_end (new Gtk.VBox (false, 0), true, true, 0);
- }
-
- public void append (string icon_name, string label_text, string description_text) {
+ content.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0);
+
+ add (content);
+ }
+
+ public void set_sensitivity(uint index, bool val) {
+ if(index < children.length() && children.nth_data(index) is Gtk.Widget)
+ children.nth_data(index).set_sensitive(val);
+ }
+
+ public void append (string icon_name, string option_text, string description_text) {
+ Gtk.Image? icon = new Gtk.Image.from_icon_name (icon_name, Gtk.IconSize.DIALOG);
+ append_from_image (icon, option_text, description_text);
+ }
+
+ public void append_from_pixbuf (Gdk.Pixbuf? icon, string option_text, string description_text) {
+ var image = new Gtk.Image.from_pixbuf (icon);
+ append_from_image (image, option_text, description_text);
+ }
+
+ public void append_from_image (Gtk.Image? icon, string option_text, string description_text) {
+
+ string _option_text = fix_text (option_text, CaseConversionMode.TITLE);
+ string _description_text = fix_text (description_text, CaseConversionMode.SENTENCE);
// Button
- var button = new Button ();
- button.set_relief (ReliefStyle.NONE);
+ var button = new Gtk.Button ();
+ button.set_relief (Gtk.ReliefStyle.NONE);
// HBox wrapper
- var hbox = new HBox (false, 6);
+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
// Add left image
- var icon = new Image.from_icon_name (icon_name, IconSize.DIALOG);
- hbox.pack_start (icon, false, true, 6);
+ if (icon != null) {
+ icon.set_pixel_size (48);
+ hbox.pack_start (icon, false, true, 6);
+ }
// Add right vbox
- var vbox = new VBox (false, 0);
+ var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
- vbox.pack_start (new HBox (false, 0), true, true, 0); // top spacing
+ vbox.pack_start (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // top spacing
// Option label
- var label = new Label ("<span weight='medium' size='12500'>" + label_text + "</span>");
+ var label = new Gtk.Label ("<span weight='medium' size='12000'>" + _option_text + "</span>");
+ var label_style = label.get_style_context();
+ label_style.add_class ("option-label");
+ label_style.add_provider (style_provider, 600);
+
label.use_markup = true;
label.set_alignment(0.0f, 0.5f);
vbox.pack_start (label, false, false, 0);
// Description label
- var description = new Label (description_text);
+ var description = new Gtk.Label ("<span weight='medium' size='11700'>" + _description_text + "</span>");
+ description.use_markup = true;
description.sensitive = false;
description.set_alignment(0.0f, 0.5f);
+
vbox.pack_start (description, false, false, 0);
- vbox.pack_end (new Gtk.VBox (false, 0), true, true, 0); // bottom spacing
+ var description_style = description.get_style_context();
+ description_style.add_class ("subtitle");
+ description_style.add_provider (style_provider, 600);
+
+ vbox.pack_end (new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0), true, true, 0); // bottom spacing
hbox.pack_start (vbox, false, true, 6);
button.add (hbox);
- children.append (button);
+ this.children.append (button);
options.pack_start (button, false, false, 0);
+ button.get_style_context().add_provider (style_provider, 700);
+
button.button_release_event.connect ( () => {
- int index = children.index (button);
- activated (index); // send signal
+ int index = this.children.index (button);
+ this.activated (index); // send signal
return false;
} );
-
- }
-
- public new void set_sensitive (int index, bool sensitivity) {
- children.nth_data (index).sensitive = sensitivity;
- }
-
+ }
+
+ private string fix_text (string text, CaseConversionMode mode) {
+
+ var fixed_text = new StringBuilder ();
+ unichar c;
+
+ switch (mode) {
+ case CaseConversionMode.UPPER_CASE:
+ for (int i = 0; text.get_next_char (ref i, out c);) {
+ if (c.islower ())
+ fixed_text.append_unichar (c.toupper ());
+ else
+ fixed_text.append_unichar (c);
+ }
+ break;
+ case CaseConversionMode.LOWER_CASE:
+ for (int i = 0; text.get_next_char (ref i, out c);) {
+ if (c.isupper ())
+ fixed_text.append_unichar (c.tolower ());
+ else
+ fixed_text.append_unichar (c);
+ }
+ break;
+ case CaseConversionMode.TOGGLE_CASE:
+ for (int i = 0; text.get_next_char (ref i, out c);) {
+ if (c.islower ())
+ fixed_text.append_unichar (c.toupper ());
+ else if (c.isupper ())
+ fixed_text.append_unichar (c.tolower ());
+ else
+ fixed_text.append_unichar (c);
+ }
+ break;
+ case CaseConversionMode.TITLE:
+ unichar last_char = ' ';
+ for (int i = 0; text.get_next_char (ref i, out c);) {
+ if (last_char.isspace () && c.islower ())
+ fixed_text.append_unichar (c.totitle ());
+ else
+ fixed_text.append_unichar (c);
+
+ last_char = c;
+ }
+ break;
+ case CaseConversionMode.SENTENCE:
+ bool fixed = false;
+ unichar last_char = ' ';
+ for (int i = 0; text.get_next_char (ref i, out c);) {
+ if (!fixed && last_char.isspace ()) {
+ if (c.islower ())
+ fixed_text.append_unichar (c.totitle ());
+ else
+ fixed_text.append_unichar (c);
+ fixed = true;
+ }
+ else {
+ fixed_text.append_unichar (c);
+ }
+ }
+
+ break;
+ }
+
+ return fixed_text.str;
+ }
}
+
+
Follow ups