[gnome-photos/wip/rishi/zoom: 4/9] Add PhotosZoomControls
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/zoom: 4/9] Add PhotosZoomControls
- Date: Wed, 14 Jun 2017 19:08:36 +0000 (UTC)
commit 9e8c64258d56b065b2a2671363653e56cdd10fbd
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 11 11:44:13 2017 +0100
Add PhotosZoomControls
https://bugzilla.gnome.org/show_bug.cgi?id=742662
src/Makefile.am | 3 +
src/photos-zoom-controls.c | 304 +++++++++++++++++++++++++++++++++++++++++++
src/photos-zoom-controls.h | 37 +++++
src/photos-zoom-controls.ui | 89 +++++++++++++
src/photos.gresource.xml | 1 +
5 files changed, 434 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index b0b0936..d7397ac 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-controls.c \
+ photos-zoom-controls.h \
photos-main.c \
$(NULL)
@@ -362,6 +364,7 @@ EXTRA_DIST = \
photos-selection-menu.ui \
photos-selection-toolbar.ui \
photos-share-dialog.ui \
+ photos-zoom-controls.ui \
photos-gom-miner.xml \
photos-thumbnailer-dbus.xml \
photos-tracker-extract-priority.xml \
diff --git a/src/photos-zoom-controls.c b/src/photos-zoom-controls.c
new file mode 100644
index 0000000..388cf2c
--- /dev/null
+++ b/src/photos-zoom-controls.c
@@ -0,0 +1,304 @@
+/*
+ * 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-zoom-controls.h"
+
+
+struct _PhotosZoomControls
+{
+ GtkBin parent_instance;
+ GAction *zoom_best_fit_action;
+ GAction *zoom_out_action;
+ GtkWidget *revealer;
+ GtkWidget *zoom_in_button;
+ GtkWidget *zoom_out_button;
+ GtkWidget *zoom_toggle_button;
+ gboolean hover;
+ guint notify_enabled_id;
+};
+
+enum
+{
+ PROP_0,
+ PROP_HOVER
+};
+
+
+G_DEFINE_TYPE (PhotosZoomControls, photos_zoom_controls, GTK_TYPE_BIN);
+
+
+static void
+photos_zoom_controls_update_buttons (PhotosZoomControls *self)
+{
+ GtkWidget *image;
+ gboolean zoom_best_fit_enabled;
+ gboolean zoom_out_enabled;
+ const gchar *icon_name;
+
+ 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_if_fail (zoom_best_fit_enabled == zoom_out_enabled);
+
+ gtk_revealer_set_reveal_child (GTK_REVEALER (self->revealer), zoom_out_enabled);
+
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), NULL);
+ gtk_actionable_set_action_target_value (GTK_ACTIONABLE (self->zoom_toggle_button), NULL);
+
+ if (zoom_out_enabled)
+ {
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), "app.zoom-best-fit");
+ }
+ else
+ {
+ gtk_actionable_set_action_target (GTK_ACTIONABLE (self->zoom_toggle_button), "d", -1.0);
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (self->zoom_toggle_button), "app.zoom-in");
+ }
+
+ icon_name = zoom_out_enabled ? "zoom-fit-best-symbolic" : "zoom-in-symbolic";
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_INVALID);
+ gtk_image_set_pixel_size (GTK_IMAGE (image), 16);
+ gtk_button_set_image (GTK_BUTTON (self->zoom_toggle_button), image);
+}
+
+
+static gboolean
+photos_zoom_controls_notify_idle (gpointer user_data)
+{
+ PhotosZoomControls *self = PHOTOS_ZOOM_CONTROLS (user_data);
+
+ self->notify_enabled_id = 0;
+ photos_zoom_controls_update_buttons (self);
+ return G_SOURCE_REMOVE;
+}
+
+
+static void
+photos_zoom_controls_notify_enabled (PhotosZoomControls *self)
+{
+ if (self->notify_enabled_id != 0)
+ return;
+
+ self->notify_enabled_id = g_idle_add (photos_zoom_controls_notify_idle, self);
+}
+
+
+static void
+photos_zoom_controls_set_hover (PhotosZoomControls *self, gboolean hover)
+{
+ if (self->hover == hover)
+ return;
+
+ self->hover = hover;
+ g_object_notify (G_OBJECT (self), "hover");
+}
+
+
+static gboolean
+photos_zoom_controls_enter_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+ PhotosZoomControls *self = PHOTOS_ZOOM_CONTROLS (widget);
+
+ if (event->detail != GDK_NOTIFY_INFERIOR)
+ photos_zoom_controls_set_hover (self, TRUE);
+
+ return GDK_EVENT_PROPAGATE;
+}
+
+
+static gboolean
+photos_zoom_controls_leave_notify (GtkWidget *widget, GdkEventCrossing *event)
+{
+ PhotosZoomControls *self = PHOTOS_ZOOM_CONTROLS (widget);
+
+ if (event->detail != GDK_NOTIFY_INFERIOR)
+ photos_zoom_controls_set_hover (self, FALSE);
+
+ return GDK_EVENT_PROPAGATE;
+}
+
+
+static void
+photos_zoom_controls_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_controls_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+ GdkWindow *window;
+
+ GTK_WIDGET_CLASS (photos_zoom_controls_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_controls_dispose (GObject *object)
+{
+ PhotosZoomControls *self = PHOTOS_ZOOM_CONTROLS (object);
+
+ if (self->notify_enabled_id != 0)
+ {
+ g_source_remove (self->notify_enabled_id);
+ self->notify_enabled_id = 0;
+ }
+
+ G_OBJECT_CLASS (photos_zoom_controls_parent_class)->dispose (object);
+}
+
+
+static void
+photos_zoom_controls_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosZoomControls *self = PHOTOS_ZOOM_CONTROLS (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_controls_init (PhotosZoomControls *self)
+{
+ GApplication *app;
+
+ app = g_application_get_default ();
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_set_has_window (GTK_WIDGET (self), TRUE);
+
+ self->zoom_best_fit_action = g_action_map_lookup_action (G_ACTION_MAP (app), "zoom-best-fit");
+ g_signal_connect_swapped (self->zoom_best_fit_action,
+ "notify::enabled",
+ G_CALLBACK (photos_zoom_controls_notify_enabled),
+ self);
+
+ self->zoom_out_action = g_action_map_lookup_action (G_ACTION_MAP (app), "zoom-out");
+ g_signal_connect_swapped (self->zoom_out_action,
+ "notify::enabled",
+ G_CALLBACK (photos_zoom_controls_notify_enabled),
+ self);
+
+ photos_zoom_controls_update_buttons (self);
+}
+
+
+static void
+photos_zoom_controls_class_init (PhotosZoomControlsClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+ object_class->dispose = photos_zoom_controls_dispose;
+ object_class->get_property = photos_zoom_controls_get_property;
+
+ widget_class->enter_notify_event = photos_zoom_controls_enter_notify;
+ widget_class->leave_notify_event = photos_zoom_controls_leave_notify;
+ widget_class->realize = photos_zoom_controls_realize;
+ widget_class->size_allocate = photos_zoom_controls_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_template_from_resource (widget_class, "/org/gnome/Photos/zoom-controls.ui");
+ gtk_widget_class_bind_template_child (widget_class, PhotosZoomControls, revealer);
+ gtk_widget_class_bind_template_child (widget_class, PhotosZoomControls, zoom_in_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosZoomControls, zoom_out_button);
+ gtk_widget_class_bind_template_child (widget_class, PhotosZoomControls, zoom_toggle_button);
+}
+
+
+GtkWidget *
+photos_zoom_controls_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_ZOOM_CONTROLS, NULL);
+}
+
+
+gboolean
+photos_zoom_controls_get_hover (PhotosZoomControls *self)
+{
+ g_return_val_if_fail (PHOTOS_IS_ZOOM_CONTROLS (self), FALSE);
+ return self->hover;
+}
diff --git a/src/photos-zoom-controls.h b/src/photos-zoom-controls.h
new file mode 100644
index 0000000..2db1b29
--- /dev/null
+++ b/src/photos-zoom-controls.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_CONTROLS_H
+#define PHOTOS_ZOOM_CONTROLS_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_ZOOM_CONTROLS (photos_zoom_controls_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosZoomControls, photos_zoom_controls, PHOTOS, ZOOM_CONTROLS, GtkBin);
+
+GtkWidget *photos_zoom_controls_new (void);
+
+gboolean photos_zoom_controls_get_hover (PhotosZoomControls *self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_ZOOM_CONTROLS_H */
diff --git a/src/photos-zoom-controls.ui b/src/photos-zoom-controls.ui
new file mode 100644
index 0000000..65e1d13
--- /dev/null
+++ b/src/photos-zoom-controls.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="PhotosZoomControls" parent="GtkBin">
+ <style>
+ <class name="toolbar"/>
+ </style>
+ <child>
+ <object class="GtkGrid">
+ <property name="orientation">GTK_ORIENTATION_VERTICAL</property>
+ <child>
+ <object class="GtkRevealer" id="revealer">
+ <property name="margin_bottom">12</property>
+ <property name="transition_type">GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP</property>
+ <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>
+ <property name="action_target">-1.0</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="GtkButton" id="zoom_out_button">
+ <property name="action_name">app.zoom-out</property>
+ <property name="action_target">-1.0</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>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="zoom_toggle_button">
+ <style>
+ <class name="osd"/>
+ </style>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/photos.gresource.xml b/src/photos.gresource.xml
index 8c56159..f0676a7 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-controls.ui" preprocess="xml-stripblanks"
compressed="true">photos-zoom-controls.ui</file>
</gresource>
<gresource prefix="/org/gnome/Photos/gtk">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]