[gimp] app: in GimpItemTreeView, use color tag of parent for children with no tag



commit 0beef7d97d01543d3ae09af044b0b4173e42a756
Author: Ell <ell_se yahoo com>
Date:   Thu Dec 7 16:42:54 2017 -0500

    app: in GimpItemTreeView, use color tag of parent for children with no tag
    
    Add gimp_item_get_merged_color_tag(), which returns the color tag
    of the nearest ancestor (including the current item) that has a
    color tag other than NONE.  Use this function in GimpItemTreeView,
    instead of gimp_item_get_color_tag(), to set the cell color of
    items, so that item's with a NONE color tag inherit the color of
    their parent.  Add a boolean "inherited" parameter to
    gimp_get_color_tag_color(), which indicates if the color tag is the
    item's actual color tag, or an inherited color tag, and modify the
    returned color accordingly, so that inherited colors are less
    saturated/lighter than non-inherited ones.

 app/actions/items-actions.c       |    4 ++--
 app/core/gimpitem.c               |   18 ++++++++++++++++++
 app/core/gimpitem.h               |    1 +
 app/dialogs/item-options-dialog.c |    2 +-
 app/widgets/gimpitemtreeview.c    |   28 ++++++++++++++++++++--------
 app/widgets/gimpwidgets-utils.c   |   10 +++++++++-
 app/widgets/gimpwidgets-utils.h   |    3 ++-
 7 files changed, 53 insertions(+), 13 deletions(-)
---
diff --git a/app/actions/items-actions.c b/app/actions/items-actions.c
index a263bfb..0cdbf4a 100644
--- a/app/actions/items-actions.c
+++ b/app/actions/items-actions.c
@@ -60,7 +60,7 @@ items_actions_setup (GimpActionGroup *group,
           gimp_action_group_set_action_context (group, action,
                                                 gimp_get_user_context (group->gimp));
 
-          gimp_get_color_tag_color (value->value, &color);
+          gimp_get_color_tag_color (value->value, &color, FALSE);
           gimp_action_group_set_action_color (group, action, &color, FALSE);
         }
     }
@@ -95,7 +95,7 @@ items_actions_update (GimpActionGroup *group,
       can_lock_pos = gimp_item_can_lock_position (item);
 
       has_color_tag = gimp_get_color_tag_color (gimp_item_get_color_tag (item),
-                                                &tag_color);
+                                                &tag_color, FALSE);
     }
 
 #define SET_SENSITIVE(action,condition) \
diff --git a/app/core/gimpitem.c b/app/core/gimpitem.c
index bfabe50..7888cf3 100644
--- a/app/core/gimpitem.c
+++ b/app/core/gimpitem.c
@@ -2203,6 +2203,24 @@ gimp_item_get_color_tag (GimpItem *item)
   return GET_PRIVATE (item)->color_tag;
 }
 
