From ad063ce60e92a2c94dfb2d711cc75780d11ac127 Mon Sep 17 00:00:00 2001 From: Otavio Pontes Date: Wed, 29 Sep 2010 17:34:35 +0000 Subject: [PATCH] From: Otavio Pontes Date: Thu, 23 Sep 2010 16:39:58 -0300 Subject: [PATCH 4/5] Adding new keyboard shortcuts to ephoto. To: otavio@profusion.mobi Also adds: - zoom in/out function to flow_browser and buttons in toolbar for zoom and rotation. - Fullscreen mode to slideshow. SVN revision: 52899 --- src/bin/ephoto.h | 1 + src/bin/ephoto_flow_browser.c | 122 ++++++++++++++++++++++++++++----- src/bin/ephoto_preferences.c | 15 ++++ src/bin/ephoto_slideshow.c | 46 ++++++++++++- src/bin/ephoto_thumb_browser.c | 98 +++++++++++++++++++++++++- 5 files changed, 262 insertions(+), 20 deletions(-) diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 6dc09c5..7b50a40 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -102,6 +102,7 @@ struct _Ephoto Evas_Object *layout; Evas_Object *flow_browser; Evas_Object *slideshow; + Evas_Object *slideshow_notify; Evas_Object *thumb_browser; Evas_Object *prefs_win; Eina_List *images; diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index 02a8a11..7f7fbb7 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -16,8 +16,12 @@ static void _ephoto_go_rotate_counterclockwise(void *data, Evas_Object *obj, voi static void _ephoto_go_rotate_clockwise(void *data, Evas_Object *obj, void *event_info); static void _ephoto_go_editor(void *data, Evas_Object *obj, void *event_info); static void _ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _ephoto_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_flow_browser_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_flow_browser_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_in(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_out(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event_info); typedef struct _Ephoto_Flow_Browser Ephoto_Flow_Browser; @@ -38,7 +42,11 @@ static const char *toolbar_items[] = { "Previous", "Next", "Last", - "Slideshow" + "Slideshow", + "Rotate CW", + "Rotate CCW", + "Zoom In", + "Zoom Out" }; static void @@ -171,6 +179,7 @@ ephoto_create_flow_browser(Evas_Object *parent) ef->toolbar = elm_toolbar_add(ef->flow_browser); elm_toolbar_icon_size_set(ef->toolbar, 24); elm_toolbar_homogenous_set(ef->toolbar, EINA_TRUE); + elm_toolbar_scrollable_set(ef->toolbar, EINA_FALSE); evas_object_size_hint_weight_set(ef->toolbar, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(ef->toolbar, EVAS_HINT_FILL, 0.5); elm_layout_content_set(ef->flow_browser, "ephoto.toolbar.swallow", ef->toolbar); @@ -200,7 +209,22 @@ ephoto_create_flow_browser(Evas_Object *parent) elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); elm_toolbar_item_add(ef->toolbar, o, "Slideshow", _ephoto_go_slideshow, ef); - + o = elm_icon_add(ef->toolbar); + elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); + elm_toolbar_item_add(ef->toolbar, o, "RotateCW", _ephoto_go_rotate_clockwise, ef); + + o = elm_icon_add(ef->toolbar); + elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); + elm_toolbar_item_add(ef->toolbar, o, "RotateCCW", _ephoto_go_rotate_counterclockwise, ef); + + o = elm_icon_add(ef->toolbar); + elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); + elm_toolbar_item_add(ef->toolbar, o, "Zoom In", _ephoto_zoom_in, ef); + + o = elm_icon_add(ef->toolbar); + elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); + elm_toolbar_item_add(ef->toolbar, o, "Zoom Out", _ephoto_zoom_out, ef); + evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_SHOW, _ephoto_flow_browser_show_cb, ef); evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_DEL, @@ -225,8 +249,10 @@ ephoto_flow_browser_image_set(Evas_Object *obj, const char *current_image) { ef->cur_image = current_image; - evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_KEY_UP, + evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_KEY_DOWN, _ephoto_key_pressed, ef); + evas_object_event_callback_add(ef->flow_browser, EVAS_CALLBACK_MOUSE_WHEEL, + _ephoto_mouse_wheel, ef); ef->iter = eina_list_data_find_list(em->images, current_image); for (i = 0; i < (sizeof (toolbar_items) / sizeof (char*)); ++i) @@ -269,30 +295,50 @@ _ephoto_flow_browser_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_i static const struct { const char *name; + const char *modifiers; void (*func)(void *data, Evas_Object *obj, void *event_info); } keys[] = { - { "Left", _ephoto_go_previous }, - { "Right", _ephoto_go_next }, - { "space", _ephoto_go_next }, - { "Escape", _ephoto_go_back }, - { "bracketleft", _ephoto_go_rotate_counterclockwise }, - { "bracketright", _ephoto_go_rotate_clockwise }, - { "e", _ephoto_go_editor }, - { NULL, NULL } + { "Left", NULL, _ephoto_go_previous }, + { "Right", NULL, _ephoto_go_next }, + { "space", NULL, _ephoto_go_next }, + { "Escape", NULL, _ephoto_go_back }, + { "bracketleft", NULL, _ephoto_go_rotate_counterclockwise }, + { "bracketright", NULL, _ephoto_go_rotate_clockwise }, + { "Home", NULL, _ephoto_go_first }, + { "End", NULL, _ephoto_go_last }, + { "F5", NULL, _ephoto_go_slideshow}, + { "plus", "Control", _ephoto_zoom_in}, + { "minus", "Control", _ephoto_zoom_out}, + { "0", "Control", _ephoto_zoom_regular_size}, + { "e", NULL, _ephoto_go_editor }, + { NULL, NULL, NULL } }; static void _ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) -{ - Ephoto_Flow_Browser *ef = data; - Evas_Event_Key_Up *eku; +{ + Evas_Event_Key_Down *eku; int i; - eku = (Evas_Event_Key_Up *)event_data; - DBG("Key name: %s", eku->keyname); + eku = (Evas_Event_Key_Down *)event_data; + DBG("Key name: %s", eku->key); for (i = 0; keys[i].name; ++i) - if (!strcmp(eku->keyname, keys[i].name)) - keys[i].func(ef, NULL, NULL); + if ((!strcmp(eku->key, keys[i].name)) && + ((keys[i].modifiers == NULL) || (evas_key_modifier_is_set(eku->modifiers, keys[i].modifiers)))) + keys[i].func(data, NULL, NULL); +} + +static void +_ephoto_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Mouse_Wheel *emw = (Evas_Event_Mouse_Wheel *) event_data; + if (evas_key_modifier_is_set(emw->modifiers, "Control")) + { + if (emw->z < 0) + _ephoto_zoom_in(data, NULL, NULL); + else + _ephoto_zoom_out(data, NULL, NULL); + } } /*Go back to the thumbnail viewer*/ @@ -397,6 +443,7 @@ _ephoto_go_rotate_counterclockwise(void *data, Evas_Object *obj, void *event_inf edje_object_signal_emit(o, "ef,state,rotate,180", "ef"); break; } + elm_toolbar_item_unselect_all(ef->toolbar); } static void @@ -424,6 +471,7 @@ _ephoto_go_rotate_clockwise(void *data, Evas_Object *obj, void *event_info) edje_object_signal_emit(o, "ef,state,rotate,0", "ef"); break; } + elm_toolbar_item_unselect_all(ef->toolbar); } static void @@ -438,3 +486,41 @@ _ephoto_go_editor(void *data, Evas_Object *obj, void *event_info) exe = ecore_exe_run(buf, NULL); ecore_exe_free(exe); } + +/* Zoom in in image */ +static void +_ephoto_zoom_in(void *data, Evas_Object *obj, void *event) +{ + Ephoto_Flow_Browser *ef = data; + double zoom; + + elm_photocam_zoom_mode_set(ef->image, ELM_PHOTOCAM_ZOOM_MODE_MANUAL); + zoom = elm_photocam_zoom_get(ef->image); + zoom -= 0.4; + if (zoom < 0.1) + zoom = 0.1; + elm_photocam_zoom_set(ef->image, zoom); + elm_toolbar_item_unselect_all(ef->toolbar); +} + +/* Zoom out in image */ +static void +_ephoto_zoom_out(void *data, Evas_Object *obj, void *event) +{ + Ephoto_Flow_Browser *ef = data; + double zoom; + + elm_photocam_zoom_mode_set(ef->image, ELM_PHOTOCAM_ZOOM_MODE_MANUAL); + zoom = elm_photocam_zoom_get(ef->image); + zoom += 0.4; + elm_photocam_zoom_set(ef->image, zoom); + elm_toolbar_item_unselect_all(ef->toolbar); +} + +/* Zoom regular size in image */ +static void +_ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event) +{ + Ephoto_Flow_Browser *ef = data; + elm_photocam_zoom_mode_set(ef->image, ELM_PHOTOCAM_ZOOM_MODE_AUTO_FIT); +} diff --git a/src/bin/ephoto_preferences.c b/src/bin/ephoto_preferences.c index 85270a4..f459f93 100644 --- a/src/bin/ephoto_preferences.c +++ b/src/bin/ephoto_preferences.c @@ -5,6 +5,15 @@ static void _ephoto_preferences_hide(void *data, Evas_Object *obj, void *event_i static void _ephoto_preferences_item_change(void *data, Evas_Object *obj, void *event_info); static void _ephoto_preferences_slideshow_transition(void *data, Evas_Object *obj, void *event_info); +static void +_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Key_Down *eku; + eku = (Evas_Event_Key_Down *)event_data; + if (!strcmp(eku->key, "Escape")) + _ephoto_preferences_hide(data, NULL, NULL); +} + void ephoto_show_preferences(Ephoto *em) { @@ -126,11 +135,16 @@ ephoto_show_preferences(Ephoto *em) elm_box_pack_end(box, o); evas_object_show(o); + + evas_object_event_callback_add(em->prefs_win, EVAS_CALLBACK_KEY_DOWN, + _ephoto_key_pressed, em); + elm_toolbar_item_select_first(tb); elm_pager_content_promote(pager, pg1); } elm_win_inwin_activate(em->prefs_win); + evas_object_focus_set(em->prefs_win, EINA_TRUE); } static void @@ -178,4 +192,5 @@ _ephoto_preferences_hide(void *data, Evas_Object *obj, void *event_info) Ephoto *em = data; evas_object_hide(em->prefs_win); + evas_object_focus_set(em->thumb_browser, EINA_TRUE); } diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index 6f8e642..e1b0a57 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -2,11 +2,29 @@ static Evas_Object *_ephoto_get_image(void *data, Evas_Object *obj); static void _ephoto_end_slideshow(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _ephoto_switch_fullscreen(); static Elm_Slideshow_Item_Class itc; static int return_view; static const char *cur_image; +/*Key is pressed*/ +static void +_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Key_Down *eku = (Evas_Event_Key_Down *)event_data; + if ((!strcmp(eku->key, "F5")) || (!strcmp(eku->key, "Escape"))) + ephoto_hide_slideshow(); + if ((!strcmp(eku->key, "F11"))) + _ephoto_switch_fullscreen(); +} + +static void +_ephoto_switch_fullscreen(void) +{ + elm_win_fullscreen_set(em->win, !elm_win_fullscreen_get(em->win)); +} + /*Create the slideshow*/ void ephoto_create_slideshow(void) @@ -18,6 +36,14 @@ ephoto_create_slideshow(void) evas_object_size_hint_align_set(em->slideshow, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_event_callback_add(em->slideshow, EVAS_CALLBACK_MOUSE_DOWN, _ephoto_end_slideshow, NULL); + evas_object_event_callback_add(em->slideshow, EVAS_CALLBACK_KEY_DOWN, + _ephoto_key_pressed, NULL); + em->slideshow_notify = elm_notify_add(em->win); + Evas_Object *label = elm_label_add(em->win); + elm_label_label_set(label, "Press F11 to turn off fullscreen"); + elm_notify_content_set(em->slideshow_notify, label); + elm_notify_orient_set(em->slideshow_notify, ELM_NOTIFY_ORIENT_TOP); + elm_notify_timeout_set(em->slideshow_notify, 2); } /*Start and show the slideshow*/ @@ -25,11 +51,13 @@ void ephoto_show_slideshow(int view, const char *current_image) { Eina_List *l = NULL, *iter = NULL; + Elm_Slideshow_Item *cur_item = NULL, *item; const char *image; int x, y, w, h; elm_slideshow_transition_set(em->slideshow, em->config->slideshow_transition); elm_slideshow_timeout_set(em->slideshow, em->config->slideshow_timeout); + elm_win_fullscreen_set(em->win, EINA_TRUE); return_view = view; cur_image = current_image; @@ -41,20 +69,36 @@ ephoto_show_slideshow(int view, const char *current_image) itc.func.get = _ephoto_get_image; itc.func.del = NULL; + elm_slideshow_clear(em->slideshow); l = em->images; EINA_LIST_FOREACH(l, iter, image) { - elm_slideshow_item_add(em->slideshow, &itc, image); + item = elm_slideshow_item_add(em->slideshow, &itc, image); + if ((current_image) && (!strcmp(image, current_image))) + cur_item = item; } + if (cur_item) + elm_slideshow_show(cur_item); + evas_object_show(em->slideshow); + evas_object_focus_set(em->slideshow, EINA_TRUE); elm_win_resize_object_add(em->win, em->slideshow); + + evas_object_show(em->slideshow_notify); } /*Hide the slideshow object*/ void ephoto_hide_slideshow(void) { + elm_win_fullscreen_set(em->win, EINA_FALSE); evas_object_hide(em->slideshow); + elm_slideshow_clear(em->slideshow); + if (return_view == 0) + evas_object_focus_set(em->thumb_browser, 1); + else if (return_view == 1) + evas_object_focus_set(em->flow_browser, 1); + // FIXME /* if (return_view == 0) diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index eec0ba6..9956bae 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -1,5 +1,7 @@ #include "ephoto.h" +#define SLIDER_MAX 300 +#define SLIDER_MIN 80 typedef struct _Ephoto_Thumb_Data Ephoto_Thumb_Data; typedef struct _Ephoto_Thumb_Browser Ephoto_Thumb_Browser; @@ -44,6 +46,53 @@ static void _ephoto_view_slideshow(void *data, Evas_Object *obj, void *event_inf static void _ephoto_preferences(void *data, Evas_Object *obj, void *event_info); static void _ephoto_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); static void _ephoto_show_cb(void *data, Evas *e, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_in(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_out(void *data, Evas_Object *obj, void *event_info); +static void _ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event_info); + +/*A key has been pressed*/ +static const struct +{ + const char *name; + const char *modifiers; + void (*func)(void *data, Evas_Object *obj, void *event_info); +} keys[] = { + { "F5", NULL, _ephoto_view_slideshow }, + { "d", "Control", _ephoto_change_directory}, + { "p", "Control", _ephoto_preferences}, + { "plus", "Control", _ephoto_zoom_in}, + { "minus", "Control", _ephoto_zoom_out}, + { "0", "Control", _ephoto_zoom_regular_size}, + { NULL, NULL, NULL } +}; + +static void +_ephoto_key_pressed(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Key_Down *eku; + int i; + + eku = (Evas_Event_Key_Down *)event_data; + DBG("Key name: %s", eku->key); + for (i = 0; keys[i].name; ++i) + if ((!strcmp(eku->key, keys[i].name)) && + ((keys[i].modifiers == NULL) || (evas_key_modifier_is_set(eku->modifiers, keys[i].modifiers)))) + keys[i].func(data, obj, NULL); +} + +static void +_ephoto_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_data) +{ + Evas_Event_Mouse_Wheel *emw = (Evas_Event_Mouse_Wheel *) event_data; + if (evas_key_modifier_is_set(emw->modifiers, "Control")) + { + if (emw->z < 0) + _ephoto_zoom_in(data, NULL, NULL); + else + _ephoto_zoom_out(data, NULL, NULL); + } +} + /*Create the thumbnail browser object*/ Evas_Object * ephoto_create_thumb_browser(Evas_Object *parent) @@ -81,7 +130,7 @@ ephoto_create_thumb_browser(Evas_Object *parent) tb->thumb_slider = elm_slider_add(tb->thbox); elm_slider_label_set(tb->thumb_slider, "Thumb Size:"); elm_slider_span_size_set(tb->thumb_slider, 100); - elm_slider_min_max_set(tb->thumb_slider, 80, 300); + elm_slider_min_max_set(tb->thumb_slider, SLIDER_MIN, SLIDER_MAX); elm_slider_value_set(tb->thumb_slider, em->config->thumb_size); elm_box_pack_end(tb->thbox, tb->thumb_slider); evas_object_smart_callback_add(tb->thumb_slider, "changed", @@ -141,6 +190,11 @@ ephoto_create_thumb_browser(Evas_Object *parent) evas_object_data_set(tb->layout, "thumb_browser", tb); evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_DEL, _ephoto_del_cb, tb); evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_SHOW, _ephoto_show_cb, tb); + evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_KEY_DOWN, + _ephoto_key_pressed, tb); + evas_object_event_callback_add(tb->layout, EVAS_CALLBACK_MOUSE_WHEEL, + _ephoto_mouse_wheel, tb); + evas_object_focus_set(tb->layout, 1); return tb->layout; } @@ -242,6 +296,48 @@ ephoto_populate_thumbnails(Evas_Object *obj) tb); } +/*Zoom out the thumbnail size*/ +static void +_ephoto_zoom_out(void *data, Evas_Object *obj, void *event) +{ + int val; + Ephoto_Thumb_Browser *tb = data; + + val = elm_slider_value_get(tb->thumb_slider); + val -= (SLIDER_MAX + SLIDER_MIN) / 10; + if (val > SLIDER_MAX) + val = SLIDER_MAX; + elm_slider_value_set(tb->thumb_slider, val); + _ephoto_slider_changed(data, obj, event); +} + +/*Zoom in the thumbnail size*/ +static void +_ephoto_zoom_in(void *data, Evas_Object *obj, void *event) +{ + int val; + Ephoto_Thumb_Browser *tb = data; + + val = elm_slider_value_get(tb->thumb_slider); + val += (SLIDER_MAX + SLIDER_MIN) / 10; + if (val > SLIDER_MAX) + val = SLIDER_MAX; + elm_slider_value_set(tb->thumb_slider, val); + _ephoto_slider_changed(data, obj, event); + +} + +/*Zoom half the thumbnail size*/ +static void +_ephoto_zoom_regular_size(void *data, Evas_Object *obj, void *event) +{ + int val; + Ephoto_Thumb_Browser *tb = data; + + val = (SLIDER_MAX + SLIDER_MIN) / 2; + elm_slider_value_set(tb->thumb_slider, val); + _ephoto_slider_changed(data, obj, event); +} /*Change the thumbnail size*/ static void _ephoto_slider_changed(void *data, Evas_Object *obj, void *event)