Lift detail window layout updates
authorPhilipp Zabel <philipp.zabel@gmail.com>
Sat, 22 May 2010 11:18:56 +0000 (13:18 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Fri, 28 May 2010 20:18:33 +0000 (22:18 +0200)
Fixes portrait mode, improves formatting and aligment,
adds an information banner for the (non-)smoker icons.

src/lift-detail-window.vala

index cc6e667..163da15 100644 (file)
@@ -30,6 +30,9 @@ public class LiftDetailWindow : StackableWindow {
 
        AdacMitfahrclub adac;
        Lift lift;
+       Alignment alignment;
+       PannableArea pannable;
+       VBox vbox;
        OssoABook.Button button_route;
        OssoABook.Button button_calendar;
        Label label_driver;
@@ -37,6 +40,8 @@ public class LiftDetailWindow : StackableWindow {
        OssoABook.Button button_sms;
        Image image_smoke;
        Label label;
+       Label label_changed;
+       Table table;
        string ics_filename = null;
 
        public LiftDetailWindow (AdacMitfahrclub _adac, Lift _lift) {
@@ -61,22 +66,29 @@ public class LiftDetailWindow : StackableWindow {
                menu.append (goto_website);
                set_main_menu (menu);
 
-               var pannable = new PannableArea ();
+               alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
+               alignment.top_padding = MARGIN_HALF;
+               alignment.left_padding = MARGIN_DOUBLE;
+               alignment.right_padding = MARGIN_DOUBLE;
+
+               pannable = new PannableArea ();
                pannable.hscrollbar_policy = PolicyType.NEVER;
 
-               var vbox = new VBox (false, 0);
+               vbox = new VBox (false, 0);
 
                var hbox = new HBox (false, 0);
 
                button_route = new OssoABook.Button (SizeType.FINGER_HEIGHT);
                button_route.style = OssoABook.ButtonStyle.LABEL;
 
+               var image_eventbox = new EventBox ();
                image_smoke = new Image ();
+               image_eventbox.add (image_smoke);
 
                hbox.pack_start (button_route, true, true, 0);
-               hbox.pack_start (image_smoke, false, false, MARGIN_DEFAULT);
+               hbox.pack_start (image_eventbox, false, false, MARGIN_DEFAULT);
 
-               var table = new Table (4, 2, false);
+               table = new Table (6, 2, false);
 
                button_calendar = new OssoABook.Button (SizeType.FINGER_HEIGHT);
                button_calendar.set_icon_name ("general_calendar");
@@ -85,6 +97,7 @@ public class LiftDetailWindow : StackableWindow {
 
                label_driver = new Label (_("Driver:"));
                label_driver.set_alignment (0.0f, 0.5f);
+               Hildon.gtk_widget_set_theme_size (label_driver, SizeType.FINGER_HEIGHT);
 
                button_phone = new OssoABook.Button (SizeType.FINGER_HEIGHT);
                button_phone.set_icon_name ("general_call");
@@ -100,25 +113,43 @@ public class LiftDetailWindow : StackableWindow {
                label.set_alignment (0.0f, 0.5f);
                label.set_line_wrap (true);
 
-               table.attach (button_calendar, 1, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
-               table.attach (label_driver, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
-               table.attach (button_phone, 1, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
-               table.attach (button_sms, 1, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
-               table.attach (label, 0, 2, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+               label_changed = new Label ("");
+               label_changed.set_alignment (1.0f, 0.0f);
+               Hildon.helper_set_logical_color (label_changed, RcFlags.FG, StateType.NORMAL, "SecondaryTextColor");
+               Hildon.helper_set_logical_font (label_changed, "SmallSystemFont");
+
+               if (BeifahrerProgram.orientation.portrait) {
+                       table.attach (button_calendar, 0, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (label_driver, 0, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+                       table.attach (button_phone, 0, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (button_sms, 0, 2, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               } else {
+                       table.attach (button_calendar, 1, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (label_driver, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+                       table.attach (button_phone, 1, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (button_sms, 1, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               }
+               table.attach (label, 0, 2, 4, 5, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+               table.attach (label_changed, 0, 2, 5, 6, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
 
                vbox.pack_start (hbox, true, true, 0);
                vbox.pack_start (table, true, true, 0);
 
                pannable.add_with_viewport (vbox);
+               alignment.add (pannable);
 
-               add (pannable);
+               alignment.show_all ();
+               add (alignment);
 
+               BeifahrerProgram.orientation.changed.connect (on_orientation_changed);
                add_contact.clicked.connect (on_add_contact_clicked);
                goto_website.clicked.connect (on_goto_website_clicked);
+               image_eventbox.button_press_event.connect (on_image_eventbox_button_pressed);
                button_calendar.clicked.connect (on_button_calendar_clicked);
                button_phone.clicked.connect (on_button_phone_clicked);
                button_sms.clicked.connect (on_button_sms_clicked);
                destroy.connect (on_destroy);
+               map_event.connect (on_map_event);
        }
 
        private async void get_lift_details () {
@@ -160,12 +191,10 @@ public class LiftDetailWindow : StackableWindow {
                if (LiftFlags.SMOKER in lift.flags) try {
                        var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_smoker", 32, IconLookupFlags.NO_SVG);
                        image_smoke.pixbuf = pixbuf;
-                       lift_text += _("smoker ");
                } catch (Error e) {
                } else if (LiftFlags.NON_SMOKER in lift.flags) try {
                        var pixbuf = IconTheme.get_default ().load_icon ("beifahrer_non_smoker", 32, IconLookupFlags.NO_SVG);
                        image_smoke.pixbuf = pixbuf;
-                       lift_text += _("non-smoker ");
                } catch (Error e) {
                }
                if (LiftFlags.ADAC_MEMBER in lift.flags)
@@ -174,10 +203,14 @@ public class LiftDetailWindow : StackableWindow {
                        lift_text += _("only women ");
                lift_text += "\n\n" + lift.description;
 
+               label.set_text (lift_text);
+
                if (lift.modified != null)
-                       lift_text += _("\nLast changed: ") + lift.modified;
+                       label_changed.set_text (_("\nLast changed: ") + lift.modified);
 
-               label.set_text (lift_text);
+               // Reduce right margin for scrollbar, if update_lift_details is called after mapping the window
+               if (vbox.allocation.height > pannable.allocation.height)
+                       alignment.right_padding = MARGIN_DEFAULT;
        }
 
        void on_button_calendar_clicked () {
@@ -212,6 +245,13 @@ public class LiftDetailWindow : StackableWindow {
                        FileUtils.remove (ics_filename);
        }
 
+       bool on_map_event (Gdk.Event event) {
+               // Reduce right margin for scrollbar, for preloaded lift
+               if (vbox.allocation.height > pannable.allocation.height)
+                       alignment.right_padding = MARGIN_DEFAULT;
+               return true;
+       }
+
        void on_button_phone_clicked () {
                var uri = "tel://";
                if (lift.cell != null)
@@ -287,4 +327,36 @@ public class LiftDetailWindow : StackableWindow {
                        Banner.show_information (this, null, _("Failed to open browser."));
                }
        }
+
+       bool on_image_eventbox_button_pressed (Gdk.EventButton event) {
+               if (event.button != 1)
+                       return true;
+               if (LiftFlags.SMOKER in lift.flags)
+                       Banner.show_information (this, null, _("Smoker"));
+               if (LiftFlags.NON_SMOKER in lift.flags)
+                       Banner.show_information (this, null, _("Non-smoker"));
+               return false;
+       }
+
+       void on_orientation_changed () {
+               // Maybe this will be fixed directly in Maemo-GTK, see
+               // http://lists.maemo.org/pipermail/maemo-developers/2010-May/026332.html
+               vbox.queue_resize ();
+
+               table.remove (button_calendar);
+               table.remove (label_driver);
+               table.remove (button_phone);
+               table.remove (button_sms);
+               if (BeifahrerProgram.orientation.portrait) {
+                       table.attach (button_calendar, 0, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (label_driver, 0, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+                       table.attach (button_phone, 0, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (button_sms, 0, 2, 3, 4, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               } else {
+                       table.attach (button_calendar, 1, 2, 0, 1, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (label_driver, 0, 1, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, MARGIN_DEFAULT, 0);
+                       table.attach (button_phone, 1, 2, 1, 2, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+                       table.attach (button_sms, 1, 2, 2, 3, AttachOptions.FILL | AttachOptions.EXPAND, AttachOptions.FILL, 0, 0);
+               }
+       }
 }