/**
 * photos_print_preview_new_with_pixbuf:
 * @pixbuf: a #GdkPixbuf
 *
 * Creates a new #PhotosPrintPreview widget, and sets the #GdkPixbuf to preview
 * on it.
 *
 * Returns: A new #PhotosPrintPreview widget.
 **/
GtkWidget *
photos_print_preview_new_with_pixbuf (GdkPixbuf *pixbuf)
{
	PhotosPrintPreview *preview;

	g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);

	preview = PHOTOS_PRINT_PREVIEW (photos_print_preview_new ());

	preview->priv->pixbuf = g_object_ref (pixbuf);

	update_relative_sizes (preview);

	return GTK_WIDGET (preview);
}
Exemplo n.º 2
0
static void
photos_print_setup_init (PhotosPrintSetup *self)
{
    GtkWidget *frame;
    GtkWidget *grid;
    GtkWidget *label;
    GtkWidget *hscale;
    GtkWidget *combobox;
    PhotosPrintSetupPrivate *priv;

#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
    gchar *locale_scale = NULL;
#endif

    self->priv = photos_print_setup_get_instance_private (self);
    priv = self->priv;

    gtk_container_set_border_width (GTK_CONTAINER (self), 12);
    gtk_orientable_set_orientation (GTK_ORIENTABLE (self), GTK_ORIENTATION_VERTICAL);
    gtk_grid_set_column_spacing (GTK_GRID (self), 18);
    gtk_grid_set_row_spacing (GTK_GRID (self), 18);

    grid = gtk_grid_new ();
    gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
    gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
    frame = photos_print_setup_wrap_in_frame (_("Position"), grid);
    gtk_grid_attach (GTK_GRID (self), frame, 0, 0, 1, 1);

    priv->left = grid_attach_spin_button_with_label (grid, _("_Left:"), 0, 0);
    priv->right = grid_attach_spin_button_with_label (grid,_("_Right:"), 0, 1);
    priv->top = grid_attach_spin_button_with_label (grid, _("_Top:"), 2, 0);
    priv->bottom = grid_attach_spin_button_with_label (grid, _("_Bottom:"), 2, 1);

    label = gtk_label_new_with_mnemonic (_("C_enter:"));
    gtk_label_set_xalign (GTK_LABEL (label), 0.0);

    combobox = gtk_combo_box_text_new ();
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), CENTER_NONE, _("None"));
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), CENTER_HORIZONTAL, _("Horizontal"));
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), CENTER_VERTICAL, _("Vertical"));
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), CENTER_BOTH, _("Both"));
    gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), CENTER_NONE);
    /* Attach combobox below right margin spinbutton and span until end */
    gtk_grid_attach_next_to (GTK_GRID (grid), combobox, priv->right, GTK_POS_BOTTOM, 3, 1);
    /* Attach the label to the left of the combobox */
    gtk_grid_attach_next_to (GTK_GRID (grid), label, combobox, GTK_POS_LEFT, 1, 1);
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox);
    priv->center = combobox;
    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (on_center_changed), self);

    grid = gtk_grid_new ();
    gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
    gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
    frame = photos_print_setup_wrap_in_frame (_("Size"), grid);
    gtk_grid_attach (GTK_GRID (self), frame, 0, 1, 1, 1);

    priv->width = grid_attach_spin_button_with_label (grid, _("_Width:"), 0, 0);
    priv->height = grid_attach_spin_button_with_label (grid, _("_Height:"), 2, 0);

    label = gtk_label_new_with_mnemonic (_("_Scaling:"));
    hscale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, 1, 100, 1);
    gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT);
    gtk_range_set_value (GTK_RANGE (hscale), 100);
    gtk_grid_attach_next_to (GTK_GRID (grid), hscale, priv->width, GTK_POS_BOTTOM, 3, 1);
    gtk_grid_attach_next_to (GTK_GRID (grid), label, hscale, GTK_POS_LEFT, 1, 1);
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), hscale);
    priv->scaling = hscale;

    label = gtk_label_new_with_mnemonic (_("_Unit:"));
    gtk_label_set_xalign (GTK_LABEL (label), 0.0);

    combobox = gtk_combo_box_text_new ();
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), UNIT_MM, _("Millimeters"));
    gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (combobox), UNIT_INCH, _("Inches"));

#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
    locale_scale = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
    if (locale_scale && locale_scale[0] == 2)
    {
        gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), UNIT_INCH);
        photos_print_setup_set_scale_unit (self, GTK_UNIT_INCH);
    }
    else
#endif
    {
        gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), UNIT_MM);
        photos_print_setup_set_scale_unit (self, GTK_UNIT_MM);
    }

    gtk_grid_attach_next_to (GTK_GRID (grid), combobox, hscale, GTK_POS_BOTTOM, 3, 1);
    gtk_grid_attach_next_to (GTK_GRID (grid), label, combobox, GTK_POS_LEFT, 1, 1);

    gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox);
    priv->unit = combobox;
    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (on_unit_changed), self);

    priv->preview = photos_print_preview_new ();

    /* FIXME: This shouldn't be set by hand */
    gtk_widget_set_size_request (priv->preview, 250, 250);

    frame = photos_print_setup_wrap_in_frame (_("Preview"), priv->preview);
    /* The preview widget needs to span the whole grid height */
    gtk_grid_attach (GTK_GRID (self), frame, 1, 0, 1, 2);

    gtk_widget_show_all (GTK_WIDGET (self));
}