+GimpColorTag
+gimp_item_get_merged_color_tag (GimpItem *item)
+{
+  g_return_val_if_fail (GIMP_IS_ITEM (item), GIMP_COLOR_TAG_NONE);
+
+  if (gimp_item_get_color_tag (item) == GIMP_COLOR_TAG_NONE)
+    {
+      GimpItem *parent;
+
+      parent = GIMP_ITEM (gimp_viewable_get_parent (GIMP_VIEWABLE (item)));
+
+      if (parent)
+        return gimp_item_get_merged_color_tag (parent);
+    }
+
+  return gimp_item_get_color_tag (item);
+}
+
 void
 gimp_item_set_lock_content (GimpItem *item,
                             gboolean  lock_content,
diff --git a/app/core/gimpitem.h b/app/core/gimpitem.h
index 53a43b4..ad2d2e5 100644
--- a/app/core/gimpitem.h
+++ b/app/core/gimpitem.h
@@ -339,6 +339,7 @@ void            gimp_item_set_color_tag      (GimpItem           *item,
                                               GimpColorTag        color_tag,
                                               gboolean            push_undo);
 GimpColorTag    gimp_item_get_color_tag      (GimpItem           *item);
+GimpColorTag  gimp_item_get_merged_color_tag (GimpItem           *item);
 
 void            gimp_item_set_lock_content   (GimpItem           *item,
                                               gboolean            lock_content,
diff --git a/app/dialogs/item-options-dialog.c b/app/dialogs/item-options-dialog.c
index 37ae93f..9b91779 100644
--- a/app/dialogs/item-options-dialog.c
+++ b/app/dialogs/item-options-dialog.c
@@ -228,7 +228,7 @@ item_options_dialog_new (GimpImage               *image,
           color_tag = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (radio),
                                                           "gimp-item-data"));
 
-          if (gimp_get_color_tag_color (color_tag, &color))
+          if (gimp_get_color_tag_color (color_tag, &color, FALSE))
             {
               GtkSettings *settings = gtk_widget_get_settings (dialog);
               gint         w, h;
diff --git a/app/widgets/gimpitemtreeview.c b/app/widgets/gimpitemtreeview.c
index 11320a1..a4a6b62 100644
--- a/app/widgets/gimpitemtreeview.c
+++ b/app/widgets/gimpitemtreeview.c
@@ -990,8 +990,10 @@ gimp_item_tree_view_insert_item (GimpContainerView *view,
 
   item_view->priv->inserting_item = FALSE;
 
-  has_color = gimp_get_color_tag_color (gimp_item_get_color_tag (item),
-                                        &color);
+  has_color = gimp_get_color_tag_color (gimp_item_get_merged_color_tag (item),
+                                        &color,
+                                        gimp_item_get_color_tag (item) ==
+                                        GIMP_COLOR_TAG_NONE);
   if (has_color)
     gimp_rgb_get_gdk_color (&color, &gdk_color);
 
@@ -1406,12 +1408,15 @@ gimp_item_tree_view_color_tag_changed (GimpItem         *item,
 
   if (iter)
     {
-      GimpRGB  color;
-      GdkColor gdk_color;
-      gboolean has_color;
-
-      has_color = gimp_get_color_tag_color (gimp_item_get_color_tag (item),
-                                            &color);
+      GimpContainer *children;
+      GimpRGB        color;
+      GdkColor       gdk_color;
+      gboolean       has_color;
+
+      has_color = gimp_get_color_tag_color (gimp_item_get_merged_color_tag (item),
+                                            &color,
+                                            gimp_item_get_color_tag (item) ==
+                                            GIMP_COLOR_TAG_NONE);
       if (has_color)
         gimp_rgb_get_gdk_color (&color, &gdk_color);
 
@@ -1419,6 +1424,13 @@ gimp_item_tree_view_color_tag_changed (GimpItem         *item,
                           view->priv->model_column_color_tag,
                           has_color ? &gdk_color : NULL,
                           -1);
+
+      children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
+
+      if (children)
+        gimp_container_foreach (children,
+                                (GFunc) gimp_item_tree_view_color_tag_changed,
+                                view);
     }
 }
 
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index b35fb69..ff3552a 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -1161,7 +1161,8 @@ gimp_get_message_icon_name (GimpMessageSeverity severity)
 
 gboolean
 gimp_get_color_tag_color (GimpColorTag  color_tag,
-                          GimpRGB      *color)
+                          GimpRGB      *color,
+                          gboolean      inherited)
 {
   static const struct
   {
@@ -1183,6 +1184,7 @@ gimp_get_color_tag_color (GimpColorTag  color_tag,
   };
 
   g_return_val_if_fail (color != NULL, FALSE);
+  g_return_val_if_fail (color_tag < G_N_ELEMENTS (colors), FALSE);
 
   if (color_tag > GIMP_COLOR_TAG_NONE)
     {
@@ -1192,6 +1194,12 @@ gimp_get_color_tag_color (GimpColorTag  color_tag,
                            colors[color_tag].b,
                            255);
 
+      if (inherited)
+        {
+          gimp_rgb_composite (color, &(GimpRGB) {1.0, 1.0, 1.0, 0.2},
+                              GIMP_RGB_COMPOSITE_NORMAL);
+        }
+
       return TRUE;
     }
 
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index b62be0a..bd7ca6f 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -87,7 +87,8 @@ void              gimp_widget_set_accel_help       (GtkWidget            *widget
 
 const gchar     * gimp_get_message_icon_name       (GimpMessageSeverity   severity);
 gboolean          gimp_get_color_tag_color         (GimpColorTag          color_tag,
-                                                    GimpRGB              *color);
+                                                    GimpRGB              *color,
+                                                    gboolean              inherited);
 
 void              gimp_pango_layout_set_scale      (PangoLayout          *layout,
                                                     double                scale);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]