[eog] Extend print preview to scale with plus and minus from keyboard as well
- From: Felix Riemann <friemann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [eog] Extend print preview to scale with plus and minus from keyboard as well
- Date: Wed, 4 Jan 2012 20:17:04 +0000 (UTC)
commit 982a69b0888fc5d0ac3427166aa5cca30b0e97b4
Author: Felix Riemann <friemann gnome org>
Date: Wed Jan 4 21:08:27 2012 +0100
Extend print preview to scale with plus and minus from keyboard as well
https://bugzilla.gnome.org/show_bug.cgi?id=495716
src/eog-print-image-setup.c | 68 +++++++++++++++++++++++++++++++++++++++---
src/eog-print-preview.c | 47 ++++++-----------------------
src/eog-print-preview.h | 6 +++-
3 files changed, 78 insertions(+), 43 deletions(-)
---
diff --git a/src/eog-print-image-setup.c b/src/eog-print-image-setup.c
index c3f38cb..7cbcf6c 100644
--- a/src/eog-print-image-setup.c
+++ b/src/eog-print-image-setup.c
@@ -634,16 +634,72 @@ on_preview_image_moved (EogPrintPreview *preview,
gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->top), y);
}
-static void
-on_preview_image_scaled (EogPrintPreview *preview,
- gpointer user_data)
+static gboolean
+on_preview_image_scrolled (GtkWidget *widget,
+ GdkEventScroll *event,
+ gpointer user_data)
{
EogPrintImageSetupPrivate *priv = EOG_PRINT_IMAGE_SETUP (user_data)->priv;
+ EogPrintPreview *preview = EOG_PRINT_PREVIEW (widget);
gfloat scale;
scale = eog_print_preview_get_scale (preview);
+ if (!eog_print_preview_point_in_image_area (preview,
+ event->x, event->y))
+ {
+ return FALSE;
+ }
+
+ switch (event->direction) {
+ case GDK_SCROLL_UP:
+ /* scale up */
+ scale *= 1.1;
+ break;
+ case GDK_SCROLL_DOWN:
+ /* scale down */
+ scale *= 0.9;
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
gtk_range_set_value (GTK_RANGE (priv->scaling), 100*scale);
+
+ return TRUE;
+}
+
+static gboolean
+on_preview_image_key_pressed (GtkWidget *widget,
+ GdkEventKey *event,
+ gpointer user_data)
+{
+ EogPrintImageSetupPrivate *priv = EOG_PRINT_IMAGE_SETUP (user_data)->priv;
+ EogPrintPreview *preview = EOG_PRINT_PREVIEW (widget);
+ gfloat scale;
+
+ scale = eog_print_preview_get_scale (preview);
+
+ switch (event->keyval) {
+ case GDK_KEY_KP_Add:
+ case GDK_KEY_plus:
+ /* scale up */
+ scale *= 1.1;
+ break;
+ case GDK_KEY_KP_Subtract:
+ case GDK_KEY_minus:
+ /* scale down */
+ scale *= 0.9;
+ break;
+ default:
+ return FALSE;
+ break;
+ }
+
+ gtk_range_set_value (GTK_RANGE (priv->scaling), 100*scale);
+
+ return TRUE;
}
/* Function taken from gtkprintunixdialog.c */
@@ -831,8 +887,10 @@ connect_signals (EogPrintImageSetup *setup)
G_CALLBACK (on_scale_format_value), NULL);
g_signal_connect (G_OBJECT (priv->preview), "image-moved",
G_CALLBACK (on_preview_image_moved), setup);
- g_signal_connect (G_OBJECT (priv->preview), "image-scaled",
- G_CALLBACK (on_preview_image_scaled), setup);
+ g_signal_connect (G_OBJECT (priv->preview), "scroll-event",
+ G_CALLBACK (on_preview_image_scrolled), setup);
+ g_signal_connect (G_OBJECT (priv->preview), "key-press-event",
+ G_CALLBACK (on_preview_image_key_pressed), setup);
}
static void
diff --git a/src/eog-print-preview.c b/src/eog-print-preview.c
index 4fed6c7..f30befc 100644
--- a/src/eog-print-preview.c
+++ b/src/eog-print-preview.c
@@ -477,7 +477,6 @@ static gboolean button_press_event_cb (GtkWidget *widget, GdkEventButton *bev,
static gboolean button_release_event_cb (GtkWidget *widget, GdkEventButton *bev, gpointer user_data);
static gboolean motion_notify_event_cb (GtkWidget *widget, GdkEventMotion *mev, gpointer user_data);
static gboolean key_press_event_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data);
-static gboolean scroll_event_cb (GtkWidget *widget, GdkEventScroll *event, gpointer user_data);
static gboolean draw_cb (GtkDrawingArea *drawing_area, cairo_t *cr, gpointer user_data);
static void size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer user_data);
@@ -558,9 +557,6 @@ eog_print_preview_new (void)
g_signal_connect (area, "size-allocate",
G_CALLBACK (size_allocate_cb), preview);
- g_signal_connect (G_OBJECT (area), "scroll-event",
- G_CALLBACK (scroll_event_cb), preview);
-
return GTK_WIDGET (preview);
}
@@ -638,6 +634,16 @@ press_inside_image_area (EogPrintPreview *preview,
return FALSE;
}
+gboolean
+eog_print_preview_point_in_image_area (EogPrintPreview *preview,
+ guint x,
+ guint y)
+{
+ g_return_val_if_fail (EOG_IS_PRINT_PREVIEW (preview), FALSE);
+
+ return press_inside_image_area (preview, x, y);
+}
+
static void
create_image_scaled (EogPrintPreview *preview)
{
@@ -976,39 +982,6 @@ motion_notify_event_cb (GtkWidget *widget,
return FALSE;
}
-static gboolean
-scroll_event_cb (GtkWidget *widget,
- GdkEventScroll *event,
- gpointer user_data)
-{
- g_assert (EOG_IS_PRINT_PREVIEW (user_data));
-
- EogPrintPreview *preview = EOG_PRINT_PREVIEW (user_data);
-
- if (press_inside_image_area (EOG_PRINT_PREVIEW (user_data),
- event->x, event->y))
- {
- gfloat scale;
- gfloat multiplier;
-
- g_object_get (preview, "image-scale", &scale, NULL);
-
- switch (event->direction) {
- case GDK_SCROLL_UP:
- /* scale up */
- multiplier = 1.1;
- break;
- case GDK_SCROLL_DOWN:
- /* scale down */
- multiplier = 0.9;
-
- }
- eog_print_preview_set_scale (preview, CLAMP (scale * multiplier, 0., 1.));
- }
- return TRUE;
-}
-
-
static void
size_allocate_cb (GtkWidget *widget,
GtkAllocation *allocation,
diff --git a/src/eog-print-preview.h b/src/eog-print-preview.h
index 4395400..fbe80c9 100644
--- a/src/eog-print-preview.h
+++ b/src/eog-print-preview.h
@@ -76,9 +76,13 @@ void eog_print_preview_set_image_position (EogPrintPreview *preview,
gdouble y);
G_GNUC_INTERNAL
+gboolean eog_print_preview_point_in_image_area (EogPrintPreview *preview,
+ guint x,
+ guint y);
+G_GNUC_INTERNAL
void eog_print_preview_set_scale (EogPrintPreview *preview,
gfloat scale);
-
+G_GNUC_INTERNAL
gfloat eog_print_preview_get_scale (EogPrintPreview *preview);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]