Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: New UI for tagging module #17488

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions data/darktableconfig.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -1881,13 +1881,6 @@
<shortdescription>ask before deleting a tag</shortdescription>
<longdescription/>
</dtconfig>
<dtconfig>
<name>plugins/lighttable/tagging/dttags</name>
<type>bool</type>
<default>false</default>
<shortdescription>whether to show darktable internal tags</shortdescription>
<longdescription/>
</dtconfig>
<dtconfig>
<name>plugins/lighttable/tagging/nosuggestion</name>
<type>bool</type>
Expand Down Expand Up @@ -1930,6 +1923,13 @@
<shortdescription>height of the tagging dictionary view</shortdescription>
<longdescription>maximum height the tagging dictionary view will grow to before scrolling</longdescription>
</dtconfig>
<dtconfig dialog="tagging">
<name>plugins/lighttable/tagging/dttags</name>
<type>bool</type>
<default>false</default>
<shortdescription>show darktable tags</shortdescription>
<longdescription>whether to show darktable internal tags in the list of attached tags</longdescription>
</dtconfig>
<dtconfig dialog="tagging">
<name>plugins/lighttable/tagging/confidence</name>
<type min="0" max="100">int</type>
Expand Down
52 changes: 52 additions & 0 deletions data/themes/darktable.css
Original file line number Diff line number Diff line change
Expand Up @@ -2320,6 +2320,58 @@ Details :
margin: 0.07em 0.28em;
}

/*---------------------------------------------------------
- Tagging module -
---------------------------------------------------------*/
flowbox.tagging
{
padding: 0.21em;
}

.dt_flowbox_sw
{
background-color: @field_bg;
}

#tag-label
{
border: 1px solid @plugin_label_color;
border-radius: 1em;
padding: 0 0.4em;
margin: 0.15em;
}

#tag-label:not(.darktable):selected,
#tag-label:not(.darktable).hover
{
background-color: @selected_bg_color;
}

#tag-label.some
{
border-style: dashed;
}

#tag-label.darktable
{
border-color: @grey_80;
}

#tag-label.darktable label
{
color: @grey_80;
}

#tag-label.category label
{
font-style: italic;
}

#tag-label.private label
{
}


