PIKApp/app/tools/pikamoveoptions.c

233 lines
7.2 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 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 <gegl.h>
#include <gtk/gtk.h>
#include "libpikabase/pikabase.h"
#include "libpikaconfig/pikaconfig.h"
#include "libpikawidgets/pikawidgets.h"
#include "tools-types.h"
#include "widgets/pikawidgets-utils.h"
#include "pikamoveoptions.h"
#include "pikatooloptions-gui.h"
#include "pika-intl.h"
enum
{
PROP_0,
PROP_MOVE_TYPE,
PROP_MOVE_CURRENT
};
static void pika_move_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void pika_move_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
G_DEFINE_TYPE (PikaMoveOptions, pika_move_options, PIKA_TYPE_TOOL_OPTIONS)
static void
pika_move_options_class_init (PikaMoveOptionsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->set_property = pika_move_options_set_property;
object_class->get_property = pika_move_options_get_property;
PIKA_CONFIG_PROP_ENUM (object_class, PROP_MOVE_TYPE,
"move-type",
NULL, NULL,
PIKA_TYPE_TRANSFORM_TYPE,
PIKA_TRANSFORM_TYPE_LAYER,
PIKA_PARAM_STATIC_STRINGS);
PIKA_CONFIG_PROP_BOOLEAN (object_class, PROP_MOVE_CURRENT,
"move-current",
NULL, NULL,
FALSE,
PIKA_PARAM_STATIC_STRINGS);
}
static void
pika_move_options_init (PikaMoveOptions *options)
{
}
static void
pika_move_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
PikaMoveOptions *options = PIKA_MOVE_OPTIONS (object);
switch (property_id)
{
case PROP_MOVE_TYPE:
options->move_type = g_value_get_enum (value);
break;
case PROP_MOVE_CURRENT:
options->move_current = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_move_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
PikaMoveOptions *options = PIKA_MOVE_OPTIONS (object);
switch (property_id)
{
case PROP_MOVE_TYPE:
g_value_set_enum (value, options->move_type);
break;
case PROP_MOVE_CURRENT:
g_value_set_boolean (value, options->move_current);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
pika_move_options_notify_type (PikaMoveOptions *move_options,
GParamSpec *pspec,
GtkWidget *frame)
{
if (move_options->move_type == PIKA_TRANSFORM_TYPE_SELECTION)
{
gtk_widget_hide (gtk_bin_get_child (GTK_BIN (frame)));
gtk_frame_set_label (GTK_FRAME (frame), _("Move selection"));
}
else
{
const gchar *false_label = NULL;
const gchar *true_label = NULL;
GtkWidget *button;
GSList *group;
gchar *title;
title = g_strdup_printf (_("Tool Toggle (%s)"),
pika_get_mod_string (pika_get_extend_selection_mask ()));
gtk_frame_set_label (GTK_FRAME (frame), title);
g_free (title);
switch (move_options->move_type)
{
case PIKA_TRANSFORM_TYPE_LAYER:
false_label = _("Pick a layer or guide");
true_label = _("Move the selected layers");
break;
case PIKA_TRANSFORM_TYPE_PATH:
false_label = _("Pick a path");
true_label = _("Move the active path");
break;
default: /* PIKA_TRANSFORM_TYPE_SELECTION */
g_return_if_reached ();
}
button = g_object_get_data (G_OBJECT (frame), "radio-button");
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
gtk_button_set_label (GTK_BUTTON (group->data), true_label);
group = g_slist_next (group);
gtk_button_set_label (GTK_BUTTON (group->data), false_label);
gtk_widget_show (gtk_bin_get_child (GTK_BIN (frame)));
}
}
GtkWidget *
pika_move_options_gui (PikaToolOptions *tool_options)
{
GObject *config = G_OBJECT (tool_options);
PikaMoveOptions *options = PIKA_MOVE_OPTIONS (tool_options);
GtkWidget *vbox = pika_tool_options_gui (tool_options);
GtkWidget *hbox;
GtkWidget *box;
GtkWidget *label;
GtkWidget *frame;
gchar *title;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
options->type_box = hbox;
label = gtk_label_new (_("Move:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
box = pika_prop_enum_icon_box_new (config, "move-type", "pika",
PIKA_TRANSFORM_TYPE_LAYER,
PIKA_TRANSFORM_TYPE_PATH);
gtk_box_pack_start (GTK_BOX (hbox), box, FALSE, FALSE, 0);
gtk_widget_show (box);
/* tool toggle */
title =
g_strdup_printf (_("Tool Toggle (%s)"),
pika_get_mod_string (pika_get_extend_selection_mask ()));
frame = pika_prop_boolean_radio_frame_new (config, "move-current",
title, "true", "false");
pika_move_options_notify_type (PIKA_MOVE_OPTIONS (config), NULL, frame);
g_signal_connect_object (config, "notify::move-type",
G_CALLBACK (pika_move_options_notify_type),
frame, 0);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
g_free (title);
return vbox;
}