Skip to content
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
36 changes: 33 additions & 3 deletions src/dtgtk/thumbnail.c
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,10 @@ static gboolean _event_rating_release(GtkWidget *widget,
rating = DT_VIEW_STAR_4;
else if(widget == thumb->w_stars[4])
rating = DT_VIEW_STAR_5;
else if(widget == thumb->w_unrate)
rating = DT_VIEW_DESERT;

if(rating != DT_VIEW_DESERT)
if(rating != DT_VIEW_DESERT || widget == thumb->w_unrate)
{
dt_ratings_apply_on_image(thumb->imgid, rating, TRUE, TRUE, TRUE);
dt_collection_update_query(darktable.collection,
Expand Down Expand Up @@ -1610,6 +1612,25 @@ GtkWidget *dt_thumbnail_create_widget(dt_thumbnail_t *thumb,
gtk_overlay_add_overlay(GTK_OVERLAY(overlays_parent), thumb->w_reject);

// the stars
// first for removing the rating
thumb->w_unrate = dtgtk_thumbnail_btn_new(dtgtk_cairo_paint_unratestar, 0, NULL);
gtk_widget_set_name(thumb->w_unrate, "thumb-unrate");
dt_action_define(&darktable.control->actions_thumb, NULL, "rating",
thumb->w_unrate, &dt_action_def_rating);
gtk_widget_set_valign(thumb->w_unrate, GTK_ALIGN_END);
gtk_widget_set_halign(thumb->w_unrate, GTK_ALIGN_START);
gtk_widget_show(thumb->w_unrate);
gtk_overlay_add_overlay(GTK_OVERLAY(overlays_parent), thumb->w_unrate);
g_signal_connect(G_OBJECT(thumb->w_unrate), "enter-notify-event",
G_CALLBACK(_event_star_enter), thumb);
g_signal_connect(G_OBJECT(thumb->w_unrate), "leave-notify-event",
G_CALLBACK(_event_star_leave), thumb);
g_signal_connect(G_OBJECT(thumb->w_unrate), "button-press-event",
G_CALLBACK(_event_rating_press), thumb);
g_signal_connect(G_OBJECT(thumb->w_unrate), "button-release-event",
G_CALLBACK(_event_rating_release),
thumb);

for(int i = 0; i < MAX_STARS; i++)
{
thumb->w_stars[i] = dtgtk_thumbnail_btn_new(dtgtk_cairo_paint_star, 0, NULL);
Expand Down Expand Up @@ -1917,6 +1938,15 @@ static void _thumb_resize_overlays(dt_thumbnail_t *thumb)
gtk_widget_set_margin_bottom(thumb->w_reject, margin_b_icons);

// stars
gtk_widget_set_size_request(thumb->w_unrate, icon_size, icon_size);
gtk_widget_set_valign(thumb->w_unrate, GTK_ALIGN_END);
gtk_widget_set_margin_bottom(thumb->w_unrate, margin_b_icons);
gtk_widget_set_margin_start(
thumb->w_unrate,
thumb->img_margin->left
+ (width - thumb->img_margin->left
- thumb->img_margin->right - (MAX_STARS + 1) * icon_size) * 0.5 );

for(int i = 0; i < MAX_STARS; i++)
{
gtk_widget_set_size_request(thumb->w_stars[i], icon_size, icon_size);
Expand All @@ -1926,8 +1956,8 @@ static void _thumb_resize_overlays(dt_thumbnail_t *thumb)
thumb->w_stars[i],
thumb->img_margin->left
+ (width - thumb->img_margin->left
- thumb->img_margin->right - MAX_STARS * icon_size) * 0.5
+ i * icon_size);
- thumb->img_margin->right - (MAX_STARS + 1) * icon_size) * 0.5
+ (i + 1) * icon_size);
}

// the color labels
Expand Down
1 change: 1 addition & 0 deletions src/dtgtk/thumbnail.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ typedef struct
GtkWidget *w_bottom_eb; // GtkEventBox -- background of the bottom infos area (contains w_bottom)
GtkWidget *w_bottom; // GtkLabel -- text of the bottom infos area, just with #thumb-bottom
GtkWidget *w_reject; // GtkDarktableThumbnailBtn -- Reject icon
GtkWidget *w_unrate; // GtkDarktableThumbnailBtn -- Unrate icon
GtkWidget *w_stars[MAX_STARS]; // GtkDarktableThumbnailBtn -- Stars icons
GtkWidget *w_color; // GtkDarktableThumbnailBtn -- Colorlabels "flower" icon

Expand Down
33 changes: 24 additions & 9 deletions src/libs/tools/ratings.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, dt_l
gtk_widget_get_allocation(widget, &allocation);

const float star_size = allocation.height;
const float star_spacing = (allocation.width - 5.0 * star_size) / 4.0;
const float star_spacing = (allocation.width - 6.0 * star_size) / 5.0;

cairo_surface_t *cst
= dt_cairo_image_surface_create(CAIRO_FORMAT_ARGB32, allocation.width, allocation.height);
Expand All @@ -152,6 +152,20 @@ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, dt_l
int x = 0;
cairo_set_line_width(cr, DT_PIXEL_APPLY_DPI(1));
gdk_cairo_set_source_rgba(cr, &fg_color);

// draw unrated star
cairo_set_source_rgba(cr, fg_color.red, fg_color.green, fg_color.blue, fg_color.alpha * 0.3);
dt_draw_star(cr, star_size / 2.0 + x, star_size / 2.0, star_size / 2.0, star_size / (2.0 * 2.5));
cairo_stroke(cr);
gdk_cairo_set_source_rgba(cr, &fg_color);
cairo_set_line_width(cr, 1.6 * cairo_get_line_width(cr));
cairo_move_to(cr, x + star_size * .1, star_size / 2.0);
cairo_line_to(cr, x + star_size * .9, star_size / 2.0);
cairo_stroke(cr);
cairo_set_line_width(cr, cairo_get_line_width(cr) / 1.6);
x += star_size + star_spacing;

// now the regular stars
d->current = 0;
for(int k = 0; k < 5; k++)
{
Expand All @@ -163,10 +177,12 @@ static gboolean _lib_ratings_draw_callback(GtkWidget *widget, cairo_t *crf, dt_l
cairo_set_source_rgba(cr, fg_color.red, fg_color.green, fg_color.blue, fg_color.alpha * 0.5);
cairo_stroke(cr);
gdk_cairo_set_source_rgba(cr, &fg_color);
if((k + 1) > d->current) d->current = darktable.control->element = (k + 1);
if((k + 1) > d->current)
d->current = darktable.control->element = (k + 1);
}
else
cairo_stroke(cr);

x += star_size + star_spacing;
}

Expand Down Expand Up @@ -194,14 +210,13 @@ static gboolean _lib_ratings_button_press_callback(GtkWidget *widget, GdkEventBu
dt_lib_module_t *self)
{
dt_lib_ratings_t *d = self->data;
if(d->current > 0)
{
GList *imgs = dt_act_on_get_images(FALSE, TRUE, FALSE);
dt_ratings_apply_on_list(imgs, d->current, TRUE);
dt_collection_update_query(darktable.collection, DT_COLLECTION_CHANGE_RELOAD, DT_COLLECTION_PROP_RATING_RANGE, imgs);

dt_control_queue_redraw_center();
}
GList *imgs = dt_act_on_get_images(FALSE, TRUE, FALSE);
dt_ratings_apply_on_list(imgs, d->current, TRUE);
dt_collection_update_query(darktable.collection, DT_COLLECTION_CHANGE_RELOAD, DT_COLLECTION_PROP_RATING_RANGE, imgs);

dt_control_queue_redraw_center();

return TRUE;
}

Expand Down
Loading