diff --git a/data/gqpe.ui b/data/gqpe.ui index 3d26f8844de7df49fd371673125950d3297e7db7..7071de7e85f2174cae4123ef10671971efb5a2a0 100644 --- a/data/gqpe.ui +++ b/data/gqpe.ui @@ -111,6 +111,77 @@ + + + True + False + 0 + horizontal + + + True + False + Zoom in + + + + True + False + zoom-in-symbolic + 1 + + + + + start + + + + + True + False + Zoom out + + + + True + False + zoom-out-symbolic + 1 + + + + + start + + + + + True + False + Zoom fit best + + + + True + False + zoom-fit-best-symbolic + 1 + + + + + start + + + + + True @@ -158,19 +229,29 @@ - - 500 - 500 + True False - 6 - True - 420 - start-here-symbolic - - + GTK_SHADOW_NONE + 500 + 500 + automatic + automatic + + + 500 + 500 + True + False + 6 + True + 420 + start-here-symbolic + + + @@ -260,11 +341,6 @@ - - - - - False diff --git a/src/application-window.vala b/src/application-window.vala index 8f26e3ca5d0e41f5f7a9b1760c60aa3e7768ed10..15f9b11d4436f8c93b8e04a324b462cdd7cd5aaa 100644 --- a/src/application-window.vala +++ b/src/application-window.vala @@ -71,6 +71,9 @@ namespace GQPE { /* The save button. */ [GtkChild] private Gtk.Button save; + /* The image scroll. */ + [GtkChild] + private Gtk.ScrolledWindow image_scroll; /* The image label. */ [GtkChild] private Gtk.Label label; @@ -174,6 +177,33 @@ namespace GQPE { rotate(Rotate.RIGHT); } + /** + * Callback for zoom in. + */ + [GtkCallback] + public void on_zoom_in_clicked() { + } + + /** + * Callback for zoom out. + */ + [GtkCallback] + public void on_zoom_out_clicked() { + } + + /** + * Callback for zoom fit. + */ + [GtkCallback] + public void on_zoom_fit_clicked() { + double w = image_scroll.get_allocated_width(); + double h = image_scroll.get_allocated_height(); + if (w <= 0.0 || h <= 0.0) + return; + photograph.resize(w, h); + image.set_from_pixbuf(photograph.pixbuf); + } + /** * Callback for save button clicked. */ @@ -210,26 +240,6 @@ namespace GQPE { enable_ui(Item.SAVE); } - /** - * Callback for image resized. - */ - [GtkCallback] - public void on_image_resize() { - double w = image.get_allocated_width(); - double h = image.get_allocated_height(); - if (w <= 0.0 || h <= 0.0) - return; - double W = photograph.pixbuf.width; - double H = photograph.pixbuf.height; - double s1 = w / W; - double s2 = h / H; - if (H * s1 <= h) - photograph.scale(s1); - else - photograph.scale(s2); - - } - /** * Opens an array of files. * @param files the array of files. diff --git a/src/photograph.vala b/src/photograph.vala index 6a041b840abe6f652905dc9398f41d7196c44bc3..1e836955bac96c26208ac54f6b998cd80419f5a4 100644 --- a/src/photograph.vala +++ b/src/photograph.vala @@ -68,7 +68,7 @@ namespace GQPE { /* The photograph metadata. */ private GExiv2.Metadata metadata; /* Private the original pixbuf. */ - private Gdk.Pixbuf pixbuf original; + private Gdk.Pixbuf original; /** * Creates a new photograph. @@ -86,10 +86,10 @@ namespace GQPE { if (original != null) return; + original = new Gdk.Pixbuf.from_file(file.get_path()); metadata = new GExiv2.Metadata(); metadata.open_path(file.get_path()); - original = new Gdk.Pixbuf.from_file(file.get_path()); if (metadata.has_tag(Tag.ORIENTATION)) { var rot = Gdk.PixbufRotation.NONE; switch (metadata.get_tag_long(Tag.ORIENTATION)) { @@ -110,28 +110,32 @@ namespace GQPE { break; } if (rot != Gdk.PixbufRotation.NONE) - pixbuf = original.rotate_simple(rot); + original = original.rotate_simple(rot); } - double scale = 500.0 / double.max(pixbuf.width, pixbuf.height); - pixbuf = pixbuf.scale_simple((int)(pixbuf.width*scale), - (int)(pixbuf.height*scale), - Gdk.InterpType.BILINEAR); + double scale = 490.0 / double.max(original.width, original.height); + pixbuf = original.scale_simple((int)(original.width*scale), + (int)(original.height*scale), + Gdk.InterpType.BILINEAR); album = (metadata.has_tag(Tag.SUBJECT)) ? metadata.get_tag_string(Tag.SUBJECT).strip() : ""; caption = (metadata.has_tag(Tag.CAPTION)) ? metadata.get_tag_string(Tag.CAPTION).strip() : ""; comment = (metadata.has_tag(Tag.DESCRIPTION)) ? metadata.get_tag_string(Tag.DESCRIPTION).strip() : ""; - - album.strip(); - caption.strip(); - comment.strip(); } - public void scale(double scale) { - pixbuf = pixbuf.scale_simple((int)(pixbuf.width*scale), - (int)(pixbuf.height*scale), - Gdk.InterpType.BILINEAR); + /** + * Resizes the photograph so it fills the given width and height. + */ + public void resize(double w, double h) { + double W = original.width; + double H = original.height; + double s1 = w / W; + double s2 = h / H; + double scale = (H * s1 <= h) ? s1 : s2; + pixbuf = original.scale_simple((int)(original.width*scale), + (int)(original.height*scale), + Gdk.InterpType.BILINEAR); } /**