[gnome-maps/wip/search-props: 4/4] wip: Add search properties view



commit 4e1780e6ff3293e117bee7f58d9cbe01320b9de2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Apr 1 21:03:10 2013 -0400

    wip: Add search properties view

 configure.ac        |    1 +
 src/Makefile-js.am  |    2 +
 src/mainWindow.js   |    9 ++--
 src/mapView.js      |   23 ++++++++-
 src/mapViewEmbed.js |  118 +++++++++++++++++++++++++++++++++++++++++++++
 src/properties.js   |  132 +++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 278 insertions(+), 7 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d8cc06d..680a113 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_SUBST(GLIB_COMPILE_RESOURCES)
 
 LIBGD_INIT([
   header-bar
+  revealer
   tagged-entry
   gir
 ])
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 2b0d22f..801e7a9 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -5,7 +5,9 @@ dist_js_DATA = \
     mainWindow.js \
     mainToolbar.js \
     mapView.js \
+    mapViewEmbed.js \
     path.js \
+    properties.js \
     utils.js
 
 BUILT_SOURCES += \
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 7188a03..344a752 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -23,7 +23,6 @@ const Gdk = imports.gi.Gdk;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const Champlain = imports.gi.Champlain;
-const GtkChamplain = imports.gi.GtkChamplain;
 const Geocode = imports.gi.GeocodeGlib;
 
 const Lang = imports.lang;
@@ -31,7 +30,7 @@ const Mainloop = imports.mainloop;
 
 const Application = imports.application;
 const MainToolbar = imports.mainToolbar;
-const MapView = imports.mapView;
+const MapViewEmbed = imports.mapViewEmbed;
 const Utils = imports.utils;
 const Config = imports.config;
 
