PIKApp/app/widgets/pikatemplateeditor.c

951 lines
36 KiB
C
Raw Permalink Normal View History

2023-09-26 00:35:21 +02:00
/* PIKA - Photo and Image Kooker Application
* a rebranding of The GNU Image Manipulation Program (created with heckimp)
* A derived work which may be trivial. However, any changes may be (C)2023 by Aldercone Studio
*
* Original copyright, applying to most contents (license remains unchanged):
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <string.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libpikamath/pikamath.h"
#include "libpikabase/pikabase.h"
#include "libpikacolor/pikacolor.h"
#include "libpikaconfig/pikaconfig.h"
#include "libpikawidgets/pikawidgets.h"
#include "widgets-types.h"
#include "config/pikacoreconfig.h"
#include "gegl/pika-babl.h"
#include "core/pika.h"
#include "core/pikatemplate.h"
#include "core/pika-utils.h"
#include "pikapropwidgets.h"
#include "pikatemplateeditor.h"
#include "pikawidgets-utils.h"
#include "pika-intl.h"
#define SB_WIDTH 8
#define MAX_COMMENT_LENGTH 512 /* arbitrary */
enum
{
PROP_0,
PROP_PIKA,
PROP_TEMPLATE
};
typedef struct _PikaTemplateEditorPrivate PikaTemplateEditorPrivate;
struct _PikaTemplateEditorPrivate
{
Pika *pika;
PikaTemplate *template;
GtkWidget *aspect_button;
gboolean block_aspect;
GtkWidget *expander;
GtkWidget *size_se;
GtkWidget *memsize_label;
GtkWidget *pixel_label;
GtkWidget *more_label;
GtkWidget *resolution_se;
GtkWidget *chain_button;
GtkWidget *precision_combo;
GtkWidget *profile_combo;
GtkWidget *simulation_profile_combo;
GtkWidget *simulation_intent_combo;
GtkWidget *simulation_bpc_toggle;
};
#define GET_PRIVATE(editor) \
((PikaTemplateEditorPrivate *) pika_template_editor_get_instance_private ((PikaTemplateEditor *) (editor)))
static void pika_template_editor_constructed (GObject *object);
static void pika_template_editor_finalize (GObject *object);
static void pika_template_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void pika_template_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static void pika_template_editor_precision_changed (GtkWidget *widget,
PikaTemplateEditor *editor);
static void pika_template_editor_simulation_intent_changed
(GtkWidget *widget,
PikaTemplateEditor *editor);
static void pika_template_editor_simulation_bpc_toggled
(GtkWidget *widget,
PikaTemplateEditor *editor);
static void pika_template_editor_aspect_callback (GtkWidget *widget,
PikaTemplateEditor *editor);
static void pika_template_editor_template_notify (PikaTemplate *template,
GParamSpec *param_spec,
PikaTemplateEditor *editor);
G_DEFINE_TYPE_WITH_PRIVATE (PikaTemplateEditor, pika_template_editor,
GTK_TYPE_BOX)
#define parent_class pika_template_editor_parent_class
static void
pika_template_editor_class_init (PikaTemplateEditorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = pika_template_editor_constructed;
object_class->finalize = pika_template_editor_finalize;
object_class->set_property = pika_template_editor_set_property;
object_class->get_property = pika_template_editor_get_property;
g_object_class_install_property (object_class, PROP_PIKA,
g_param_spec_object ("pika", NULL, NULL,
PIKA_TYPE_PIKA,
PIKA_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, PROP_TEMPLATE,
g_param_spec_object ("template", NULL, NULL,
PIKA_TYPE_TEMPLATE,
PIKA_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
}
static void
pika_template_editor_init (PikaTemplateEditor *editor)
{
gtk_orientable_set_orientation (GTK_ORIENTABLE (editor),
GTK_ORIENTATION_VERTICAL);
gtk_box_set_spacing (GTK_BOX (editor), 12);
}
static void
pika_template_editor_constructed (GObject *object)
{
PikaTemplateEditor *editor = PIKA_TEMPLATE_EDITOR (object);
PikaTemplateEditorPrivate *private = GET_PRIVATE (object);
PikaTemplate *template;
GtkWidget *aspect_box;
GtkWidget *frame;
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *grid;
GtkWidget *label;
GtkAdjustment *adjustment;
GtkWidget *width;
GtkWidget *height;
GtkWidget *xres;
GtkWidget *yres;
GtkWidget *combo;
GtkWidget *scrolled_window;
GtkWidget *text_view;
GtkTextBuffer *text_buffer;
GtkListStore *store;
gchar *text;
gint row;
G_OBJECT_CLASS (parent_class)->constructed (object);
pika_assert (private->pika != NULL);
pika_assert (private->template != NULL);
template = private->template;
/* Image size frame */
frame = pika_frame_new (_("Image Size"));
gtk_box_pack_start (GTK_BOX (editor), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
gtk_container_add (GTK_CONTAINER (frame), grid);
gtk_widget_show (grid);
adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 0);
width = pika_spin_button_new (adjustment, 1.0, 2);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (width), TRUE);
gtk_entry_set_width_chars (GTK_ENTRY (width), SB_WIDTH);
adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 0);
height = pika_spin_button_new (adjustment, 1.0, 2);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (height), TRUE);
gtk_entry_set_width_chars (GTK_ENTRY (height), SB_WIDTH);
/* the image size labels */
label = gtk_label_new_with_mnemonic (_("_Width:"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), width);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_widget_show (label);
label = gtk_label_new_with_mnemonic (_("H_eight:"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), height);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_widget_show (label);
/* create the sizeentry which keeps it all together */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_grid_attach (GTK_GRID (grid), hbox, 1, 0, 1, 2);
gtk_widget_show (hbox);
private->size_se = pika_size_entry_new (0,
pika_template_get_unit (template),
_("%p"),
TRUE, FALSE, FALSE, SB_WIDTH,
PIKA_SIZE_ENTRY_UPDATE_SIZE);
gtk_box_pack_start (GTK_BOX (hbox), private->size_se, FALSE, FALSE, 0);
gtk_widget_show (private->size_se);
pika_size_entry_add_field (PIKA_SIZE_ENTRY (private->size_se),
GTK_SPIN_BUTTON (height), NULL);
gtk_grid_attach (GTK_GRID (private->size_se), height, 0, 1, 1, 1);
gtk_widget_show (height);
pika_size_entry_add_field (PIKA_SIZE_ENTRY (private->size_se),
GTK_SPIN_BUTTON (width), NULL);
gtk_grid_attach (GTK_GRID (private->size_se), width, 0, 0, 1, 1);
gtk_widget_show (width);
pika_prop_coordinates_connect (G_OBJECT (template),
"width", "height", "unit",
private->size_se, NULL,
pika_template_get_resolution_x (template),
pika_template_get_resolution_y (template));
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_grid_attach (GTK_GRID (grid), hbox, 1, 2, 2, 1);
gtk_widget_show (hbox);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
gtk_widget_show (vbox);
aspect_box = pika_enum_icon_box_new (PIKA_TYPE_ASPECT_TYPE,
"pika", GTK_ICON_SIZE_MENU,
G_CALLBACK (pika_template_editor_aspect_callback),
editor, NULL,
&private->aspect_button);
gtk_widget_hide (private->aspect_button); /* hide "square" */
gtk_box_pack_start (GTK_BOX (vbox), aspect_box, FALSE, FALSE, 0);
gtk_widget_show (aspect_box);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
private->pixel_label = gtk_label_new (NULL);
pika_label_set_attributes (GTK_LABEL (private->pixel_label),
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
-1);
gtk_label_set_xalign (GTK_LABEL (private->pixel_label), 0.0);
gtk_box_pack_start (GTK_BOX (vbox), private->pixel_label, FALSE, FALSE, 0);
gtk_widget_show (private->pixel_label);
private->more_label = gtk_label_new (NULL);
pika_label_set_attributes (GTK_LABEL (private->more_label),
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
-1);
gtk_label_set_xalign (GTK_LABEL (private->more_label), 0.0);
gtk_box_pack_start (GTK_BOX (vbox), private->more_label, FALSE, FALSE, 0);
gtk_widget_show (private->more_label);
#ifdef ENABLE_MEMSIZE_LABEL
private->memsize_label = gtk_label_new (NULL);
pika_label_set_attributes (GTK_LABEL (private->memsize_label),
PANGO_ATTR_SCALE, PANGO_SCALE_SMALL,
PANGO_ATTR_WEIGHT, PANGO_WEIGHT_BOLD,
-1);
gtk_label_set_xalign (GTK_LABEL (private->memsize_label), 0.0);
gtk_box_pack_start (GTK_BOX (vbox), private->memsize_label, FALSE, FALSE, 0);
gtk_widget_show (private->memsize_label);
#endif
text = g_strdup_printf ("<b>%s</b>", _("_Advanced Options"));
private->expander = g_object_new (GTK_TYPE_EXPANDER,
"label", text,
"use-markup", TRUE,
"use-underline", TRUE,
NULL);
g_free (text);
gtk_box_pack_start (GTK_BOX (editor), private->expander, TRUE, TRUE, 0);
gtk_widget_show (private->expander);
frame = pika_frame_new ("<expander>");
gtk_container_add (GTK_CONTAINER (private->expander), frame);
gtk_widget_show (frame);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_size_request (scrolled_window, -1, 300);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_OUT);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_NEVER,
GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (frame), scrolled_window);
gtk_widget_show (scrolled_window);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
gtk_container_set_border_width (GTK_CONTAINER (grid), 16);
gtk_container_add (GTK_CONTAINER (scrolled_window), grid);
gtk_widget_show (grid);
adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 0);
xres = pika_spin_button_new (adjustment, 1.0, 2);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (xres), TRUE);
gtk_entry_set_width_chars (GTK_ENTRY (xres), SB_WIDTH);
adjustment = gtk_adjustment_new (1, 1, 1, 1, 10, 0);
yres = pika_spin_button_new (adjustment, 1.0, 2);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (yres), TRUE);
gtk_entry_set_width_chars (GTK_ENTRY (yres), SB_WIDTH);
/* the resolution labels */
label = gtk_label_new_with_mnemonic (_("_X resolution:"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), xres);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_widget_show (label);
label = gtk_label_new_with_mnemonic (_("_Y resolution:"));
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), yres);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_widget_show (label);
/* the resolution sizeentry */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_grid_attach (GTK_GRID (grid), hbox, 1, 0, 1, 2);
gtk_widget_show (hbox);
private->resolution_se =
pika_size_entry_new (0,
pika_template_get_resolution_unit (template),
_("pixels/%s"),
FALSE, FALSE, FALSE, SB_WIDTH,
PIKA_SIZE_ENTRY_UPDATE_RESOLUTION);
gtk_box_pack_start (GTK_BOX (hbox), private->resolution_se, FALSE, FALSE, 0);
gtk_widget_show (private->resolution_se);
pika_size_entry_add_field (PIKA_SIZE_ENTRY (private->resolution_se),
GTK_SPIN_BUTTON (yres), NULL);
gtk_grid_attach (GTK_GRID (private->resolution_se), yres, 0, 1, 1, 1);
gtk_widget_show (yres);
pika_size_entry_add_field (PIKA_SIZE_ENTRY (private->resolution_se),
GTK_SPIN_BUTTON (xres), NULL);
gtk_grid_attach (GTK_GRID (private->resolution_se), xres, 0, 0, 1, 1);
gtk_widget_show (xres);
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 0,
pika_template_get_resolution_x (template),
FALSE);
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 1,
pika_template_get_resolution_y (template),
FALSE);
/* the resolution chainbutton */
private->chain_button = pika_chain_button_new (PIKA_CHAIN_RIGHT);
gtk_grid_attach (GTK_GRID (private->resolution_se), private->chain_button, 1, 0, 1, 2);
gtk_widget_show (private->chain_button);
pika_prop_coordinates_connect (G_OBJECT (template),
"xresolution", "yresolution",
"resolution-unit",
private->resolution_se, private->chain_button,
1.0, 1.0);
row = 2;
combo = pika_prop_enum_combo_box_new (G_OBJECT (template),
"image-type",
PIKA_RGB, PIKA_GRAY);
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("Color _space:"), 0.0, 0.5,
combo, 1);
/* construct the precision combo manually, instead of using
* pika_prop_enum_combo_box_new(), so that we only reset the gamma combo when
* the precision is changed through the ui. see issue #3025.
*/
store = pika_enum_store_new_with_range (PIKA_TYPE_COMPONENT_TYPE,
PIKA_COMPONENT_TYPE_U8,
PIKA_COMPONENT_TYPE_FLOAT);
private->precision_combo = g_object_new (PIKA_TYPE_ENUM_COMBO_BOX,
"model", store,
NULL);
g_object_unref (store);
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Precision:"), 0.0, 0.5,
private->precision_combo, 1);
pika_int_combo_box_set_active (PIKA_INT_COMBO_BOX (private->precision_combo),
pika_babl_component_type (
pika_template_get_precision (template)));
g_signal_connect (private->precision_combo, "changed",
G_CALLBACK (pika_template_editor_precision_changed),
editor);
combo = pika_prop_enum_combo_box_new (G_OBJECT (template), "trc",
PIKA_TRC_LINEAR,
PIKA_TRC_NON_LINEAR);
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Gamma:"), 0.0, 0.5,
combo, 1);
private->profile_combo =
pika_prop_profile_combo_box_new (G_OBJECT (template),
"color-profile",
NULL,
_("Choose A Color Profile"),
G_OBJECT (private->pika->config),
"color-profile-path");
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("Co_lor profile:"), 0.0, 0.5,
private->profile_combo, 1);
private->simulation_profile_combo =
pika_prop_profile_combo_box_new (G_OBJECT (template),
"simulation-profile",
NULL,
_("Choose A Soft-Proofing Color Profile"),
G_OBJECT (private->pika->config),
"color-profile-path");
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Soft-proofing color profile:"), 0.0, 0.5,
private->simulation_profile_combo, 1);
private->simulation_intent_combo =
pika_prop_enum_combo_box_new (G_OBJECT (template),
"simulation-intent",
0, 0);
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Soft-proofing rendering intent:"), 0.0, 0.5,
private->simulation_intent_combo, 1);
g_signal_connect (private->simulation_intent_combo, "changed",
G_CALLBACK (pika_template_editor_simulation_intent_changed),
editor);
private->simulation_bpc_toggle =
pika_prop_check_button_new (G_OBJECT (template), "simulation-bpc",
_("_Use Black Point Compensation"));
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
NULL, 0.0, 0.5,
private->simulation_bpc_toggle, 1);
g_signal_connect (private->simulation_bpc_toggle, "toggled",
G_CALLBACK (pika_template_editor_simulation_bpc_toggled),
editor);
combo = pika_prop_enum_combo_box_new (G_OBJECT (template),
"fill-type",
0, 0);
pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("_Fill with:"), 0.0, 0.5,
combo, 1);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
label = pika_grid_attach_aligned (GTK_GRID (grid), 0, row++,
_("Comme_nt:"), 0.0, 0.0,
scrolled_window, 1);
text_buffer = pika_prop_text_buffer_new (G_OBJECT (template),
"comment", MAX_COMMENT_LENGTH);
text_view = gtk_text_view_new_with_buffer (text_buffer);
g_object_unref (text_buffer);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), GTK_WRAP_WORD);
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
gtk_widget_show (text_view);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), text_view);
g_signal_connect_object (template, "notify",
G_CALLBACK (pika_template_editor_template_notify),
editor, 0);
/* call the notify callback once to get the labels set initially */
pika_template_editor_template_notify (template, NULL, editor);
}
static void
pika_template_editor_finalize (GObject *object)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (object);
g_clear_object (&private->template);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
pika_template_editor_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_PIKA:
private->pika = g_value_get_object (value); /* don't ref */
break;
case PROP_TEMPLATE:
private->template = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_template_editor_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (object);
switch (property_id)
{
case PROP_PIKA:
g_value_set_object (value, private->pika);
break;
case PROP_TEMPLATE:
g_value_set_object (value, private->template);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
GtkWidget *
pika_template_editor_new (PikaTemplate *template,
Pika *pika,
gboolean edit_template)
{
PikaTemplateEditor *editor;
PikaTemplateEditorPrivate *private;
g_return_val_if_fail (PIKA_IS_TEMPLATE (template), NULL);
g_return_val_if_fail (PIKA_IS_PIKA (pika), NULL);
editor = g_object_new (PIKA_TYPE_TEMPLATE_EDITOR,
"pika", pika,
"template", template,
NULL);
private = GET_PRIVATE (editor);
if (edit_template)
{
GtkWidget *grid;
GtkWidget *entry;
GtkWidget *icon_picker;
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
gtk_box_pack_start (GTK_BOX (editor), grid, FALSE, FALSE, 0);
gtk_box_reorder_child (GTK_BOX (editor), grid, 0);
gtk_widget_show (grid);
entry = pika_prop_entry_new (G_OBJECT (private->template), "name", 128);
pika_grid_attach_aligned (GTK_GRID (grid), 0, 0,
_("_Name:"), 1.0, 0.5,
entry, 1);
icon_picker = pika_prop_icon_picker_new (PIKA_VIEWABLE (private->template),
pika);
pika_grid_attach_aligned (GTK_GRID (grid), 0, 1,
_("_Icon:"), 1.0, 0.5,
icon_picker, 1);
}
return GTK_WIDGET (editor);
}
PikaTemplate *
pika_template_editor_get_template (PikaTemplateEditor *editor)
{
g_return_val_if_fail (PIKA_IS_TEMPLATE_EDITOR (editor), NULL);
return GET_PRIVATE (editor)->template;
}
void
pika_template_editor_show_advanced (PikaTemplateEditor *editor,
gboolean expanded)
{
PikaTemplateEditorPrivate *private;
g_return_if_fail (PIKA_IS_TEMPLATE_EDITOR (editor));
private = GET_PRIVATE (editor);
gtk_expander_set_expanded (GTK_EXPANDER (private->expander), expanded);
}
GtkWidget *
pika_template_editor_get_size_se (PikaTemplateEditor *editor)
{
g_return_val_if_fail (PIKA_IS_TEMPLATE_EDITOR (editor), NULL);
return GET_PRIVATE (editor)->size_se;
}
GtkWidget *
pika_template_editor_get_resolution_se (PikaTemplateEditor *editor)
{
g_return_val_if_fail (PIKA_IS_TEMPLATE_EDITOR (editor), NULL);
return GET_PRIVATE (editor)->resolution_se;
}
GtkWidget *
pika_template_editor_get_resolution_chain (PikaTemplateEditor *editor)
{
g_return_val_if_fail (PIKA_IS_TEMPLATE_EDITOR (editor), NULL);
return GET_PRIVATE (editor)->chain_button;
}
/* private functions */
static void
pika_template_editor_precision_changed (GtkWidget *widget,
PikaTemplateEditor *editor)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
PikaComponentType component_type;
PikaTRCType trc;
pika_int_combo_box_get_active (PIKA_INT_COMBO_BOX (widget),
(gint *) &component_type);
g_object_get (private->template,
"trc", &trc,
NULL);
trc = pika_suggest_trc_for_component_type (component_type, trc);
g_object_set (private->template,
"component-type", component_type,
"trc", trc,
NULL);
}
static void
pika_template_editor_simulation_intent_changed (GtkWidget *widget,
PikaTemplateEditor *editor)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
PikaColorRenderingIntent intent;
pika_int_combo_box_get_active (PIKA_INT_COMBO_BOX (widget),
(gint *) &intent);
g_object_set (private->template,
"simulation-intent", intent,
NULL);
}
static void
pika_template_editor_simulation_bpc_toggled (GtkWidget *widget,
PikaTemplateEditor *editor)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
gboolean bpc = FALSE;
bpc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
g_object_set (private->template,
"simulation-bpc", bpc,
NULL);
}
static void
pika_template_editor_set_pixels (PikaTemplateEditor *editor,
PikaTemplate *template)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
gchar *text;
text = g_strdup_printf (ngettext ("%d × %d pixel",
"%d × %d pixels",
pika_template_get_height (template)),
pika_template_get_width (template),
pika_template_get_height (template));
gtk_label_set_text (GTK_LABEL (private->pixel_label), text);
g_free (text);
}
static void
pika_template_editor_aspect_callback (GtkWidget *widget,
PikaTemplateEditor *editor)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
if (! private->block_aspect &&
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
{
PikaTemplate *template = private->template;
gint width = pika_template_get_width (template);
gint height = pika_template_get_height (template);
gdouble xresolution = pika_template_get_resolution_x (template);
gdouble yresolution = pika_template_get_resolution_y (template);
if (width == height)
{
private->block_aspect = TRUE;
pika_int_radio_group_set_active (GTK_RADIO_BUTTON (private->aspect_button),
PIKA_ASPECT_SQUARE);
private->block_aspect = FALSE;
return;
}
g_signal_handlers_block_by_func (template,
pika_template_editor_template_notify,
editor);
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 0,
yresolution, FALSE);
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 1,
xresolution, FALSE);
g_object_set (template,
"width", height,
"height", width,
"xresolution", yresolution,
"yresolution", xresolution,
NULL);
g_signal_handlers_unblock_by_func (template,
pika_template_editor_template_notify,
editor);
pika_template_editor_set_pixels (editor, template);
}
}
static void
pika_template_editor_template_notify (PikaTemplate *template,
GParamSpec *param_spec,
PikaTemplateEditor *editor)
{
PikaTemplateEditorPrivate *private = GET_PRIVATE (editor);
PikaAspectType aspect;
const gchar *desc;
gchar *text;
gint width;
gint height;
gint xres;
gint yres;
if (param_spec)
{
if (! strcmp (param_spec->name, "xresolution"))
{
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 0,
pika_template_get_resolution_x (template),
FALSE);
}
else if (! strcmp (param_spec->name, "yresolution"))
{
pika_size_entry_set_resolution (PIKA_SIZE_ENTRY (private->size_se), 1,
pika_template_get_resolution_y (template),
FALSE);
}
else if (! strcmp (param_spec->name, "component-type"))
{
g_signal_handlers_block_by_func (private->precision_combo,
pika_template_editor_precision_changed,
editor);
pika_int_combo_box_set_active (
PIKA_INT_COMBO_BOX (private->precision_combo),
pika_babl_component_type (pika_template_get_precision (template)));
g_signal_handlers_unblock_by_func (private->precision_combo,
pika_template_editor_precision_changed,
editor);
}
}
#ifdef ENABLE_MEMSIZE_LABEL
text = g_format_size (pika_template_get_initial_size (template));
gtk_label_set_text (GTK_LABEL (private->memsize_label), text);
g_free (text);
#endif
pika_template_editor_set_pixels (editor, template);
width = pika_template_get_width (template);
height = pika_template_get_height (template);
if (width > height)
aspect = PIKA_ASPECT_LANDSCAPE;
else if (height > width)
aspect = PIKA_ASPECT_PORTRAIT;
else
aspect = PIKA_ASPECT_SQUARE;
private->block_aspect = TRUE;
pika_int_radio_group_set_active (GTK_RADIO_BUTTON (private->aspect_button),
aspect);
private->block_aspect = FALSE;
pika_enum_get_value (PIKA_TYPE_IMAGE_BASE_TYPE,
pika_template_get_base_type (template),
NULL, NULL, &desc, NULL);
xres = ROUND (pika_template_get_resolution_x (template));
yres = ROUND (pika_template_get_resolution_y (template));
if (xres != yres)
text = g_strdup_printf (_("%d × %d ppi, %s"), xres, yres, desc);
else
text = g_strdup_printf (_("%d ppi, %s"), yres, desc);
gtk_label_set_text (GTK_LABEL (private->more_label), text);
g_free (text);
if (! param_spec ||
! strcmp (param_spec->name, "image-type") ||
! strcmp (param_spec->name, "precision"))
{
PikaColorProfile *profile;
GtkListStore *profile_store;
GFile *file;
gchar *path;
file = pika_directory_file ("profilerc", NULL);
profile_store = pika_color_profile_store_new (file);
g_object_unref (file);
pika_color_profile_store_add_defaults (PIKA_COLOR_PROFILE_STORE (profile_store),
private->pika->config->color_management,
pika_template_get_base_type (template),
pika_template_get_precision (template),
NULL);
gtk_combo_box_set_model (GTK_COMBO_BOX (private->profile_combo),
GTK_TREE_MODEL (profile_store));
/* Simulation Profile should not be set by default */
file = pika_directory_file ("profilerc", NULL);
profile_store = pika_color_profile_store_new (file);
g_object_unref (file);
pika_color_profile_store_add_file (PIKA_COLOR_PROFILE_STORE (profile_store),
NULL, NULL);
/* Add Preferred CMYK profile if it exists */
profile =
pika_color_config_get_cmyk_color_profile (PIKA_COLOR_CONFIG (private->pika->config->color_management),
NULL);
if (profile)
{
g_object_get (G_OBJECT (private->pika->config->color_management),
"cmyk-profile", &path, NULL);
file = pika_file_new_for_config_path (path, NULL);
g_free (path);
text = g_strdup_printf (_("Preferred CMYK (%s)"),
pika_color_profile_get_label (profile));
g_object_unref (profile);
pika_color_profile_store_add_file (PIKA_COLOR_PROFILE_STORE (profile_store),
file, text);
g_object_unref (file);
g_free (text);
}
gtk_combo_box_set_model (GTK_COMBO_BOX (private->simulation_profile_combo),
GTK_TREE_MODEL (profile_store));
g_object_unref (profile_store);
g_object_get (template,
"color-profile", &file,
NULL);
pika_color_profile_combo_box_set_active_file (PIKA_COLOR_PROFILE_COMBO_BOX (private->profile_combo),
file, NULL);
if (file)
g_object_unref (file);
g_object_get (template,
"simulation-profile", &file,
NULL);
pika_color_profile_combo_box_set_active_file (PIKA_COLOR_PROFILE_COMBO_BOX (private->simulation_profile_combo),
file, NULL);
if (file)
g_object_unref (file);
}
}