commit d0b41032710970969a806d889c85070c5210eaf2
parent f676416e8618aa288f0790b1acc2fbca2aaba810
Author: Paul <paul@claws-mail.org>
Date: Wed, 30 Dec 2020 15:03:40 +0000
rework image viewer
add options, when resizing images, to either fit the image width or fit the image height. image height is the default. regardless of this setting, when displaying images inline they will fit the height
Diffstat:
7 files changed, 86 insertions(+), 22 deletions(-)
diff --git a/src/gtk/gtkutils.c b/src/gtk/gtkutils.c
@@ -1707,8 +1707,8 @@ claws_input_add (gint source,
*
* @return a GdkPixbuf
*/
-GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
- int box_height)
+GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, gboolean inline_img,
+ gboolean fit_img_height, int box_width, int box_height)
{
gint w, h, orientation, angle;
gint avail_width, avail_height;
@@ -1779,9 +1779,20 @@ GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *src_pixbuf, int box_width,
avail_height = box_height;
if (box_width != -1 && box_height != -1 && avail_width - 100 > 0) {
- if (w > avail_width || h > avail_height) {
- h = (avail_width * h) / w;
- w = avail_width;
+ if (inline_img || fit_img_height) {
+ if (w > avail_width) {
+ h = (avail_width * h) / w;
+ w = avail_width;
+ }
+ if (h > avail_height) {
+ w = (avail_height * w) / h;
+ h = avail_height;
+ }
+ } else {
+ if (w > avail_width || h > avail_height) {
+ h = (avail_width * h) / w;
+ w = avail_width;
+ }
}
t_pixbuf = gdk_pixbuf_scale_simple(pixbuf,
w, h, GDK_INTERP_BILINEAR);
diff --git a/src/gtk/gtkutils.h b/src/gtk/gtkutils.h
@@ -1,6 +1,6 @@
/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2017 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
*
* 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
@@ -181,8 +181,9 @@ gboolean gtkut_list_view_select_row(GtkWidget *list, gint row);
GtkUIManager *gtkut_create_ui_manager(void);
GtkUIManager *gtkut_ui_manager(void);
-GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, int box_width,
- int box_height);
+GdkPixbuf *claws_load_pixbuf_fitting(GdkPixbuf *pixbuf, gboolean inline_img,
+ gboolean fit_img_height,
+ int box_width, int box_height);
GtkWidget *gtkut_time_select_combo_new();
void gtkut_time_select_select_by_time(GtkComboBox *combo, int hour, int minute);
diff --git a/src/image_viewer.c b/src/image_viewer.c
@@ -1,6 +1,6 @@
/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
*
* 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
@@ -48,6 +48,7 @@ struct _ImageViewer
gchar *file;
MimeInfo *mimeinfo;
gboolean resize_img;
+ gboolean fit_img_height;
GtkWidget *scrolledwin;
GtkWidget *image;
@@ -103,24 +104,24 @@ static void image_viewer_load_image(ImageViewer *imageviewer)
#if GDK_PIXBUF_MINOR >= 28
if (gdk_pixbuf_animation_is_static_image(animation)
- || imageviewer->resize_img) {
+ || imageviewer->resize_img || imageviewer->fit_img_height) {
pixbuf = gdk_pixbuf_animation_get_static_image(animation);
g_object_ref(pixbuf);
g_object_unref(animation);
animation = NULL;
#else
- if (imageviewer->resize_img) {
+ if (imageviewer->resize_img || imageviewer->fit_img_height) {
#endif
if (imageviewer->resize_img) {
- gtk_widget_get_allocation(
- gtk_widget_get_parent(imageviewer->notebook), &allocation);
- pixbuf = claws_load_pixbuf_fitting(pixbuf,
+ gtk_widget_get_allocation(imageviewer->scrolledwin, &allocation);
+ pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE,
+ imageviewer->fit_img_height,
allocation.width,
allocation.height);
}
else
- pixbuf = claws_load_pixbuf_fitting(pixbuf, -1, -1);
+ pixbuf = claws_load_pixbuf_fitting(pixbuf, FALSE, imageviewer->fit_img_height, -1, -1);
}
if (error && !pixbuf && !animation) {
@@ -216,6 +217,7 @@ static void image_viewer_clear_viewer(MimeViewer *_mimeviewer)
imageviewer->file = NULL;
imageviewer->mimeinfo = NULL;
imageviewer->resize_img = prefs_common.resize_img;
+ imageviewer->fit_img_height = prefs_common.fit_img_height;
}
static void image_viewer_destroy_viewer(MimeViewer *_mimeviewer)
@@ -266,6 +268,10 @@ static gboolean scrolledwin_button_cb(GtkWidget *scrolledwin, GdkEventButton *ev
imageviewer->resize_img = !imageviewer->resize_img;
image_viewer_load_image(imageviewer);
return TRUE;
+ } else if (event->button == 3 && imageviewer->image) {
+ imageviewer->fit_img_height = !imageviewer->fit_img_height;
+ image_viewer_load_image(imageviewer);
+ return TRUE;
}
return FALSE;
}
@@ -392,6 +398,7 @@ static MimeViewer *image_viewer_create(void)
imageviewer->mimeviewer.get_selection = NULL;
imageviewer->resize_img = prefs_common.resize_img;
+ imageviewer->fit_img_height = prefs_common.fit_img_height;
imageviewer->scrolledwin = scrolledwin;
imageviewer->image = gtk_image_new();
diff --git a/src/prefs_common.c b/src/prefs_common.c
@@ -428,6 +428,8 @@ static PrefParam param[] = {
NULL, NULL, NULL},
{"inline_image", "TRUE", &prefs_common.inline_img, P_BOOL,
NULL, NULL, NULL},
+ {"fit_image_height", "TRUE", &prefs_common.fit_img_height, P_BOOL,
+ NULL, NULL, NULL},
{"display_folder_unread_num", "0",
&prefs_common.display_folder_unread, P_INT,
diff --git a/src/prefs_common.h b/src/prefs_common.h
@@ -246,6 +246,7 @@ struct _PrefsCommon
gboolean display_img;
gboolean resize_img;
gboolean inline_img;
+ gboolean fit_img_height;
gboolean trans_hdr;
gint display_folder_unread;
diff --git a/src/prefs_image_viewer.c b/src/prefs_image_viewer.c
@@ -1,6 +1,6 @@
/*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail Team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2020 the Claws Mail Team
*
* 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
@@ -44,6 +44,8 @@ typedef struct _ImageViewerPage
GtkWidget *autoload_img;
GtkWidget *resize_img;
+ GtkWidget *fit_img_height_radiobtn;
+ GtkWidget *fit_img_width_radiobtn;
GtkWidget *inline_img;
GtkWidget *print_imgs;
}ImageViewerPage;
@@ -57,6 +59,11 @@ static void imageviewer_create_widget_func(PrefsPage * _page,
GtkWidget *table;
GtkWidget *autoload_img;
GtkWidget *resize_img;
+ GtkWidget *vbox;
+ GtkWidget *hbox;
+ GtkWidget *fit_img_label;
+ GtkWidget *fit_img_height_radiobtn;
+ GtkWidget *fit_img_width_radiobtn;
GtkWidget *inline_img;
GtkWidget *print_imgs;
@@ -80,26 +87,58 @@ static void imageviewer_create_widget_func(PrefsPage * _page,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
+ vbox = gtk_vbox_new(FALSE, VSPACING);
+ hbox = gtk_hbox_new(FALSE, 8);
+ gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+ gtk_widget_show(vbox);
+ gtk_widget_show(hbox);
+
+ fit_img_label = gtk_label_new (_("Fit image"));
+ gtk_widget_show(fit_img_label);
+ CLAWS_SET_TIP(fit_img_label,
+ _("Right-clicking image toggles fitting height/width"));
+ gtk_box_pack_start(GTK_BOX(hbox), fit_img_label, FALSE, FALSE, 0);
+
+ fit_img_height_radiobtn = gtk_radio_button_new_with_label(NULL, _("Height"));
+ gtk_widget_show(fit_img_height_radiobtn);
+ gtk_box_pack_start(GTK_BOX(hbox), fit_img_height_radiobtn, FALSE, FALSE, 0);
+
+ fit_img_width_radiobtn = gtk_radio_button_new_with_label_from_widget(
+ GTK_RADIO_BUTTON(fit_img_height_radiobtn), _("Width"));
+ gtk_widget_show(fit_img_width_radiobtn);
+ gtk_box_pack_start(GTK_BOX(hbox), fit_img_width_radiobtn, FALSE, FALSE, 0);
+ gtk_table_attach(GTK_TABLE(table), vbox, 0, 1, 2, 3,
+ (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
+ (GtkAttachOptions) (0), 0, 0);
+
inline_img = gtk_check_button_new_with_label(_("Display images inline"));
gtk_widget_show(inline_img);
- gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 2, 3,
+ gtk_table_attach(GTK_TABLE(table), inline_img, 0, 1, 3, 4,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
print_imgs = gtk_check_button_new_with_label(_("Print images"));
gtk_widget_show(print_imgs);
- gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 3, 4,
+ gtk_table_attach(GTK_TABLE(table), print_imgs, 0, 1, 4, 5,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(resize_img), prefs_common.resize_img);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(autoload_img), prefs_common.display_img);
+ if (prefs_common.fit_img_height)
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_height_radiobtn), TRUE);
+ else
+ gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fit_img_width_radiobtn), TRUE);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(inline_img), prefs_common.inline_img);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(print_imgs), prefs_common.print_imgs);
+
+ SET_TOGGLE_SENSITIVITY(resize_img, vbox);
prefs_imageviewer->window = GTK_WIDGET(window);
prefs_imageviewer->autoload_img = autoload_img;
prefs_imageviewer->resize_img = resize_img;
+ prefs_imageviewer->fit_img_height_radiobtn = fit_img_height_radiobtn;
+ prefs_imageviewer->fit_img_width_radiobtn = fit_img_width_radiobtn;
prefs_imageviewer->inline_img = inline_img;
prefs_imageviewer->print_imgs = print_imgs;
@@ -120,6 +159,9 @@ static void imageviewer_save_func(PrefsPage * _page)
prefs_common.resize_img =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(imageviewer->resize_img));
+ prefs_common.fit_img_height =
+ gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
+ (imageviewer->fit_img_height_radiobtn));
prefs_common.inline_img =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(imageviewer->inline_img));
diff --git a/src/textview.c b/src/textview.c
@@ -735,8 +735,8 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
}
gtk_widget_get_allocation(textview->scrolledwin, &allocation);
- pixbuf = claws_load_pixbuf_fitting(pixbuf,
- allocation.width,
+ pixbuf = claws_load_pixbuf_fitting(pixbuf, prefs_common.inline_img,
+ prefs_common.fit_img_height, allocation.width,
allocation.height);
if (textview->stop_loading) {