Commit 1d852035 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

image viewer: added a toolbar button to change transparency style

parent bbcd4408
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg2"
version="1.1"
inkscape:version="0.92.4 5da689c313, 2019-01-14"
sodipodi:docname="transparency-style-symbolic.svg">
<defs
id="defs4">
<linearGradient
id="linearGradient3946">
<stop
id="stop3948"
offset="0"
style="stop-color:#000000;stop-opacity:0.74698794;" />
<stop
id="stop3950"
offset="1"
style="stop-color:#000000;stop-opacity:0.02409638;" />
</linearGradient>
<linearGradient
id="linearGradient3830-9">
<stop
style="stop-color:#000000;stop-opacity:0.74698794;"
offset="0"
id="stop3832-7" />
<stop
style="stop-color:#000000;stop-opacity:0.02409638;"
offset="1"
id="stop3834-5" />
</linearGradient>
<linearGradient
id="linearGradient3984">
<stop
style="stop-color:#f4deba;stop-opacity:1;"
offset="0"
id="stop3986" />
<stop
style="stop-color:#de9625;stop-opacity:0;"
offset="1"
id="stop3988" />
</linearGradient>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#555753"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="1"
inkscape:pageshadow="2"
inkscape:zoom="16"
inkscape:cx="-10.16721"
inkscape:cy="4.2655646"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:snap-grids="true"
inkscape:window-width="1920"
inkscape:window-height="1136"
inkscape:window-x="0"
inkscape:window-y="27"
inkscape:window-maximized="1"
showborder="true"
fit-margin-top="0"
fit-margin-right="0"
fit-margin-left="0"
fit-margin-bottom="0"
showguides="true"
inkscape:guide-bbox="true">
<inkscape:grid
type="xygrid"
id="grid7044"
empspacing="8"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
originx="-31.97559"
originy="-816.00002"
spacingx="1"
spacingy="1" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Livello 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-31.97559,-220.36218)">
<path
style="opacity:1;fill:#bebebe;fill-opacity:1;stroke:none"
d="m 34,222.3622 6,0 0,6 -6,0 z"
id="rect3782"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path3801"
d="m 40,228.3622 6,0 0,6 -6,0 z"
style="fill:#bebebe;fill-opacity:1;stroke:none" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path824"
d="m 40,222.3622 h 6 v 6 h -6 z"
style="opacity:0.5;fill:#bebebe;fill-opacity:1;stroke:none" />
<path
style="opacity:0.5;fill:#bebebe;fill-opacity:1;stroke:none"
d="m 34,228.3622 h 6 v 6 h -6 z"
id="path826"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
</g>
</svg>
...@@ -162,6 +162,33 @@ gth_browser_activate_apply_icc_profile (GSimpleAction *action, ...@@ -162,6 +162,33 @@ gth_browser_activate_apply_icc_profile (GSimpleAction *action,
} }
void
gth_browser_activate_transparency_style (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GthBrowser *browser = user_data;
const char *state;
GthImageViewer *image_viewer;
state = g_variant_get_string (parameter, NULL);
g_simple_action_set_state (action, g_variant_new_string (state));
if (state == NULL)
return;
image_viewer = GTH_IMAGE_VIEWER (gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (gth_browser_get_viewer_page (browser))));
if (strcmp (state, "checkered") == 0)
gth_image_viewer_set_transparency_style (image_viewer, GTH_TRANSPARENCY_STYLE_CHECKERED);
else if (strcmp (state, "white") == 0)
gth_image_viewer_set_transparency_style (image_viewer, GTH_TRANSPARENCY_STYLE_WHITE);
else if (strcmp (state, "gray") == 0)
gth_image_viewer_set_transparency_style (image_viewer, GTH_TRANSPARENCY_STYLE_GRAY);
else if (strcmp (state, "black") == 0)
gth_image_viewer_set_transparency_style (image_viewer, GTH_TRANSPARENCY_STYLE_BLACK);
}
void void
gth_browser_activate_image_zoom (GSimpleAction *action, gth_browser_activate_image_zoom (GSimpleAction *action,
GVariant *parameter, GVariant *parameter,
......
...@@ -39,5 +39,6 @@ DEF_ACTION_CALLBACK (gth_browser_activate_apply_icc_profile) ...@@ -39,5 +39,6 @@ DEF_ACTION_CALLBACK (gth_browser_activate_apply_icc_profile)
DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom) DEF_ACTION_CALLBACK (gth_browser_activate_image_zoom)
DEF_ACTION_CALLBACK (gth_browser_activate_toggle_animation) DEF_ACTION_CALLBACK (gth_browser_activate_toggle_animation)
DEF_ACTION_CALLBACK (gth_browser_activate_step_animation) DEF_ACTION_CALLBACK (gth_browser_activate_step_animation)
DEF_ACTION_CALLBACK (gth_browser_activate_transparency_style)
#endif /* ACTIONS_H */ #endif /* ACTIONS_H */
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<interface> <interface>
<object class ="GtkPopoverMenu" id="transparency_popover">
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">9</property>
<property name="orientation">vertical</property>
<property name="width_request">200</property>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Checkered</property>
<property name="action-name">win.transparency-style</property>
<property name="action-target">'checkered'</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">White</property>
<property name="action-name">win.transparency-style</property>
<property name="action-target">'white'</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Gray</property>
<property name="action-name">win.transparency-style</property>
<property name="action-target">'gray'</property>
</object>
</child>
<child>
<object class="GtkModelButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="text" translatable="yes">Black</property>
<property name="action-name">win.transparency-style</property>
<property name="action-target">'black'</property>
</object>
</child>
</object>
</child>
</object>
<object class ="GtkPopoverMenu" id="zoom_popover"> <object class ="GtkPopoverMenu" id="zoom_popover">
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
......
...@@ -30,13 +30,14 @@ ...@@ -30,13 +30,14 @@
#define UPDATE_QUALITY_DELAY 200 #define UPDATE_QUALITY_DELAY 200
#define UPDATE_VISIBILITY_DELAY 100 #define UPDATE_VISIBILITY_DELAY 100
#define N_HEADER_BAR_BUTTONS 6 #define N_HEADER_BAR_BUTTONS 7
#define HIDE_OVERVIEW_TIMEOUT 2 /* in seconds */ #define HIDE_OVERVIEW_TIMEOUT 2 /* in seconds */
#define OVERLAY_MARGIN 10 #define OVERLAY_MARGIN 10
#define ZOOM_BUTTON 2 #define ZOOM_BUTTON 2
#define APPLY_ICC_PROFILE_BUTTON 3 #define APPLY_ICC_PROFILE_BUTTON 3
#define TOGGLE_ANIMATION_BUTTON 4 #define TOGGLE_ANIMATION_BUTTON 4
#define STEP_ANIMATION_BUTTON 5 #define STEP_ANIMATION_BUTTON 5
#define TRANSPARENCY_STYLE_BUTTON 6
#undef ALWAYS_LOAD_ORIGINAL_SIZE #undef ALWAYS_LOAD_ORIGINAL_SIZE
#define N_FORWARD_PRELOADERS 2 #define N_FORWARD_PRELOADERS 2
#define N_BACKWARD_PRELOADERS 2 #define N_BACKWARD_PRELOADERS 2
...@@ -61,6 +62,7 @@ static const GActionEntry actions[] = { ...@@ -61,6 +62,7 @@ static const GActionEntry actions[] = {
{ "toggle-animation", toggle_action_activated, NULL, "true", gth_browser_activate_toggle_animation }, { "toggle-animation", toggle_action_activated, NULL, "true", gth_browser_activate_toggle_animation },
{ "step-animation", gth_browser_activate_step_animation }, { "step-animation", gth_browser_activate_step_animation },
{ "image-zoom", gth_browser_activate_image_zoom, "s", "''", NULL }, { "image-zoom", gth_browser_activate_image_zoom, "s", "''", NULL },
{ "transparency-style", gth_browser_activate_transparency_style, "s", "''", NULL },
}; };
...@@ -931,13 +933,35 @@ pref_transparency_style_changed (GSettings *settings, ...@@ -931,13 +933,35 @@ pref_transparency_style_changed (GSettings *settings,
char *key, char *key,
gpointer user_data) gpointer user_data)
{ {
GthImageViewerPage *self = user_data; GthImageViewerPage *self = user_data;
GthTransparencyStyle style;
GAction *action;
const char *state;
if (! self->priv->active || (self->priv->viewer == NULL)) if (! self->priv->active || (self->priv->viewer == NULL))
return; return;
gth_image_viewer_set_transparency_style (GTH_IMAGE_VIEWER (self->priv->viewer), style = g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_TRANSPARENCY_STYLE);
g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_TRANSPARENCY_STYLE)); state = "";
switch (style) {
case GTH_TRANSPARENCY_STYLE_CHECKERED:
state = "checkered";
break;
case GTH_TRANSPARENCY_STYLE_WHITE:
state = "white";
break;
case GTH_TRANSPARENCY_STYLE_GRAY:
state = "gray";
break;
case GTH_TRANSPARENCY_STYLE_BLACK:
state = "black";
break;
}
action = g_action_map_lookup_action (G_ACTION_MAP (self->priv->browser), "transparency-style");
if (action != NULL)
g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_string (state));
gth_image_viewer_set_transparency_style (GTH_IMAGE_VIEWER (self->priv->viewer), style);
} }
...@@ -1160,6 +1184,12 @@ gth_image_viewer_page_real_activate (GthViewerPage *base, ...@@ -1160,6 +1184,12 @@ gth_image_viewer_page_real_activate (GthViewerPage *base,
_("Next frame"), _("Next frame"),
"win.step-animation", "win.step-animation",
NULL); NULL);
self->priv->buttons[TRANSPARENCY_STYLE_BUTTON] =
gth_browser_add_header_bar_menu_button (browser,
GTH_BROWSER_HEADER_SECTION_VIEWER_OTHER_COMMANDS,
"transparency-symbolic",
_("Transparency"),
_gtk_builder_get_widget (self->priv->builder, "transparency_popover"));
gth_window_add_accelerators (GTH_WINDOW (browser), accelerators, G_N_ELEMENTS (accelerators)); gth_window_add_accelerators (GTH_WINDOW (browser), accelerators, G_N_ELEMENTS (accelerators));
...@@ -1550,6 +1580,7 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base) ...@@ -1550,6 +1580,7 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base)
{ {
GthImageViewerPage *self; GthImageViewerPage *self;
GthImage *image; GthImage *image;
gboolean enable_action;
gboolean is_animation; gboolean is_animation;
self = (GthImageViewerPage*) base; self = (GthImageViewerPage*) base;
...@@ -1558,8 +1589,13 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base) ...@@ -1558,8 +1589,13 @@ gth_image_viewer_page_real_update_sensitivity (GthViewerPage *base)
gth_window_enable_action (GTH_WINDOW (self->priv->browser), "image-redo", gth_image_history_can_redo (self->priv->history)); gth_window_enable_action (GTH_WINDOW (self->priv->browser), "image-redo", gth_image_history_can_redo (self->priv->history));
image = gth_image_viewer_get_image (GTH_IMAGE_VIEWER (self->priv->viewer)); image = gth_image_viewer_get_image (GTH_IMAGE_VIEWER (self->priv->viewer));
gtk_widget_set_visible (self->priv->buttons[APPLY_ICC_PROFILE_BUTTON], (image != NULL) && (gth_image_get_icc_profile (image) != NULL)); enable_action = (image != NULL) && (gth_image_get_icc_profile (image) != NULL);
gth_window_enable_action (GTH_WINDOW (self->priv->browser), "apply-icc-profile", (image != NULL) && (gth_image_get_icc_profile (image) != NULL)); gtk_widget_set_visible (self->priv->buttons[APPLY_ICC_PROFILE_BUTTON], enable_action);
gth_window_enable_action (GTH_WINDOW (self->priv->browser), "apply-icc-profile", enable_action);
enable_action = (self->priv->file_data != NULL) && _g_mime_type_has_transparency (gth_file_data_get_mime_type (self->priv->file_data));
gtk_widget_set_visible (self->priv->buttons[TRANSPARENCY_STYLE_BUTTON], enable_action);
gth_window_enable_action (GTH_WINDOW (self->priv->browser), "transparency-style", enable_action);
is_animation = gth_image_viewer_is_animation (GTH_IMAGE_VIEWER (self->priv->viewer)); is_animation = gth_image_viewer_is_animation (GTH_IMAGE_VIEWER (self->priv->viewer));
gtk_widget_set_visible (self->priv->buttons[TOGGLE_ANIMATION_BUTTON], is_animation); gtk_widget_set_visible (self->priv->buttons[TOGGLE_ANIMATION_BUTTON], is_animation);
...@@ -2198,8 +2234,7 @@ gth_image_viewer_page_reset_viewer_tool (GthImageViewerPage *self) ...@@ -2198,8 +2234,7 @@ gth_image_viewer_page_reset_viewer_tool (GthImageViewerPage *self)
g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_ZOOM_CHANGE)); g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_ZOOM_CHANGE));
gth_image_viewer_set_reset_scrollbars (GTH_IMAGE_VIEWER (self->priv->viewer), gth_image_viewer_set_reset_scrollbars (GTH_IMAGE_VIEWER (self->priv->viewer),
g_settings_get_boolean (self->priv->settings, PREF_IMAGE_VIEWER_RESET_SCROLLBARS)); g_settings_get_boolean (self->priv->settings, PREF_IMAGE_VIEWER_RESET_SCROLLBARS));
gth_image_viewer_set_transparency_style (GTH_IMAGE_VIEWER (self->priv->viewer), pref_transparency_style_changed (self->priv->settings, NULL, self);
g_settings_get_enum (self->priv->settings, PREF_IMAGE_VIEWER_TRANSPARENCY_STYLE));
_gth_image_viewer_page_enable_drag_source (self, TRUE); _gth_image_viewer_page_enable_drag_source (self, TRUE);
} }
......
...@@ -3156,6 +3156,17 @@ _g_mime_type_is_audio (const char *mime_type) ...@@ -3156,6 +3156,17 @@ _g_mime_type_is_audio (const char *mime_type)
} }
gboolean
_g_mime_type_has_transparency (const char *mime_type)
{
g_return_val_if_fail (mime_type != NULL, FALSE);
return (strcmp (mime_type, "image/png") == 0)
|| (strcmp (mime_type, "image/gif") == 0)
|| (strcmp (mime_type, "image/svg+xml") == 0);
}
char * char *
_g_settings_get_uri (GSettings *settings, _g_settings_get_uri (GSettings *settings,
const char *key) const char *key)
......
...@@ -343,6 +343,7 @@ gboolean _g_mime_type_is_image (const char *mime_type); ...@@ -343,6 +343,7 @@ gboolean _g_mime_type_is_image (const char *mime_type);
gboolean _g_mime_type_is_raw (const char *mime_type); gboolean _g_mime_type_is_raw (const char *mime_type);
gboolean _g_mime_type_is_video (const char *mime_type); gboolean _g_mime_type_is_video (const char *mime_type);
gboolean _g_mime_type_is_audio (const char *mime_type); gboolean _g_mime_type_is_audio (const char *mime_type);
gboolean _g_mime_type_has_transparency (const char *mime_type);
/* GSettings utils */ /* GSettings utils */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment