aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-05-02 22:45:32 +0200
committerThomas White <taw@bitwiz.me.uk>2019-05-02 23:02:40 +0200
commit589cbbd83943a24998b88a676ac8a5dec2a41c28 (patch)
tree95c47b0820a45d12de6593f08dac9a27909bc9f3
parentf170c993f12c36df69cd8c4617e87b6f14b58f36 (diff)
Implement Insert->Image
-rw-r--r--data/menus.ui6
-rw-r--r--src/slide_window.c89
2 files changed, 95 insertions, 0 deletions
diff --git a/data/menus.ui b/data/menus.ui
index ed7a0da..019bbed 100644
--- a/data/menus.ui
+++ b/data/menus.ui
@@ -117,10 +117,16 @@
<attribute name='label' translatable='yes'>Slide</attribute>
<attribute name='action'>win.slide</attribute>
</item>
+ </section>
+ <section>
<item>
<attribute name='label' translatable='yes'>Slide title</attribute>
<attribute name='action'>win.slidetitle</attribute>
</item>
+ <item>
+ <attribute name='label' translatable='yes'>Image</attribute>
+ <attribute name='action'>win.image</attribute>
+ </item>
</section>
</submenu>
diff --git a/src/slide_window.c b/src/slide_window.c
index 8bfd8b3..f291ed6 100644
--- a/src/slide_window.c
+++ b/src/slide_window.c
@@ -33,6 +33,9 @@
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <math.h>
+#include <libintl.h>
+#define _(x) gettext(x)
+
#include <narrative.h>
#include <slide.h>
#include <gtkslideview.h>
@@ -63,6 +66,91 @@ static void insert_slidetitle_sig(GSimpleAction *action, GVariant *parameter,
}
+static gint insert_image_response_sig(GtkWidget *d, gint response, SlideWindow *sw)
+{
+ GtkWidget *cb;
+ const char *size_str;
+
+ cb = gtk_file_chooser_get_extra_widget(GTK_FILE_CHOOSER(d));
+ size_str = gtk_combo_box_get_active_id(GTK_COMBO_BOX(cb));
+
+ if ( response == GTK_RESPONSE_ACCEPT ) {
+
+ char *filename;
+ struct frame_geom geom;
+ char *fn;
+ double slide_w, slide_h;
+ gint image_w, image_h;
+ double aspect;
+ GdkPixbufFormat *f;
+
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d));
+ fn = strdup(filename);
+ if ( fn == NULL ) return 0;
+
+ if ( slide_get_logical_size(sw->slide, narrative_get_stylesheet(sw->n),
+ &slide_w, &slide_h) ) return 0;
+
+ f = gdk_pixbuf_get_file_info(filename, &image_w, &image_h);
+ if ( f == NULL ) return 0;
+ aspect = (double)image_h / image_w;
+ g_free(filename);
+
+ if ( strcmp(size_str, "normal") == 0 ) {
+ geom.x.len = slide_w/4.0; geom.x.unit = LENGTH_UNIT;
+ geom.y.len = slide_h/4.0; geom.y.unit = LENGTH_UNIT;
+ geom.w.len = slide_w/2.0; geom.w.unit = LENGTH_UNIT;
+ geom.h.len = geom.w.len*aspect; geom.h.unit = LENGTH_UNIT;
+ }
+
+ if ( strcmp(size_str, "fillentire") == 0 ) {
+ geom.x.len = 0.0; geom.x.unit = LENGTH_UNIT;
+ geom.y.len = 0.0; geom.y.unit = LENGTH_UNIT;
+ geom.w.len = 1.0; geom.w.unit = LENGTH_FRAC;
+ geom.h.len = 1.0; geom.h.unit = LENGTH_FRAC;
+ }
+
+ slide_add_image(sw->slide, fn, geom);
+ }
+
+ gtk_widget_destroy(d);
+
+ return 0;
+}
+
+
+static void insert_image_sig(GSimpleAction *action, GVariant *parameter,
+ gpointer vp)
+{
+ SlideWindow *sw = vp;
+ GtkWidget *d;
+ GtkWidget *cb;
+
+ d = gtk_file_chooser_dialog_new(_("Insert image"),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Insert"), GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ cb = gtk_combo_box_text_new();
+
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(cb), "normal",
+ _("Make the image about half the width of the slide"));
+ gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(cb), "fillentire",
+ _("Fill the entire slide, even the title and footer regions"));
+
+ gtk_combo_box_set_active_id(GTK_COMBO_BOX(cb), "normal");
+
+ gtk_file_chooser_set_extra_widget(GTK_FILE_CHOOSER(d), cb);
+
+ g_signal_connect(G_OBJECT(d), "response",
+ G_CALLBACK(insert_image_response_sig), sw);
+
+ gtk_widget_show_all(d);
+}
+
+
static void paste_sig(GSimpleAction *action, GVariant *parameter,
gpointer vp)
{
@@ -205,6 +293,7 @@ GActionEntry sw_entries[] = {
{ "next", next_slide_sig, NULL, NULL, NULL },
{ "last", last_slide_sig, NULL, NULL, NULL },
{ "slidetitle", insert_slidetitle_sig, NULL, NULL, NULL },
+ { "image", insert_image_sig, NULL, NULL, NULL },
};