[gnome-photos/wip/rishi/zoom: 8/9] Add PhotosZoomBar



commit 407b3b0402cb04609b26de1507b4b8a5cc36892d
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 11 11:44:13 2017 +0100

    Add PhotosZoomBar

 src/Makefile.am          |    3 +
 src/photos-zoom-bar.c    |  303 ++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-zoom-bar.h    |   37 ++++++
 src/photos-zoom-bar.ui   |   89 ++++++++++++++
 src/photos.gresource.xml |    1 +
 5 files changed, 433 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6bf99ef..0160e9f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -278,6 +278,8 @@ gnome_photos_SOURCES = \
        photos-view-container.h \
        photos-widget-shader.c \
        photos-widget-shader.h \
+       photos-zoom-bar.c \
+       photos-zoom-bar.h \
        photos-main.c \
        $(NULL)
 
@@ -361,6 +363,7 @@ EXTRA_DIST = \
        photos-selection-menu.ui \
        photos-selection-toolbar.ui \
        photos-share-dialog.ui \
+       photos-zoom-bar.ui \
        photos-gom-miner.xml \
        photos-thumbnailer-dbus.xml \
        photos-tracker-extract-priority.xml \
diff --git a/src/photos-zoom-bar.c b/src/photos-zoom-bar.c
new file mode 100644
index 0000000..85cf9c8
--- /dev/null
+++ b/src/photos-zoom-bar.c
@@ -0,0 +1,303 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <string.h>
+
+#include <gio/gio.h>
+
+#include "photos-glib.h"
+#include "photos-zoom-bar.h"
+
+
+struct _PhotosZoomBar
+{
+  GtkBin parent_instance;
+  GAction *zoom_best_fit_action;
+  GAction *zoom_out_action;
+  GtkWidget *revealer;
+  GtkWidget *zoom_best_fit_button;
+  GtkWidget *zoom_in_button;
+  GtkWidget *zoom_out_button;
+  gboolean hover;
+  guint notify_enabled_id;
+};
+
+enum
+{
+  PROP_0,
+  PROP_HOVER
+};
+
+
+G_DEFINE_TYPE (PhotosZoomBar, photos_zoom_bar, GTK_TYPE_BIN);
+
+
+static gboolean
+photos_zoom_bar_notify_idle (gpointer user_data)
+{
+  PhotosZoomBar *self = PHOTOS_ZOOM_BAR (user_data);
+  gboolean zoom_best_fit_enabled;
+  gboolean zoom_out_enabled;
+
+  self->notify_enabled_id = 0;
+
+  zoom_best_fit_enabled = g_action_get_enabled (self->zoom_best_fit_action);
+  zoom_out_enabled = g_action_get_enabled (self->zoom_out_action);
+  g_return_val_if_fail (zoom_best_fit_enabled == zoom_out_enabled, G_SOURCE_REMOVE);
+
+  gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), zoom_out_enabled);
+
+  return G_SOURCE_REMOVE;
+}
+
+
+static void
+photos_zoom_bar_notify_enabled (PhotosZoomBar *self)
+{
+  if (self->notify_enabled_id != 0)
+    return;
+
+  self->notify_enabled_id = g_idle_add (photos_zoom_bar_notify_idle, self);
+}
+
+
+static void
+photos_zoom_bar_set_hover (PhotosZoomBar *self, gboolean hover)
+{
+  if (self->hover == hover)
+    return;
+
+  self->hover = hover;
+  g_object_notify (G_OBJECT (self), "hover");
+}
+
+
+static gboolean
+photos_zoom_bar_draw (GtkWidget *widget, cairo_t *cr)
+{
+  GtkAllocation allocation;
+  GtkStyleContext *context;
+  gboolean ret_val;
+
+  gtk_widget_get_allocation (widget, &allocation);
+  context = gtk_widget_get_style_context (widget);
+  gtk_render_background (context, cr, 0, 0, (gdouble) allocation.width, (gdouble) allocation.height);
+  gtk_render_frame (context, cr, 0, 0, (gdouble) allocation.width, (gdouble) allocation.height);
+
+  ret_val = GTK_WIDGET_CLASS (photos_zoom_bar_parent_class)->draw (widget, cr);
+  return ret_val;
+}
+
+
+static gboolean
+photos_zoom_bar_enter_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+  PhotosZoomBar *self = PHOTOS_ZOOM_BAR (widget);
+
+  if (event->detail != GDK_NOTIFY_INFERIOR)
+    photos_zoom_bar_set_hover (self, TRUE);
+
+  return GDK_EVENT_PROPAGATE;
+}
+
+
+static gboolean
+photos_zoom_bar_leave_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+  PhotosZoomBar *self = PHOTOS_ZOOM_BAR (widget);
+
+  if (event->detail != GDK_NOTIFY_INFERIOR)
+    photos_zoom_bar_set_hover (self, FALSE);
+
+  return GDK_EVENT_PROPAGATE;
+}
+
+
+static void
+photos_zoom_bar_realize (GtkWidget *widget)
+{
+  GdkVisual *visual;
+  GdkWindow *parent_window;
+  GdkWindow *window;
+  GdkWindowAttr attributes;
+  GtkAllocation allocation;
+  gint attributes_mask;
+
+  gtk_widget_set_realized (widget, TRUE);
+
+  attributes.event_mask = gtk_widget_get_events (widget);
+  attributes.event_mask |= (GDK_BUTTON_PRESS_MASK
+                            | GDK_BUTTON_RELEASE_MASK
+                            | GDK_ENTER_NOTIFY_MASK
+                            | GDK_LEAVE_NOTIFY_MASK);
+
+  gtk_widget_get_allocation (widget, &allocation);
+  attributes.x = allocation.x;
+  attributes.y = allocation.y;
+  attributes.width = allocation.width;
+  attributes.height = allocation.height;
+
+  attributes.wclass = GDK_INPUT_OUTPUT;
+
+  visual = gtk_widget_get_visual (widget);
+  attributes.visual = visual;
+
+  attributes.window_type = GDK_WINDOW_CHILD;
+
+  attributes_mask = GDK_WA_VISUAL | GDK_WA_X | GDK_WA_Y;
+
+  parent_window = gtk_widget_get_parent_window (widget);
+  window = gdk_window_new (parent_window, &attributes, attributes_mask);
+  gtk_widget_set_window (widget, g_object_ref (window));
+  gtk_widget_register_window (widget, window);
+
+  g_object_unref (window);
+}
+
+
+static void
+photos_zoom_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+  GdkWindow *window;
+
+  GTK_WIDGET_CLASS (photos_zoom_bar_parent_class)->size_allocate (widget, allocation);
+
+  if (!gtk_widget_get_realized (widget))
+    return;
+
+  window = gtk_widget_get_window (widget);
+  gdk_window_move_resize (window, allocation->x, allocation->y, allocation->width, allocation->height);
+}
+
+
+static void
+photos_zoom_bar_dispose (GObject *object)
+{
+  PhotosZoomBar *self = PHOTOS_ZOOM_BAR (object);
+
+  if (self->notify_enabled_id != 0)
+    {
+      g_source_remove (self->notify_enabled_id);
+      self->notify_enabled_id = 0;
+    }
+
+  G_OBJECT_CLASS (photos_zoom_bar_parent_class)->dispose (object);
+}
+
+
+static void
+photos_zoom_bar_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+  PhotosZoomBar *self = PHOTOS_ZOOM_BAR (object);
+
+  switch (prop_id)
+    {
+    case PROP_HOVER:
+      g_value_set_boolean (value, self->hover);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_zoom_bar_init (PhotosZoomBar *self)
+{
+  GApplication *app;
+  const gchar *action_name;
+  const gchar *action_name_with_prefix;
+
+  app = g_application_get_default ();
+
+  gtk_widget_init_template (GTK_WIDGET (self));
+  gtk_widget_set_has_window (GTK_WIDGET (self), TRUE);
+
+  action_name_with_prefix = gtk_actionable_get_action_name (GTK_ACTIONABLE (self->zoom_best_fit_button));
+  action_name = photos_action_name_strip_prefix (action_name_with_prefix);
+  self->zoom_best_fit_action = g_action_map_lookup_action (G_ACTION_MAP (app), action_name);
+  g_signal_connect_swapped (self->zoom_best_fit_action,
+                            "notify::enabled",
+                            G_CALLBACK (photos_zoom_bar_notify_enabled),
+                            self);
+
+  action_name_with_prefix = gtk_actionable_get_action_name (GTK_ACTIONABLE (self->zoom_out_button));
+  action_name = photos_action_name_strip_prefix (action_name_with_prefix);
+  self->zoom_out_action = g_action_map_lookup_action (G_ACTION_MAP (app), action_name);
+  g_signal_connect_swapped (self->zoom_out_action,
+                            "notify::enabled",
+                            G_CALLBACK (photos_zoom_bar_notify_enabled),
+                            self);
+}
+
+
+static void
+photos_zoom_bar_class_init (PhotosZoomBarClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+  object_class->dispose = photos_zoom_bar_dispose;
+  object_class->get_property = photos_zoom_bar_get_property;
+
+  widget_class->draw = photos_zoom_bar_draw;
+  widget_class->enter_notify_event = photos_zoom_bar_enter_notify;
+  widget_class->leave_notify_event = photos_zoom_bar_leave_notify;
+  widget_class->realize = photos_zoom_bar_realize;
+  widget_class->size_allocate = photos_zoom_bar_size_allocate;
+
+  g_object_class_install_property (object_class,
+                                   PROP_HOVER,
+                                   g_param_spec_boolean ("hover",
+                                                         "Hover",
+                                                         "Whether the widget is hovered",
+                                                         FALSE,
+                                                         G_PARAM_EXPLICIT_NOTIFY |
+                                                         G_PARAM_READABLE |
+                                                         G_PARAM_STATIC_STRINGS));
+
+  gtk_widget_class_set_css_name (widget_class, "toolbar");
+
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Photos/zoom-bar.ui");
+  gtk_widget_class_bind_template_child (widget_class, PhotosZoomBar, revealer);
+  gtk_widget_class_bind_template_child (widget_class, PhotosZoomBar, zoom_best_fit_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosZoomBar, zoom_in_button);
+  gtk_widget_class_bind_template_child (widget_class, PhotosZoomBar, zoom_out_button);
+}
+
+
+GtkWidget *
+photos_zoom_bar_new (void)
+{
+  return g_object_new (PHOTOS_TYPE_ZOOM_BAR, NULL);
+}
+
+
+gboolean
+photos_zoom_bar_get_hover (PhotosZoomBar *self)
+{
+  g_return_val_if_fail (PHOTOS_IS_ZOOM_BAR (self), FALSE);
+  return self->hover;
+}
diff --git a/src/photos-zoom-bar.h b/src/photos-zoom-bar.h
new file mode 100644
index 0000000..3a2f61c
--- /dev/null
+++ b/src/photos-zoom-bar.h
@@ -0,0 +1,37 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_ZOOM_BAR_H
+#define PHOTOS_ZOOM_BAR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_ZOOM_BAR (photos_zoom_bar_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosZoomBar, photos_zoom_bar, PHOTOS, ZOOM_BAR, GtkBin);
+
+GtkWidget       *photos_zoom_bar_new                (void);
+
+gboolean         photos_zoom_bar_get_hover          (PhotosZoomBar *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_ZOOM_BAR_H */
diff --git a/src/photos-zoom-bar.ui b/src/photos-zoom-bar.ui
new file mode 100644
index 0000000..cd6e703
--- /dev/null
+++ b/src/photos-zoom-bar.ui
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Photos - access, organize and share your photos on GNOME
+ Copyright © 2017 Red Hat, Inc.
+
+ 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 2
+ 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, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+-->
+<interface>
+  <template class="PhotosZoomBar" parent="GtkBin">
+    <style>
+      <class name="toolbar"/>
+    </style>
+    <child>
+      <object class="GtkBox">
+        <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+        <style>
+          <class name="linked"/>
+        </style>
+        <child>
+          <object class="GtkButton" id="zoom_in_button">
+            <property name="action_name">app.zoom-in</property>
+            <style>
+              <class name="image-button"/>
+              <class name="osd"/>
+            </style>
+            <child>
+              <object class="GtkImage">
+                <property name="icon_name">zoom-in-symbolic</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkRevealer" id="revealer">
+            <child>
+              <object class="GtkBox">
+                <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+                <style>
+                  <class name="linked"/>
+                </style>
+                <child>
+                  <object class="GtkButton" id="zoom_out_button">
+                    <property name="action_name">app.zoom-out</property>
+                    <style>
+                      <class name="image-button"/>
+                      <class name="osd"/>
+                    </style>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="icon_name">zoom-out-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkButton" id="zoom_best_fit_button">
+                    <property name="action_name">app.zoom-best-fit</property>
+                    <style>
+                      <class name="image-button"/>
+                      <class name="osd"/>
+                    </style>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="icon_name">zoom-fit-best-symbolic</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 8c56159..5a199b5 100644
--- a/src/photos.gresource.xml
+++ b/src/photos.gresource.xml
@@ -32,6 +32,7 @@
     <file alias="selection-menu.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-menu.ui</file>
     <file alias="selection-toolbar.ui" preprocess="xml-stripblanks" 
compressed="true">photos-selection-toolbar.ui</file>
     <file alias="share-dialog.ui" preprocess="xml-stripblanks" 
compressed="true">photos-share-dialog.ui</file>
+    <file alias="zoom-bar.ui" preprocess="xml-stripblanks" compressed="true">photos-zoom-bar.ui</file>
   </gresource>
 
   <gresource prefix="/org/gnome/Photos/gtk">


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