[evince/gestures: 1/2] ev-view: Add pinch/zoom gesture to handle document zooming
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/gestures: 1/2] ev-view: Add pinch/zoom gesture to handle document zooming
- Date: Thu, 24 Jul 2014 11:49:16 +0000 (UTC)
commit 73a54a7281855321158128a44eda447171999faf
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Mar 28 19:55:03 2014 +0100
ev-view: Add pinch/zoom gesture to handle document zooming
This is delegated on a GtkGestureZoom. When triggered, the document
will be zoomed based on the distance changes between both fingers.
When the gesture is not active, regular event handling (text selection,
clicking, etc...) will happen.
libview/ev-view-private.h | 4 +++
libview/ev-view.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 53 insertions(+), 1 deletions(-)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 7727bbb..1c7ff62 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -222,6 +222,10 @@ struct _EvView {
gboolean cursor_visible;
guint cursor_blink_timeout_id;
guint cursor_blink_time;
+
+ /* Gestures */
+ GtkGesture *zoom_gesture;
+ gdouble prev_zoom_scale;
};
struct _EvViewClass {
diff --git a/libview/ev-view.c b/libview/ev-view.c
index 26700d5..5d3850e 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4636,7 +4636,10 @@ ev_view_button_press_event (GtkWidget *widget,
if (!view->document)
return FALSE;
-
+
+ if (gtk_gesture_is_recognized (view->zoom_gesture))
+ return TRUE;
+
if (!gtk_widget_has_focus (widget)) {
gtk_widget_grab_focus (widget);
}
@@ -4957,6 +4960,9 @@ ev_view_motion_notify_event (GtkWidget *widget,
if (!view->document)
return FALSE;
+ if (gtk_gesture_is_recognized (view->zoom_gesture))
+ return TRUE;
+
window = gtk_widget_get_window (widget);
if (event->is_hint || event->window != window) {
@@ -5113,6 +5119,9 @@ ev_view_button_release_event (GtkWidget *widget,
view->image_dnd_info.in_drag = FALSE;
+ if (gtk_gesture_is_recognized (view->zoom_gesture))
+ return TRUE;
+
if (view->scroll_info.autoscrolling) {
ev_view_autoscroll_stop (view);
view->pressed_button = -1;
@@ -6209,6 +6218,8 @@ ev_view_finalize (GObject *object)
g_object_unref (view->image_dnd_info.image);
view->image_dnd_info.image = NULL;
+ g_object_unref (view->zoom_gesture);
+
G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
}
@@ -6888,6 +6899,33 @@ on_notify_scale_factor (EvView *view,
}
static void
+zoom_gesture_begin_cb (GtkGesture *gesture,
+ GdkEventSequence *sequence,
+ EvView *view)
+{
+ view->prev_zoom_scale = 1;
+}
+
+static void
+zoom_scale_changed_cb (GtkGestureZoom *gesture,
+ gdouble scale,
+ EvView *view)
+{
+ gdouble factor;
+
+ view->drag_info.in_drag = FALSE;
+ view->image_dnd_info.in_drag = FALSE;
+
+ factor = scale - view->prev_zoom_scale + 1;
+ view->prev_zoom_scale = scale;
+ ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
+
+ if ((factor < 1.0 && ev_view_can_zoom_out (view)) ||
+ (factor >= 1.0 && ev_view_can_zoom_in (view)))
+ ev_view_zoom (view, factor);
+}
+
+static void
ev_view_init (EvView *view)
{
GtkStyleContext *context;
@@ -6902,6 +6940,7 @@ ev_view_init (EvView *view)
gtk_style_context_add_class (context, "view");
gtk_widget_set_events (GTK_WIDGET (view),
+ GDK_TOUCH_MASK |
GDK_EXPOSURE_MASK |
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
@@ -6939,6 +6978,15 @@ ev_view_init (EvView *view)
g_signal_connect (view, "notify::scale-factor",
G_CALLBACK (on_notify_scale_factor), NULL);
+
+ view->zoom_gesture = gtk_gesture_zoom_new (GTK_WIDGET (view));
+ gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (view->zoom_gesture),
+ GTK_PHASE_CAPTURE);
+
+ g_signal_connect (view->zoom_gesture, "begin",
+ G_CALLBACK (zoom_gesture_begin_cb), view);
+ g_signal_connect (view->zoom_gesture, "scale-changed",
+ G_CALLBACK (zoom_scale_changed_cb), view);
}
/*** Callbacks ***/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]