static void
photos_print_setup_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (object);
    PhotosPrintSetupPrivate *priv = self->priv;

    switch (prop_id)
    {
    case PROP_NODE:
    {
        GdkPixbuf *pixbuf;

        priv->node = GEGL_NODE (g_value_dup_object (value));
        pixbuf = photos_utils_create_pixbuf_from_node (priv->node);
        if (pixbuf != NULL)
        {
            g_object_set (priv->preview, "pixbuf", pixbuf, NULL);
            g_object_unref (pixbuf);
        }
    }
    break;
    case PROP_PAGE_SETUP:
        priv->page_setup = GTK_PAGE_SETUP (g_value_get_object (value));
        break;
    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
static gboolean
on_preview_image_scrolled (GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;
    PhotosPrintPreview *preview = PHOTOS_PRINT_PREVIEW (widget);
    gfloat scale;

    scale = photos_print_preview_get_scale (preview);

    if (!photos_print_preview_point_in_image_area (preview, event->x, event->y))
        return FALSE;

    switch (event->direction)
    {
    case GDK_SCROLL_UP:
        /* scale up */
        scale *= 1.1;
        break;
    case GDK_SCROLL_DOWN:
        /* scale down */
        scale *= 0.9;
        break;
    case GDK_SCROLL_LEFT:
    case GDK_SCROLL_RIGHT:
    case GDK_SCROLL_SMOOTH:
    default:
        return FALSE;
        break;
    }

    gtk_range_set_value (GTK_RANGE (priv->scaling), 100*scale);

    return TRUE;
}
static gboolean
on_preview_image_key_pressed (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
{
    PhotosPrintSetupPrivate *priv = PHOTOS_PRINT_SETUP (user_data)->priv;
    PhotosPrintPreview *preview = PHOTOS_PRINT_PREVIEW (widget);
    gfloat scale;

    scale = photos_print_preview_get_scale (preview);

    switch (event->keyval)
    {
    case GDK_KEY_KP_Add:
    case GDK_KEY_plus:
        /* scale up */
        scale *= 1.1;
        break;
    case GDK_KEY_KP_Subtract:
    case GDK_KEY_minus:
        /* scale down */
        scale *= 0.9;
        break;
    default:
        return FALSE;
        break;
    }

    gtk_range_set_value (GTK_RANGE (priv->scaling), 100*scale);

    return TRUE;
}
static void
on_height_value_changed (GtkSpinButton *spinbutton,
                         gpointer       user_data)
{
    PhotosPrintSetupPrivate *priv = PHOTOS_PRINT_SETUP (user_data)->priv;

    photos_print_setup_size_changed (PHOTOS_PRINT_SETUP (user_data),
                                     priv->height, priv->width,
                                     priv->top, priv->bottom,
                                     priv->left, priv->right,
                                     gtk_page_setup_get_page_height (priv->page_setup,
                                             priv->current_unit),
                                     gtk_page_setup_get_page_width (priv->page_setup,
                                             priv->current_unit),
                                     CHANGE_VERT);
}
static void
photos_print_operation_update_custom_widget (GtkPrintOperation *operation,
                                             GtkWidget *widget,
                                             GtkPageSetup *page_setup,
                                             GtkPrintSettings *settings)
{
  photos_print_setup_update (PHOTOS_PRINT_SETUP (widget), page_setup);
}
static void
photos_print_operation_custom_widget_apply (GtkPrintOperation *operation, GtkWidget *widget)
{
  PhotosPrintOperation *self = PHOTOS_PRINT_OPERATION (operation);

  photos_print_setup_get_options (PHOTOS_PRINT_SETUP (widget),
                                  &self->left_margin,
                                  &self->top_margin,
                                  &self->scale_factor,
                                  &self->unit);
}
static void
photos_print_setup_dispose (GObject *object)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (object);
    PhotosPrintSetupPrivate *priv = self->priv;

    g_clear_object (&priv->node);
    g_clear_object (&priv->page_setup);

    G_OBJECT_CLASS (photos_print_setup_parent_class)->dispose (object);
}
static void
on_bottom_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;

    photos_print_setup_position_values_changed (self,
            priv->bottom,
            priv->top,
            priv->height,
            gtk_page_setup_get_page_height (priv->page_setup,
                                            priv->current_unit),
            CHANGE_VERT);
}
static void
on_right_value_changed (GtkSpinButton *spinbutton, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;

    photos_print_setup_position_values_changed (self,
            priv->right,
            priv->left,
            priv->width,
            gtk_page_setup_get_page_width (priv->page_setup,
                                           priv->current_unit),
            CHANGE_HORIZ);
}
Example #10
0
static void
on_scale_changed (GtkRange *range, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;
    GeglRectangle bbox;
    gdouble height;
    gdouble scale;
    gdouble width;
    gdouble left, right, top, bottom;
    gdouble page_width, page_height;
    gdouble factor;

    gtk_combo_box_set_active (GTK_COMBO_BOX (priv->center), CENTER_NONE);

    bbox = gegl_node_get_bounding_box (priv->node);
    factor = get_scale_to_px_factor (self);

    width = (gdouble) bbox.width / factor;
    height = (gdouble) bbox.height / factor;

    left = gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->left));
    top = gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->top));

    scale = CLAMP (0.01 * gtk_range_get_value (range), 0, photos_print_setup_get_max_percentage (self));

    photos_print_preview_set_scale (PHOTOS_PRINT_PREVIEW (priv->preview), scale);

    width  *= scale;
    height *= scale;

    page_width = gtk_page_setup_get_page_width (priv->page_setup, priv->current_unit);
    page_height = gtk_page_setup_get_page_height (priv->page_setup, priv->current_unit);

    update_image_pos_ranges (self, page_width, page_height, width, height);

    right = page_width - left - width;
    bottom = page_height - top - height;

    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->width), width);
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->height), height);
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->right), right);
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->bottom), bottom);
}
Example #11
0
static void
on_center_changed (GtkComboBox *combobox, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;
    gint active;

    active = gtk_combo_box_get_active (combobox);

    switch (active)
    {
    case CENTER_HORIZONTAL:
        photos_print_setup_center (gtk_page_setup_get_page_width (priv->page_setup,
                                   priv->current_unit),
                                   gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->width)),
                                   GTK_SPIN_BUTTON (priv->left),
                                   GTK_SPIN_BUTTON (priv->right));
        break;
    case CENTER_VERTICAL:
        photos_print_setup_center (gtk_page_setup_get_page_height (priv->page_setup,
                                   priv->current_unit),
                                   gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->height)),
                                   GTK_SPIN_BUTTON (priv->top),
                                   GTK_SPIN_BUTTON (priv->bottom));
        break;
    case CENTER_BOTH:
        photos_print_setup_center (gtk_page_setup_get_page_width (priv->page_setup,
                                   priv->current_unit),
                                   gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->width)),
                                   GTK_SPIN_BUTTON (priv->left),
                                   GTK_SPIN_BUTTON (priv->right));
        photos_print_setup_center (gtk_page_setup_get_page_height (priv->page_setup,
                                   priv->current_unit),
                                   gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->height)),
                                   GTK_SPIN_BUTTON (priv->top),
                                   GTK_SPIN_BUTTON (priv->bottom));
        break;
    case CENTER_NONE:
    default:
        break;
    }

    gtk_combo_box_set_active (combobox, active);
}
Example #12
0
static void
on_preview_pixbuf_moved (PhotosPrintPreview *preview, gpointer user_data)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (user_data);
    PhotosPrintSetupPrivate *priv = self->priv;
    gdouble x;
    gdouble y;

    photos_print_preview_get_image_position (preview, &x, &y);

    if (priv->current_unit == GTK_UNIT_MM)
    {
        x *= FACTOR_INCH_TO_MM;
        y *= FACTOR_INCH_TO_MM;
    }

    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->left), x);
    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->top), y);
}
Example #13
0
static void
on_unit_changed (GtkComboBox *combobox, gpointer user_data)
{
    GtkUnit unit = GTK_UNIT_INCH;

    switch (gtk_combo_box_get_active (combobox))
    {
    case UNIT_INCH:
        unit = GTK_UNIT_INCH;
        break;
    case UNIT_MM:
        unit = GTK_UNIT_MM;
        break;
    default:
        g_assert_not_reached ();
    }

    photos_print_setup_set_scale_unit (PHOTOS_PRINT_SETUP (user_data), unit);
}
Example #14
0
static void
photos_print_setup_constructed (GObject *object)
{
    PhotosPrintSetup *self = PHOTOS_PRINT_SETUP (object);
    PhotosPrintSetupPrivate *priv = self->priv;

    G_OBJECT_CLASS (photos_print_setup_parent_class)->constructed (object);

    photos_print_setup_set_initial_values (self);
    photos_print_preview_set_from_page_setup (PHOTOS_PRINT_PREVIEW (priv->preview), priv->page_setup);

    g_signal_connect (priv->left, "value-changed", G_CALLBACK (on_left_value_changed), self);
    g_signal_connect (priv->right, "value-changed", G_CALLBACK (on_right_value_changed), self);
    g_signal_connect (priv->top, "value-changed", G_CALLBACK (on_top_value_changed), self);
    g_signal_connect (priv->bottom, "value-changed", G_CALLBACK (on_bottom_value_changed), self);
    g_signal_connect (priv->width, "value-changed", G_CALLBACK (on_width_value_changed), self);
    g_signal_connect (priv->height, "value-changed", G_CALLBACK (on_height_value_changed), self);
    g_signal_connect (priv->scaling, "value-changed", G_CALLBACK (on_scale_changed), self);
    g_signal_connect (priv->scaling, "format-value", G_CALLBACK (on_scale_format_value), NULL);
    g_signal_connect (priv->preview, "pixbuf-moved", G_CALLBACK (on_preview_pixbuf_moved), self);
    g_signal_connect (priv->preview, "scroll-event", G_CALLBACK (on_preview_image_scrolled), self);
    g_signal_connect (priv->preview, "key-press-event", G_CALLBACK (on_preview_image_key_pressed), self);
}