/* ??? TO BE REMOVED ON DT 5.0 : script_manager power button */
button#pb_off
{
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ FILE(GLOB SOURCE_FILES
"develop/masks/path.c"
"develop/pixelpipe.c"
"develop/tiling.c"
"dtgobj/tag.c"
"dtgtk/button.c"
"dtgtk/culling.c"
"dtgtk/drawingarea.c"
Expand All @@ -130,6 +131,7 @@ FILE(GLOB SOURCE_FILES
"dtgtk/resetlabel.c"
"dtgtk/sidepanel.c"
"dtgtk/stylemenu.c"
"dtgtk/taglabel.c"
"dtgtk/thumbnail.c"
"dtgtk/thumbnail_btn.c"
"dtgtk/thumbtable.c"
Expand Down
6 changes: 6 additions & 0 deletions src/common/tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ gchar *dt_tag_get_name(const guint tagid)
return name;
}

gboolean dt_tag_is_user_tag(const dt_tag_t *tag)
{
return !g_str_has_prefix(tag->tag, "darktable|")
|| g_str_has_prefix(tag->tag, "darktable|style|");
}

void dt_tag_rename(const guint tagid, const gchar *new_tagname)
{
sqlite3_stmt *stmt;
Expand Down
4 changes: 4 additions & 0 deletions src/common/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct dt_tag_t
gint flags;
} dt_tag_t;


typedef enum dt_tag_flags_t
{
DT_TF_NONE = 0,
Expand Down Expand Up @@ -82,6 +83,9 @@ ssize_t dt_tag_export(const char *filename);
/** get the name of specified id */
gchar *dt_tag_get_name(const guint tagid);

/** checks if tag is a user tag */
gboolean dt_tag_is_user_tag(const dt_tag_t *tag);

/** removes a tag from db and from assigned images. \param final TRUE
* actually performs the remove \return the amount of images
* affected. */
Expand Down
69 changes: 69 additions & 0 deletions src/dtgobj/tag.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
This file is part of darktable,
Copyright (C) 2024 darktable developers.

darktable 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.

darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
*/

#include "tag.h"

G_DEFINE_TYPE (DtTagObj, dt_tag_obj, G_TYPE_OBJECT)

static void _dt_tag_obj_dispose(GObject *gobject)
{
G_OBJECT_CLASS(dt_tag_obj_parent_class)->dispose(gobject);
}

static void _dt_tag_obj_finalize(GObject *gobject)
{
DtTagObj *self = DT_TAG_OBJ(gobject);

g_free(self->tag.tag);
self->tag.tag = NULL;
g_free(self->tag.leave);
self->tag.leave = NULL;
g_free(self->tag.synonym);
self->tag.synonym = NULL;

G_OBJECT_CLASS(dt_tag_obj_parent_class)->finalize (gobject);
}

static void dt_tag_obj_class_init(DtTagObjClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);

object_class->dispose = _dt_tag_obj_dispose;
object_class->finalize = _dt_tag_obj_finalize;
}

static void dt_tag_obj_init(DtTagObj *self)
{
}

GObject *dt_tag_obj_new(const dt_tag_t *tag)
{
DtTagObj *self = g_object_new(dt_tag_obj_get_type(), NULL);
memcpy(&self->tag, tag, sizeof(dt_tag_t));
self->tag.tag = g_strdup(tag->tag);
self->tag.leave = g_strdup(tag->leave);
self->tag.synonym = g_strdup(tag->synonym);
return (GObject *)self;
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

46 changes: 46 additions & 0 deletions src/dtgobj/tag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
This file is part of darktable,
Copyright (C) 2024 darktable developers.

darktable 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.

darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include <glib.h>

#include "common/tags.h"

G_BEGIN_DECLS

// GObject of dt_tag_t
#define DT_TYPE_TAG_OBJ dt_tag_obj_get_type()
G_DECLARE_FINAL_TYPE(DtTagObj, dt_tag_obj, DT, TAG_OBJ, GObject)

struct _DtTagObj
{
GObject parent_instance;
dt_tag_t tag;
};

GObject *dt_tag_obj_new(const dt_tag_t *tag);

G_END_DECLS

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

120 changes: 120 additions & 0 deletions src/dtgtk/taglabel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
This file is part of darktable,
Copyright (C) 2024 darktable developers.

darktable 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.

darktable 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 darktable. If not, see <http://www.gnu.org/licenses/>.
*/

#include "taglabel.h"
#include "gui/gtk.h"
#include <string.h>

G_DEFINE_TYPE(GtkDarktableTagLabel, dtgtk_tag_label, GTK_TYPE_FLOW_BOX_CHILD);

static void dtgtk_tag_label_class_init(GtkDarktableTagLabelClass *klass)
{
}

static void dtgtk_tag_label_init(GtkDarktableTagLabel *tag_label)
{
}

static gboolean _tag_label_enter_leave_notify_callback(GtkWidget *widget,
GdkEventCrossing *event,
gpointer user_data)
{
g_return_val_if_fail(widget != NULL, FALSE);

GtkWidget *tag_label = gtk_widget_get_parent(widget);
g_return_val_if_fail(tag_label != NULL, FALSE);

if(event->type == GDK_ENTER_NOTIFY)
dt_gui_add_class(tag_label, "hover");
else
dt_gui_remove_class(tag_label, "hover");
return FALSE;
}

static gboolean _tag_label_button_press_notify_callback(GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
g_return_val_if_fail(widget != NULL, FALSE);

if(event->type == GDK_BUTTON_PRESS && event->button == 3)
{
GtkFlowBoxChild *tag_label = GTK_FLOW_BOX_CHILD(gtk_widget_get_parent(widget));
g_return_val_if_fail(tag_label != NULL, FALSE);

GtkFlowBox *flow_box = GTK_FLOW_BOX(gtk_widget_get_parent(GTK_WIDGET(tag_label)));
g_return_val_if_fail(flow_box != NULL, FALSE);

gtk_flow_box_select_child(flow_box, tag_label);
}
return FALSE;
}

// Public functions
GtkWidget *dtgtk_tag_label_new(const dt_tag_t *tag)
{
GtkDarktableTagLabel *tag_label;
tag_label = g_object_new(dtgtk_tag_label_get_type(), NULL);

tag_label->tagid = tag->id;

GtkWidget *event_box = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(tag_label), event_box);
gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box), FALSE);
gtk_widget_set_events(event_box,
GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK
| GDK_BUTTON_PRESS_MASK);
g_signal_connect(G_OBJECT(event_box), "enter-notify-event",
G_CALLBACK(_tag_label_enter_leave_notify_callback), NULL);
g_signal_connect(G_OBJECT(event_box), "leave-notify-event",
G_CALLBACK(_tag_label_enter_leave_notify_callback), NULL);
g_signal_connect(G_OBJECT(event_box), "button-press-event",
G_CALLBACK(_tag_label_button_press_notify_callback), NULL);

GtkWidget *label = gtk_label_new(tag->leave);
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_START);
gtk_label_set_max_width_chars(GTK_LABEL(label), 10);
gtk_container_add(GTK_CONTAINER(event_box), label);

gtk_widget_show_all(GTK_WIDGET(tag_label));

gtk_widget_set_name(GTK_WIDGET(tag_label), "tag-label");

GtkStyleContext *context = gtk_widget_get_style_context(GTK_WIDGET(tag_label));
if(!dt_tag_is_user_tag(tag))
gtk_style_context_add_class(context, "darktable");

if(tag->flags & DT_TF_CATEGORY)
gtk_style_context_add_class(context, "category");

if(tag->flags & DT_TF_PRIVATE)
gtk_style_context_add_class(context, "private");

if(tag->select == DT_TS_SOME_IMAGES)
gtk_style_context_add_class(context, "some");

gtk_widget_set_tooltip_text(GTK_WIDGET(tag_label), tag->tag);
return (GtkWidget *)tag_label;
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

Loading
Loading