@@ -94,8 +93,10 @@ const MainWindow = new Lang.Class({
         this._toolbar = new MainToolbar.MainToolbar(this);
         grid.add(this._toolbar.widget);
 
-        this.mapView = new MapView.MapView();
-        grid.add(this.mapView.widget);
+        this._embed = new MapViewEmbed.MapViewEmbed();
+        grid.add(this._embed);
+
+        this.mapView = this._embed.mapView;
 
         grid.show_all();
     },
diff --git a/src/mapView.js b/src/mapView.js
index f68ef19..3639a50 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -22,8 +22,10 @@ const Gdk = imports.gi.Gdk;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
 const Champlain = imports.gi.Champlain;
-const GtkChamplain = imports.gi.GtkChamplain;
+const Clutter = imports.gi.Clutter;
 const Geocode = imports.gi.GeocodeGlib;
+const Gd = imports.gi.Gd;
+const GtkClutter = imports.gi.GtkClutter;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
@@ -32,12 +34,19 @@ const Application = imports.application;
 const Utils = imports.utils;
 const _ = imports.gettext.gettext;
 
+const MapType = {
+   STREET:  Champlain.MAP_SOURCE_OSM_MAPQUEST,
+   /* This should be CHAMPLAIN_MAP_SOURCE_OAM but that currently causes a crash: bug#697304 */
+   TERRAIN: Champlain.MAP_SOURCE_MFF_RELIEF,
+   CYCLING: Champlain.MAP_SOURCE_OSM_CYCLE_MAP,
+   TRANSIT: Champlain.MAP_SOURCE_OSM_TRANSPORT_MAP
+}
+
 const MapView = new Lang.Class({
     Name: 'MapView',
 
     _init: function(app) {
-        this.widget = new GtkChamplain.Embed();
-        this.actor = this.widget.get_view();
+        this.actor = new Champlain.View();
 
         this._view = this.actor;
 
@@ -45,9 +54,17 @@ const MapView = new Lang.Class({
         this._markerLayer.set_selection_mode(Champlain.SelectionMode.SINGLE);
         this._view.add_layer(this._markerLayer);
 
+        this._factory = Champlain.MapSourceFactory.dup_default();
+        this.setMapType(MapType.STREET);
+
         this._gotoUserLocation();
     },
 
+    setMapType: function(mapType) {
+        let source = this._factory.create_cached_source(mapType);
+        this._view.set_map_source(source);
+    },
+
     geocodeSearch: function(string) {
         let forward = Geocode.Forward.new_for_string(string);
 
diff --git a/src/mapViewEmbed.js b/src/mapViewEmbed.js
new file mode 100644
index 0000000..e51349b
--- /dev/null
+++ b/src/mapViewEmbed.js
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ *
+ * GNOME Maps 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 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps 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 GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc gnome org>
+ *         Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ */
+
+const Gdk = imports.gi.Gdk;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Champlain = imports.gi.Champlain;
+const Clutter = imports.gi.Clutter;
+const Geocode = imports.gi.GeocodeGlib;
+const Gd = imports.gi.Gd;
+const GtkClutter = imports.gi.GtkClutter;
+const Properties = imports.properties;
+const MapView = imports.mapView;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+
+const Application = imports.application;
+const Utils = imports.utils;
+const _ = imports.gettext.gettext;
+
+const MapViewEmbed = new Lang.Class({
+    Name: 'MapViewEmbed',
+    Extends: GtkClutter.Embed,
+
+    _init: function() {
+        this.parent();
+
+        this._cursorHandOpen = Gdk.Cursor.new(Gdk.CursorType.HAND1);
+        this._cursorHandClosed = Gdk.Cursor.new(Gdk.CursorType.FLEUR);
+
+        this.mapView = new MapView.MapView();
+        this._layout = new Clutter.BinLayout();
+        this._actor = new Clutter.Actor({ layout_manager: this._layout,
+                                          x_expand: true,
+                                          y_expand: true });
+
+        this.mapView.actor.x_expand = true;
+        this.mapView.actor.y_expand = true;
+        this._actor.add_child(this.mapView.actor);
+
+        this._properties = new Properties.Properties(this.mapView);
+        this._actor.add_child(this._properties.actor);
+
+        let stage = this.get_stage();
+        stage.add_actor(this._actor);
+
+        this.connect('button-press-event', Lang.bind(this, this._onButtonPress));
+        this.connect('button-release-event', Lang.bind(this, this._onButtonRelease));
+    },
+
+    vfunc_realize: function(params) {
+        this.parent(params);
+        this._updateViewStyle();
+    },
+
+    vfunc_style_updated: function(params) {
+        this.parent(params);
+        this._updateViewStyle();
+    },
+
+    vfunc_size_allocate: function(params) {
+        this.parent(params);
+
+        let allocation = this.get_allocation();
+
+        this.mapView.actor.set_size(allocation.width,
+                                    allocation.height);
+    },
+
+    _onButtonPress: function(event) {
+        this.get_window().set_cursor(this._cursorHandClosed);
+        return false;
+    },
+
+    _onButtonRelease: function() {
+        this.get_window().set_cursor(this._cursorHandOpen);
+        return false;
+    },
+
+    _updateViewStyle: function() {
+        function clutterColorFromRGBA(rgba) {
+            return new Clutter.Color({ red: rgba.red * 255,
+                                       green: rgba.green * 255,
+                                       blue: rgba.blue * 255,
+                                       alpha: rgba.alpha * 255 });
+        }
+
+        let context = this.get_style_context();
+        let rgba = context.get_color(Gtk.StateFlags.SELECTED);
+        let color = clutterColorFromRGBA(rgba);
+        Champlain.Marker.set_selection_text_color(color);
+
+        rgba = context.get_background_color(Gtk.StateFlags.SELECTED);
+        color = clutterColorFromRGBA(rgba);
+        Champlain.Marker.set_selection_color(color);
+
+        this.get_window().set_cursor(this._cursorHandOpen);
+    }
+});
diff --git a/src/properties.js b/src/properties.js
new file mode 100644
index 0000000..3fd15ae
--- /dev/null
+++ b/src/properties.js
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011, 2012, 2013 Red Hat, Inc.
+ *
+ * GNOME Maps 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 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps 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 GNOME Maps; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ */
+
+const Clutter = imports.gi.Clutter;
+const Gdk = imports.gi.Gdk;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const Champlain = imports.gi.Champlain;
+const GtkClutter = imports.gi.GtkClutter;
+const Geocode = imports.gi.GeocodeGlib;
+const Gd = imports.gi.Gd;
+const MapView = imports.mapView;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+
+const Utils = imports.utils;
+const _ = imports.gettext.gettext;
+
+const Properties = new Lang.Class({
+    Name: 'Properties',
+
+    _init: function(mapView) {
+        this._mapView = mapView;
+        this.actor = new Clutter.Actor({ layout_manager: new Clutter.BoxLayout({ spacing: 12 }),
+                                         y_expand: true,
+                                         x_align: Clutter.ActorAlign.END });
+
+        // create the button
+        let revealButton = new Gd.HeaderSimpleButton({ symbolic_icon_name: 'go-previous-symbolic',
+                                                       valign: Gtk.Align.CENTER });
+        revealButton.get_style_context().add_class('osd');
+        revealButton.show();
+
+        // then the sidebar itself, packed into the revealer
+        let propsGrid = new Gtk.Grid({ vexpand: true,
+                                       hexpand: true,
+                                       margin_top: 50,
+                                       margin_left: 20,
+                                       margin_right: 20,
+                                       row_spacing: 15,
+                                       orientation: Gtk.Orientation.VERTICAL,
+                                       valign: Gtk.Align.FILL });
+
+        let label = new Gtk.Label({ label: _("<b>Map Type</b>"),
+                                    use_markup: true });
+        propsGrid.add(label);
+
+        let radioGrid = new Gtk.Grid({ row_spacing: 5,
+                                       orientation: Gtk.Orientation.VERTICAL });
+        propsGrid.add(radioGrid);
+        /*let radio = Gtk.RadioButton.new_with_label_from_widget(null, _("Street"));
+        radio.connect("toggled", Lang.bind(this, function(radio) {
+            if (!radio.get_active())
+                return;
+            log ("setting street view");
+            mapView.setMapType(MapView.MapType.STREET);
+        }));
+        radioGrid.add(radio);
+        radio = Gtk.RadioButton.new_with_label_from_widget(radio, _("Terrain"));
+        radioGrid.add(radio);
+        radio = Gtk.RadioButton.new_with_label_from_widget(radio, _("Cycling"));
+        radioGrid.add(radio);
+        radio = Gtk.RadioButton.new_with_label_from_widget(radio, _("Transit"));
+        radioGrid.add(radio);*/
+        var radio = this.addMapTypeRadio(null, radioGrid, _("Street"), MapView.MapType.STREET);
+        this.addMapTypeRadio(radio, radioGrid, _("Terrain"), MapView.MapType.TERRAIN);
+        this.addMapTypeRadio(radio, radioGrid, _("Cycling"), MapView.MapType.CYCLING);
+        this.addMapTypeRadio(radio, radioGrid, _("Transit"), MapView.MapType.TRANSIT);
+
+        let propsContainer = new Gtk.Frame({ child: propsGrid,
+                                             shadow_type: Gtk.ShadowType.NONE });
+
+        let revealer = new Gd.Revealer({ child: propsContainer,
+                                         reveal_child: false,
+                                         orientation: Gtk.Orientation.VERTICAL });
+        revealer.show_all();
+
+        revealButton.connect('clicked', Lang.bind(this, function() {
+            if (revealer.reveal_child) {
+                revealer.reveal_child = false;
+                revealButton.symbolic_icon_name = 'go-previous-symbolic';
+            } else {
+                revealer.reveal_child = true;
+                revealButton.symbolic_icon_name = 'go-next-symbolic';
+            }
+        }));
+
+        // now create actors
+        let buttonActor = new GtkClutter.Actor({ contents: revealButton,
+                                                 x_align: Clutter.ActorAlign.END });
+
+        this.actor.add_child(buttonActor);
+
+        let revealerActor = new GtkClutter.Actor({ contents: revealer,
+                                                   x_align: Clutter.ActorAlign.END,
+                                                   x_expand: true,
+                                                   y_expand: true });
+        this.actor.add_child(revealerActor);
+    },
+
+    addMapTypeRadio: function(groupLeader, container, label, mapType) {
+        let radio = Gtk.RadioButton.new_with_label_from_widget(groupLeader, label);
+        radio.connect("toggled", Lang.bind(this, function(radio) {
+            if (!radio.get_active())
+                return;
+
+            this._mapView.setMapType(mapType);
+        }));
+
+        container.add(radio);
+
+        return radio;
+    }
+});


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]